]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.diagram/src/org/simantics/diagram/symbolcontribution/ElementSymbolItem.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.diagram / src / org / simantics / diagram / symbolcontribution / ElementSymbolItem.java
index 50ad79612b2fabed9d454427327e68d72e9e686e..8a8a796f527234072b7f88db60f65143d8b72b54 100644 (file)
@@ -1,96 +1,96 @@
-/*******************************************************************************\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.diagram.symbolcontribution;\r
-\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.RequestProcessor;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.common.request.ResourceRead;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.procedure.Listener;\r
-import org.simantics.db.request.Read;\r
-import org.simantics.diagram.query.DiagramRequests;\r
-import org.simantics.diagram.symbollibrary.ISymbolGroup;\r
-import org.simantics.diagram.symbollibrary.ISymbolItem;\r
-import org.simantics.diagram.synchronization.graph.BasicResources;\r
-import org.simantics.g2d.element.ElementClass;\r
-import org.simantics.g2d.element.handler.StaticSymbol;\r
-import org.simantics.ui.SimanticsUI;\r
-import org.simantics.utils.datastructures.cache.ProvisionException;\r
-import org.simantics.utils.datastructures.hints.IHintObservable;\r
-\r
-/**\r
- * @author Tuukka Lehtonen\r
- */\r
-public class ElementSymbolItem extends SymbolItem {\r
-\r
-    public ElementSymbolItem(Resource item, String name, ISymbolGroup group) {\r
-        super(\r
-                AdaptableTriple.make(\r
-                        item,\r
-                        // Prevents infinite recursion which will happen\r
-                        // if SymbolGroup is used as group ID.\r
-                        group instanceof IIdentifiedObject ? ((IIdentifiedObject) group).getId() : group,\r
-                        // Name is in the identification so that name\r
-                        // changes refresh the symbol library\r
-                        name),\r
-                name,\r
-                group);\r
-    }\r
-\r
-    public ElementSymbolItem(Resource item, String name, String description, ISymbolGroup group) {\r
-        super(\r
-                AdaptableTriple.make(\r
-                        item,\r
-                        // Prevents infinite recursion which will happen\r
-                        // if SymbolGroup is used as group ID.\r
-                        group instanceof IIdentifiedObject ? ((IIdentifiedObject) group).getId() : group,\r
-                        // Name is in the identification so that name\r
-                        // changes refresh the symbol library\r
-                        name),\r
-                name,\r
-                description,\r
-                group);\r
-    }\r
-\r
-    @Override\r
-    public ElementClass getElementClass(IHintObservable hints) {\r
-        Resource item = adapt(Resource.class);\r
-        RequestProcessor sgrp = SimanticsUI.peekSession();\r
-        if (sgrp == null)\r
-            throw new ProvisionException("No RequestProcessor available for querying an ElementClass for resource " + item);\r
-        try {\r
-            Listener<ElementClass> listener = hints.getHint(ISymbolItem.KEY_ELEMENT_CLASS_LISTENER);\r
-            ElementClass ec = listener == null\r
-                    ? sgrp.syncRequest(createRequest(item, hints))\r
-                    : sgrp.syncRequest(createRequest(item, hints), listener);\r
-            if (ec == null)\r
-                throw new ProvisionException("ElementClass query failed, returned null");\r
-            if (!ec.containsClass(StaticSymbol.class))\r
-                throw new ProvisionException("ElementClass " + ec + " does not provide a StaticSymbol handler");\r
-            return ec;\r
-        } catch (DatabaseException e) {\r
-            throw new ProvisionException(e);\r
-        }\r
-    }\r
-\r
-    private Read<ElementClass> createRequest(Resource item, final IHintObservable hints) {\r
-        return new ResourceRead<ElementClass>(item) {\r
-            @Override\r
-            public ElementClass perform(ReadGraph graph) throws DatabaseException {\r
-                BasicResources.getInstance(graph);\r
-                return graph.syncRequest( DiagramRequests.getElementClass(resource, hints) );\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.diagram.symbolcontribution;
+
+import org.simantics.db.ReadGraph;
+import org.simantics.db.RequestProcessor;
+import org.simantics.db.Resource;
+import org.simantics.db.common.request.ResourceRead;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.procedure.Listener;
+import org.simantics.db.request.Read;
+import org.simantics.diagram.query.DiagramRequests;
+import org.simantics.diagram.symbollibrary.ISymbolGroup;
+import org.simantics.diagram.symbollibrary.ISymbolItem;
+import org.simantics.diagram.synchronization.graph.BasicResources;
+import org.simantics.g2d.element.ElementClass;
+import org.simantics.g2d.element.handler.StaticSymbol;
+import org.simantics.ui.SimanticsUI;
+import org.simantics.utils.datastructures.cache.ProvisionException;
+import org.simantics.utils.datastructures.hints.IHintObservable;
+
+/**
+ * @author Tuukka Lehtonen
+ */
+public class ElementSymbolItem extends SymbolItem {
+
+    public ElementSymbolItem(Resource item, String name, ISymbolGroup group) {
+        super(
+                AdaptableTriple.make(
+                        item,
+                        // Prevents infinite recursion which will happen
+                        // if SymbolGroup is used as group ID.
+                        group instanceof IIdentifiedObject ? ((IIdentifiedObject) group).getId() : group,
+                        // Name is in the identification so that name
+                        // changes refresh the symbol library
+                        name),
+                name,
+                group);
+    }
+
+    public ElementSymbolItem(Resource item, String name, String description, ISymbolGroup group) {
+        super(
+                AdaptableTriple.make(
+                        item,
+                        // Prevents infinite recursion which will happen
+                        // if SymbolGroup is used as group ID.
+                        group instanceof IIdentifiedObject ? ((IIdentifiedObject) group).getId() : group,
+                        // Name is in the identification so that name
+                        // changes refresh the symbol library
+                        name),
+                name,
+                description,
+                group);
+    }
+
+    @Override
+    public ElementClass getElementClass(IHintObservable hints) {
+        Resource item = adapt(Resource.class);
+        RequestProcessor sgrp = SimanticsUI.peekSession();
+        if (sgrp == null)
+            throw new ProvisionException("No RequestProcessor available for querying an ElementClass for resource " + item);
+        try {
+            Listener<ElementClass> listener = hints.getHint(ISymbolItem.KEY_ELEMENT_CLASS_LISTENER);
+            ElementClass ec = listener == null
+                    ? sgrp.syncRequest(createRequest(item, hints))
+                    : sgrp.syncRequest(createRequest(item, hints), listener);
+            if (ec == null)
+                throw new ProvisionException("ElementClass query failed, returned null");
+            if (!ec.containsClass(StaticSymbol.class))
+                throw new ProvisionException("ElementClass " + ec + " does not provide a StaticSymbol handler");
+            return ec;
+        } catch (DatabaseException e) {
+            throw new ProvisionException(e);
+        }
+    }
+
+    private Read<ElementClass> createRequest(Resource item, final IHintObservable hints) {
+        return new ResourceRead<ElementClass>(item) {
+            @Override
+            public ElementClass perform(ReadGraph graph) throws DatabaseException {
+                BasicResources.getInstance(graph);
+                return graph.syncRequest( DiagramRequests.getElementClass(resource, hints) );
+            }
+        };
+    }
+
+}