X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.modeling.ui%2Fsrc%2Forg%2Fsimantics%2Fmodeling%2Fui%2FdiagramEditor%2FPopulateElementDropParticipant.java;fp=bundles%2Forg.simantics.modeling.ui%2Fsrc%2Forg%2Fsimantics%2Fmodeling%2Fui%2FdiagramEditor%2FPopulateElementDropParticipant.java;h=4f27406025f752cd713b5dcc77cab0a5a2a2a6e0;hb=43607377385ee1735725510837195d095f357c42;hp=3b6da0b5bd69b4d683bcfc5fbe995031908cf02a;hpb=f9414daee0c65900deb73ab81a2d7f157c6bd5e4;p=simantics%2Fplatform.git 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; } }); }