-package org.simantics.modeling.mapping;\r
-\r
-import java.util.ArrayList;\r
-import java.util.Collection;\r
-import java.util.Set;\r
-\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.WriteGraph;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.layer0.adapter.impl.DefaultPasteHandler;\r
-import org.simantics.db.layer0.util.ClipboardUtils;\r
-import org.simantics.db.layer0.util.PasteEventHandler;\r
-import org.simantics.db.layer0.util.SimanticsClipboard.Representation;\r
-import org.simantics.db.layer0.util.SimanticsKeys;\r
-import org.simantics.graph.representation.TransferableGraph1;\r
-\r
-/**\r
- * Paste handler for Component and it's Element.\r
- * \r
- * @author Marko Luukkainen <marko.luukkainen@vtt.fi>\r
- *\r
- */\r
-public abstract class ComponentAndElementPasteHandler extends DefaultPasteHandler{\r
-\r
- protected boolean includeComponent = true;\r
- protected boolean includeElement = true;\r
- \r
- /**\r
- * Creates Paste Handler for target composite (Composite where the data is copied).\r
- * @param composite\r
- */\r
- public ComponentAndElementPasteHandler(Resource composite) {\r
- super(composite);\r
- }\r
- \r
- /**\r
- * Creates Paste Handler for target composite (Composite where the data is copied).\r
- * @param composite\r
- * @param includeComponent true if component is copied. (component must exist in the source data).\r
- * @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. \r
- */\r
- public ComponentAndElementPasteHandler(Resource composite, boolean includeComponent, boolean includeElement) {\r
- super(composite);\r
- if (!includeComponent && !includeElement)\r
- throw new IllegalArgumentException();\r
- this.includeElement = includeElement;\r
- this.includeComponent = includeComponent;\r
- \r
- }\r
-\r
- /**\r
- * Returns configuration composite\r
- * \r
- * TODO: Current Modeling, Structural, or Diagram Ontologies do not have specific relation/type for configuration, so it is impossible to create generic implementation.\r
- * \r
- * @param graph\r
- * @return\r
- * @throws DatabaseException\r
- */\r
- abstract protected Resource getConfiguration(ReadGraph graph) throws DatabaseException;\r
- \r
- public void onPaste(WriteGraph graph, ComponentAndElementPasteImportAdvisor advisor, Set<Representation> representations) throws DatabaseException {\r
- \r
- }\r
- \r
- /**\r
- * Called if the PasteImportAdviosr had to create the element.\r
- * This happens if an element was required, but the copied data did not include the element.\r
- * \r
- * Override this method if your element requires custom data. \r
- * \r
- * @param graph\r
- * @param element\r
- * @throws DatabaseException\r
- */\r
- protected void createdElementInAdvisor(WriteGraph graph, Resource element) throws DatabaseException {\r
- \r
- }\r
- \r
- @Override\r
- public Collection<Resource> pasteObject(WriteGraph graph, Set<Representation> object, PasteEventHandler handler) throws DatabaseException {\r
- Collection<Resource> result = new ArrayList<Resource>();\r
- \r
- TransferableGraph1 tg = ClipboardUtils.accept(graph, object, SimanticsKeys.KEY_TRANSFERABLE_GRAPH);\r
- if (tg != null) {\r
-\r
- doPaste(graph, object, tg, result);\r
- }\r
- return result;\r
- }\r
- \r
- public void doPaste(WriteGraph graph, Set<Representation> object, TransferableGraph1 tg, Collection<Resource> result) throws DatabaseException{\r
- Resource resource = (Resource)getAdapter(Resource.class);\r
- Resource configuration = getConfiguration(graph);\r
- ComponentAndElementPasteImportAdvisor advisor = new ComponentAndElementPasteImportAdvisor(graph, configuration, includeComponent, includeElement) {\r
- @Override\r
- public void createElement(WriteGraph graph, Resource element)\r
- throws DatabaseException {\r
- createdElementInAdvisor(graph, element);\r
- }\r
- }; \r
- execute(graph, tg, resource, advisor);\r
- advisor.attach(graph);\r
- onPaste(graph, advisor, object);\r
- if (advisor.getComponent() != null)\r
- result.add(advisor.getComponent());\r
- else if (advisor.getElement() != null)\r
- result.add(advisor.getElement());\r
- }\r
- \r
- \r
- \r
- \r
-}\r
+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 <marko.luukkainen@vtt.fi>
+ *
+ */
+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<Representation> 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<Resource> pasteObject(WriteGraph graph, Set<Representation> object, PasteEventHandler handler) throws DatabaseException {
+ Collection<Resource> result = new ArrayList<Resource>();
+
+ 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<Representation> object, TransferableGraph1 tg, Collection<Resource> 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());
+ }
+
+
+
+
+}