]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.charts/src/org/simantics/charts/ui/ChartGroupPasteHandler.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.charts / src / org / simantics / charts / ui / ChartGroupPasteHandler.java
index 8e3055d36ae136dd7e0f60560e747ff0499824d9..3a9bc7f6a542b9345db1fdc0aa7ebeea3a9ecbb0 100644 (file)
-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- *     VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.charts.ui;\r
-\r
-import java.util.ArrayList;\r
-import java.util.Collection;\r
-import java.util.Collections;\r
-import java.util.HashSet;\r
-import java.util.List;\r
-import java.util.Set;\r
-\r
-import org.simantics.charts.ontology.ChartResource;\r
-import org.simantics.databoard.util.ObjectUtils;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.WriteGraph;\r
-import org.simantics.db.common.request.WriteResultRequest;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.layer0.adapter.PasteHandlerAdapter;\r
-import org.simantics.db.layer0.request.PossibleModel;\r
-import org.simantics.db.layer0.util.ClipboardUtils;\r
-import org.simantics.db.layer0.util.PasteEventHandler;\r
-import org.simantics.db.layer0.util.SimanticsClipboard;\r
-import org.simantics.db.layer0.util.SimanticsClipboard.Representation;\r
-import org.simantics.db.layer0.util.SimanticsKeys;\r
-import org.simantics.utils.ui.dialogs.ShowError;\r
-\r
-/**\r
- * @author Tuukka Lehtonen\r
- */\r
-public class ChartGroupPasteHandler extends PasteHandlerAdapter {\r
-\r
-    private Resource chartGroup;\r
-\r
-    public ChartGroupPasteHandler(Resource chartGroup) {\r
-        this.chartGroup = chartGroup;\r
-    }\r
-\r
-    @Override\r
-    public Collection<Resource> pasteFromClipboard(WriteGraph graph, SimanticsClipboard clipboard, PasteEventHandler handler) throws DatabaseException {\r
-        final List<Set<Representation>> copied = new ArrayList<>();\r
-        final List<Resource> cut = new ArrayList<>();\r
-        for (Set<Representation> object : clipboard.getContents()) {\r
-            Collection<Resource> rs = ClipboardUtils.accept(object, SimanticsKeys.KEY_COPY_RESOURCES);\r
-            if (rs != null) {\r
-                copied.add(object);\r
-            } else {\r
-                rs = ClipboardUtils.accept(object, SimanticsKeys.KEY_CUT_RESOURCES);\r
-                if (rs != null)\r
-                    cut.addAll(rs);\r
-            }\r
-        }\r
-\r
-        if (copied.isEmpty() && cut.isEmpty())\r
-            return Collections.emptyList();\r
-\r
-        return graph.syncRequest(new WriteResultRequest<Collection<Resource>>() {\r
-            @Override\r
-            public Collection<Resource> perform(WriteGraph graph) throws DatabaseException {\r
-\r
-                ChartResource CHART = ChartResource.getInstance(graph);\r
-\r
-                Resource expectedModel = graph.syncRequest( new PossibleModel(chartGroup) );\r
-                if (!copied.isEmpty()) {\r
-                    Set<Set<Representation>> sources = new HashSet<>();\r
-                    for (Set<Representation> r : copied) {\r
-                        Collection<Resource> srcs = ClipboardUtils.accept(r, SimanticsKeys.KEY_COPY_RESOURCES);\r
-                        for(Resource src : srcs) {\r
-                            if (graph.isInstanceOf(src, CHART.Chart)) {\r
-                                Resource model = graph.syncRequest(new PossibleModel(src));\r
-                                if (ObjectUtils.objectEquals(expectedModel, model)) {\r
-                                    sources.add(r);\r
-                                }\r
-                            }\r
-                        }\r
-                    }\r
-                    return ChartGroupDropActionFactory.copyChartsRequest(chartGroup, sources).perform(graph);\r
-                } else if (!cut.isEmpty()) {\r
-                    Set<Resource> sources = new HashSet<>();\r
-                    for (Resource r : cut) {\r
-                        if (graph.isInstanceOf(r, CHART.Chart)) {\r
-                            Resource model = graph.syncRequest(new PossibleModel(r));\r
-                            if (ObjectUtils.objectEquals(expectedModel, model))\r
-                                sources.add(r);\r
-                        }\r
-                    }\r
-                    String error = ChartGroupDropActionFactory.validateDrop(graph, chartGroup, sources);\r
-                    if (error != null) {\r
-                        ShowError.showError("Cut Failed", error, (Throwable) null);\r
-                        return Collections.emptyList();\r
-                    }\r
-                    return ChartGroupDropActionFactory.moveChartsRequest(chartGroup, sources).perform(graph);\r
-                }\r
-                \r
-                return Collections.emptyList();\r
-                \r
-            }\r
-        });\r
-    }\r
-\r
-    @SuppressWarnings("rawtypes")\r
-    @Override\r
-    public Object getAdapter(Class adapter) {\r
-        if (Resource.class == adapter)\r
-            return chartGroup;\r
-        return null;\r
-    }\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.charts.ui;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.simantics.charts.ontology.ChartResource;
+import org.simantics.databoard.util.ObjectUtils;
+import org.simantics.db.Resource;
+import org.simantics.db.WriteGraph;
+import org.simantics.db.common.request.WriteResultRequest;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.adapter.PasteHandlerAdapter;
+import org.simantics.db.layer0.request.PossibleModel;
+import org.simantics.db.layer0.util.ClipboardUtils;
+import org.simantics.db.layer0.util.PasteEventHandler;
+import org.simantics.db.layer0.util.SimanticsClipboard;
+import org.simantics.db.layer0.util.SimanticsClipboard.Representation;
+import org.simantics.db.layer0.util.SimanticsKeys;
+import org.simantics.utils.ui.dialogs.ShowError;
+
+/**
+ * @author Tuukka Lehtonen
+ */
+public class ChartGroupPasteHandler extends PasteHandlerAdapter {
+
+    private Resource chartGroup;
+
+    public ChartGroupPasteHandler(Resource chartGroup) {
+        this.chartGroup = chartGroup;
+    }
+
+    @Override
+    public Collection<Resource> pasteFromClipboard(WriteGraph graph, SimanticsClipboard clipboard, PasteEventHandler handler) throws DatabaseException {
+        final List<Set<Representation>> copied = new ArrayList<>();
+        final List<Resource> cut = new ArrayList<>();
+        for (Set<Representation> object : clipboard.getContents()) {
+            Collection<Resource> rs = ClipboardUtils.accept(object, SimanticsKeys.KEY_COPY_RESOURCES);
+            if (rs != null) {
+                copied.add(object);
+            } else {
+                rs = ClipboardUtils.accept(object, SimanticsKeys.KEY_CUT_RESOURCES);
+                if (rs != null)
+                    cut.addAll(rs);
+            }
+        }
+
+        if (copied.isEmpty() && cut.isEmpty())
+            return Collections.emptyList();
+
+        return graph.syncRequest(new WriteResultRequest<Collection<Resource>>() {
+            @Override
+            public Collection<Resource> perform(WriteGraph graph) throws DatabaseException {
+
+                ChartResource CHART = ChartResource.getInstance(graph);
+
+                Resource expectedModel = graph.syncRequest( new PossibleModel(chartGroup) );
+                if (!copied.isEmpty()) {
+                    Set<Set<Representation>> sources = new HashSet<>();
+                    for (Set<Representation> r : copied) {
+                        Collection<Resource> srcs = ClipboardUtils.accept(r, SimanticsKeys.KEY_COPY_RESOURCES);
+                        for(Resource src : srcs) {
+                            if (graph.isInstanceOf(src, CHART.Chart)) {
+                                Resource model = graph.syncRequest(new PossibleModel(src));
+                                if (ObjectUtils.objectEquals(expectedModel, model)) {
+                                    sources.add(r);
+                                }
+                            }
+                        }
+                    }
+                    return ChartGroupDropActionFactory.copyChartsRequest(chartGroup, sources).perform(graph);
+                } else if (!cut.isEmpty()) {
+                    Set<Resource> sources = new HashSet<>();
+                    for (Resource r : cut) {
+                        if (graph.isInstanceOf(r, CHART.Chart)) {
+                            Resource model = graph.syncRequest(new PossibleModel(r));
+                            if (ObjectUtils.objectEquals(expectedModel, model))
+                                sources.add(r);
+                        }
+                    }
+                    String error = ChartGroupDropActionFactory.validateDrop(graph, chartGroup, sources);
+                    if (error != null) {
+                        ShowError.showError("Cut Failed", error, (Throwable) null);
+                        return Collections.emptyList();
+                    }
+                    return ChartGroupDropActionFactory.moveChartsRequest(chartGroup, sources).perform(graph);
+                }
+                
+                return Collections.emptyList();
+                
+            }
+        });
+    }
+
+    @SuppressWarnings("rawtypes")
+    @Override
+    public Object getAdapter(Class adapter) {
+        if (Resource.class == adapter)
+            return chartGroup;
+        return null;
+    }
+
+}