From 43607377385ee1735725510837195d095f357c42 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Hannu=20Niemist=C3=B6?= Date: Wed, 4 Oct 2017 12:19:19 +0300 Subject: [PATCH] (refs #7526) Allow population of UC to diagram directly Change-Id: I23b480f326107baaf0996e9da8c2670caab0585f --- .../PopulateElementDropParticipant.java | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/PopulateElementDropParticipant.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/PopulateElementDropParticipant.java index 3b6da0b5b..4f2740602 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/PopulateElementDropParticipant.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/PopulateElementDropParticipant.java @@ -159,10 +159,10 @@ public class PopulateElementDropParticipant extends AbstractDiagramParticipant i } try { - String valid = validateDrop(synchronizer.getSession(), r, + Object errorOrSymbolResource = validateDrop(synchronizer.getSession(), r, diagram. getHint(DiagramModelHints.KEY_DIAGRAM_RESOURCE)); - if (valid == null) { - ElementClassDragItem item = new ElementClassDragItem(synchronizer.getNodeClass(r)); + if (errorOrSymbolResource instanceof Resource) { + ElementClassDragItem item = new ElementClassDragItem(synchronizer.getNodeClass((Resource)errorOrSymbolResource)); item.getHintContext().setHint(ElementHints.KEY_TRANSFORM, AffineTransform.getScaleInstance(1, 1)); dp.add(item); } @@ -207,10 +207,10 @@ public class PopulateElementDropParticipant extends AbstractDiagramParticipant i } } - private String validateDrop(RequestProcessor processor, final Resource draggedResource, final Resource dropTarget) throws DatabaseException { - return processor.syncRequest(new UniqueRead() { + private Object validateDrop(RequestProcessor processor, final Resource draggedResource, final Resource dropTarget) throws DatabaseException { + return processor.syncRequest(new UniqueRead() { @Override - public String perform(ReadGraph graph) throws DatabaseException { + public Object perform(ReadGraph graph) throws DatabaseException { // System.out.println("dragged resource: " + draggedResource); // System.out.println("drop target resource: " + dropTarget); Resource sourceModel = graph.syncRequest(new PossibleIndexRoot(draggedResource)); @@ -240,18 +240,28 @@ public class PopulateElementDropParticipant extends AbstractDiagramParticipant i } } + // Check if dragged object is symbol or component type and determine other + Resource componentType; + Resource symbol = graph.getPossibleObject(draggedResource, MOD.ComponentTypeToSymbol); + + if(symbol != null) + componentType = draggedResource; + else { + componentType = graph.getPossibleObject(draggedResource, MOD.SymbolToComponentType); + symbol = draggedResource; + } + // Prevent dragging a symbol of component type into its own configuration. - Resource componentTypeFromSymbol = graph.getPossibleObject(draggedResource, MOD.SymbolToComponentType); - if (componentTypeFromSymbol != null) { + if (componentType != null) { if (configuration != null) { Resource componentTypeFromDiagram = graph.getPossibleObject(configuration, STR.Defines); - if (componentTypeFromDiagram != null && componentTypeFromSymbol.equals(componentTypeFromDiagram)) { + if (componentTypeFromDiagram != null && componentType.equals(componentTypeFromDiagram)) { return "Cannot instantiate user component within its own configuration."; } } } - return null; + return symbol; } }); } -- 2.47.1