]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.browsing.ui.model/src/org/simantics/browsing/ui/model/nodetypes/SpecialNodeType.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.browsing.ui.model / src / org / simantics / browsing / ui / model / nodetypes / SpecialNodeType.java
index 9020abd57f8cd0ba271fd1270807a42ed87d62ff..ddd6113ff57ca77ee6f0e08ca0a7f54ec4836ebf 100644 (file)
-/*******************************************************************************\r
- * Copyright (c) 2010, 2011 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.browsing.ui.model.nodetypes;\r
-\r
-import java.util.Collection;\r
-import java.util.Collections;\r
-\r
-import org.eclipse.core.runtime.Platform;\r
-import org.osgi.framework.Bundle;\r
-import org.simantics.browsing.ui.NodeContext;\r
-import org.simantics.browsing.ui.common.NodeContextBuilder;\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.Statement;\r
-import org.simantics.db.common.utils.NameUtils;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.layer0.variable.Variable;\r
-import org.simantics.ui.selection.WorkbenchSelectionElement;\r
-import org.simantics.viewpoint.ontology.ViewpointResource;\r
-\r
-public class SpecialNodeType implements NodeType {\r
-    public Resource resource;\r
-    Class<?> contentType;\r
-    \r
-    public SpecialNodeType(Resource resource, Class<?> contentType) {\r
-        this.resource = resource;\r
-        this.contentType = contentType;\r
-    }\r
-    \r
-    public static SpecialNodeType create(ReadGraph g, Resource r) throws DatabaseException {\r
-        ViewpointResource vr = ViewpointResource.getInstance(g);\r
-        String contentTypeName = g.getPossibleRelatedValue(r, vr.HasContentType);\r
-        Class<?> contentType;\r
-        if("Resource".equals(contentTypeName))\r
-            contentType = Resource.class;\r
-        else if("Statement".equals(contentTypeName))\r
-            contentType = Statement.class;\r
-        else if("Variable".equals(contentTypeName))\r
-            contentType = Variable.class;\r
-        else {\r
-            contentType = Object.class;\r
-            if(contentTypeName != null)\r
-                try {\r
-                    String bundleId = g.getPossibleRelatedValue(r, vr.HasBundle);\r
-                    Bundle bundle = null;\r
-                    if (bundleId != null) {\r
-                        bundle = Platform.getBundle(bundleId);\r
-                        if (bundle == null)\r
-                            System.err.println("Referenced bundle '" + bundleId + "' not found in platform.");\r
-                    }\r
-                    if (bundle != null)\r
-                        contentType = bundle.loadClass(contentTypeName);\r
-                    else\r
-                        contentType = Class.forName(contentTypeName);\r
-                } catch (ClassNotFoundException e) {\r
-                    System.err.println("Unknown content type " + contentTypeName);\r
-                }\r
-            else\r
-                System.err.println("Content type is NULL.");\r
-        }\r
-        return new SpecialNodeType(r, contentType);\r
-    }\r
-\r
-    @Override\r
-    public NodeContext createNodeContext(ReadGraph graph, Object content)\r
-            throws DatabaseException {\r
-        if(contentType.isInstance(content))\r
-            return NodeContextBuilder.buildWithData(KEY_SEQUENCE,\r
-                    new Object[] {content, this}\r
-            );\r
-        else\r
-            return null;\r
-    }\r
-\r
-    @Override\r
-    public Class<?> getContentType() {\r
-        return contentType;\r
-    }\r
-\r
-    @Override\r
-    public int hashCode() {\r
-        return resource.hashCode();\r
-    }\r
-\r
-    @Override\r
-    public boolean equals(Object obj) {\r
-        if (this == obj)\r
-            return true;\r
-        if (obj == null)\r
-            return false;\r
-        if (getClass() != obj.getClass())\r
-            return false;\r
-        SpecialNodeType other = (SpecialNodeType) obj;\r
-        return resource.equals(other.resource);\r
-    }\r
-\r
-    @Override\r
-    public boolean inherits(ReadGraph graph, NodeType superType) {\r
-        // Special node type does not support inheritance\r
-        return equals(superType);\r
-    }\r
-\r
-    @Override\r
-    public Collection<NodeType> getSuper(ReadGraph g) {\r
-        return Collections.emptyList();\r
-    }\r
-    \r
-    @Override\r
-    public String toString(ReadGraph graph) throws DatabaseException {\r
-        return "(" + NameUtils.getSafeName(graph, resource) + ")";\r
-    }\r
-\r
-    @Override\r
-    public WorkbenchSelectionElement getWorkbenchSelectionElement(NodeContext context) {\r
-        return null;\r
-    }\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2010, 2011 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.browsing.ui.model.nodetypes;
+
+import java.util.Collection;
+import java.util.Collections;
+
+import org.eclipse.core.runtime.Platform;
+import org.osgi.framework.Bundle;
+import org.simantics.browsing.ui.NodeContext;
+import org.simantics.browsing.ui.common.NodeContextBuilder;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.Statement;
+import org.simantics.db.common.utils.NameUtils;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.variable.Variable;
+import org.simantics.ui.selection.WorkbenchSelectionElement;
+import org.simantics.viewpoint.ontology.ViewpointResource;
+
+public class SpecialNodeType implements NodeType {
+    public Resource resource;
+    Class<?> contentType;
+    
+    public SpecialNodeType(Resource resource, Class<?> contentType) {
+        this.resource = resource;
+        this.contentType = contentType;
+    }
+    
+    public static SpecialNodeType create(ReadGraph g, Resource r) throws DatabaseException {
+        ViewpointResource vr = ViewpointResource.getInstance(g);
+        String contentTypeName = g.getPossibleRelatedValue(r, vr.HasContentType);
+        Class<?> contentType;
+        if("Resource".equals(contentTypeName))
+            contentType = Resource.class;
+        else if("Statement".equals(contentTypeName))
+            contentType = Statement.class;
+        else if("Variable".equals(contentTypeName))
+            contentType = Variable.class;
+        else {
+            contentType = Object.class;
+            if(contentTypeName != null)
+                try {
+                    String bundleId = g.getPossibleRelatedValue(r, vr.HasBundle);
+                    Bundle bundle = null;
+                    if (bundleId != null) {
+                        bundle = Platform.getBundle(bundleId);
+                        if (bundle == null)
+                            System.err.println("Referenced bundle '" + bundleId + "' not found in platform.");
+                    }
+                    if (bundle != null)
+                        contentType = bundle.loadClass(contentTypeName);
+                    else
+                        contentType = Class.forName(contentTypeName);
+                } catch (ClassNotFoundException e) {
+                    System.err.println("Unknown content type " + contentTypeName);
+                }
+            else
+                System.err.println("Content type is NULL.");
+        }
+        return new SpecialNodeType(r, contentType);
+    }
+
+    @Override
+    public NodeContext createNodeContext(ReadGraph graph, Object content)
+            throws DatabaseException {
+        if(contentType.isInstance(content))
+            return NodeContextBuilder.buildWithData(KEY_SEQUENCE,
+                    new Object[] {content, this}
+            );
+        else
+            return null;
+    }
+
+    @Override
+    public Class<?> getContentType() {
+        return contentType;
+    }
+
+    @Override
+    public int hashCode() {
+        return resource.hashCode();
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj)
+            return true;
+        if (obj == null)
+            return false;
+        if (getClass() != obj.getClass())
+            return false;
+        SpecialNodeType other = (SpecialNodeType) obj;
+        return resource.equals(other.resource);
+    }
+
+    @Override
+    public boolean inherits(ReadGraph graph, NodeType superType) {
+        // Special node type does not support inheritance
+        return equals(superType);
+    }
+
+    @Override
+    public Collection<NodeType> getSuper(ReadGraph g) {
+        return Collections.emptyList();
+    }
+    
+    @Override
+    public String toString(ReadGraph graph) throws DatabaseException {
+        return "(" + NameUtils.getSafeName(graph, resource) + ")";
+    }
+
+    @Override
+    public WorkbenchSelectionElement getWorkbenchSelectionElement(NodeContext context) {
+        return null;
+    }
+
+}