]> gerrit.simantics Code Review - simantics/district.git/blobdiff - org.simantics.district.selection.ui/src/org/simantics/district/selection/ui/handlers/CreateNewElementSelector.java
UI for diagram element selection
[simantics/district.git] / org.simantics.district.selection.ui / src / org / simantics / district / selection / ui / handlers / CreateNewElementSelector.java
diff --git a/org.simantics.district.selection.ui/src/org/simantics/district/selection/ui/handlers/CreateNewElementSelector.java b/org.simantics.district.selection.ui/src/org/simantics/district/selection/ui/handlers/CreateNewElementSelector.java
new file mode 100644 (file)
index 0000000..b9df8b8
--- /dev/null
@@ -0,0 +1,39 @@
+package org.simantics.district.selection.ui.handlers;
+
+import org.eclipse.e4.core.contexts.IEclipseContext;
+import org.eclipse.e4.core.di.annotations.CanExecute;
+import org.eclipse.e4.core.di.annotations.Execute;
+import org.eclipse.e4.ui.workbench.IWorkbench;
+import org.eclipse.e4.ui.workbench.modeling.ESelectionService;
+import org.eclipse.jface.window.Window;
+import org.eclipse.swt.widgets.Shell;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.district.selection.ui.parts.EditSelectorDialog;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class CreateNewElementSelector {
+
+       private static final Logger LOGGER = LoggerFactory.getLogger(CreateNewElementSelector.class);
+
+       @CanExecute
+       public boolean canExecute(ESelectionService selectionService) {
+               return true;
+       }
+       
+       @Execute
+       public void createNewElementSelector(IEclipseContext context, IWorkbench workbench) {
+               Shell shell = context.getActive(Shell.class);
+               EditSelectorDialog dialog = new EditSelectorDialog(shell, null);
+               LOGGER.debug("Opening dialog");
+               int result = dialog.open();
+               LOGGER.debug("Dialog closed with result code " + result);
+               if (result == Window.OK) {
+                       try {
+                               dialog.writeSelection();
+                       } catch (DatabaseException e) {
+                               LOGGER.error("Writing new element selection failed", e);
+                       }
+               }
+       }
+}