简体   繁体   中英

e4 custom savehandler dialog for a part

In my e4 application I've got multiple parts, all of which contain a MDirtyable. Now there is a specific one for which I'd like to show a custom dialog when prompting the user for saving. I was trying to set a custom handler in the MWindow context but that will change the behavior for all active parts, not just the one i'm interested in. Is there any way I can achieve this ? I'm thinking something about getting the context for a part only, and change the handler in it, but I don't know if that's possible. Thanks in advance.

Update: Thanks for your answers. So far I tried changing back to default handler after the custom part is being saved. Here's some code:

//custom part
@PostConstruct
public void createComposite(Composite parent, MWindow window) {

    this.windowContext = window.getContext(); //get current context
    this.old = windowContext.get(ISaveHandler.class); //save current handler
    windowContext.set(ISaveHandler.class, new CustomSaveHandler()); //set a custom handler
}

and when the saving is done change back to default handler

@Persist
public void save() {
    dirty.setDirty(false);
    windowContext.set(ISaveHandler.class, old); //switch to old handler
}

So this works fine when I open a custom part, make some changes to it and then close. But if there are multiple parts opened, they will all inherit the custom handler untill I close the custom part. Any other ideas ?

No, the save handler is looked up in the MWindow context so you can't set it for just a single part.

You would have to reproduce the standard behavior in the save handler for the other parts.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM