\r
public class SysdynDiagramEditor extends ResourceEditorPart {\r
\r
- EditorCanvas canvas;\r
- IDiagram diagram;\r
- IMapping mapping;\r
- Frame frame;\r
- boolean disposed = false; \r
- \r
- IElementListener elementUpdateListener = new IElementListener() {\r
- \r
+ EditorCanvas canvas;\r
+ IDiagram diagram;\r
+ IMapping mapping;\r
+ Frame frame;\r
+ boolean disposed = false; \r
+ Composite frameComposite;\r
+\r
+ IElementListener elementUpdateListener = new IElementListener() {\r
+\r
@Override\r
public void elementUpdated(IElement element) {\r
mapping.rangeModified(element);\r
}\r
- \r
+\r
@Override\r
public void elementRemoved(IElement element) {\r
mapping.rangeModified(element);\r
mapping.rangeModified(diagram);\r
}\r
};\r
- \r
- protected void readDiagram(ReadGraph g) throws DatabaseException {\r
- SysdynDiagramSchema schema = new SysdynDiagramSchema(g);\r
- mapping = Mappings.createWithListening(schema);\r
- \r
- try {\r
- diagram = (IDiagram)mapping.map(g, getInputResource());\r
- for(IElement element : diagram.getElements())\r
- element.addListener(elementUpdateListener);\r
- } catch (MappingException e) {\r
- e.printStackTrace();\r
- }\r
- \r
- final Session session = g.getSession();\r
- mapping.addMappingListener(new IMappingListener() {\r
- \r
- @Override\r
- public void rangeModified() {\r
- SwingUtilities.invokeLater(new Runnable() {\r
+\r
+ protected void readDiagram(ReadGraph g) throws DatabaseException {\r
+ SysdynDiagramSchema schema = new SysdynDiagramSchema(g);\r
+ mapping = Mappings.createWithListening(schema);\r
+\r
+ try {\r
+ diagram = (IDiagram)mapping.map(g, getInputResource());\r
+ for(IElement element : diagram.getElements())\r
+ element.addListener(elementUpdateListener);\r
+ } catch (MappingException e) {\r
+ e.printStackTrace();\r
+ }\r
+\r
+ final Session session = g.getSession();\r
+ mapping.addMappingListener(new IMappingListener() {\r
+\r
+ @Override\r
+ public void rangeModified() {\r
+ SwingUtilities.invokeLater(new Runnable() {\r
\r
@Override\r
public void run() {\r
session.syncRequest(new WriteRequest() { \r
@Override\r
public void perform(WriteGraph graph)\r
- throws DatabaseException {\r
+ throws DatabaseException {\r
mapping.updateDomain(graph);\r
} \r
});\r
e.printStackTrace();\r
} \r
}\r
- \r
- }); \r
- }\r
- \r
- @Override\r
- public void domainModified() {\r
- SwingUtilities.invokeLater(new Runnable() {\r
+\r
+ }); \r
+ }\r
+\r
+ @Override\r
+ public void domainModified() {\r
+ SwingUtilities.invokeLater(new Runnable() {\r
\r
@Override\r
public void run() {\r
e.printStackTrace();\r
} \r
}\r
- \r
- }); \r
- }\r
- \r
- });\r
- \r
- diagram.addDiagramListener(new IDiagramListener() {\r
- \r
- @Override\r
- public void elementAdded(IElement element) {\r
- mapping.rangeModified(diagram); \r
- element.addListener(elementUpdateListener);\r
- }\r
- \r
- @Override\r
- public void elementRemoved(IElement element) {\r
- }\r
- \r
- });\r
- }\r
- \r
- @Override\r
- public void init(IEditorSite site, IEditorInput input)\r
- throws PartInitException {\r
- super.init(site, input);\r
- \r
- try {\r
- SimanticsUI.getSession().syncRequest(new ReadRequest() {\r
- \r
- @Override\r
- public void run(ReadGraph g) throws DatabaseException {\r
- readDiagram(g); \r
- }\r
- \r
- });\r
- \r
- SimanticsUI.getSession().asyncRequest(\r
- new TitleRequest(site.getId(), getResourceInput()) {\r
- @Override\r
- public String perform(ReadGraph graph) throws DatabaseException {\r
- Builtins b = graph.getBuiltins();\r
- Resource r = graph.getSingleObject(\r
- getResourceInput().getResource(),\r
- b.IsConfigurationOf);\r
- String label = graph.getPossibleRelatedValue(r, b.HasLabel);\r
- return label;\r
- }\r
- },\r
- new TitleUpdater(site.getShell().getDisplay(), new Callback<String>() {\r
- @Override\r
- public void run(String partName) {\r
- setPartName(partName);\r
- }\r
- }, new Callable<Boolean>() {\r
- @Override\r
- public Boolean call() {\r
- return disposed;\r
- }\r
- }));\r
- } catch (DatabaseException e) {\r
- e.printStackTrace();\r
- } \r
- }\r
- \r
- @Override\r
- public void createPartControl(final Composite parent) {\r
- final Composite composite = new Composite(parent, \r
- SWT.NO_BACKGROUND | SWT.EMBEDDED);\r
- frame = SWT_AWT.new_Frame(composite);\r
- \r
+\r
+ }); \r
+ }\r
+\r
+ });\r
+\r
+ diagram.addDiagramListener(new IDiagramListener() {\r
+\r
+ @Override\r
+ public void elementAdded(IElement element) {\r
+ mapping.rangeModified(diagram); \r
+ element.addListener(elementUpdateListener);\r
+ }\r
+\r
+ @Override\r
+ public void elementRemoved(IElement element) {\r
+ }\r
+\r
+ });\r
+ }\r
+\r
+ @Override\r
+ public void init(IEditorSite site, IEditorInput input)\r
+ throws PartInitException {\r
+ super.init(site, input);\r
+\r
+ try {\r
+ SimanticsUI.getSession().syncRequest(new ReadRequest() {\r
+\r
+ @Override\r
+ public void run(ReadGraph g) throws DatabaseException {\r
+ readDiagram(g); \r
+ }\r
+\r
+ });\r
+\r
+ SimanticsUI.getSession().asyncRequest(\r
+ new TitleRequest(site.getId(), getResourceInput()) {\r
+ @Override\r
+ public String perform(ReadGraph graph) throws DatabaseException {\r
+ Builtins b = graph.getBuiltins();\r
+ Resource r = graph.getSingleObject(\r
+ getResourceInput().getResource(),\r
+ b.IsConfigurationOf);\r
+ String label = graph.getPossibleRelatedValue(r, b.HasLabel);\r
+ return label;\r
+ }\r
+ },\r
+ new TitleUpdater(site.getShell().getDisplay(), new Callback<String>() {\r
+ @Override\r
+ public void run(String partName) {\r
+ setPartName(partName);\r
+ }\r
+ }, new Callable<Boolean>() {\r
+ @Override\r
+ public Boolean call() {\r
+ return disposed;\r
+ }\r
+ }));\r
+ } catch (DatabaseException e) {\r
+ e.printStackTrace();\r
+ } \r
+ }\r
+\r
+ @Override\r
+ public void createPartControl(final Composite parent) {\r
+ frameComposite = new Composite(parent, \r
+ SWT.NO_BACKGROUND | SWT.EMBEDDED);\r
+ frame = SWT_AWT.new_Frame(frameComposite);\r
+\r
final ActiveSelectionProvider selectionProvider = new ActiveSelectionProvider();\r
getSite().setSelectionProvider(selectionProvider);\r
- \r
+\r
final OpenContextMenu openContextMenu = new OpenContextMenu(\r
parent, getSite(), "#SysdynDiagramPopup");\r
- \r
+\r
SwingUtilities.invokeLater(new Runnable() {\r
\r
@Override\r
public void run() { \r
- DiagramEditor editor = new DiagramEditor(null, diagram); \r
- \r
- DefaultEventHandlers.configure(editor);\r
- editor.addEventHandler(1, "key(A)", new CreateAuxiliary());\r
- editor.addEventHandler(1, "key(S)", new CreateStock());\r
- editor.addEventHandler(1, "key(V)", new CreateValve());\r
- editor.addEventHandler(1, "key(C)", new CreateCloud());\r
- editor.addEventHandler(1, "drag(alt+left)", new ConnectDependency());\r
- editor.addEventHandler(1, "drag(alt+right)", new ConnectFlow());\r
- editor.addEventHandler(1, "release(right)", openContextMenu); \r
- \r
- canvas = new EditorCanvas(editor);\r
+ DiagramEditor editor = new DiagramEditor(null, diagram); \r
+\r
+ DefaultEventHandlers.configure(editor);\r
+ editor.addEventHandler(1, "key(A)", new CreateAuxiliary());\r
+ editor.addEventHandler(1, "key(S)", new CreateStock());\r
+ editor.addEventHandler(1, "key(V)", new CreateValve());\r
+ editor.addEventHandler(1, "key(C)", new CreateCloud());\r
+ editor.addEventHandler(1, "drag(alt+left)", new ConnectDependency());\r
+ editor.addEventHandler(1, "drag(alt+right)", new ConnectFlow());\r
+ editor.addEventHandler(1, "release(right)", openContextMenu); \r
+\r
+ canvas = new EditorCanvas(editor);\r
frame.add(canvas);\r
- \r
- canvas.requestFocus(); \r
- \r
+\r
+ setFocus();\r
+\r
editor.getSelection().addSelectionListener(new ISelectionListener() {\r
- \r
+\r
@Override\r
public void selectionChanged(ISelection selection) {\r
final ArrayList<Resource> resources = new ArrayList<Resource>(selection.size());\r
for(IElement element : selection)\r
resources.add(mapping.inverseGet(element));\r
- composite.getDisplay().asyncExec(new Runnable() {\r
+ getFrameComposite().getDisplay().asyncExec(new Runnable() {\r
\r
@Override\r
public void run() {\r
- if(!composite.isDisposed())\r
+ if(!getFrameComposite().isDisposed())\r
selectionProvider.setSelection(new StructuredSelection(resources));\r
}\r
- \r
+\r
});\r
}\r
- \r
+\r
});\r
}\r
- \r
+\r
});\r
- }\r
-\r
- @Override\r
- public void setFocus() {\r
- if(canvas != null)\r
- canvas.requestFocus(); \r
- }\r
- \r
- @Override\r
- public void dispose() {\r
- mapping.dispose();\r
- frame.dispose();\r
- disposed = true;\r
- }\r
- \r
- @SuppressWarnings("unchecked")\r
+ }\r
+\r
@Override\r
- public Object getAdapter(Class adapter) {\r
- if (adapter == INode.class) {\r
- return canvas.getEditor().getSceneGraph();\r
- }\r
- return super.getAdapter(adapter);\r
- }\r
+ public void setFocus() { \r
+ if(canvas == null || !canvas.requestFocusInWindow()) {\r
+ getFrameComposite().getDisplay().asyncExec(new Runnable() {\r
+ @Override\r
+ public void run() {\r
+ if(!getFrameComposite().isDisposed())\r
+ getFrameComposite().setFocus(); \r
+ }\r
+ });\r
+ }\r
+ }\r
+\r
+ @Override\r
+ public void dispose() {\r
+ mapping.dispose();\r
+ frame.dispose();\r
+ disposed = true;\r
+ }\r
+\r
+ @SuppressWarnings("unchecked")\r
+ @Override\r
+ public Object getAdapter(Class adapter) {\r
+ if (adapter == INode.class) {\r
+ return canvas.getEditor().getSceneGraph();\r
+ }\r
+ return super.getAdapter(adapter);\r
+ }\r
+\r
+ private Composite getFrameComposite() {\r
+ return this.frameComposite;\r
+ }\r
\r
}\r