Search in sources :

Example 1 with WorkbenchHook

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();
        }
    }
}
Also used : WorkbenchHookFactory(eu.esdihumboldt.hale.ui.application.workbench.extension.WorkbenchHookFactory) WorkbenchHook(eu.esdihumboldt.hale.ui.application.workbench.WorkbenchHook) WorkbenchHookExtension(eu.esdihumboldt.hale.ui.application.workbench.extension.WorkbenchHookExtension)

Example 2 with WorkbenchHook

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;
    }
}
Also used : Shell(org.eclipse.swt.widgets.Shell) WorkbenchHook(eu.esdihumboldt.hale.ui.application.workbench.WorkbenchHook) ProjectService(eu.esdihumboldt.hale.ui.service.project.ProjectService) MessageBox(org.eclipse.swt.widgets.MessageBox)

Aggregations

WorkbenchHook (eu.esdihumboldt.hale.ui.application.workbench.WorkbenchHook)2 WorkbenchHookExtension (eu.esdihumboldt.hale.ui.application.workbench.extension.WorkbenchHookExtension)1 WorkbenchHookFactory (eu.esdihumboldt.hale.ui.application.workbench.extension.WorkbenchHookFactory)1 ProjectService (eu.esdihumboldt.hale.ui.service.project.ProjectService)1 MessageBox (org.eclipse.swt.widgets.MessageBox)1 Shell (org.eclipse.swt.widgets.Shell)1