1 /*******************************************************************************
\r
2 * Copyright (c) 2014 Association for Decentralized Information Management
\r
3 * in Industry THTH ry.
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 * Semantum Oy - initial API and implementation
\r
12 *******************************************************************************/
\r
13 package org.simantics.ui.workbench;
\r
15 import org.simantics.databoard.Bindings;
\r
16 import org.simantics.db.ReadGraph;
\r
17 import org.simantics.db.Resource;
\r
18 import org.simantics.db.common.request.UnaryRead;
\r
19 import org.simantics.db.exception.DatabaseException;
\r
20 import org.simantics.layer0.Layer0;
\r
23 * A simple request that takes an IResourceEditorInput as input and calculates
\r
24 * the following editor title from it:
\r
25 * <code>input-name (input-parent-name)</code>.
\r
27 * @author Hannu Niemistö
\r
28 * @author Tuukka Lehtonen
\r
31 public class TitleWithParentNameRequest extends UnaryRead<IResourceEditorInput, String> {
\r
33 public TitleWithParentNameRequest(IResourceEditorInput input) {
\r
38 public String perform(ReadGraph graph) throws DatabaseException {
\r
39 Layer0 L0 = Layer0.getInstance(graph);
\r
40 Resource r = parameter.getResource();
\r
41 Resource parent = graph.getPossibleObject(r, L0.PartOf);
\r
42 String name = safeName(graph, r, "No name", L0);
\r
43 String parentName = safeName(graph, parent, "No parent", L0);
\r
44 return name + " (" + parentName + ")";
\r
47 protected String safeName(ReadGraph graph, Resource r, String noNameValue, Layer0 L0) throws DatabaseException {
\r
49 String name = graph.getPossibleRelatedValue(r, L0.HasName, Bindings.STRING);
\r