]> gerrit.simantics Code Review - simantics/district.git/commitdiff
Selection queries from explicit sets of elements. 79/2679/2
authorReino Ruusu <reino.ruusu@semantum.fi>
Fri, 22 Feb 2019 15:11:00 +0000 (17:11 +0200)
committerReino Ruusu <reino.ruusu@semantum.fi>
Mon, 25 Feb 2019 09:00:03 +0000 (09:00 +0000)
gitlab #28

Change-Id: Iac2f3a51b66b37b4fbe04dc1f351327231ea00c7

org.simantics.district.selection.ui/META-INF/MANIFEST.MF
org.simantics.district.selection.ui/src/org/simantics/district/selection/ui/ElementSelectorTableUI.java
org.simantics.district.selection.ui/src/org/simantics/district/selection/ui/handlers/CreateNewElementSelector.java
org.simantics.district.selection.ui/src/org/simantics/district/selection/ui/handlers/EditElementSelector.java
org.simantics.district.selection.ui/src/org/simantics/district/selection/ui/parts/EditSelectorDialog.java

index 91f612467b3def8af02497cdb53725dfdb7f1102..31f83e3870963682239f00c21654ebf41e53353f 100644 (file)
@@ -26,7 +26,9 @@ Require-Bundle: javax.inject,
  org.simantics.district.route.ontology,
  org.simantics.modeling.ontology,
  org.simantics.silk.ontology;bundle-version="1.1.0",
- org.simantics.district.network.ui
+ org.simantics.district.network.ui,
+ org.simantics.structural.ontology,
+ org.simantics.diagram.ontology
 Bundle-ManifestVersion: 2
 Bundle-RequiredExecutionEnvironment: JavaSE-1.8
 Bundle-Vendor: Semantum oy
index 8ed8d3e16c7d5ddbd5b5a1ef36ad7805f5c7ee7e..09f34609497f5e0b792597932848edf541355e5c 100644 (file)
@@ -38,6 +38,7 @@ import org.simantics.district.network.ui.DistrictNetworkUIUtil;
 import org.simantics.district.selection.ElementSelectionResource;
 import org.simantics.district.selection.ElementSelector;
 import org.simantics.district.selection.ElementSelector.DiagramGenerator;
+import org.simantics.district.selection.ElementSelector.ExplicitGenerator;
 import org.simantics.layer0.Layer0;
 import org.simantics.scl.runtime.Lists;
 import org.simantics.scl.runtime.function.FunctionImpl1;
@@ -245,7 +246,7 @@ public class ElementSelectorTableUI extends Composite {
                                        }
                                });
                                
