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