Skip to main content


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: 699
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
Eclipse UserFriend
That's pretty appropriate.
Previous Topic:Eclipse 4 editors
Next Topic:How to implement a Job that can be canceled
Goto Forum:
  


Current Time: Thu Apr 25 22:45:08 GMT 2024

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

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

Back to the top