]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/DefaultTerminalNamingStrategy.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.modeling.ui / src / org / simantics / modeling / ui / diagramEditor / DefaultTerminalNamingStrategy.java
index 78a4714ebb9b65ed820b89b2d0283f63ed6a0db5..b24970ffd67a1b7cb5f1c26db62b09ad0399dee4 100644 (file)
-/*******************************************************************************\r
- * Copyright (c) 2012 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
- *     Semantum Oy - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.modeling.ui.diagramEditor;\r
-\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.common.request.UnaryRead;\r
-import org.simantics.db.common.utils.NameUtils;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.diagram.synchronization.graph.DiagramGraphUtil;\r
-import org.simantics.g2d.diagram.participant.pointertool.TerminalUtil.TerminalInfo;\r
-import org.simantics.g2d.element.ElementUtils;\r
-import org.simantics.layer0.Layer0;\r
-import org.simantics.modeling.ModelingResources;\r
-import org.simantics.modeling.ui.diagramEditor.TerminalInformer.TerminalNamingStrategy;\r
-import org.simantics.structural.stubs.StructuralResource2;\r
-import org.simantics.structural2.queries.Terminal;\r
-\r
-/**\r
- * @author Tuukka Lehtonen\r
- */\r
-public final class DefaultTerminalNamingStrategy implements TerminalNamingStrategy {\r
-\r
-    @Override\r
-    public String getName(ReadGraph graph, TerminalInfo info) throws DatabaseException {\r
-        Terminal t = graph.syncRequest(new ResolveTerminal(info));\r
-        if (t == null)\r
-            return "Could not resolve component terminal";\r
-        return graph.syncRequest(new TerminalMessage(t));\r
-    }\r
-\r
-    public static class ResolveTerminal extends UnaryRead<TerminalInfo, Terminal> {\r
-\r
-        public ResolveTerminal(TerminalInfo parameter) {\r
-            super(parameter);\r
-        }\r
-\r
-        @Override\r
-        public Terminal perform(ReadGraph graph) throws DatabaseException {\r
-            ModelingResources mr = ModelingResources.getInstance(graph);\r
-\r
-            Object elementObject = ElementUtils.getObject(parameter.e);\r
-            if (!(elementObject instanceof Resource))\r
-                return null;\r
-            Resource element = (Resource) elementObject;\r
-\r
-            Resource diagramBindingRelation = DiagramGraphUtil.getConnectionPointOfTerminal(graph, parameter.t);\r
-            if (diagramBindingRelation == null)\r
-                return null;\r
-\r
-            Resource component = graph.getPossibleObject(element, mr.ElementToComponent);\r
-            Resource connectionRelation = graph.getPossibleObject(diagramBindingRelation, mr.DiagramConnectionRelationToConnectionRelation);\r
-            if (component == null || connectionRelation == null)\r
-                return null;\r
-\r
-            return new Terminal(component, connectionRelation);\r
-        }\r
-\r
-    }\r
-\r
-    static class TerminalMessage extends UnaryRead<Terminal, String> {\r
-\r
-        public TerminalMessage(Terminal terminal) {\r
-            super(terminal);\r
-        }\r
-\r
-        @Override\r
-        public String perform(ReadGraph graph) throws DatabaseException {\r
-            Layer0 L0 = Layer0.getInstance(graph);\r
-            StructuralResource2 STR = StructuralResource2.getInstance(graph);\r
-\r
-            String name = getStringPropertyValue(graph, parameter.getRelation(), L0.HasName);\r
-            String label = getStringPropertyValue(graph, parameter.getRelation(), L0.HasLabel);\r
-            String componentName = NameUtils.getSafeName(graph, parameter.getComponent());\r
-            Resource componentType = graph.getPossibleType(parameter.getComponent(), STR.Component);\r
-            String componentTypeName = componentType != null\r
-                    ? getStringPropertyValue(graph, componentType, L0.HasLabel)\r
-                    : null;\r
-\r
-            StringBuilder sb = new StringBuilder();\r
-            if (name.equals(label)) {\r
-                sb.append(name);\r
-            } else {\r
-                sb.append("(").append(name).append(") ").append(label);\r
-            }\r
-            sb.append(" [").append(componentName);\r
-            if (componentTypeName != null)\r
-                sb.append(" : ").append(componentTypeName);\r
-            sb.append("]");\r
-\r
-            return sb.toString();\r
-        }\r
-\r
-        private String getStringPropertyValue(ReadGraph graph, Resource entity, Resource property) throws DatabaseException {\r
-            String name = graph.getPossibleRelatedValue2(entity, property);\r
-            return name != null ? name : NameUtils.getSafeName(graph, entity);\r
-        }\r
-\r
-    }\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2012 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:
+ *     Semantum Oy - initial API and implementation
+ *******************************************************************************/
+package org.simantics.modeling.ui.diagramEditor;
+
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.common.request.UnaryRead;
+import org.simantics.db.common.utils.NameUtils;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.diagram.synchronization.graph.DiagramGraphUtil;
+import org.simantics.g2d.diagram.participant.pointertool.TerminalUtil.TerminalInfo;
+import org.simantics.g2d.element.ElementUtils;
+import org.simantics.layer0.Layer0;
+import org.simantics.modeling.ModelingResources;
+import org.simantics.modeling.ui.diagramEditor.TerminalInformer.TerminalNamingStrategy;
+import org.simantics.structural.stubs.StructuralResource2;
+import org.simantics.structural2.queries.Terminal;
+
+/**
+ * @author Tuukka Lehtonen
+ */
+public final class DefaultTerminalNamingStrategy implements TerminalNamingStrategy {
+
+    @Override
+    public String getName(ReadGraph graph, TerminalInfo info) throws DatabaseException {
+        Terminal t = graph.syncRequest(new ResolveTerminal(info));
+        if (t == null)
+            return "Could not resolve component terminal";
+        return graph.syncRequest(new TerminalMessage(t));
+    }
+
+    public static class ResolveTerminal extends UnaryRead<TerminalInfo, Terminal> {
+
+        public ResolveTerminal(TerminalInfo parameter) {
+            super(parameter);
+        }
+
+        @Override
+        public Terminal perform(ReadGraph graph) throws DatabaseException {
+            ModelingResources mr = ModelingResources.getInstance(graph);
+
+            Object elementObject = ElementUtils.getObject(parameter.e);
+            if (!(elementObject instanceof Resource))
+                return null;
+            Resource element = (Resource) elementObject;
+
+            Resource diagramBindingRelation = DiagramGraphUtil.getConnectionPointOfTerminal(graph, parameter.t);
+            if (diagramBindingRelation == null)
+                return null;
+
+            Resource component = graph.getPossibleObject(element, mr.ElementToComponent);
+            Resource connectionRelation = graph.getPossibleObject(diagramBindingRelation, mr.DiagramConnectionRelationToConnectionRelation);
+            if (component == null || connectionRelation == null)
+                return null;
+
+            return new Terminal(component, connectionRelation);
+        }
+
+    }
+
+    static class TerminalMessage extends UnaryRead<Terminal, String> {
+
+        public TerminalMessage(Terminal terminal) {
+            super(terminal);
+        }
+
+        @Override
+        public String perform(ReadGraph graph) throws DatabaseException {
+            Layer0 L0 = Layer0.getInstance(graph);
+            StructuralResource2 STR = StructuralResource2.getInstance(graph);
+
+            String name = getStringPropertyValue(graph, parameter.getRelation(), L0.HasName);
+            String label = getStringPropertyValue(graph, parameter.getRelation(), L0.HasLabel);
+            String componentName = NameUtils.getSafeName(graph, parameter.getComponent());
+            Resource componentType = graph.getPossibleType(parameter.getComponent(), STR.Component);
+            String componentTypeName = componentType != null
+                    ? getStringPropertyValue(graph, componentType, L0.HasLabel)
+                    : null;
+
+            StringBuilder sb = new StringBuilder();
+            if (name.equals(label)) {
+                sb.append(name);
+            } else {
+                sb.append("(").append(name).append(") ").append(label);
+            }
+            sb.append(" [").append(componentName);
+            if (componentTypeName != null)
+                sb.append(" : ").append(componentTypeName);
+            sb.append("]");
+
+            return sb.toString();
+        }
+
+        private String getStringPropertyValue(ReadGraph graph, Resource entity, Resource property) throws DatabaseException {
+            String name = graph.getPossibleRelatedValue2(entity, property);
+            return name != null ? name : NameUtils.getSafeName(graph, entity);
+        }
+
+    }
+
+}