-/*******************************************************************************\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.spreadsheet.ui;\r
-\r
-import java.awt.geom.AffineTransform;\r
-import java.util.Collections;\r
-import java.util.List;\r
-\r
-import org.eclipse.jface.viewers.IStructuredSelection;\r
-import org.simantics.databoard.Bindings;\r
-import org.simantics.databoard.util.URIStringUtils;\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.Session;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.request.Read;\r
-import org.simantics.diagram.adapter.GraphToDiagramSynchronizer;\r
-import org.simantics.diagram.participant.PopulateSelectionDropParticipant;\r
-import org.simantics.g2d.dnd.ElementClassDragItem;\r
-import org.simantics.g2d.element.ElementHints;\r
-import org.simantics.layer0.Layer0;\r
-import org.simantics.spreadsheet.resource.SpreadsheetResource;\r
-import org.simantics.utils.ui.ISelectionUtils;\r
-\r
-public class PopulateSheetDropParticipant extends PopulateSelectionDropParticipant {\r
-\r
- public PopulateSheetDropParticipant(GraphToDiagramSynchronizer synchronizer) {\r
- super(synchronizer);\r
- }\r
-\r
- @Override\r
- public List<ElementClassDragItem> getElements(Session session, IStructuredSelection selection) throws DatabaseException {\r
-\r
- final Resource resource = ISelectionUtils.filterSingleSelection(selection, Resource.class);\r
- if(resource == null) return Collections.emptyList();\r
-\r
- return session.syncRequest(new Read<List<ElementClassDragItem>>() {\r
-\r
- @Override\r
- public List<ElementClassDragItem> perform(ReadGraph graph) throws DatabaseException {\r
-\r
- SpreadsheetResource sr = SpreadsheetResource.getInstance(graph);\r
- if(graph.isInstanceOf(resource, sr.Spreadsheet)) {\r
- Layer0 L0 = Layer0.getInstance(graph);\r
- ElementClassDragItem item = new ElementClassDragItem(SheetFactory.createSheetClass(sr.SpreadsheetElement));\r
- item.getHintContext().setHint(SheetClass.KEY_SHEET, resource);\r
- String rvi = "/" + URIStringUtils.escape((String)graph.getPossibleRelatedValue(resource, L0.HasName, Bindings.STRING));\r
- item.getHintContext().setHint(SheetClass.KEY_RVI, rvi);\r
- item.getHintContext().setHint(ElementHints.KEY_TRANSFORM, AffineTransform.getScaleInstance(1,1));\r
- return Collections.singletonList(item);\r
- } else {\r
- return Collections.emptyList();\r
- }\r
-\r
- }\r
-\r
- });\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.spreadsheet.ui;
+
+import java.awt.geom.AffineTransform;
+import java.util.Collections;
+import java.util.List;
+
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.simantics.databoard.Bindings;
+import org.simantics.databoard.util.URIStringUtils;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.Session;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.request.Read;
+import org.simantics.diagram.adapter.GraphToDiagramSynchronizer;
+import org.simantics.diagram.participant.PopulateSelectionDropParticipant;
+import org.simantics.g2d.dnd.ElementClassDragItem;
+import org.simantics.g2d.element.ElementHints;
+import org.simantics.layer0.Layer0;
+import org.simantics.spreadsheet.resource.SpreadsheetResource;
+import org.simantics.utils.ui.ISelectionUtils;
+
+public class PopulateSheetDropParticipant extends PopulateSelectionDropParticipant {
+
+ public PopulateSheetDropParticipant(GraphToDiagramSynchronizer synchronizer) {
+ super(synchronizer);
+ }
+
+ @Override
+ public List<ElementClassDragItem> getElements(Session session, IStructuredSelection selection) throws DatabaseException {
+
+ final Resource resource = ISelectionUtils.filterSingleSelection(selection, Resource.class);
+ if(resource == null) return Collections.emptyList();
+
+ return session.syncRequest(new Read<List<ElementClassDragItem>>() {
+
+ @Override
+ public List<ElementClassDragItem> perform(ReadGraph graph) throws DatabaseException {
+
+ SpreadsheetResource sr = SpreadsheetResource.getInstance(graph);
+ if(graph.isInstanceOf(resource, sr.Spreadsheet)) {
+ Layer0 L0 = Layer0.getInstance(graph);
+ ElementClassDragItem item = new ElementClassDragItem(SheetFactory.createSheetClass(sr.SpreadsheetElement));
+ item.getHintContext().setHint(SheetClass.KEY_SHEET, resource);
+ String rvi = "/" + URIStringUtils.escape((String)graph.getPossibleRelatedValue(resource, L0.HasName, Bindings.STRING));
+ item.getHintContext().setHint(SheetClass.KEY_RVI, rvi);
+ item.getHintContext().setHint(ElementHints.KEY_TRANSFORM, AffineTransform.getScaleInstance(1,1));
+ return Collections.singletonList(item);
+ } else {
+ return Collections.emptyList();
+ }
+
+ }
+
+ });
+
+ }
+
}
\ No newline at end of file