From 11ad7d688b004970a64c2cb680fdc220c55403db Mon Sep 17 00:00:00 2001 From: Tuukka Lehtonen Date: Thu, 24 Oct 2019 00:53:27 +0300 Subject: [PATCH] Allow product-specific customization of new network diagram creation gitlab #64 Change-Id: I71e44be7c3f38740101b35e53b0e6e594aa2f1b8 --- .../graph/DistrictNetworkViewpoint.pgraph | 8 +- .../ontology/DistrictNetworkResource.java | 3 - .../ui/function/DefaultMappingsDialog.java | 263 ++++++++++++++++ .../network/ui/function/Functions.java | 286 +----------------- 4 files changed, 276 insertions(+), 284 deletions(-) create mode 100644 org.simantics.district.network.ui/src/org/simantics/district/network/ui/function/DefaultMappingsDialog.java diff --git a/org.simantics.district.network.ontology/graph/DistrictNetworkViewpoint.pgraph b/org.simantics.district.network.ontology/graph/DistrictNetworkViewpoint.pgraph index 373a5992..40c66c1e 100644 --- a/org.simantics.district.network.ontology/graph/DistrictNetworkViewpoint.pgraph +++ b/org.simantics.district.network.ontology/graph/DistrictNetworkViewpoint.pgraph @@ -25,7 +25,7 @@ DNAC.newDiagramContribution : L0.Template DNAC = DN.ActionContext : VP.BrowseContext VP.BrowseContext.IsIncludedIn MOD.ModelingActionContext - @DNAC.newDiagramContribution "Network Diagram" IMAGES.MapImage ACTIONS.NewDNDiagram +// @DNAC.newDiagramContribution "Network Diagram" IMAGES.MapImage ACTIONS.NewDNDiagram DNBC = DN.BrowseContext : VP.BrowseContext VP.BrowseContext.IsIncludedIn MOD.ModelingBrowseContext @@ -36,9 +36,9 @@ DNBC = DN.BrowseContext : VP.BrowseContext ACTIONS = DN.Actions : L0.Library -ACTIONS.NewDNDiagram : MOD.NewComposite - MOD.NewComposite.HasCompositeType DN.Composite - MOD.NewComposite.HasDefaultName "NewNetworkDiagram" +//ACTIONS.NewDNDiagram : MOD.NewComposite +// MOD.NewComposite.HasCompositeType DN.Composite +// MOD.NewComposite.HasDefaultName "NewNetworkDiagram" IMAGES = DN.Images : L0.Library diff --git a/org.simantics.district.network.ontology/src/org/simantics/district/network/ontology/DistrictNetworkResource.java b/org.simantics.district.network.ontology/src/org/simantics/district/network/ontology/DistrictNetworkResource.java index 89087af1..8644aaa0 100644 --- a/org.simantics.district.network.ontology/src/org/simantics/district/network/ontology/DistrictNetworkResource.java +++ b/org.simantics.district.network.ontology/src/org/simantics/district/network/ontology/DistrictNetworkResource.java @@ -13,7 +13,6 @@ public class DistrictNetworkResource { public final Resource ActionContext; public final Resource ActionContext_newDiagramContribution; public final Resource Actions; - public final Resource Actions_NewDNDiagram; public final Resource AddLayerToDNDiagramTemplate; public final Resource ArrowLengthPropertyParameterType; public final Resource ArrowLengthStyle; @@ -464,7 +463,6 @@ public class DistrictNetworkResource { public static final String ActionContext = "http://www.simantics.org/DistrictNetwork-1.0/ActionContext"; public static final String ActionContext_newDiagramContribution = "http://www.simantics.org/DistrictNetwork-1.0/ActionContext/newDiagramContribution"; public static final String Actions = "http://www.simantics.org/DistrictNetwork-1.0/Actions"; - public static final String Actions_NewDNDiagram = "http://www.simantics.org/DistrictNetwork-1.0/Actions/NewDNDiagram"; public static final String AddLayerToDNDiagramTemplate = "http://www.simantics.org/DistrictNetwork-1.0/AddLayerToDNDiagramTemplate"; public static final String ArrowLengthPropertyParameterType = "http://www.simantics.org/DistrictNetwork-1.0/ArrowLengthPropertyParameterType"; public static final String ArrowLengthStyle = "http://www.simantics.org/DistrictNetwork-1.0/ArrowLengthStyle"; @@ -925,7 +923,6 @@ public class DistrictNetworkResource { ActionContext = getResourceOrNull(graph, URIs.ActionContext); ActionContext_newDiagramContribution = getResourceOrNull(graph, URIs.ActionContext_newDiagramContribution); Actions = getResourceOrNull(graph, URIs.Actions); - Actions_NewDNDiagram = getResourceOrNull(graph, URIs.Actions_NewDNDiagram); AddLayerToDNDiagramTemplate = getResourceOrNull(graph, URIs.AddLayerToDNDiagramTemplate); ArrowLengthPropertyParameterType = getResourceOrNull(graph, URIs.ArrowLengthPropertyParameterType); ArrowLengthStyle = getResourceOrNull(graph, URIs.ArrowLengthStyle); diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/function/DefaultMappingsDialog.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/function/DefaultMappingsDialog.java new file mode 100644 index 00000000..efe7b85e --- /dev/null +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/function/DefaultMappingsDialog.java @@ -0,0 +1,263 @@ +package org.simantics.district.network.ui.function; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.dialogs.SelectionStatusDialog; +import org.simantics.Simantics; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.IndexRoot; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.ServiceException; +import org.simantics.district.network.ontology.DistrictNetworkResource; +import org.simantics.layer0.Layer0; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class DefaultMappingsDialog extends SelectionStatusDialog { + + private static final Logger LOGGER = LoggerFactory.getLogger(DefaultMappingsDialog.class); + + private Combo vertexMappingCombo; + private Combo rightClickMappingCombo; + private Combo leftClickMappingCombo; + private Combo edgeMappingCombo; + //private Combo crsCombo; + private Composite composite; + + private Resource configuration; + private Map vertexMappings = new HashMap<>(); + private Map edgeMappings = new HashMap<>(); + private Map composites = new HashMap<>(); + private Map crss = new HashMap<>(); + + private Resource defaultVertexMapping; + private Resource defaultEdgeMapping; + private Resource rightClickVertexMapping; + private Resource leftClickVertexMapping; + //private Resource defaultCRS; + + //private Combo compositeMappingCombo; + //private Combo componentMappingCombo; + + protected DefaultMappingsDialog(Shell parentShell, Resource configuration) { + super(parentShell); + this.configuration = configuration; + setTitle("Select mappings for new DN diagram"); + } + + public Resource getDefaultVertexMapping() { + return defaultVertexMapping; + } + + public Resource getRightClickVertexMapping() { + return rightClickVertexMapping; + } + + public Resource getLeftClickVertexMapping() { + return leftClickVertexMapping; + } + + public Resource getDefaultEdgeMapping() { + return defaultEdgeMapping; + } + + @Override + protected Control createDialogArea(Composite parent) { + composite = (Composite) super.createDialogArea(parent); + + createMappingsGroup(composite); + //createExistingCompositeGroup(composite); + //createCRSSettingsGroup(composite); + + // compute default values + Simantics.getSession().asyncRequest(new ReadRequest() { + + @Override + public void run(ReadGraph graph) throws DatabaseException { + Resource indexRoot = graph.sync(new IndexRoot(configuration)); + vertexMappings = Functions.getVertexMappings(graph, indexRoot); + edgeMappings = Functions.getEdgeMappings(graph, indexRoot); + + composites = getComposites(graph, configuration); + + crss = Functions.getCRSs(graph, configuration); + + composite.getDisplay().asyncExec(() -> { + + vertexMappingCombo.setItems(vertexMappings.keySet().toArray(new String[vertexMappings.size()])); + rightClickMappingCombo.setItems(vertexMappings.keySet().toArray(new String[vertexMappings.size()])); + leftClickMappingCombo.setItems(vertexMappings.keySet().toArray(new String[vertexMappings.size()])); + edgeMappingCombo.setItems(edgeMappings.keySet().toArray(new String[edgeMappings.size()])); + + //crsCombo.setItems(crss.keySet().toArray(new String[crss.size()])); + + //compositeMappingCombo.setItems(composites.keySet().toArray(new String[composites.size()])); + vertexMappingCombo.select(0); + rightClickMappingCombo.select(0); + leftClickMappingCombo.select(0); + edgeMappingCombo.select(0); + + //crsCombo.select(0); + + //if (!composites.isEmpty()) + // compositeMappingCombo.select(0); + }); + + } + }); + return composite; + } + + protected Map getComposites(ReadGraph graph, Resource element) throws DatabaseException { + List nonDistrictComposites = composites.values().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) { + LOGGER.error("Could not read name of " + mapping, e); + } + }); + return result; + } + + private void createMappingsGroup(Composite parent) { + Group group= new Group(parent, SWT.NONE); + group.setFont(parent.getFont()); + group.setText("Default mappings"); + 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 vertexMappingLabel = new Label(cmposite, SWT.NONE); + vertexMappingLabel.setText("Default vertex mapping"); + + vertexMappingCombo = new Combo(cmposite, SWT.READ_ONLY | SWT.BORDER); + GridDataFactory.fillDefaults().grab(true, false).applyTo(vertexMappingCombo); + + Label rightClickMappingLabel = new Label(cmposite, SWT.NONE); + rightClickMappingLabel.setText("Default right click mapping"); + + rightClickMappingCombo = new Combo(cmposite, SWT.READ_ONLY | SWT.BORDER); + GridDataFactory.fillDefaults().grab(true, false).applyTo(vertexMappingCombo); + + Label leftClickMappingLabel = new Label(cmposite, SWT.NONE); + leftClickMappingLabel.setText("Default left click mapping"); + + leftClickMappingCombo = new Combo(cmposite, SWT.READ_ONLY | SWT.BORDER); + GridDataFactory.fillDefaults().grab(true, false).applyTo(vertexMappingCombo); + + Label edgeMappingLabel = new Label(cmposite, SWT.NONE); + edgeMappingLabel.setText("Default edge mapping"); + + edgeMappingCombo = new Combo(cmposite, SWT.READ_ONLY | SWT.BORDER); + 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()); + group.setText("CRS settings"); + 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 vertexMappingLabel = new Label(cmposite, SWT.NONE); + vertexMappingLabel.setText("Default CRS"); + + //crsCombo = new Combo(cmposite, SWT.READ_ONLY | SWT.BORDER); + //GridData textData = new GridData(SWT.FILL, SWT.CENTER, true, false); + //crsCombo.setLayoutData(textData); + } + + + @Override + protected void computeResult() { + defaultVertexMapping = vertexMappings.get(vertexMappingCombo.getItem(vertexMappingCombo.getSelectionIndex())); + defaultEdgeMapping = edgeMappings.get(edgeMappingCombo.getItem(edgeMappingCombo.getSelectionIndex())); + rightClickVertexMapping = vertexMappings.get(rightClickMappingCombo.getItem(rightClickMappingCombo.getSelectionIndex())); + leftClickVertexMapping = vertexMappings.get(leftClickMappingCombo.getItem(leftClickMappingCombo.getSelectionIndex())); + //defaultCRS = crss.get(crsCombo.getItem(crsCombo.getSelectionIndex())); + } + + public Resource getCRS() { + return crss.get("EPSG_4326"); // this is only supported + } + +} \ No newline at end of file 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 14c75030..2513c39d 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 @@ -12,20 +12,7 @@ import java.util.Set; 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; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Group; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.dialogs.SelectionStatusDialog; import org.simantics.NameLabelUtil; import org.simantics.Simantics; import org.simantics.browsing.ui.common.modifiers.EnumeratedValue; @@ -35,28 +22,21 @@ import org.simantics.databoard.Bindings; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.Session; -import org.simantics.db.WriteGraph; import org.simantics.db.common.request.IndexRoot; import org.simantics.db.common.request.ObjectsWithType; -import org.simantics.db.common.request.ReadRequest; -import org.simantics.db.common.request.WriteRequest; -import org.simantics.db.common.request.WriteResultRequest; import org.simantics.db.exception.DatabaseException; import org.simantics.db.exception.RuntimeDatabaseException; -import org.simantics.db.exception.ServiceException; import org.simantics.db.layer0.QueryIndexUtils; import org.simantics.db.layer0.util.Layer0Utils; import org.simantics.db.layer0.variable.Variable; import org.simantics.db.layer0.variable.Variables; import org.simantics.db.layer0.variable.Variables.Role; import org.simantics.db.procedure.Procedure; +import org.simantics.db.request.WriteResult; import org.simantics.district.network.DistrictNetworkUtil; import org.simantics.district.network.ontology.DistrictNetworkResource; import org.simantics.layer0.Layer0; -import org.simantics.modeling.ModelingResources; -import org.simantics.modeling.adapters.NewCompositeActionFactory; import org.simantics.modeling.typicals.TypicalUtil; -import org.simantics.operation.Layer0X; import org.simantics.scl.compiler.commands.CommandSession; import org.simantics.scl.compiler.commands.CommandSessionImportEntry; import org.simantics.scl.compiler.errors.CompilationError; @@ -211,7 +191,6 @@ public class Functions { @SCLValue(type = "Resource -> String -> Resource -> Resource") public static Resource compositeInstantiator(final Resource compositeType, final String defaultName, final Resource target) throws DatabaseException { - return TypicalUtil.syncExec(procedure -> { if (!SWTUtils.asyncExec(PlatformUI.getWorkbench().getDisplay(), () -> { try { @@ -225,239 +204,7 @@ public class Functions { }); } - private static class DefaultMappingsDialog extends SelectionStatusDialog { - - private Combo vertexMappingCombo; - private Combo rightClickMappingCombo; - private Combo leftClickMappingCombo; - private Combo edgeMappingCombo; - //private Combo crsCombo; - private Composite composite; - - private Resource configuration; - private Map vertexMappings = new HashMap<>(); - private Map edgeMappings = new HashMap<>(); - private Map composites = new HashMap<>(); - private Map crss = new HashMap<>(); - - private Resource defaultVertexMapping; - private Resource defaultEdgeMapping; - private Resource rightClickVertexMapping; - private Resource leftClickVertexMapping; - //private Resource defaultCRS; - - //private Combo compositeMappingCombo; - //private Combo componentMappingCombo; - - protected DefaultMappingsDialog(Shell parentShell, Resource configuration) { - super(parentShell); - this.configuration = configuration; - setTitle("Select mappings for new DN diagram"); - } - - public Resource getDefaultVertexMapping() { - return defaultVertexMapping; - } - - public Resource getRightClickVertexMapping() { - return rightClickVertexMapping; - } - - public Resource getLeftClickVertexMapping() { - return leftClickVertexMapping; - } - - public Resource getDefaultEdgeMapping() { - return defaultEdgeMapping; - } - - @Override - protected Control createDialogArea(Composite parent) { - composite = (Composite) super.createDialogArea(parent); - - createMappingsGroup(composite); - //createExistingCompositeGroup(composite); - //createCRSSettingsGroup(composite); - - // compute default values - Simantics.getSession().asyncRequest(new ReadRequest() { - - @Override - public void run(ReadGraph graph) throws DatabaseException { - Resource indexRoot = graph.sync(new IndexRoot(configuration)); - vertexMappings = getVertexMappings(graph, indexRoot); - edgeMappings = getEdgeMappings(graph, indexRoot); - - composites = getComposites(graph, configuration); - - crss = getCRSs(graph, configuration); - - composite.getDisplay().asyncExec(() -> { - - vertexMappingCombo.setItems(vertexMappings.keySet().toArray(new String[vertexMappings.size()])); - rightClickMappingCombo.setItems(vertexMappings.keySet().toArray(new String[vertexMappings.size()])); - leftClickMappingCombo.setItems(vertexMappings.keySet().toArray(new String[vertexMappings.size()])); - edgeMappingCombo.setItems(edgeMappings.keySet().toArray(new String[edgeMappings.size()])); - - //crsCombo.setItems(crss.keySet().toArray(new String[crss.size()])); - - //compositeMappingCombo.setItems(composites.keySet().toArray(new String[composites.size()])); - vertexMappingCombo.select(0); - rightClickMappingCombo.select(0); - leftClickMappingCombo.select(0); - edgeMappingCombo.select(0); - - //crsCombo.select(0); - - //if (!composites.isEmpty()) - // compositeMappingCombo.select(0); - }); - - } - }); - return composite; - } - - protected Map getComposites(ReadGraph graph, Resource element) throws DatabaseException { - List nonDistrictComposites = composites.values().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) { - LOGGER.error("Could not read name of " + mapping, e); - } - }); - return result; - } - - private void createMappingsGroup(Composite parent) { - Group group= new Group(parent, SWT.NONE); - group.setFont(parent.getFont()); - group.setText("Default mappings"); - 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 vertexMappingLabel = new Label(cmposite, SWT.NONE); - vertexMappingLabel.setText("Default vertex mapping"); - - vertexMappingCombo = new Combo(cmposite, SWT.READ_ONLY | SWT.BORDER); - GridDataFactory.fillDefaults().grab(true, false).applyTo(vertexMappingCombo); - - Label rightClickMappingLabel = new Label(cmposite, SWT.NONE); - rightClickMappingLabel.setText("Default right click mapping"); - - rightClickMappingCombo = new Combo(cmposite, SWT.READ_ONLY | SWT.BORDER); - GridDataFactory.fillDefaults().grab(true, false).applyTo(vertexMappingCombo); - - Label leftClickMappingLabel = new Label(cmposite, SWT.NONE); - leftClickMappingLabel.setText("Default left click mapping"); - - leftClickMappingCombo = new Combo(cmposite, SWT.READ_ONLY | SWT.BORDER); - GridDataFactory.fillDefaults().grab(true, false).applyTo(vertexMappingCombo); - - Label edgeMappingLabel = new Label(cmposite, SWT.NONE); - edgeMappingLabel.setText("Default edge mapping"); - - edgeMappingCombo = new Combo(cmposite, SWT.READ_ONLY | SWT.BORDER); - 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()); - group.setText("CRS settings"); - 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 vertexMappingLabel = new Label(cmposite, SWT.NONE); - vertexMappingLabel.setText("Default CRS"); - - //crsCombo = new Combo(cmposite, SWT.READ_ONLY | SWT.BORDER); - //GridData textData = new GridData(SWT.FILL, SWT.CENTER, true, false); - //crsCombo.setLayoutData(textData); - } - - - @Override - protected void computeResult() { - defaultVertexMapping = vertexMappings.get(vertexMappingCombo.getItem(vertexMappingCombo.getSelectionIndex())); - defaultEdgeMapping = edgeMappings.get(edgeMappingCombo.getItem(edgeMappingCombo.getSelectionIndex())); - rightClickVertexMapping = vertexMappings.get(rightClickMappingCombo.getItem(rightClickMappingCombo.getSelectionIndex())); - leftClickVertexMapping = vertexMappings.get(leftClickMappingCombo.getItem(leftClickMappingCombo.getSelectionIndex())); - //defaultCRS = crss.get(crsCombo.getItem(crsCombo.getSelectionIndex())); - } - - public Resource getCRS() { - return crss.get("EPSG_4326"); // this is only supported - } - - } - - private static void queryInitialValuesAndCreateComposite(final Resource compositeType, final Resource target, + public static void queryInitialValuesAndCreateComposite(final Resource compositeType, final Resource target, String defaultName, final Procedure procedure) { DefaultMappingsDialog dialog = new DefaultMappingsDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), target); @@ -465,20 +212,15 @@ public class Functions { procedure.execute(null); return; } - Simantics.getSession().asyncRequest(new WriteResultRequest() { - @Override - public Resource perform(WriteGraph graph) throws DatabaseException { - return DistrictNetworkUtil.createNetworkDiagram(graph, target, compositeType, defaultName, - dialog.getDefaultEdgeMapping(), - dialog.getDefaultVertexMapping(), - dialog.getRightClickVertexMapping(), - dialog.getLeftClickVertexMapping(), - dialog.getCRS() + Simantics.getSession().asyncRequest((WriteResult) graph -> { + return DistrictNetworkUtil.createNetworkDiagram(graph, target, compositeType, defaultName, + dialog.getDefaultEdgeMapping(), + dialog.getDefaultVertexMapping(), + dialog.getRightClickVertexMapping(), + dialog.getLeftClickVertexMapping(), + dialog.getCRS() ); - } - - }, new Procedure() { @Override @@ -507,16 +249,6 @@ public class Functions { return results; } - private static List listInstanceNames(ReadGraph graph, Variable context, Resource type) throws DatabaseException { - Resource indexRoot = Variables.getIndexRoot(graph, context); - DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph); - List properties = Collections.emptyList();//QueryIndexUtils.searchByType(graph, indexRoot, DN.Vertex_ScaleProperty); - return properties.stream() - .map(m -> createEnumeratedValue(graph, m)) - .map(EnumeratedValue::getName) - .collect(Collectors.toList()); - } - @SCLValue(type = "ReadGraph -> Resource -> Variable -> b") public static Function1 hasDiameterValue(ReadGraph graph, Resource resource, Variable context) throws DatabaseException { return directPropertyValueFunction(DistrictNetworkResource.getInstance(graph).Edge_HasDiameter, 0); -- 2.45.2