]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/modelBrowser/model/Parameter.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.modeling.ui / src / org / simantics / modeling / ui / modelBrowser / model / Parameter.java
index 0f1f1b49a1331a926be241114634b172fdbae21d..afa7c7ad34ceaa82774e49e740796805790896d6 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 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.Statement;\r
-import org.simantics.db.WriteGraph;\r
-import org.simantics.db.common.primitiverequest.RelatedValueImplied;\r
-import org.simantics.db.common.request.WriteRequest;\r
-import org.simantics.db.common.utils.NameUtils;\r
-import org.simantics.db.exception.DatabaseException;\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 Parameter extends Node implements IModifiable {\r
-\r
-    Resource instance;\r
-    Resource relation;\r
-    Resource connectionType;\r
-    Resource connectionDirection;\r
-    boolean isLeaf;\r
-\r
-    public Resource getTerminalRelation(ReadGraph graph, Resource relation) throws DatabaseException {\r
-        StructuralResource2 sr = StructuralResource2.getInstance(graph);\r
-        for(Resource bound : graph.getObjects(relation, sr.IsBoundBy)) {\r
-            if(graph.isInstanceOf(bound, sr.Connection)) {\r
-                for(Statement terminalInverse : graph.getStatements(bound, sr.IsConnectedTo)) {\r
-                    if(graph.isInstanceOf(terminalInverse.getObject(), sr.Component)) {\r
-                        return graph.getInverse(terminalInverse.getPredicate());\r
-                    }\r
-                }\r
-            }\r
-        }\r
-        return null;\r
-    }\r
-\r
-    public Resource getConnectionType(ReadGraph graph, Resource connectionPoint) throws DatabaseException {\r
-        StructuralResource2 sr = StructuralResource2.getInstance(graph);\r
-        ModelingResources mr = ModelingResources.getInstance(graph);\r
-        for(Resource bound : graph.getObjects(relation, sr.IsBoundBy)) {\r
-            if(graph.isInstanceOf(bound, sr.Connection)) {\r
-                Resource diagramConn = graph.getPossibleObject(bound, mr.ConnectionToDiagramConnection);\r
-                if(diagramConn != null) {\r
-                    return graph.getPossibleObject(diagramConn, sr.HasConnectionType);\r
-                }\r
-            }\r
-        }\r
-        return null;\r
-    }\r
-\r
-    public Parameter(ReadGraph g, Resource resource, Resource instance, boolean isLeaf) throws DatabaseException {\r
-        super(resource);\r
-        this.instance = instance;\r
-        StructuralResource2 sr = StructuralResource2.getInstance(g);\r
-        this.relation = g.getSingleObject(resource, sr.Binds);\r
-//             this.connectionType = g.getPossibleObject(resource, sr.HasConnectionType);\r
-        this.connectionDirection = g.getPossibleObject(resource, sr.HasConnectionDirection);\r
-        this.isLeaf = isLeaf;\r
-        this.connectionType = getConnectionType(g, relation);\r
-    }\r
-\r
-    @Override\r
-    public String getLabel(ReadGraph g) throws DatabaseException {\r
-       Layer0 b = Layer0.getInstance(g);\r
-        String name = g.getPossibleRelatedValue(relation, b.HasName);\r
-        if(name == null)\r
-            return "Unnamed parameter";\r
-        if(connectionType != null) {\r
-            name = name + " : " + NameUtils.getSafeName(g, connectionType);\r
-            if(connectionDirection != null) {\r
-                StructuralResource2 sr = StructuralResource2.getInstance(g);\r
-                name = name + ", " +\r
-                (sr.InputDirection.equals(connectionDirection) ? "in" :\r
-                    sr.OutputDirection.equals(connectionDirection) ? "out" :\r
-                        NameUtils.getSafeName(g, connectionDirection));\r
-            }\r
-        }\r
-        return name;\r
-    }\r
-\r
-    @Override\r
-    public ImageDescriptor getImage(ReadGraph g) throws DatabaseException {\r
-        /*StructuralResource2 sr = StructuralResource2.getInstance(g);\r
-        if (g.isInstanceOf(resource, sr.LiteralVariable))\r
-            return Activator.VARIABLE_ICON;*/\r
-        return Activator.OPEN_CONNECTION_ICON;\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
-        Parameter other = (Parameter)obj;\r
-        return resource.equals(other.resource)\r
-        && relation.equals(other.relation)\r
-        && (instance == null ? other.instance==null : instance.equals(other.instance))\r
-        && isLeaf == other.isLeaf\r
-        && (connectionType == null ? other.connectionType == null : connectionType.equals(other.connectionType));\r
-    }\r
-\r
-    @Override\r
-    public int hashCode() {\r
-        return ((getClass().hashCode()*31 + relation.hashCode()) * 31  +\r
-                (instance == null ? 0 : instance.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
-                try {\r
-                       Layer0 b = Layer0.getInstance(session);\r
-                    return session.syncRequest(new RelatedValueImplied<String>(relation, b.HasName));\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(relation, b.HasName, label);\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.modeling.ui.modelBrowser.model;
+
+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.Statement;
+import org.simantics.db.WriteGraph;
+import org.simantics.db.common.primitiverequest.RelatedValueImplied;
+import org.simantics.db.common.request.WriteRequest;
+import org.simantics.db.common.utils.NameUtils;
+import org.simantics.db.exception.DatabaseException;
+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 Parameter extends Node implements IModifiable {
+
+    Resource instance;
+    Resource relation;
+    Resource connectionType;
+    Resource connectionDirection;
+    boolean isLeaf;
+
+    public Resource getTerminalRelation(ReadGraph graph, Resource relation) throws DatabaseException {
+        StructuralResource2 sr = StructuralResource2.getInstance(graph);
+        for(Resource bound : graph.getObjects(relation, sr.IsBoundBy)) {
+            if(graph.isInstanceOf(bound, sr.Connection)) {
+                for(Statement terminalInverse : graph.getStatements(bound, sr.IsConnectedTo)) {
+                    if(graph.isInstanceOf(terminalInverse.getObject(), sr.Component)) {
+                        return graph.getInverse(terminalInverse.getPredicate());
+                    }
+                }
+            }
+        }
+        return null;
+    }
+
+    public Resource getConnectionType(ReadGraph graph, Resource connectionPoint) throws DatabaseException {
+        StructuralResource2 sr = StructuralResource2.getInstance(graph);
+        ModelingResources mr = ModelingResources.getInstance(graph);
+        for(Resource bound : graph.getObjects(relation, sr.IsBoundBy)) {
+            if(graph.isInstanceOf(bound, sr.Connection)) {
+                Resource diagramConn = graph.getPossibleObject(bound, mr.ConnectionToDiagramConnection);
+                if(diagramConn != null) {
+                    return graph.getPossibleObject(diagramConn, sr.HasConnectionType);
+                }
+            }
+        }
+        return null;
+    }
+
+    public Parameter(ReadGraph g, Resource resource, Resource instance, boolean isLeaf) throws DatabaseException {
+        super(resource);
+        this.instance = instance;
+        StructuralResource2 sr = StructuralResource2.getInstance(g);
+        this.relation = g.getSingleObject(resource, sr.Binds);
+//             this.connectionType = g.getPossibleObject(resource, sr.HasConnectionType);
+        this.connectionDirection = g.getPossibleObject(resource, sr.HasConnectionDirection);
+        this.isLeaf = isLeaf;
+        this.connectionType = getConnectionType(g, relation);
+    }
+
+    @Override
+    public String getLabel(ReadGraph g) throws DatabaseException {
+       Layer0 b = Layer0.getInstance(g);
+        String name = g.getPossibleRelatedValue(relation, b.HasName);
+        if(name == null)
+            return "Unnamed parameter";
+        if(connectionType != null) {
+            name = name + " : " + NameUtils.getSafeName(g, connectionType);
+            if(connectionDirection != null) {
+                StructuralResource2 sr = StructuralResource2.getInstance(g);
+                name = name + ", " +
+                (sr.InputDirection.equals(connectionDirection) ? "in" :
+                    sr.OutputDirection.equals(connectionDirection) ? "out" :
+                        NameUtils.getSafeName(g, connectionDirection));
+            }
+        }
+        return name;
+    }
+
+    @Override
+    public ImageDescriptor getImage(ReadGraph g) throws DatabaseException {
+        /*StructuralResource2 sr = StructuralResource2.getInstance(g);
+        if (g.isInstanceOf(resource, sr.LiteralVariable))
+            return Activator.VARIABLE_ICON;*/
+        return Activator.OPEN_CONNECTION_ICON;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if(this == obj)
+            return true;
+        if(obj == null)
+            return false;
+        if(!getClass().equals(obj.getClass()))
+            return false;
+        Parameter other = (Parameter)obj;
+        return resource.equals(other.resource)
+        && relation.equals(other.relation)
+        && (instance == null ? other.instance==null : instance.equals(other.instance))
+        && isLeaf == other.isLeaf
+        && (connectionType == null ? other.connectionType == null : connectionType.equals(other.connectionType));
+    }
+
+    @Override
+    public int hashCode() {
+        return ((getClass().hashCode()*31 + relation.hashCode()) * 31  +
+                (instance == null ? 0 : instance.hashCode()))*31 + resource.hashCode();
+    }    
+
+    @Override
+    public Modifier getModifier(final Session session, String columnId) {
+        return new Modifier() {
+
+            @Override
+            public String getValue() {
+                try {
+                       Layer0 b = Layer0.getInstance(session);
+                    return session.syncRequest(new RelatedValueImplied<String>(relation, b.HasName));
+                } 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(relation, b.HasName, label);
+                    }
+
+                });
+            }
+
+        };
+    }
+}