Search in sources :

Example 1 with WebTemplatesDialog

use of eu.esdihumboldt.hale.ui.templates.webtemplates.WebTemplatesDialog in project hale by halestudio.

the class OpenWebTemplate method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final Display display = HandlerUtil.getActiveShell(event).getDisplay();
    ProgressMonitorDialog taskDlg = new ProgressMonitorDialog(HandlerUtil.getActiveShell(event));
    try {
        taskDlg.run(true, false, new IRunnableWithProgress() {

            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                monitor.beginTask("Downloading template list", IProgressMonitor.UNKNOWN);
                // load templates
                final List<WebTemplate> templates;
                try {
                    templates = WebTemplateLoader.load();
                } catch (Exception e) {
                    log.userError("Failed to download template list", e);
                    return;
                } finally {
                    monitor.done();
                }
                if (templates != null) {
                    // launch dialog asynchronously in display thread
                    display.asyncExec(new Runnable() {

                        @Override
                        public void run() {
                            WebTemplatesDialog dlg = new WebTemplatesDialog(display.getActiveShell(), templates);
                            if (dlg.open() == WebTemplatesDialog.OK) {
                                WebTemplate template = dlg.getObject();
                                if (template != null) {
                                    ProjectService ps = PlatformUI.getWorkbench().getService(ProjectService.class);
                                    ps.load(template.getProject());
                                }
                            }
                        }
                    });
                }
            }
        });
    } catch (InvocationTargetException | InterruptedException e) {
        log.userError("Failed to download template list", e);
    }
    return null;
}
Also used : ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) WebTemplatesDialog(eu.esdihumboldt.hale.ui.templates.webtemplates.WebTemplatesDialog) ProjectService(eu.esdihumboldt.hale.ui.service.project.ProjectService) InvocationTargetException(java.lang.reflect.InvocationTargetException) ExecutionException(org.eclipse.core.commands.ExecutionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) WebTemplate(eu.esdihumboldt.hale.ui.templates.webtemplates.WebTemplate) List(java.util.List) Display(org.eclipse.swt.widgets.Display)

Aggregations

ProjectService (eu.esdihumboldt.hale.ui.service.project.ProjectService)1 WebTemplate (eu.esdihumboldt.hale.ui.templates.webtemplates.WebTemplate)1 WebTemplatesDialog (eu.esdihumboldt.hale.ui.templates.webtemplates.WebTemplatesDialog)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 List (java.util.List)1 ExecutionException (org.eclipse.core.commands.ExecutionException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)1 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)1 Display (org.eclipse.swt.widgets.Display)1