use of eu.esdihumboldt.hale.ui.application.workbench.WorkbenchHook in project hale by halestudio.
the class ApplicationWorkbenchAdvisor method preStartup.
@Override
public void preStartup() {
super.preStartup();
try {
ProxySettings.install();
} catch (Exception ex) {
// $NON-NLS-1$
_log.warn("Setting the Proxy configuration failed: " + ex.getMessage());
}
/*
* Initialize RecentResources so they are not loaded when the first
* import dialog is opened.
*
* TODO instead use a workbench hook?!
*/
PlatformUI.getWorkbench().getService(RecentResources.class);
// initialize workbench hooks
Builder<WorkbenchHook> builder = ImmutableList.builder();
WorkbenchHookExtension ext = new WorkbenchHookExtension();
for (WorkbenchHookFactory fact : ext.getFactories()) {
try {
builder.add(fact.createExtensionObject());
} catch (Exception e) {
// ignore
e.printStackTrace();
}
}
hooks = builder.build();
// call workbench hooks
for (WorkbenchHook hook : hooks) {
try {
hook.preStartup(getWorkbenchConfigurer().getWorkbench());
} catch (Exception e) {
e.printStackTrace();
}
}
}
use of eu.esdihumboldt.hale.ui.application.workbench.WorkbenchHook in project hale by halestudio.
the class ApplicationWorkbenchAdvisor method preShutdown.
/**
* @see WorkbenchAdvisor#preShutdown()
*/
@Override
public boolean preShutdown() {
// call workbench hooks
boolean shutdownCanceled = false;
for (WorkbenchHook hook : hooks) {
try {
if (!hook.preShutdown(getWorkbenchConfigurer().getWorkbench())) {
shutdownCanceled = true;
}
} catch (Exception e) {
e.printStackTrace();
}
}
if (shutdownCanceled) {
return false;
}
// ask for save if there are changes
// TODO use a workbench hook for this
ProjectService ps = PlatformUI.getWorkbench().getService(ProjectService.class);
if (ps.isChanged()) {
Shell shell = PlatformUI.getWorkbench().getWorkbenchWindows()[0].getShell();
MessageBox mb = new MessageBox(shell, SWT.YES | SWT.NO | SWT.CANCEL | SWT.ICON_QUESTION);
// $NON-NLS-1$
mb.setMessage(Messages.ApplicationWorkbenchAdvisor_1);
// $NON-NLS-1$
mb.setText(Messages.ApplicationWorkbenchAdvisor_2);
int result = mb.open();
if (result == SWT.CANCEL) {
return false;
} else if (result == SWT.YES) {
// try saving project
ps.save();
if (ps.isChanged()) {
return false;
}
return true;
} else {
return true;
}
} else {
return true;
}
}
Aggregations