-/*******************************************************************************\r
- * Copyright (c) 2007, 2012 Association for Decentralized Information Management in\r
- * 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.editor;\r
-\r
-import java.util.ArrayList;\r
-import java.util.Collection;\r
-import java.util.Collections;\r
-import java.util.List;\r
-import java.util.Set;\r
-\r
-import org.eclipse.core.runtime.IStatus;\r
-import org.eclipse.core.runtime.Status;\r
-import org.simantics.Simantics;\r
-import org.simantics.charts.Activator;\r
-import org.simantics.charts.query.AddChartItem;\r
-import org.simantics.charts.query.ChartItemDescriptor;\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.WriteRequest;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.layer0.request.PossibleModel;\r
-import org.simantics.db.layer0.util.ClipboardUtils;\r
-import org.simantics.db.layer0.util.SimanticsClipboard.Representation;\r
-import org.simantics.db.layer0.util.SimanticsKeys;\r
-import org.simantics.g2d.canvas.ICanvasParticipant;\r
-import org.simantics.g2d.canvas.impl.AbstractCanvasParticipant;\r
-import org.simantics.modeling.ModelingResources;\r
-import org.simantics.scenegraph.g2d.events.EventHandlerReflection.EventHandler;\r
-import org.simantics.scenegraph.g2d.events.command.CommandEvent;\r
-import org.simantics.scenegraph.g2d.events.command.Commands;\r
-\r
-/**\r
- * Handles paste to TimeSeriesEditor\r
- * \r
- * @author toni.kalajainen\r
- */\r
-public class ChartPasteHandler2 extends AbstractCanvasParticipant implements ICanvasParticipant {\r
-\r
- private Resource chart;\r
-\r
- public ChartPasteHandler2(Resource chart) {\r
- this.chart = chart;\r
- }\r
-\r
- @EventHandler(priority = 0)\r
- public boolean handleCommandEvent(CommandEvent e) {\r
-\r
- if (e.command == Commands.PASTE) {\r
-\r
- final List<Resource> resources = new ArrayList<Resource>();\r
- for (Set<Representation> object : Simantics.getClipboard().getContents()) {\r
- Collection<Resource> rs;\r
- try {\r
- rs = ClipboardUtils.accept(object, SimanticsKeys.KEY_COPY_RESOURCES);\r
- if (rs != null)\r
- resources.addAll(rs);\r
- } catch (DatabaseException ex) {\r
- Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID,\r
- "Failed to retrieve clipboard contents.", ex));\r
- }\r
- }\r
-\r
- if (resources.isEmpty())\r
- return true;\r
-\r
- Simantics.getSession().asyncRequest(new WriteRequest() {\r
- @Override\r
- public void perform(WriteGraph graph) throws DatabaseException {\r
- Resource expectedModel = graph.syncRequest(new PossibleModel(chart));\r
- if (expectedModel == null || chart == null)\r
- return;\r
- ModelingResources MOD = ModelingResources.getInstance(graph);\r
- List<ChartItemDescriptor> refs = new ArrayList<ChartItemDescriptor>();\r
- for (Resource r : resources) {\r
- if (graph.isInstanceOf(r, MOD.Subscription_Item)) {\r
- Resource model = graph.syncRequest(new PossibleModel(r));\r
- if (ObjectUtils.objectEquals(expectedModel, model))\r
- refs.add(AddChartItem.createDescriptor(graph, r));\r
- }\r
- }\r
-\r
- if (!refs.isEmpty()) {\r
- AddChartItem.addAndMoveChartItems(chart, refs, Collections.<Resource> emptySet())\r
- .perform(graph);\r
- }\r
- }\r
- });\r
- return true;\r
- }\r
-\r
- return false;\r
-\r
- }\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2012 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.editor;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.simantics.Simantics;
+import org.simantics.charts.Activator;
+import org.simantics.charts.query.AddChartItem;
+import org.simantics.charts.query.ChartItemDescriptor;
+import org.simantics.databoard.util.ObjectUtils;
+import org.simantics.db.Resource;
+import org.simantics.db.WriteGraph;
+import org.simantics.db.common.request.WriteRequest;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.request.PossibleModel;
+import org.simantics.db.layer0.util.ClipboardUtils;
+import org.simantics.db.layer0.util.SimanticsClipboard.Representation;
+import org.simantics.db.layer0.util.SimanticsKeys;
+import org.simantics.g2d.canvas.ICanvasParticipant;
+import org.simantics.g2d.canvas.impl.AbstractCanvasParticipant;
+import org.simantics.modeling.ModelingResources;
+import org.simantics.scenegraph.g2d.events.EventHandlerReflection.EventHandler;
+import org.simantics.scenegraph.g2d.events.command.CommandEvent;
+import org.simantics.scenegraph.g2d.events.command.Commands;
+
+/**
+ * Handles paste to TimeSeriesEditor
+ *
+ * @author toni.kalajainen
+ */
+public class ChartPasteHandler2 extends AbstractCanvasParticipant implements ICanvasParticipant {
+
+ private Resource chart;
+
+ public ChartPasteHandler2(Resource chart) {
+ this.chart = chart;
+ }
+
+ @EventHandler(priority = 0)
+ public boolean handleCommandEvent(CommandEvent e) {
+
+ if (e.command == Commands.PASTE) {
+
+ final List<Resource> resources = new ArrayList<Resource>();
+ for (Set<Representation> object : Simantics.getClipboard().getContents()) {
+ Collection<Resource> rs;
+ try {
+ rs = ClipboardUtils.accept(object, SimanticsKeys.KEY_COPY_RESOURCES);
+ if (rs != null)
+ resources.addAll(rs);
+ } catch (DatabaseException ex) {
+ Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID,
+ "Failed to retrieve clipboard contents.", ex));
+ }
+ }
+
+ if (resources.isEmpty())
+ return true;
+
+ Simantics.getSession().asyncRequest(new WriteRequest() {
+ @Override
+ public void perform(WriteGraph graph) throws DatabaseException {
+ Resource expectedModel = graph.syncRequest(new PossibleModel(chart));
+ if (expectedModel == null || chart == null)
+ return;
+ ModelingResources MOD = ModelingResources.getInstance(graph);
+ List<ChartItemDescriptor> refs = new ArrayList<ChartItemDescriptor>();
+ for (Resource r : resources) {
+ if (graph.isInstanceOf(r, MOD.Subscription_Item)) {
+ Resource model = graph.syncRequest(new PossibleModel(r));
+ if (ObjectUtils.objectEquals(expectedModel, model))
+ refs.add(AddChartItem.createDescriptor(graph, r));
+ }
+ }
+
+ if (!refs.isEmpty()) {
+ AddChartItem.addAndMoveChartItems(chart, refs, Collections.<Resource> emptySet())
+ .perform(graph);
+ }
+ }
+ });
+ return true;
+ }
+
+ return false;
+
+ }
+
+}