]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.ui/src/org/simantics/ui/workbench/TitleRequest.java
Modified OpenWith for further customization.
[simantics/platform.git] / bundles / org.simantics.ui / src / org / simantics / ui / workbench / TitleRequest.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
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
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.ui.workbench;
13
14 import org.simantics.db.ReadGraph;
15 import org.simantics.db.Resource;
16 import org.simantics.db.common.utils.NameUtils;
17 import org.simantics.db.exception.AdaptionException;
18 import org.simantics.db.exception.DatabaseException;
19 import org.simantics.db.request.Read;
20
21 /**
22  * @author Tuukka Lehtonen
23  */
24 public class TitleRequest implements Read<String> {
25
26     private final String               editorId;
27
28     private final IResourceEditorInput input;
29
30     public TitleRequest(String editorId, IResourceEditorInput input) {
31         this.editorId = editorId;
32         this.input = input;
33     }
34
35     @Override
36     public String perform(ReadGraph graph) throws DatabaseException {
37         Resource r = input.getResource();
38
39         try {
40             String n = null;
41             IEditorNamingService ems = EditorNaming.getNamingService(graph, r);
42             if (ems != null)
43                 n = ems.getName(graph, editorId, input);
44             if (n == null) {
45                 if (r == null)
46                     return "no input resource";
47                 n = graph.adapt(r, String.class);
48             }
49
50             return n;
51         } catch (AdaptionException e) {
52             return NameUtils.getSafeName(graph, r);
53         }
54     }
55
56 }