--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2011 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.issues.ui;\r
+\r
+import org.eclipse.ui.IWorkbenchPart;\r
+import org.simantics.Simantics;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.common.request.ResourceRead;\r
+import org.simantics.db.common.utils.NameUtils;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.management.ISessionContext;\r
+import org.simantics.diagram.stubs.DiagramResource;\r
+import org.simantics.issues.ui.ontology.IssueUIResource;\r
+import org.simantics.modeling.ModelingResources;\r
+import org.simantics.ui.workbench.IPropertyPage;\r
+import org.simantics.views.swt.ModelledView;\r
+\r
+/**\r
+ * @author Antti Villberg\r
+ */\r
+public class IssueView2 extends ModelledView {\r
+\r
+ @Override\r
+ protected String configurationURI() {\r
+ return IssueUIResource.URIs.IssueView;\r
+ }\r
+\r
+ @Override\r
+ protected void inputChanged(IWorkbenchPart part, Object input) {\r
+ //System.out.println("input: " + input);\r
+ updateViewDescription(input);\r
+ super.inputChanged(part, input);\r
+ }\r
+\r
+ private void updateViewDescription(Object input) {\r
+ if (input instanceof Resource) {\r
+ Resource r = (Resource) input;\r
+ ISessionContext ctx = getSessionContext();\r
+ if (ctx != null) {\r
+ try {\r
+ String desc = ctx.getSession().syncRequest(new ResourceRead<String>(r) {\r
+ @Override\r
+ public String perform(ReadGraph graph) throws DatabaseException {\r
+ Resource r = resource;\r
+ Resource config = getConfiguration(graph, r);\r
+ if (config != null)\r
+ r = config;\r
+\r
+ return formName(graph, r);\r
+ }\r
+\r
+ private String formName(ReadGraph graph, Resource r) throws DatabaseException {\r
+ String name = NameUtils.getSafeName(graph, r);\r
+ final Resource project = Simantics.getProjectResource();\r
+ String projectUri = project != null ? graph.getPossibleURI(project) : "";\r
+ String uri = graph.getPossibleURI(r);\r
+ if (uri != null) {\r
+ if (uri.startsWith(projectUri))\r
+ uri = uri.substring(projectUri.length());\r
+ }\r
+ return uri != null ? name + " (" + uri + ")" : name;\r
+ }\r
+\r
+ private Resource getConfiguration(ReadGraph graph, Resource r) throws DatabaseException {\r
+ DiagramResource DIA = DiagramResource.getInstance(graph);\r
+ Resource diagram = graph.getPossibleObject(r, DIA.RuntimeDiagram_HasConfiguration);\r
+ if (diagram == null)\r
+ return r;\r
+ ModelingResources MOD = ModelingResources.getInstance(graph);\r
+ Resource config = graph.getPossibleObject(diagram, MOD.DiagramToComposite);\r
+ if (config == null)\r
+ return diagram;\r
+ return config;\r
+ }\r
+ });\r
+ setContentDescription(desc);\r
+ } catch (DatabaseException e) {\r
+ setContentDescription(e.getMessage());\r
+ }\r
+ }\r
+ setVisible(true);\r
+ } else {\r
+ setContentDescription("Issues not available.");\r
+ setVisible(false);\r
+ }\r
+ }\r
+\r
+ @Override\r
+ protected IPropertyPage getPropertyPage() {\r
+ //return new PropertyPage(getSite());\r
+ return null;\r
+ }\r
+\r
+}\r