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.issues.ui;
14 import org.eclipse.ui.IWorkbenchPart;
15 import org.simantics.Simantics;
16 import org.simantics.db.ReadGraph;
17 import org.simantics.db.Resource;
18 import org.simantics.db.common.request.ResourceRead;
19 import org.simantics.db.common.utils.NameUtils;
20 import org.simantics.db.exception.DatabaseException;
21 import org.simantics.db.management.ISessionContext;
22 import org.simantics.diagram.stubs.DiagramResource;
23 import org.simantics.issues.ui.ontology.IssueUIResource;
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 IssueView2 extends ModelledView {
34 protected String configurationURI() {
35 return IssueUIResource.URIs.IssueView;
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());
71 return uri != null ? name + " (" + uri + ")" : name;
74 private Resource getConfiguration(ReadGraph graph, Resource r) throws DatabaseException {
75 DiagramResource DIA = DiagramResource.getInstance(graph);
76 Resource diagram = graph.getPossibleObject(r, DIA.RuntimeDiagram_HasConfiguration);
79 ModelingResources MOD = ModelingResources.getInstance(graph);
80 Resource config = graph.getPossibleObject(diagram, MOD.DiagramToComposite);
86 setContentDescription(desc);
87 } catch (DatabaseException e) {
88 setContentDescription(e.getMessage());
93 setContentDescription("Issues not available.");
99 protected IPropertyPage getPropertyPage() {
100 //return new PropertyPage(getSite());