]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/modelBrowser/model/Component.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.modeling.ui / src / org / simantics / modeling / ui / modelBrowser / model / Component.java
index eca555ea0945a1ca29e27a4abbe4d8a6e7dcb111..c6a711013845501b30757889a8e2e18e9f3fd82a 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.ResourceArray;\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.ui.Activator;\r
-import org.simantics.structural.stubs.StructuralResource2;\r
-\r
-@Deprecated\r
-public class Component extends PathNode implements IModifiable {\r
-\r
-    Resource type;\r
-\r
-    public Component(ReadGraph g, Resource resource) throws DatabaseException {\r
-        super(resource);\r
-        StructuralResource2 sr = StructuralResource2.getInstance(g);\r
-        type = g.getSingleType(resource, sr.Component);\r
-    }\r
-\r
-    INode type(ReadGraph g) throws DatabaseException {\r
-        return new ComponentType(g, type, resource);\r
-    }\r
-\r
-    @Override\r
-    public Collection<?> getChildren(ReadGraph g) throws DatabaseException {\r
-        Layer0 l0 = Layer0.getInstance(g);\r
-\r
-        StructuralResource2 sr = StructuralResource2.getInstance(g);\r
-        Resource composite = g.getPossibleObject(type, sr.IsDefinedBy);\r
-        ArrayList<Object> result = new ArrayList<Object>();\r
-        result.addAll(new Interface(type, resource, true).getChildren(g));\r
-        ResourceArray newPath = null;\r
-        if(path != null) {\r
-            newPath = path.appended(resource);\r
-        } else {\r
-            newPath = new ResourceArray(resource);\r
-        }\r
-        if(composite != null)\r
-            for(Resource component : g.getObjects(composite, l0.ConsistsOf)) {\r
-                INode node = g.getPossibleAdapter(component, INode.class);\r
-                if (node != null) {\r
-                    if(node instanceof IPathNode) {\r
-                        ((IPathNode)node).setPath(newPath);\r
-                    }\r
-                    result.add(node);\r
-                }\r
-            }\r
-        return result;\r
-    }\r
-\r
-    @Override\r
-    public ImageDescriptor getImage(ReadGraph g) {\r
-        return Activator.COMPONENT_ICON;\r
-    }\r
-\r
-    @Override\r
-    public String getLabel(ReadGraph g) throws DatabaseException {\r
-        Layer0 l0 = Layer0.getInstance(g);\r
-        String name = (String)g.getPossibleRelatedValue(resource, l0.HasName);\r
-        if(name == null)\r
-            name = "";\r
-        return name + " : " + type(g).getLabel(g);\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
-        Component other = (Component)obj;\r
-        return resource.equals(other.resource)\r
-        && type.equals(other.type);\r
-    }\r
-\r
-    @Override\r
-    public int hashCode() {\r
-        return (getClass().hashCode()*31 + type.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.ResourceArray;
+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.ui.Activator;
+import org.simantics.structural.stubs.StructuralResource2;
+
+@Deprecated
+public class Component extends PathNode implements IModifiable {
+
+    Resource type;
+
+    public Component(ReadGraph g, Resource resource) throws DatabaseException {
+        super(resource);
+        StructuralResource2 sr = StructuralResource2.getInstance(g);
+        type = g.getSingleType(resource, sr.Component);
+    }
+
+    INode type(ReadGraph g) throws DatabaseException {
+        return new ComponentType(g, type, resource);
+    }
+
+    @Override
+    public Collection<?> getChildren(ReadGraph g) throws DatabaseException {
+        Layer0 l0 = Layer0.getInstance(g);
+
+        StructuralResource2 sr = StructuralResource2.getInstance(g);
+        Resource composite = g.getPossibleObject(type, sr.IsDefinedBy);
+        ArrayList<Object> result = new ArrayList<Object>();
+        result.addAll(new Interface(type, resource, true).getChildren(g));
+        ResourceArray newPath = null;
+        if(path != null) {
+            newPath = path.appended(resource);
+        } else {
+            newPath = new ResourceArray(resource);
+        }
+        if(composite != null)
+            for(Resource component : g.getObjects(composite, l0.ConsistsOf)) {
+                INode node = g.getPossibleAdapter(component, INode.class);
+                if (node != null) {
+                    if(node instanceof IPathNode) {
+                        ((IPathNode)node).setPath(newPath);
+                    }
+                    result.add(node);
+                }
+            }
+        return result;
+    }
+
+    @Override
+    public ImageDescriptor getImage(ReadGraph g) {
+        return Activator.COMPONENT_ICON;
+    }
+
+    @Override
+    public String getLabel(ReadGraph g) throws DatabaseException {
+        Layer0 l0 = Layer0.getInstance(g);
+        String name = (String)g.getPossibleRelatedValue(resource, l0.HasName);
+        if(name == null)
+            name = "";
+        return name + " : " + type(g).getLabel(g);
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if(this == obj)
+            return true;
+        if(obj == null)
+            return false;
+        if(!getClass().equals(obj.getClass()))
+            return false;
+        Component other = (Component)obj;
+        return resource.equals(other.resource)
+        && type.equals(other.type);
+    }
+
+    @Override
+    public int hashCode() {
+        return (getClass().hashCode()*31 + type.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);
+                    }
+                });
+            }
+
+        };
+    }
+}