Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » Create graphical elements by create new diagram
Create graphical elements by create new diagram [message #963181] Mon, 29 October 2012 16:22 Go to next message
Markus Knoop is currently offline Markus Knoop
Messages: 14
Registered: January 2012
Junior Member
Hello,

i need some help. I want to create some graphical elements while create a new diagram. This elements are not parts of the model, only a graphical representation. For example it should visualize the user a start point as dot. So i create a dummy class, create an AddFeature and CreateFeature. I tried to trigger the creation of this element inside the DiagramProvider.postInit(), but get an exception:

java.lang.IllegalStateException: Cannot modify resource set without a write transaction

What is the correct approach to this? By create a new diagram, there should be a simple dot as start point inside the diagram?

Regards,
Markus
Re: Create graphical elements by create new diagram [message #964293 is a reply to message #963181] Tue, 30 October 2012 12:07 Go to previous messageGo to next message
Michael Wenz is currently offline Michael Wenz
Messages: 1618
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Markus,

you need to execute your features within a write transaction for the
resource set/transactional editing domain. This is due to Graphiti using EMF
Transactions underneath. Simply execute your feature on the command stack of
the editor, there is a executeFeature method in DiagramEditor that does
exactly that.

Michael
Re: Create graphical elements by create new diagram [message #964369 is a reply to message #964293] Tue, 30 October 2012 13:16 Go to previous messageGo to next message
Markus Knoop is currently offline Markus Knoop
Messages: 14
Registered: January 2012
Junior Member
Thnaks for help. Now it works fine by execute this as command.
Re: Create graphical elements by create new diagram [message #983962 is a reply to message #964369] Wed, 14 November 2012 09:34 Go to previous messageGo to next message
Saniya Mirajkar is currently offline Saniya Mirajkar
Messages: 30
Registered: August 2012
Member
Hi Michael,

I am also getting same error and as per your suggestion I try to execute my add feature on the command stack of editor using executeFeature method in DiagramEditor.

The following assert in DiagramEditor gives me Nullpointer Error:

DefaultEditDomain domain = getEditDomain();

        // Make sure the editor is valid
        Assert.isNotNull(domain);


Is there something that I am missing?
Re: Create graphical elements by create new diagram [message #985797 is a reply to message #983962] Fri, 16 November 2012 08:34 Go to previous messageGo to next message
Michael Wenz is currently offline Michael Wenz
Messages: 1618
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Hemlata,

it seems that the editor is not correctly initialized. This method will only
work with a correctly opened editor. How do you retrieve that editor?

Michael
Re: Create graphical elements by create new diagram [message #985842 is a reply to message #985797] Fri, 16 November 2012 10:58 Go to previous messageGo to next message
Saniya Mirajkar is currently offline Saniya Mirajkar
Messages: 30
Registered: August 2012
Member
I use following stuff to create my diagram and open it :
IWorkbenchPage page = PlatformUI.getWorkbench()
                    .getActiveWorkbenchWindow().getActivePage();

      IEditorInput input = getEditorInput();
     
      // Create the pictogram for selected object

      final Diagram diagram = Graphiti.getPeCreateService()
                    .createDiagram(DIAGRAM_TYPE, object.getName(),
                            false);
       DiagramEditor editor = new DiagramEditor();
       
       final DiagramTypeProvider dtyProvider = (DiagramTypeProvider) ExtensionManager
                    .getSingleton().createDiagramTypeProvider(
                            DIAGRAM_TYPE_PROVIDER_ID);

       dtyProvider.init(diagram, editor);
         
       page.openEditor(input, DiagramEditor.DIAGRAM_EDITOR_ID);


and the getEditorInput() is as follows:

public static IEditorInput getEditorInput() throws Exception {

        DiagramEditorInput result = null;

        final IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();

        final IProject project = root.getProject("Graphiti");

          IFile diagramFile = project.getFile("Test" + "." + "diagram");

        URI emfURI = URI.createURI(diagramFile.getFullPath().toString());
     
            if (emfURI != null) {

            URI diagramUri = emfURI.appendFragment("/0");

            result = new   DiagramEditorInput(diagramUri,
                         DiagramTypeProvider.DIAGRAMTYPE_PROVIDER_ID);
       
        }

        return result;
    }

Re: Create graphical elements by create new diagram [message #986729 is a reply to message #985842] Wed, 21 November 2012 13:23 Go to previous message
Michael Wenz is currently offline Michael Wenz
Messages: 1618
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Hemlata,

why do you construct a DiagramEditor by yourself? All you should need to do
is create a DiagramEditorInput instance and pass it to
page.openEditor(input, DiagramEditor.DIAGRAM_EDITOR_ID);

The diagram needs to be persisted in file.

Michael
Previous Topic:Getting started with non EMF Domain Models, need an example
Next Topic:Export Graphiti diagram image via API
Goto Forum:
  


Current Time: Sat Oct 25 19:09:50 GMT 2014

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

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