-                               if (query.getGenerator() instanceof DiagramGenerator) {
+                               if (query.getGenerator() instanceof DiagramGenerator || query.getGenerator() instanceof ExplicitGenerator) {
                                        DistrictNetworkUIUtil.openDNDiagramWithSelection(event.getViewer().getControl().getDisplay(), result);
                                }
                                else {
index b9df8b8460c5da6fb910465bc04ad7ca893e4bb1..10ea9e81346c364da8eccfcab7dc0a2b51b853bd 100644 (file)
@@ -3,12 +3,15 @@ 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.services.IServiceConstants;
 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.Resource;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.district.selection.ui.parts.EditSelectorDialog;
+import org.simantics.utils.ui.AdaptionUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -23,8 +26,10 @@ public class CreateNewElementSelector {
        
        @Execute
        public void createNewElementSelector(IEclipseContext context, IWorkbench workbench) {
+               Object currentSelection = context.get(IServiceConstants.ACTIVE_SELECTION);
+               
                Shell shell = context.getActive(Shell.class);
-               EditSelectorDialog dialog = new EditSelectorDialog(shell, null);
+               EditSelectorDialog dialog = new EditSelectorDialog(shell, null, AdaptionUtils.adaptToCollection(currentSelection, Resource.class));
                LOGGER.debug("Opening dialog");
                int result = dialog.open();
                LOGGER.debug("Dialog closed with result code " + result);
index f914d1618ce10adf7ea36243777cd8453bcf304e..69fcbccdb234b62cdab00e38dd8a0dfecab20067 100644 (file)
@@ -1,20 +1,26 @@
 package org.simantics.district.selection.ui.handlers;
 
+import java.util.Collection;
+
 import javax.inject.Inject;
 
-import org.eclipse.e4.core.contexts.ContextInjectionFactory;
 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.model.application.ui.basic.MPart;
+import org.eclipse.e4.ui.services.IServiceConstants;
 import org.eclipse.e4.ui.workbench.IWorkbench;
 import org.eclipse.e4.ui.workbench.modeling.EPartService;
 import org.eclipse.e4.ui.workbench.modeling.ESelectionService;
 import org.eclipse.jface.window.Window;
 import org.eclipse.swt.widgets.Shell;
+import org.simantics.db.Resource;
 import org.simantics.db.exception.DatabaseException;
+import org.simantics.district.selection.ElementSelector;
+import org.simantics.district.selection.ElementSelector.ExplicitGenerator;
 import org.simantics.district.selection.ui.parts.EditSelectorDialog;
 import org.simantics.district.selection.ui.parts.ElementSelectionView;
+import org.simantics.utils.ui.AdaptionUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -40,6 +46,8 @@ public class EditElementSelector {
 
        @Execute
        public void editElementSelector(IEclipseContext context, IWorkbench workbench) {
+               Object currentSelection = context.get(IServiceConstants.ACTIVE_SELECTION);
+               
                MPart part = partService.getActivePart();
                if (part == null) return;
                
@@ -49,8 +57,17 @@ public class EditElementSelector {
                
                ElementSelectionView view = (ElementSelectionView)object;
                
+               Collection<Resource> selection;
+               ElementSelector selectedItem = view.getSelectedItem();
+               if (selectedItem.getGenerator() instanceof ExplicitGenerator) {
+                       selection = ((ExplicitGenerator)selectedItem.getGenerator()).elements;
+               }
+               else {
+                       selection = AdaptionUtils.adaptToCollection(currentSelection, Resource.class);
+               }
+               
                Shell shell = context.getActive(Shell.class);
-               EditSelectorDialog dialog = new EditSelectorDialog(shell, view.getSelectedItem());
+               EditSelectorDialog dialog = new EditSelectorDialog(shell, selectedItem, selection);
                
                LOGGER.debug("Opening dialog");
                int result = dialog.open();
index 42270da9253fee7d6726b2b8b16257fcffb8b437..b68c3fe11148504c43348c540b0b21ea51f2cb1b 100644 (file)
@@ -1,6 +1,7 @@
 package org.simantics.district.selection.ui.parts;
 
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -38,8 +39,10 @@ import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.exception.RuntimeDatabaseException;
 import org.simantics.db.layer0.QueryIndexUtils;
 import org.simantics.db.layer0.request.ActiveModels;
+import org.simantics.db.layer0.util.Layer0Utils;
 import org.simantics.db.request.Read;
 import org.simantics.db.request.WriteResult;
+import org.simantics.diagram.stubs.DiagramResource;
 import org.simantics.district.region.ontology.DiagramRegionsResource;
 import org.simantics.district.route.ontology.RouteResource;
 import org.simantics.district.selection.ElementSelectionResource;
@@ -69,6 +72,9 @@ public class EditSelectorDialog extends Dialog {
        private static Logger LOGGER = LoggerFactory.getLogger(EditSelectorDialog.class);
        
        private ElementSelector elementSelector;
+       
+       // Currently selected elements
+       Collection<Resource> currentSelection;
 
        // Data for comboboxes
        Map<Resource, String> diagrams;
@@ -106,7 +112,7 @@ public class EditSelectorDialog extends Dialog {
        private Composite content;
 
        @Inject
-       public EditSelectorDialog(Shell shell, ElementSelector elementSelector) {
+       public EditSelectorDialog(Shell shell, ElementSelector elementSelector, Collection<Resource> currentSelection) {
                super(shell);
                
                this.elementSelector = elementSelector;
@@ -124,6 +130,8 @@ public class EditSelectorDialog extends Dialog {
                        }
                }
                
+               this.currentSelection = currentSelection;
+               
                final Map<Resource, String> regions = new HashMap<>();
                final Map<Resource, String> routes = new HashMap<>();
                
@@ -229,8 +237,11 @@ public class EditSelectorDialog extends Dialog {
                        public void perform(WriteGraph graph) throws DatabaseException {
                                Layer0 L0 = Layer0.getInstance(graph);
                                ElementSelectionResource ES = ElementSelectionResource.getInstance(graph);
+                               ModelingResources MOD = ModelingResources.getInstance(graph);
+                               DiagramResource DIA = DiagramResource.getInstance(graph);
                                
                                graph.markUndoPoint();
+                               Layer0Utils.addCommentMetadata(graph, "Created new element selection");
                                
                                Resource lib = ElementSelectionUtils.ensureSelectionLibrary(graph);
                                
@@ -258,12 +269,26 @@ public class EditSelectorDialog extends Dialog {
                                        break;
                                case 1:
                                        generatorType = ES.Generator_Diagram;
-                                       Resource composite = graph.getPossibleObject(diagram, ModelingResources.getInstance(graph).DiagramToComposite);
+                                       Resource composite = graph.getPossibleObject(diagram, MOD.DiagramToComposite);
                                        graph.claim(generator, ES.Generator_HasDiagram, composite != null ? composite : diagram);
                                        break;
                                case 2:
                                        generatorType = ES.Generator_Explicit;
-                                       // TODO: Claim relations to current selection elements
+                                       for (Resource r : currentSelection) {
+                                               // No connections
+                                               if (graph.isInstanceOf(r, DIA.Connection))
+                                                       continue;
+                                               if (!graph.isInstanceOf(r, DIA.Element)) {
+                                                       if (!graph.hasStatement(r, MOD.ComponentToElement))
+                                                               continue;
+                                                       
+                                                       r = graph.getPossibleObject(r, MOD.ComponentToElement);
+                                                       if (r == null)
+                                                               continue;
+                                               }
+                                                       
+                                               graph.claim(generator, ES.Generator_HasSelectedElement, r);
+                                       }
                                        break;
                                default: throw new IllegalStateException("Invalid source index " + generatorIndex);
                                }