1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2010 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 *******************************************************************************/
\r
12 package org.simantics.ui.workbench;
\r
14 import org.simantics.Simantics;
\r
15 import org.simantics.db.ReadGraph;
\r
16 import org.simantics.db.Resource;
\r
17 import org.simantics.db.common.request.PossibleIndexRoot;
\r
18 import org.simantics.db.exception.DatabaseException;
\r
19 import org.simantics.db.layer0.variable.Variable;
\r
20 import org.simantics.db.layer0.variable.Variables;
\r
21 import org.simantics.project.IProject;
\r
24 * An IProject service for naming editors while working on a project.
\r
26 * @author Tuukka Lehtonen
\r
28 public final class EditorNaming {
\r
34 * @throws DatabaseException
\r
36 public static IEditorNamingService getNamingService(ReadGraph graph, Resource resource) throws DatabaseException {
\r
37 IEditorNamingService ems = graph.getPossibleAdapter(resource, IEditorNamingService.class);
\r
39 Resource model = graph.syncRequest(new PossibleIndexRoot(resource));
\r
40 if (model != null) {
\r
41 ems = graph.getPossibleAdapter(model, IEditorNamingService.class);
\r
47 IProject p = Simantics.peekProject();
\r
48 ems = p.getHint(IEditorNamingService.KEY_EDITOR_NAMING_SERVICE);
\r
58 * @throws DatabaseException
\r
60 public static IEditorNamingService getNamingService(ReadGraph graph, Variable variable) throws DatabaseException {
\r
61 IEditorNamingService ems = null;
\r
63 Resource r = variable.getPossibleRepresents(graph);
\r
65 ems = graph.getPossibleAdapter(r, IEditorNamingService.class);
\r
69 Resource model = Variables.getModel(graph, variable);
\r
70 ems = graph.getPossibleAdapter(model, IEditorNamingService.class);
\r
71 } catch (DatabaseException e) {
\r
72 // Ignore missing model, in this case the variable is lost anyway.
\r
78 IProject p = Simantics.peekProject();
\r
80 ems = p.getHint(IEditorNamingService.KEY_EDITOR_NAMING_SERVICE);
\r