From 5750b5736279abe0d3e310b2da4fc1be3ffa0004 Mon Sep 17 00:00:00 2001 From: jsimomaa Date: Thu, 2 Feb 2017 12:43:22 +0200 Subject: [PATCH] Adding more functionality to dialog for creating DN diagram refs #6958 Change-Id: I5a23c319e80965da518b992ec6e321174bf72e2c --- .../network/ui/function/Functions.java | 93 ++++++++++++++++++- 1 file changed, 92 insertions(+), 1 deletion(-) diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/function/Functions.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/function/Functions.java index 016a1420..7ae65134 100644 --- a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/function/Functions.java +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/function/Functions.java @@ -9,6 +9,8 @@ import java.util.stream.Collectors; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.layout.GridDataFactory; import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Combo; @@ -34,10 +36,10 @@ import org.simantics.db.common.request.ReadRequest; import org.simantics.db.common.request.WriteRequest; import org.simantics.db.exception.DatabaseException; import org.simantics.db.exception.RuntimeDatabaseException; +import org.simantics.db.exception.ServiceException; import org.simantics.db.layer0.variable.Variable; import org.simantics.db.layer0.variable.Variables.Role; import org.simantics.db.procedure.Procedure; -import org.simantics.diagram.stubs.DiagramResource; import org.simantics.district.network.ontology.DistrictNetworkResource; import org.simantics.layer0.Layer0; import org.simantics.modeling.ModelingResources; @@ -193,9 +195,13 @@ public class Functions { private Resource configuration; private Map vertexMappings = new HashMap<>(); private Map edgeMappings = new HashMap<>(); + private Map composites = new HashMap<>(); + private Map> components = new HashMap<>(); private Resource defaultVertexMapping; private Resource defaultEdgeMapping; + private Combo compositeMappingCombo; + private Combo componentMappingCombo; protected DefaultMappingsDialog(Shell parentShell, Resource configuration) { super(parentShell); @@ -216,6 +222,7 @@ public class Functions { composite = (Composite) super.createDialogArea(parent); createMappingsGroup(composite); + createExistingCompositeGroup(composite); createCRSSettingsGroup(composite); // compute default values @@ -227,12 +234,21 @@ public class Functions { vertexMappings = getVertexMappings(graph, configuration); edgeMappings = getEdgeMappings(graph, configuration); + composites = getComposites(graph, configuration); + if (composites.size() > 0) { + components = getComponents(graph, composites.get(0)); + } + + composite.getDisplay().asyncExec(() -> { vertexMappingCombo.setItems(vertexMappings.keySet().toArray(new String[vertexMappings.size()])); edgeMappingCombo.setItems(edgeMappings.keySet().toArray(new String[edgeMappings.size()])); + compositeMappingCombo.setItems(composites.keySet().toArray(new String[composites.size()])); vertexMappingCombo.select(0); edgeMappingCombo.select(0); + if (!composites.isEmpty()) + compositeMappingCombo.select(0); }); } @@ -240,6 +256,35 @@ public class Functions { return composite; } + protected Map> getComponents(ReadGraph graph, Resource resource) { + // TODO Auto-generated method stub + return null; + } + + protected Map getComposites(ReadGraph graph, Resource element) throws DatabaseException { + Resource indexRoot = graph.sync(new IndexRoot(element)); + List composites = ModelingUtils.searchByType(graph, indexRoot, StructuralResource2.getInstance(graph).Composite); + List nonDistrictComposites = composites.stream().filter(comp -> { + try { + return !graph.isInstanceOf(comp, DistrictNetworkResource.getInstance(graph).Composite); + } catch (ServiceException e1) { + LOGGER.error("Could not check if composite " + comp + " is instanceOf DistrictNetwork.composite"); + return false; + } + }).collect(Collectors.toList()); + Map result = new HashMap<>(nonDistrictComposites.size()); + Layer0 L0 = Layer0.getInstance(graph); + nonDistrictComposites.forEach(mapping -> { + try { + String name = graph.getRelatedValue2(mapping, L0.HasName); + result.put(name, mapping); + } catch (DatabaseException e) { + e.printStackTrace(); + } + }); + return result; + } + private void createMappingsGroup(Composite parent) { Group group= new Group(parent, SWT.NONE); group.setFont(parent.getFont()); @@ -264,6 +309,52 @@ public class Functions { GridDataFactory.fillDefaults().grab(true, false).applyTo(edgeMappingCombo); } + private void createExistingCompositeGroup(Composite parent) { + Group group= new Group(parent, SWT.NONE); + group.setFont(parent.getFont()); + group.setText("Mapped composite"); + GridDataFactory.fillDefaults().grab(true, false).applyTo(group); + group.setLayout(new GridLayout(1, false)); + + Composite cmposite = new Composite(group, SWT.NONE); + cmposite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); + cmposite.setLayout(new GridLayout(2, false)); + + Label compositeMappingLabel = new Label(cmposite, SWT.NONE); + compositeMappingLabel.setText("Select composite"); + + compositeMappingCombo = new Combo(cmposite, SWT.READ_ONLY | SWT.BORDER); + GridDataFactory.fillDefaults().grab(true, false).applyTo(compositeMappingCombo); + compositeMappingCombo.addSelectionListener(new SelectionAdapter() { + + @Override + public void widgetSelected(SelectionEvent e) { + super.widgetSelected(e); + recalculateMappapleComponents(); + } + }); + + Label compojnentMappingLabel = new Label(cmposite, SWT.NONE); + compojnentMappingLabel.setText("Select component"); + + componentMappingCombo = new Combo(cmposite, SWT.READ_ONLY | SWT.BORDER); + GridDataFactory.fillDefaults().grab(true, false).applyTo(componentMappingCombo); + } + + protected void recalculateMappapleComponents() { + Simantics.getSession().asyncRequest(new ReadRequest() { + + @Override + public void run(ReadGraph graph) throws DatabaseException { + + + composite.getDisplay().asyncExec(() -> { + + }); + } + }); + } + private void createCRSSettingsGroup(Composite parent) { Group group= new Group(parent, SWT.NONE); group.setFont(parent.getFont()); -- 2.45.1