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
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;
}
});
- if (query.getGenerator() instanceof DiagramGenerator) {
+ if (query.getGenerator() instanceof DiagramGenerator || query.getGenerator() instanceof ExplicitGenerator) {
DistrictNetworkUIUtil.openDNDiagramWithSelection(event.getViewer().getControl().getDisplay(), result);
}
else {
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;
@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);
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;
@Execute
public void editElementSelector(IEclipseContext context, IWorkbench workbench) {
+ Object currentSelection = context.get(IServiceConstants.ACTIVE_SELECTION);
+
MPart part = partService.getActivePart();
if (part == null) return;
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();
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;
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;
private static Logger LOGGER = LoggerFactory.getLogger(EditSelectorDialog.class);
private ElementSelector elementSelector;
+
+ // Currently selected elements
+ Collection<Resource> currentSelection;
// Data for comboboxes
Map<Resource, String> diagrams;
private Composite content;
@Inject
- public EditSelectorDialog(Shell shell, ElementSelector elementSelector) {
+ public EditSelectorDialog(Shell shell, ElementSelector elementSelector, Collection<Resource> currentSelection) {
super(shell);
this.elementSelector = elementSelector;
}
}
+ this.currentSelection = currentSelection;
+
final Map<Resource, String> regions = new HashMap<>();
final Map<Resource, String> routes = new HashMap<>();
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);
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);
}