1 /*******************************************************************************
2 * Copyright (c) 2007, 2011 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.diagram.profile.view;
14 import org.eclipse.ui.IWorkbenchPart;
15 import org.simantics.Simantics;
16 import org.simantics.databoard.util.URIStringUtils;
17 import org.simantics.db.ReadGraph;
18 import org.simantics.db.Resource;
19 import org.simantics.db.common.request.ResourceRead;
20 import org.simantics.db.common.utils.NameUtils;
21 import org.simantics.db.exception.DatabaseException;
22 import org.simantics.db.management.ISessionContext;
23 import org.simantics.diagram.stubs.DiagramResource;
24 import org.simantics.modeling.ModelingResources;
25 import org.simantics.ui.workbench.IPropertyPage;
26 import org.simantics.views.swt.ModelledView;
29 * @author Antti Villberg
31 public class ProfilesView extends ModelledView {
34 protected String configurationURI() {
35 return DiagramResource.URIs.ProfilesView;
39 protected void inputChanged(IWorkbenchPart part, Object input) {
40 //System.out.println("input: " + input);
41 updateViewDescription(input);
42 super.inputChanged(part, input);
45 private void updateViewDescription(Object input) {
46 if (input instanceof Resource) {
47 Resource r = (Resource) input;
48 ISessionContext ctx = getSessionContext();
51 String desc = ctx.getSession().syncRequest(new ResourceRead<String>(r) {
53 public String perform(ReadGraph graph) throws DatabaseException {
54 Resource r = resource;
55 Resource config = getConfiguration(graph, r);
59 return formName(graph, r);
62 private String formName(ReadGraph graph, Resource r) throws DatabaseException {
63 String name = NameUtils.getSafeName(graph, r);
64 final Resource project = Simantics.getProjectResource();
65 String projectUri = project != null ? graph.getPossibleURI(project) : "";
66 String uri = graph.getPossibleURI(r);
68 if (uri.startsWith(projectUri))
69 uri = uri.substring(projectUri.length());
70 uri = URIStringUtils.unescape(uri);
72 return uri != null ? name + " (" + uri + ")" : name;
75 private Resource getConfiguration(ReadGraph graph, Resource r) throws DatabaseException {
76 DiagramResource DIA = DiagramResource.getInstance(graph);
77 Resource diagram = graph.getPossibleObject(r, DIA.RuntimeDiagram_HasConfiguration);
80 ModelingResources MOD = ModelingResources.getInstance(graph);
81 Resource config = graph.getPossibleObject(diagram, MOD.DiagramToComposite);
87 setContentDescription(desc);
88 } catch (DatabaseException e) {
89 setContentDescription(e.getMessage());
94 setContentDescription("Profiles not available.");
100 protected IPropertyPage getPropertyPage() {
101 //return new PropertyPage(getSite());