-package org.simantics.modeling.ui.componentTypeEditor;\r
-\r
-import org.eclipse.jface.resource.ImageDescriptor;\r
-import org.eclipse.ui.PartInitException;\r
-import org.eclipse.ui.PlatformUI;\r
-import org.simantics.Simantics;\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.common.request.ReadRequest;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.modeling.ModelingResources;\r
-import org.simantics.modeling.ui.Activator;\r
-import org.simantics.structural.stubs.StructuralResource2;\r
-import org.simantics.ui.workbench.ResourceEditorInput;\r
-import org.simantics.ui.workbench.editor.AbstractResourceEditorAdapter;\r
-\r
-public class ProceduralComponentInstanceViewerEditorAdapter extends\r
- AbstractResourceEditorAdapter {\r
- \r
- public static final ImageDescriptor ICON = ImageDescriptor.createFromURL(Activator.getDefault().getBundle()\r
- .getResource("icons/shape_3d_gray.png"));\r
- public static final String EDITOR_ID = "org.simantics.modeling.ui.proceduralComponentInstanceViewer";\r
- \r
- public ProceduralComponentInstanceViewerEditorAdapter() {\r
- super("Procedural Component Instance Viewer", ICON, -10);\r
- }\r
-\r
- private static Resource browseComponent(ReadGraph graph, Resource input) throws DatabaseException {\r
- ModelingResources MOD = ModelingResources.getInstance(graph);\r
- \r
- Resource temp = graph.getPossibleObject(input, MOD.ElementToComponent);\r
- if(temp != null)\r
- return temp;\r
- else\r
- return input;\r
- }\r
- \r
- @Override\r
- protected boolean canHandle(ReadGraph graph, Resource input)\r
- throws DatabaseException {\r
- input = browseComponent(graph, input);\r
- StructuralResource2 STR = StructuralResource2.getInstance(graph);\r
- Resource type = graph.getPossibleType(input, STR.Component);\r
- if(type == null)\r
- return false;\r
- return graph.isInstanceOf(type, STR.ProceduralComponentType);\r
- }\r
- \r
- @Override\r
- protected void openEditor(final Resource input) throws Exception {\r
- Simantics.getSession().asyncRequest(new ReadRequest() {\r
- @Override\r
- public void run(ReadGraph graph) throws DatabaseException {\r
- final Resource actualInput = browseComponent(graph, input);\r
- PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {\r
- @Override\r
- public void run() {\r
- try {\r
- openEditorWithId(EDITOR_ID, new ResourceEditorInput(EDITOR_ID, actualInput));\r
- } catch (PartInitException e) {\r
- e.printStackTrace();\r
- }\r
- }\r
- \r
- });\r
- }\r
- \r
- });\r
- }\r
- \r
-}\r
+package org.simantics.modeling.ui.componentTypeEditor;
+
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
+import org.simantics.Simantics;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.common.request.ReadRequest;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.modeling.ModelingResources;
+import org.simantics.modeling.ui.Activator;
+import org.simantics.structural.stubs.StructuralResource2;
+import org.simantics.ui.workbench.ResourceEditorInput;
+import org.simantics.ui.workbench.editor.AbstractResourceEditorAdapter;
+
+public class ProceduralComponentInstanceViewerEditorAdapter extends
+ AbstractResourceEditorAdapter {
+
+ public static final ImageDescriptor ICON = ImageDescriptor.createFromURL(Activator.getDefault().getBundle()
+ .getResource("icons/shape_3d_gray.png"));
+ public static final String EDITOR_ID = "org.simantics.modeling.ui.proceduralComponentInstanceViewer";
+
+ public ProceduralComponentInstanceViewerEditorAdapter() {
+ super("Procedural Component Instance Viewer", ICON, -10);
+ }
+
+ private static Resource browseComponent(ReadGraph graph, Resource input) throws DatabaseException {
+ ModelingResources MOD = ModelingResources.getInstance(graph);
+
+ Resource temp = graph.getPossibleObject(input, MOD.ElementToComponent);
+ if(temp != null)
+ return temp;
+ else
+ return input;
+ }
+
+ @Override
+ protected boolean canHandle(ReadGraph graph, Resource input)
+ throws DatabaseException {
+ input = browseComponent(graph, input);
+ StructuralResource2 STR = StructuralResource2.getInstance(graph);
+ Resource type = graph.getPossibleType(input, STR.Component);
+ if(type == null)
+ return false;
+ return graph.isInstanceOf(type, STR.ProceduralComponentType);
+ }
+
+ @Override
+ protected void openEditor(final Resource input) throws Exception {
+ Simantics.getSession().asyncRequest(new ReadRequest() {
+ @Override
+ public void run(ReadGraph graph) throws DatabaseException {
+ final Resource actualInput = browseComponent(graph, input);
+ PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
+ @Override
+ public void run() {
+ try {
+ openEditorWithId(EDITOR_ID, new ResourceEditorInput(EDITOR_ID, actualInput));
+ } catch (PartInitException e) {
+ e.printStackTrace();
+ }
+ }
+
+ });
+ }
+
+ });
+ }
+
+}