-package org.simantics.modeling.ui.componentTypeEditor;\r
-\r
-import java.util.ArrayList;\r
-import java.util.List;\r
-\r
-import org.eclipse.ui.IEditorInput;\r
-import org.simantics.NameLabelMode;\r
-import org.simantics.NameLabelUtil;\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.common.ResourceArray;\r
-import org.simantics.db.common.request.PossibleIndexRoot;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.layer0.Layer0;\r
-import org.simantics.modeling.ui.features.EditorNamingService2;\r
-import org.simantics.ui.workbench.IEditorNamingService2;\r
-import org.simantics.ui.workbench.IResourceEditorInput;\r
-\r
-/**\r
- * Tries to:\r
- * <ul>\r
- * <li>resolve input path from model configuration to put in the tooltip</li>\r
- * <li>add (model-name) suffix to editor tooltip to tell apart editors with same title.</li>\r
- * </ul>\r
- * \r
- * The goal tooltip format is: path/input-name (model-name)\r
- * \r
- * @author Tuukka Lehtonen\r
- */\r
-public class ProceduralComponentTypeEditorNamingService extends EditorNamingService2 implements IEditorNamingService2 {\r
-\r
- @Override\r
- public String getName(ReadGraph graph, String editorId, IEditorInput input) throws DatabaseException {\r
- if (input instanceof IResourceEditorInput) {\r
- Resource code = ((IResourceEditorInput) input).getResource();\r
- if (code != null) {\r
- return truncated(getPropertyOwnerName(graph, code) + " (Code)", 256);\r
- }\r
- }\r
- return "Unsupported input: " + input;\r
- }\r
-\r
- @Override\r
- public String getToolTipText(ReadGraph graph, String editorId, IEditorInput input) throws DatabaseException {\r
- if (input instanceof IResourceEditorInput) {\r
- Resource code = ((IResourceEditorInput) input).getResource();\r
- if (code != null) {\r
- StringBuilder sb = new StringBuilder();\r
- getTooltip(graph, editorId, (IResourceEditorInput) input, sb);\r
- return sb.toString();\r
- }\r
- }\r
- return "Unsupported input: " + input;\r
- }\r
-\r
- private StringBuilder getTooltip(ReadGraph graph, String editorId, IResourceEditorInput input, StringBuilder sb) throws DatabaseException {\r
- Resource r = ((IResourceEditorInput) input).getResource();\r
- NameLabelMode mode = NameLabelUtil.getNameLabelMode(graph);\r
-\r
- String name = getName(graph, editorId, input);\r
- Layer0 L0 = Layer0.getInstance(graph);\r
- Resource owner = graph.getPossibleObject(r, L0.PropertyOf);\r
- if (owner != null) {\r
- Resource root = graph.syncRequest(new PossibleIndexRoot(owner));\r
- if (root != null) {\r
- ResourceArray path = getPathInIndexRoot(graph, owner);\r
- for (int i = path.size() - 2; i > 0; --i) {\r
- String segment = NameLabelUtil.modalName(graph, path.get(i), mode);\r
- if (segment.contains("/"))\r
- segment = "\"" + segment + "\"";\r
-\r
- sb.append(segment).append("/");\r
- }\r
- sb.append(name);\r
- String rootLabel = NameLabelUtil.modalName(graph, root, mode);\r
- sb.append(" (" + rootLabel + ")");\r
- return sb;\r
- }\r
- }\r
- sb.append(name);\r
- return sb;\r
- }\r
-\r
- private String getPropertyOwnerName(ReadGraph graph, Resource property) throws DatabaseException {\r
- Layer0 L0 = Layer0.getInstance(graph);\r
- Resource owner = graph.getPossibleObject(property, L0.PropertyOf);\r
- if (owner == null)\r
- return "No owner (Code)";\r
- return graph.getPossibleRelatedValue(owner, L0.HasName);\r
- }\r
-\r
- private static ResourceArray getPathInIndexRoot(ReadGraph graph, Resource r) throws DatabaseException {\r
- Layer0 L0 = Layer0.getInstance(graph);\r
- List<Resource> path = new ArrayList<Resource>();\r
- while (true) {\r
- path.add(r);\r
- if (graph.isInstanceOf(r, L0.IndexRoot))\r
- return new ResourceArray(path);\r
- Resource partOf = graph.getPossibleObject(r, L0.PartOf);\r
- if (partOf == null)\r
- return ResourceArray.EMPTY;\r
- r = partOf;\r
- }\r
- }\r
-\r
+package org.simantics.modeling.ui.componentTypeEditor;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.ui.IEditorInput;
+import org.simantics.NameLabelMode;
+import org.simantics.NameLabelUtil;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.common.ResourceArray;
+import org.simantics.db.common.request.PossibleIndexRoot;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.layer0.Layer0;
+import org.simantics.modeling.ui.features.EditorNamingService2;
+import org.simantics.ui.workbench.IEditorNamingService2;
+import org.simantics.ui.workbench.IResourceEditorInput;
+
+/**
+ * Tries to:
+ * <ul>
+ * <li>resolve input path from model configuration to put in the tooltip</li>
+ * <li>add (model-name) suffix to editor tooltip to tell apart editors with same title.</li>
+ * </ul>
+ *
+ * The goal tooltip format is: path/input-name (model-name)
+ *
+ * @author Tuukka Lehtonen
+ */
+public class ProceduralComponentTypeEditorNamingService extends EditorNamingService2 implements IEditorNamingService2 {
+
+ @Override
+ public String getName(ReadGraph graph, String editorId, IEditorInput input) throws DatabaseException {
+ if (input instanceof IResourceEditorInput) {
+ Resource code = ((IResourceEditorInput) input).getResource();
+ if (code != null) {
+ return truncated(getPropertyOwnerName(graph, code) + " (Code)", 256); //$NON-NLS-1$
+ }
+ }
+ return NLS.bind(Messages.ProceduralComponentTypeEditorNamingService_UnsupportedInput, input);
+ }
+
+ @Override
+ public String getToolTipText(ReadGraph graph, String editorId, IEditorInput input) throws DatabaseException {
+ if (input instanceof IResourceEditorInput) {
+ Resource code = ((IResourceEditorInput) input).getResource();
+ if (code != null) {
+ StringBuilder sb = new StringBuilder();
+ getTooltip(graph, editorId, (IResourceEditorInput) input, sb);
+ return sb.toString();
+ }
+ }
+ return NLS.bind(Messages.ProceduralComponentTypeEditorNamingService_UnsupportedInput, input);
+ }
+
+ private StringBuilder getTooltip(ReadGraph graph, String editorId, IResourceEditorInput input, StringBuilder sb) throws DatabaseException {
+ Resource r = ((IResourceEditorInput) input).getResource();
+ NameLabelMode mode = NameLabelUtil.getNameLabelMode(graph);
+
+ String name = getName(graph, editorId, input);
+ Layer0 L0 = Layer0.getInstance(graph);
+ Resource owner = graph.getPossibleObject(r, L0.PropertyOf);
+ if (owner != null) {
+ Resource root = graph.syncRequest(new PossibleIndexRoot(owner));
+ if (root != null) {
+ ResourceArray path = getPathInIndexRoot(graph, owner);
+ for (int i = path.size() - 2; i > 0; --i) {
+ String segment = NameLabelUtil.modalName(graph, path.get(i), mode);
+ if (segment.contains("/")) //$NON-NLS-1$
+ segment = "\"" + segment + "\""; //$NON-NLS-1$ //$NON-NLS-2$
+
+ sb.append(segment).append("/"); //$NON-NLS-1$
+ }
+ sb.append(name);
+ String rootLabel = NameLabelUtil.modalName(graph, root, mode);
+ sb.append(" (" + rootLabel + ")"); //$NON-NLS-1$ //$NON-NLS-2$
+ return sb;
+ }
+ }
+ sb.append(name);
+ return sb;
+ }
+
+ private String getPropertyOwnerName(ReadGraph graph, Resource property) throws DatabaseException {
+ Layer0 L0 = Layer0.getInstance(graph);
+ Resource owner = graph.getPossibleObject(property, L0.PropertyOf);
+ if (owner == null)
+ return "No owner (Code)"; //$NON-NLS-1$
+ return graph.getPossibleRelatedValue(owner, L0.HasName);
+ }
+
+ private static ResourceArray getPathInIndexRoot(ReadGraph graph, Resource r) throws DatabaseException {
+ Layer0 L0 = Layer0.getInstance(graph);
+ List<Resource> path = new ArrayList<Resource>();
+ while (true) {
+ path.add(r);
+ if (graph.isInstanceOf(r, L0.IndexRoot))
+ return new ResourceArray(path);
+ Resource partOf = graph.getPossibleObject(r, L0.PartOf);
+ if (partOf == null)
+ return ResourceArray.EMPTY;
+ r = partOf;
+ }
+ }
+
}
\ No newline at end of file