1 package org.simantics.district.selection.ui.handlers;
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.services.IServiceConstants;
7 import org.eclipse.e4.ui.workbench.IWorkbench;
8 import org.eclipse.e4.ui.workbench.modeling.ESelectionService;
9 import org.eclipse.jface.window.Window;
10 import org.eclipse.swt.widgets.Shell;
11 import org.simantics.db.Resource;
12 import org.simantics.db.exception.DatabaseException;
13 import org.simantics.district.selection.ui.parts.EditSelectorDialog;
14 import org.simantics.utils.ui.AdaptionUtils;
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
18 public class CreateNewElementSelector {
20 private static final Logger LOGGER = LoggerFactory.getLogger(CreateNewElementSelector.class);
23 public boolean canExecute(ESelectionService selectionService) {
28 public void createNewElementSelector(IEclipseContext context, IWorkbench workbench) {
29 Object currentSelection = context.get(IServiceConstants.ACTIVE_SELECTION);
31 Shell shell = context.getActive(Shell.class);
32 EditSelectorDialog dialog = new EditSelectorDialog(shell, null, AdaptionUtils.adaptToCollection(currentSelection, Resource.class));
33 LOGGER.debug("Opening dialog");
34 int result = dialog.open();
35 LOGGER.debug("Dialog closed with result code " + result);
36 if (result == Window.OK) {
38 dialog.writeSelection();
39 } catch (DatabaseException e) {
40 LOGGER.error("Writing new element selection failed", e);