Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » How can I implement 'not save and not close the part' behavior when dirty part will be closed?(I want to implement the similar behavior as ISaveablePart2#promptToSaveOnClose() is returning an CANCEL.)
How can I implement 'not save and not close the part' behavior when dirty part will be closed? [message #1172938] Wed, 06 November 2013 07:06 Go to next message
Ken DevL. is currently offline Ken DevL.Friend
Messages: 2
Registered: November 2013
Location: Tokyo, Japan.
Junior Member
Hello,

I have a Part which have MDirtyable field and @Persist method.

I want to implement the similar behavior as ISaveablePart2#promptToSaveOnClose() is returning an CANCEL.

That is, When a Part will be closed,
1) First, prompt to user to select save, do not save or cancel.
2) If cancel is selected, quit @Persist method and not close this Part.

Actually, validate unsaved data before to prompt to user. And if validate is failed, I want to quit @Persist method and do not want to close the Part.

For that reason, I cannot use the default ISaveHandler#promptToSave(MPart) which is set to WindowContext(IEclipseContext).


Does anyone have an idea to solve this?

Thanks,
Ken
Re: How can I implement 'not save and not close the part' behavior when dirty part will be closed? [message #1194975 is a reply to message #1172938] Mon, 18 November 2013 19:50 Go to previous messageGo to next message
Jonas Helming is currently offline Jonas HelmingFriend
Messages: 483
Registered: July 2009
Senior Member
Have you tried to replace the default SaveHandler?
Am 06.11.2013 15:14, schrieb Ken DevL.:
> Hello,
>
> I have a Part which have MDirtyable field and @Persist method.
>
> I want to implement the similar behavior as
> ISaveablePart2#promptToSaveOnClose() is returning an CANCEL.
>
> That is, When a Part will be closed,
> 1) First, prompt to user to select save, do not save or cancel.
> 2) If cancel is selected, quit @Persist method and not close this Part.
>
> Actually, validate unsaved data before to prompt to user. And if
> validate is failed, I want to quit @Persist method and do not want to
> close the Part.
>
> For that reason, I cannot use the default
> ISaveHandler#promptToSave(MPart) which is set to
> WindowContext(IEclipseContext).
>
>
> Does anyone have an idea to solve this?
>
> Thanks,
> Ken
Re: How can I implement 'not save and not close the part' behavior when dirty part will be closed? [message #1236536 is a reply to message #1194975] Mon, 27 January 2014 12:59 Go to previous messageGo to next message
Ken DevL. is currently offline Ken DevL.Friend
Messages: 2
Registered: November 2013
Location: Tokyo, Japan.
Junior Member
Hi, Jonas.

Thank you for your comment.
I am very sorry my reply is late. I am come back to this work finally.

I do not think the following implementation is correct, but it works for me.


1. Register my EventHandler to IEventBroker with APP_STARTUP_COMPLETE event on annotated with @ProcessAdditions method.

eventBroker.subscribe(UIEvents.UILifeCycle.APP_STARTUP_COMPLETE,
    new CustomHandlersRegistrationHandler());


2. Set CustomHandlers to IEclipseContext which have MWindow on EventHandler#handleEvent() method.

MWindow window = application.getSelectedElement();
IEclipseContext windowContext = window.getContext();

windowContext.set(ISaveHandler.class, new CustomSaveHandler());
windowContext.set(IWindowCloseHandler.class, new CustomWindowCloseHandler());


3. Implement close() method on CustomWindowCloseHandler.

@Override
public boolean close(MWindow window) {
  for(MDirtyable dirtyable: partService.getDirtyParts()) {
    if(dirtyable.isDirty() == false) {
      continue;
    }

    MPart part = (MPart) dirtyable;
    if(partService.savePart(part, true) == false) {
      return false;
    }
  }
  return true;
}



I want you to tell me if there is a more appropriate implementation.

Thanks,
ken
Re: How can I implement 'not save and not close the part' behavior when dirty part will be closed? [message #1237255 is a reply to message #1236536] Wed, 29 January 2014 08:49 Go to previous message
Sopot Cela is currently offline Sopot CelaFriend
Messages: 597
Registered: December 2010
Senior Member

That's pretty appropriate.
Previous Topic:Eclipse 4 editors
Next Topic:Editor Questions - multiple editors / Form Editor in e4
Goto Forum:
  


Current Time: Thu Nov 27 19:57:55 GMT 2014

Powered by FUDForum. Page generated in 0.01603 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software