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