]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/modelBrowser/model/ComponentType.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.modeling.ui / src / org / simantics / modeling / ui / modelBrowser / model / ComponentType.java
index 21869f15d0251820613e70540932fd556a45de87..419268d860af7eb1f4f0ffc1b4cd9f934174a39d 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.modeling.ui.modelBrowser.model;\r
-\r
-import java.util.ArrayList;\r
-import java.util.Collection;\r
-\r
-import org.eclipse.jface.resource.ImageDescriptor;\r
-import org.simantics.browsing.ui.common.node.IModifiable;\r
-import org.simantics.browsing.ui.content.Labeler.Modifier;\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.Session;\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.request.Read;\r
-import org.simantics.layer0.Layer0;\r
-import org.simantics.modeling.ModelingResources;\r
-import org.simantics.modeling.ui.Activator;\r
-import org.simantics.structural.stubs.StructuralResource2;\r
-\r
-@Deprecated\r
-public class ComponentType extends Node implements IModifiable {\r
-\r
-    final static boolean showFolders = true;\r
-\r
-    Resource content;\r
-    Resource instance;\r
-\r
-    public ComponentType(ReadGraph g, Resource resource) throws DatabaseException {\r
-        this(g, resource, null);\r
-    }\r
-\r
-    public ComponentType(ReadGraph g, Resource resource, Resource instance) throws DatabaseException {\r
-        super(resource);\r
-        StructuralResource2 sr = StructuralResource2.getInstance(g);\r
-        this.content = g.getPossibleObject(resource, sr.IsDefinedBy);\r
-        this.instance = instance;\r
-    }\r
-\r
-    @Override\r
-    public Collection<?> getChildren(ReadGraph g) throws DatabaseException {\r
-        Collection<INode> ret = new ArrayList<INode>(3);\r
-        ret.add(new Interface(resource, instance, false));\r
-        if(content != null) {\r
-            ret.add(new Decorator(g.adapt(content, INode.class)) {\r
-                @Override\r
-                public String getLabel(ReadGraph g) {\r
-                    return "Content";\r
-                }\r
-            });\r
-        }\r
-        for(Resource symbol : g.getObjects(resource, ModelingResources.getInstance(g).ComponentTypeToSymbol))\r
-            ret.add(new Symbol(symbol));\r
-        if(!showFolders) {\r
-            ArrayList<Object> flatten = new ArrayList<Object>();\r
-            for(INode n : ret)\r
-                flatten.addAll(n.getChildren(g));\r
-            return flatten;\r
-        }\r
-        return ret;\r
-    }\r
-\r
-    @Override\r
-    public ImageDescriptor getImage(ReadGraph g) {\r
-        return Activator.COMPONENT_TYPE_ICON;\r
-    }\r
-\r
-    @Override\r
-    public String getLabel(ReadGraph g) throws DatabaseException {\r
-       Layer0 b = Layer0.getInstance(g);\r
-       return g.getPossibleRelatedValue(resource, b.HasName);\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().equals(obj.getClass()))\r
-            return false;\r
-        ComponentType other = (ComponentType)obj;\r
-        return resource.equals(other.resource)\r
-        && content.equals(other.content)\r
-        && (instance == null ? other.instance == null : instance.equals(other.instance));\r
-    }\r
-\r
-    @Override\r
-    public int hashCode() {\r
-        return ((getClass().hashCode()*31 + (instance == null ? 0 : instance.hashCode()))*31\r
-                +  content.hashCode())*31 + resource.hashCode();\r
-    }\r
-\r
-    @Override\r
-    public Modifier getModifier(final Session session, String columnId) {\r
-        return new Modifier() {\r
-\r
-            @Override\r
-            public String getValue() {\r
-                Read<String> request =\r
-                    new Read<String>() {\r
-\r
-                    @Override\r
-                    public String perform(ReadGraph graph) throws DatabaseException {\r
-                       Layer0 b = Layer0.getInstance(graph);\r
-                        String name = graph.getPossibleRelatedValue(resource, b.HasName);\r
-                        return name != null ? name : "";\r
-                    }\r
-\r
-                };\r
-                try {\r
-                    return session.syncRequest(request);\r
-                } catch (DatabaseException e) {\r
-                    e.printStackTrace();\r
-                    return "";\r
-                }\r
-            }\r
-\r
-            @Override\r
-            public String isValid(String label) {\r
-                return null;\r
-            }\r
-\r
-            @Override\r
-            public void modify(final String label) {\r
-                session.asyncRequest(new WriteRequest() {\r
-                    @Override\r
-                    public void perform(WriteGraph graph) throws DatabaseException {\r
-                       Layer0 b = Layer0.getInstance(graph);\r
-                        graph.claimLiteral(resource, b.HasName, label);\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.modeling.ui.modelBrowser.model;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.simantics.browsing.ui.common.node.IModifiable;
+import org.simantics.browsing.ui.content.Labeler.Modifier;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.Session;
+import org.simantics.db.WriteGraph;
+import org.simantics.db.common.request.WriteRequest;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.request.Read;
+import org.simantics.layer0.Layer0;
+import org.simantics.modeling.ModelingResources;
+import org.simantics.modeling.ui.Activator;
+import org.simantics.structural.stubs.StructuralResource2;
+
+@Deprecated
+public class ComponentType extends Node implements IModifiable {
+
+    final static boolean showFolders = true;
+
+    Resource content;
+    Resource instance;
+
+    public ComponentType(ReadGraph g, Resource resource) throws DatabaseException {
+        this(g, resource, null);
+    }
+
+    public ComponentType(ReadGraph g, Resource resource, Resource instance) throws DatabaseException {
+        super(resource);
+        StructuralResource2 sr = StructuralResource2.getInstance(g);
+        this.content = g.getPossibleObject(resource, sr.IsDefinedBy);
+        this.instance = instance;
+    }
+
+    @Override
+    public Collection<?> getChildren(ReadGraph g) throws DatabaseException {
+        Collection<INode> ret = new ArrayList<INode>(3);
+        ret.add(new Interface(resource, instance, false));
+        if(content != null) {
+            ret.add(new Decorator(g.adapt(content, INode.class)) {
+                @Override
+                public String getLabel(ReadGraph g) {
+                    return "Content";
+                }
+            });
+        }
+        for(Resource symbol : g.getObjects(resource, ModelingResources.getInstance(g).ComponentTypeToSymbol))
+            ret.add(new Symbol(symbol));
+        if(!showFolders) {
+            ArrayList<Object> flatten = new ArrayList<Object>();
+            for(INode n : ret)
+                flatten.addAll(n.getChildren(g));
+            return flatten;
+        }
+        return ret;
+    }
+
+    @Override
+    public ImageDescriptor getImage(ReadGraph g) {
+        return Activator.COMPONENT_TYPE_ICON;
+    }
+
+    @Override
+    public String getLabel(ReadGraph g) throws DatabaseException {
+       Layer0 b = Layer0.getInstance(g);
+       return g.getPossibleRelatedValue(resource, b.HasName);
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if(this == obj)
+            return true;
+        if(obj == null)
+            return false;
+        if(!getClass().equals(obj.getClass()))
+            return false;
+        ComponentType other = (ComponentType)obj;
+        return resource.equals(other.resource)
+        && content.equals(other.content)
+        && (instance == null ? other.instance == null : instance.equals(other.instance));
+    }
+
+    @Override
+    public int hashCode() {
+        return ((getClass().hashCode()*31 + (instance == null ? 0 : instance.hashCode()))*31
+                +  content.hashCode())*31 + resource.hashCode();
+    }
+
+    @Override
+    public Modifier getModifier(final Session session, String columnId) {
+        return new Modifier() {
+
+            @Override
+            public String getValue() {
+                Read<String> request =
+                    new Read<String>() {
+
+                    @Override
+                    public String perform(ReadGraph graph) throws DatabaseException {
+                       Layer0 b = Layer0.getInstance(graph);
+                        String name = graph.getPossibleRelatedValue(resource, b.HasName);
+                        return name != null ? name : "";
+                    }
+
+                };
+                try {
+                    return session.syncRequest(request);
+                } catch (DatabaseException e) {
+                    e.printStackTrace();
+                    return "";
+                }
+            }
+
+            @Override
+            public String isValid(String label) {
+                return null;
+            }
+
+            @Override
+            public void modify(final String label) {
+                session.asyncRequest(new WriteRequest() {
+                    @Override
+                    public void perform(WriteGraph graph) throws DatabaseException {
+                       Layer0 b = Layer0.getInstance(graph);
+                        graph.claimLiteral(resource, b.HasName, label);
+                    }
+                });
+            }
+
+        };
+    }
+}