X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.modeling%2Fsrc%2Forg%2Fsimantics%2Fmodeling%2Fmapping%2FComponentAndElementPasteHandler.java;h=d3d4a8fc14d69669a884f674aad523e5a4f18c9b;hp=f24454b3b8b6d99194b4e7d4f214a8a00e3765a0;hb=3a10ce856f7124f83cf03d6e7f7576da237a7cbb;hpb=969bd23cab98a79ca9101af33334000879fb60c5 diff --git a/bundles/org.simantics.modeling/src/org/simantics/modeling/mapping/ComponentAndElementPasteHandler.java b/bundles/org.simantics.modeling/src/org/simantics/modeling/mapping/ComponentAndElementPasteHandler.java index f24454b3b..d3d4a8fc1 100644 --- a/bundles/org.simantics.modeling/src/org/simantics/modeling/mapping/ComponentAndElementPasteHandler.java +++ b/bundles/org.simantics.modeling/src/org/simantics/modeling/mapping/ComponentAndElementPasteHandler.java @@ -1,115 +1,115 @@ -package org.simantics.modeling.mapping; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Set; - -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.WriteGraph; -import org.simantics.db.exception.DatabaseException; -import org.simantics.db.layer0.adapter.impl.DefaultPasteHandler; -import org.simantics.db.layer0.util.ClipboardUtils; -import org.simantics.db.layer0.util.PasteEventHandler; -import org.simantics.db.layer0.util.SimanticsClipboard.Representation; -import org.simantics.db.layer0.util.SimanticsKeys; -import org.simantics.graph.representation.TransferableGraph1; - -/** - * Paste handler for Component and it's Element. - * - * @author Marko Luukkainen - * - */ -public abstract class ComponentAndElementPasteHandler extends DefaultPasteHandler{ - - protected boolean includeComponent = true; - protected boolean includeElement = true; - - /** - * Creates Paste Handler for target composite (Composite where the data is copied). - * @param composite - */ - public ComponentAndElementPasteHandler(Resource composite) { - super(composite); - } - - /** - * Creates Paste Handler for target composite (Composite where the data is copied). - * @param composite - * @param includeComponent true if component is copied. (component must exist in the source data). - * @param includeElement true if element is copied. If the element is not included in the source data and this flag is true, the element is created. - */ - public ComponentAndElementPasteHandler(Resource composite, boolean includeComponent, boolean includeElement) { - super(composite); - if (!includeComponent && !includeElement) - throw new IllegalArgumentException(); - this.includeElement = includeElement; - this.includeComponent = includeComponent; - - } - - /** - * Returns configuration composite - * - * TODO: Current Modeling, Structural, or Diagram Ontologies do not have specific relation/type for configuration, so it is impossible to create generic implementation. - * - * @param graph - * @return - * @throws DatabaseException - */ - abstract protected Resource getConfiguration(ReadGraph graph) throws DatabaseException; - - public void onPaste(WriteGraph graph, ComponentAndElementPasteImportAdvisor advisor, Set representations) throws DatabaseException { - - } - - /** - * Called if the PasteImportAdviosr had to create the element. - * This happens if an element was required, but the copied data did not include the element. - * - * Override this method if your element requires custom data. - * - * @param graph - * @param element - * @throws DatabaseException - */ - protected void createdElementInAdvisor(WriteGraph graph, Resource element) throws DatabaseException { - - } - - @Override - public Collection pasteObject(WriteGraph graph, Set object, PasteEventHandler handler) throws DatabaseException { - Collection result = new ArrayList(); - - TransferableGraph1 tg = ClipboardUtils.accept(graph, object, SimanticsKeys.KEY_TRANSFERABLE_GRAPH); - if (tg != null) { - - doPaste(graph, object, tg, result); - } - return result; - } - - public void doPaste(WriteGraph graph, Set object, TransferableGraph1 tg, Collection result) throws DatabaseException{ - Resource resource = (Resource)getAdapter(Resource.class); - Resource configuration = getConfiguration(graph); - ComponentAndElementPasteImportAdvisor advisor = new ComponentAndElementPasteImportAdvisor(graph, configuration, includeComponent, includeElement) { - @Override - public void createElement(WriteGraph graph, Resource element) - throws DatabaseException { - createdElementInAdvisor(graph, element); - } - }; - execute(graph, tg, resource, advisor); - advisor.attach(graph); - onPaste(graph, advisor, object); - if (advisor.getComponent() != null) - result.add(advisor.getComponent()); - else if (advisor.getElement() != null) - result.add(advisor.getElement()); - } - - - - -} +package org.simantics.modeling.mapping; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Set; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.adapter.impl.DefaultPasteHandler; +import org.simantics.db.layer0.util.ClipboardUtils; +import org.simantics.db.layer0.util.PasteEventHandler; +import org.simantics.db.layer0.util.SimanticsClipboard.Representation; +import org.simantics.db.layer0.util.SimanticsKeys; +import org.simantics.graph.representation.TransferableGraph1; + +/** + * Paste handler for Component and it's Element. + * + * @author Marko Luukkainen + * + */ +public abstract class ComponentAndElementPasteHandler extends DefaultPasteHandler{ + + protected boolean includeComponent = true; + protected boolean includeElement = true; + + /** + * Creates Paste Handler for target composite (Composite where the data is copied). + * @param composite + */ + public ComponentAndElementPasteHandler(Resource composite) { + super(composite); + } + + /** + * Creates Paste Handler for target composite (Composite where the data is copied). + * @param composite + * @param includeComponent true if component is copied. (component must exist in the source data). + * @param includeElement true if element is copied. If the element is not included in the source data and this flag is true, the element is created. + */ + public ComponentAndElementPasteHandler(Resource composite, boolean includeComponent, boolean includeElement) { + super(composite); + if (!includeComponent && !includeElement) + throw new IllegalArgumentException(); + this.includeElement = includeElement; + this.includeComponent = includeComponent; + + } + + /** + * Returns configuration composite + * + * TODO: Current Modeling, Structural, or Diagram Ontologies do not have specific relation/type for configuration, so it is impossible to create generic implementation. + * + * @param graph + * @return + * @throws DatabaseException + */ + abstract protected Resource getConfiguration(ReadGraph graph) throws DatabaseException; + + public void onPaste(WriteGraph graph, ComponentAndElementPasteImportAdvisor advisor, Set representations) throws DatabaseException { + + } + + /** + * Called if the PasteImportAdviosr had to create the element. + * This happens if an element was required, but the copied data did not include the element. + * + * Override this method if your element requires custom data. + * + * @param graph + * @param element + * @throws DatabaseException + */ + protected void createdElementInAdvisor(WriteGraph graph, Resource element) throws DatabaseException { + + } + + @Override + public Collection pasteObject(WriteGraph graph, Set object, PasteEventHandler handler) throws DatabaseException { + Collection result = new ArrayList(); + + TransferableGraph1 tg = ClipboardUtils.accept(graph, object, SimanticsKeys.KEY_TRANSFERABLE_GRAPH); + if (tg != null) { + + doPaste(graph, object, tg, result); + } + return result; + } + + public void doPaste(WriteGraph graph, Set object, TransferableGraph1 tg, Collection result) throws DatabaseException{ + Resource resource = (Resource)getAdapter(Resource.class); + Resource configuration = getConfiguration(graph); + ComponentAndElementPasteImportAdvisor advisor = new ComponentAndElementPasteImportAdvisor(graph, configuration, includeComponent, includeElement) { + @Override + public void createElement(WriteGraph graph, Resource element) + throws DatabaseException { + createdElementInAdvisor(graph, element); + } + }; + execute(graph, tg, resource, advisor); + advisor.attach(graph); + onPaste(graph, advisor, object); + if (advisor.getComponent() != null) + result.add(advisor.getComponent()); + else if (advisor.getElement() != null) + result.add(advisor.getElement()); + } + + + + +}