]> gerrit.simantics Code Review - simantics/district.git/blob
b9df8b8460c5da6fb910465bc04ad7ca893e4bb1
[simantics/district.git] /
1 package org.simantics.district.selection.ui.handlers;
2
3 import org.eclipse.e4.core.contexts.IEclipseContext;
4 import org.eclipse.e4.core.di.annotations.CanExecute;
5 import org.eclipse.e4.core.di.annotations.Execute;
6 import org.eclipse.e4.ui.workbench.IWorkbench;
7 import org.eclipse.e4.ui.workbench.modeling.ESelectionService;
8 import org.eclipse.jface.window.Window;
9 import org.eclipse.swt.widgets.Shell;
10 import org.simantics.db.exception.DatabaseException;
11 import org.simantics.district.selection.ui.parts.EditSelectorDialog;
12 import org.slf4j.Logger;
13 import org.slf4j.LoggerFactory;
14
15 public class CreateNewElementSelector {
16
17         private static final Logger LOGGER = LoggerFactory.getLogger(CreateNewElementSelector.class);
18
19         @CanExecute
20         public boolean canExecute(ESelectionService selectionService) {
21                 return true;
22         }
23         
24         @Execute
25         public void createNewElementSelector(IEclipseContext context, IWorkbench workbench) {
26                 Shell shell = context.getActive(Shell.class);
27                 EditSelectorDialog dialog = new EditSelectorDialog(shell, null);
28                 LOGGER.debug("Opening dialog");
29                 int result = dialog.open();
30                 LOGGER.debug("Dialog closed with result code " + result);
31                 if (result == Window.OK) {
32                         try {
33                                 dialog.writeSelection();
34                         } catch (DatabaseException e) {
35                                 LOGGER.error("Writing new element selection failed", e);
36                         }
37                 }
38         }
39 }