]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.issues.ui/src/org/simantics/issues/ui/IssueView2.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.issues.ui / src / org / simantics / issues / ui / IssueView2.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2011 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.issues.ui;
13
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;
27
28 /**
29  * @author Antti Villberg
30  */
31 public class IssueView2 extends ModelledView {
32
33     @Override
34     protected String configurationURI() {
35         return IssueUIResource.URIs.IssueView;
36     }
37
38     @Override
39     protected void inputChanged(IWorkbenchPart part, Object input) {
40         //System.out.println("input: " + input);
41         updateViewDescription(input);
42         super.inputChanged(part, input);
43     }
44
45     private void updateViewDescription(Object input) {
46         if (input instanceof Resource) {
47             Resource r = (Resource) input;
48             ISessionContext ctx = getSessionContext();
49             if (ctx != null) {
50                 try {
51                     String desc = ctx.getSession().syncRequest(new ResourceRead<String>(r) {
52                         @Override
53                         public String perform(ReadGraph graph) throws DatabaseException {
54                             Resource r = resource;
55                             Resource config = getConfiguration(graph, r);
56                             if (config != null)
57                                 r = config;
58
59                             return formName(graph, r);
60                         }
61
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);
67                             if (uri != null) {
68                                 if (uri.startsWith(projectUri))
69                                     uri = uri.substring(projectUri.length());
70                             }
71                             return uri != null ? name + " (" + uri + ")" : name;
72                         }
73
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);
77                             if (diagram == null)
78                                 return r;
79                             ModelingResources MOD = ModelingResources.getInstance(graph);
80                             Resource config = graph.getPossibleObject(diagram, MOD.DiagramToComposite);
81                             if (config == null)
82                                 return diagram;
83                             return config;
84                         }
85                     });
86                     setContentDescription(desc);
87                 } catch (DatabaseException e) {
88                     setContentDescription(e.getMessage());
89                 }
90             }
91             setVisible(true);
92         } else {
93             setContentDescription("Issues not available.");
94             setVisible(false);
95         }
96     }
97
98     @Override
99     protected IPropertyPage getPropertyPage() {
100         //return new PropertyPage(getSite());
101         return null;
102     }
103
104 }