Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » trying to create a simulator using Graphiti
trying to create a simulator using Graphiti [message #878591] Tue, 29 May 2012 15:17 Go to next message
Johnny Qin is currently offline Johnny QinFriend
Messages: 40
Registered: April 2012
Member
Hi everyone,

As we all know, Graphiti provides org.eclipse.graphiti.ui.editor.DiagramEditor as main class for the Graphiti diagram editor. Is there a Graphiti view available?

I expect to use such a view to implement a simulator that takes diagram object (diagram object comes either from an opened Graphiti diagram editor, or from the diagram file or non-file resource). This simulator should be able to display the editor's graphical view, reflect programmatical changes. Because it is an eclipse view, it won't expect user to explicitly hit save button. (ideally the digram object used by simulator could reside in memory instead of file resource, and could be abandoned after simulation)


If there is no Graphiti View supported, I might use a Graphiti editor instead. In this case, there will be 2 editors. First one is the real editor, the second one will be simulator (without Palette and editable areas). In the launcher of the real editor, I plan to use IHandlerServer to execute a command that will get access to active workbench window.
ScxmlDiagramEditor diagramEditor = (ScxmlDiagramEditor) iWorkbenchPage.getActiveEditor();
        IHandlerService handlerService = (IHandlerService) diagramEditor.getSite().getService(IHandlerService.class);
        try {
            handlerService.executeCommand("com.company.designer.scxml.ui.opensimulator", null);
        } catch (Exception ex) {
            ex.printStackTrace();
            throw new RuntimeException("com.company.designer.scxml.ui.opensimulator not found");
        }

Within the command execution, I can tell workbench window to open a new page. In this new page, simulator should be opened and filled with diagram object (just like a clone of editor).
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
        IWorkbenchPage editorPage = window.getActivePage();
        IWorkbenchPage simulatorPage = null;
        try {
            simulatorPage = window.openPage(DesignerPerspective.ID, null);
        } catch (WorkbenchException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        try {
            if (simulatorPage != null) {
                simulatorPage.openEditor(editorPage.getActiveEditor().getEditorInput(), ScxmlDiagramSimulator.DIAGRAM_SIMULATOR_ID);
            }
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }


The
simulatorPage.openEditor(editorPage.getActiveEditor().getEditorInput(), ScxmlDiagramSimulator.DIAGRAM_SIMULATOR_ID);

gave me this error:
org.eclipse.swt.SWTException: Invalid thread access
	at org.eclipse.swt.SWT.error(SWT.java:4282)
	at org.eclipse.swt.SWT.error(SWT.java:4197)
	at org.eclipse.swt.SWT.error(SWT.java:4168)
	at org.eclipse.swt.widgets.Display.error(Display.java:1065)
	at org.eclipse.swt.widgets.Display.checkDevice(Display.java:618)
	at org.eclipse.swt.widgets.Display.getSystemCursor(Display.java:1878)
	at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:59)
	at org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPage.java:2789)
	at org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPage.java:2773)
	at org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPage.java:2756)
	at com.company.designer.scxml.ui.simulation.OpenSimulatorHandler.execute(OpenSimulatorHandler.java:60)
	at org.eclipse.ui.internal.handlers.HandlerProxy.execute(HandlerProxy.java:293)
	at org.eclipse.core.commands.Command.executeWithChecks(Command.java:476)
	at org.eclipse.ui.internal.handlers.HandlerService.executeCommand(HandlerService.java:178)
	at org.eclipse.ui.internal.handlers.SlaveHandlerService.executeCommand(SlaveHandlerService.java:247)
	at org.eclipse.ui.internal.handlers.SlaveHandlerService.executeCommand(SlaveHandlerService.java:247)
	at com.company.designer.scxml.ui.launcher.ScxmlLaunchConfigurationDelegate.getResources(ScxmlLaunchConfigurationDelegate.java:108)
	at com.company.designer.scxml.ui.launcher.ScxmlLaunchConfigurationDelegate.launch(ScxmlLaunchConfigurationDelegate.java:75)
	at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:854)
	at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:703)
	at org.eclipse.debug.internal.ui.DebugUIPlugin.buildAndLaunch(DebugUIPlugin.java:937)
	at org.eclipse.debug.internal.ui.DebugUIPlugin$8.run(DebugUIPlugin.java:1141)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)


The difficulty here is how to pass digram object from editor to simulator, or should simulator load digram object from pictogram model of file resource?

Any ideas or suggestions are highly appreciated!

Thanks a lot to guys who have been developing this great framework.

Regards,
Johnny

[Updated on: Tue, 29 May 2012 15:22]

Report message to a moderator

Re: trying to create a simulator using Graphiti [message #878659 is a reply to message #878591] Tue, 29 May 2012 17:07 Go to previous message
Johnny Qin is currently offline Johnny QinFriend
Messages: 40
Registered: April 2012
Member
I think I have found solution for the invalid thread access exception.
It's because openEditor() is ui operation, and cannot be executed in non-ui thread.

Solution is to use Display.getDefault().asyncExec(new Runnable)
Display.getDefault().asyncExec(new Runnable() {
                
                @Override
                public void run() {
                    // TODO Auto-generated method stub
                    try {
                        workbenchPage.openEditor(editorInput, ScxmlDiagramSimulator.DIAGRAM_SIMULATOR_ID);
                    } catch (PartInitException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
            });


still working on simulator implementation... will come back to this post if came across obstacles Smile

Previous Topic:Ability to get visible size of diagram?
Next Topic:get access to Diagram from DiagramEditor
Goto Forum:
  


Current Time: Sun Dec 21 13:34:54 GMT 2014

Powered by FUDForum. Page generated in 0.01466 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software