@PostConstruct
public void createPartControl(Composite parent, MPart part, MWindow window) {
* * *
ISaveHandler saveHandler = new ISaveHandler() {
@Override
public Save[] promptToSave(Collection<MPart> arg0) {
return null; // I don't have any situations where this could happen
}
@Override
public Save promptToSave(MPart part) {
if (part.isDirty()) {
boolean confirm = MessageDialog.openConfirm(shell, "Lose changes?",
"Closing this editor will lose any unsaved changes.\n" +
"Are you sure you want to do that?");
return (confirm ? Save.NO : Save.CANCEL);
} else {
return Save.NO; // Mine don't actually save
}
}
};
window.getContext().set(ISaveHandler.class, saveHandler);
IWindowCloseHandler handler = new IWindowCloseHandler() {
@Override
public boolean close(MWindow window) {
if (!partService.getDirtyParts().isEmpty()) {
return MessageDialog.openConfirm(shell, "Lose changes?",
"Closing this window will lose any unsaved changes in editors.\n" +
"Are you sure you want to do that?");
} else {
return true;
}
}
};
window.getContext().set(IWindowCloseHandler.class, handler);