--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2014 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
+ * Semantum Oy - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.ui.workbench;\r
+\r
+import org.simantics.databoard.Bindings;\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.exception.DatabaseException;\r
+import org.simantics.layer0.Layer0;\r
+\r
+/**\r
+ * A simple request that takes an IResourceEditorInput as input and calculates\r
+ * the following editor title from it:\r
+ * <code>input-name (input-parent-name)</code>.\r
+ * \r
+ * @author Hannu Niemistö\r
+ * @author Tuukka Lehtonen\r
+ * @see TitleRequest\r
+ */\r
+public class TitleWithParentNameRequest extends UnaryRead<IResourceEditorInput, String> {\r
+\r
+ public TitleWithParentNameRequest(IResourceEditorInput input) {\r
+ super(input);\r
+ }\r
+\r
+ @Override\r
+ public String perform(ReadGraph graph) throws DatabaseException {\r
+ Layer0 L0 = Layer0.getInstance(graph);\r
+ Resource r = parameter.getResource();\r
+ Resource parent = graph.getPossibleObject(r, L0.PartOf);\r
+ String name = safeName(graph, r, "No name", L0);\r
+ String parentName = safeName(graph, parent, "No parent", L0);\r
+ return name + " (" + parentName + ")";\r
+ }\r
+\r
+ protected String safeName(ReadGraph graph, Resource r, String noNameValue, Layer0 L0) throws DatabaseException {\r
+ if (r != null) {\r
+ String name = graph.getPossibleRelatedValue(r, L0.HasName, Bindings.STRING);\r
+ if (name != null) {\r
+ return name;\r
+ }\r
+ }\r
+ return noNameValue;\r
+ }\r
+ \r
+}\r