Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » Getting started with non EMF Domain Models, need an example(It would be great to have a Graphiti example/tutorial with POJO Objects.)
Re: Getting started with non EMF Domain Models, need an example [message #900976 is a reply to message #900565] Thu, 09 August 2012 09:35 Go to previous messageGo to next message
Saniya Mirajkar is currently offline Saniya MirajkarFriend
Messages: 31
Registered: August 2012
Member
Thanks Nikolai for the example.

I can now successfully add the rectangular shapes programmatically in my diagram editor.

In my case DiagramTypeProvider was not initialised properly since I open the editor programtically.

I now set the TransactionEditingDomain and the DiagramEditor that is created in above code to my DiagramTypeProvider. I use the following code to add the pictogram for the domainObject

	AddContext addContext = new AddContext();
		addContext.setNewObject(domainObject);

		addContext.setLocation(200, 300);
		addContext.setSize(100, 200);
		addContext.setTargetContainer(diagram);
		dtyProvider.getFeatureProvider()
				.addIfPossible(addContext);


It just works great now.

Re: Getting started with non EMF Domain Models, need an example [message #945725 is a reply to message #900976] Mon, 15 October 2012 15:24 Go to previous messageGo to next message
Lars Heinemann is currently offline Lars HeinemannFriend
Messages: 21
Registered: January 2011
Junior Member

Using the attached project from this thread I am trying to get the properties view be filled with the properties of the current selection in the diagram but I am somehow unable to get it working. Tried to implement IPropertySource within the domain model objects but that doesn't seem to be enough. Any idea what I am missing here / what is required to get the properties view filled with the properties of the currently selected figure in the diagram?

thanks in advance,
Lars
Re: Getting started with non EMF Domain Models, need an example [message #947592 is a reply to message #945725] Wed, 17 October 2012 08:17 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1931
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Lars,

did you have a look into the tutorial? There is a section that deals with
registering tabbed property sheets. In the filter implementation you will
need to exchange the Graphiti link service (will work only for EObjects)
with the implementation you use to to link your POJO domain objects to the
pictogram elements.

Michael
Re: Getting started with non EMF Domain Models, need an example [message #974965 is a reply to message #947592] Wed, 07 November 2012 13:29 Go to previous messageGo to next message
Saniya Mirajkar is currently offline Saniya MirajkarFriend
Messages: 31
Registered: August 2012
Member
Hi ,

I use the example in this post as reference for creating Graphiti diagrams.The latest code that is posted on this thread works for me in version 0.9.1 perfectly.

I have recently migrated my code from version 0.8.2 to 0.9.1 with which my code does not seem to work.I am doing nothing different apart from replacing the code with appropriate API of 0.9.1.

I use the following code in my Action class to open the editor:

            IWorkbenchPage page = PlatformUI.getWorkbench()
                    .getActiveWorkbenchWindow().getActivePage();

            final IEditorInput editorInput = RepositoryUtils.getEditorInput();

            final DiagramTypeProvider dtyProvider = (DiagramTypeProvider) 
            ExtensionManager.getSingleton().createDiagramTypeProvider(
                            DIAGRAM_TYPE_PROVIDER_ID);

            final Diagram diagram = Graphiti.getPeCreateService()
                    .createDiagram(DIAGRAM_TYPE, "Test Diagram",
                            false);

            final TestDiagramEditor diagramEditor = new TestDiagramEditor();

            dtyProvider.init(diagram, diagramEditor);

           page.openEditor(editorInput,TestDiagramEditor.DIAGRAM_EDITOR_ID);


And the code for getEditorInput() of RepositoryUtils is as follows:

public static IEditorInput getEditorInput() throws Exception {

        private final static String DIAGRAM_NAME = "NonEmf.diagramNonEmf";
        String diagramFileName = "";
        String dataFileName = "";
        
        final IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();

        IPath path = root.getLocation();
        dataFileName = path +  "/files/NonEmf.xml";
        diagramFileName = path +  "/files/NonEmf.diagramNonEmf";

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

        if (!project.exists()) {
               project.create(null);

        }
           if (!(project.isOpen())) {
            project.open(null);
        }
      
        IFile diagramFile = project.getFile(DIAGRAM_NAME);
        URI emfURI = URI.createURI(diagramFile.toString());

        TestDiagramEditorInput result = null;

        if (emfURI != null) {
                    
            URI diagramUri = emfURI.appendFragment("/0");
         
           result = new TestDiagramEditorInput(diagramUri, null);
            result.setDataFileName(dataFileName);
            result.setDiagramFileName(diagramFileName);
        }
    return result;
    }
}

The same thing used to work for me for version 0.8.2. Now I do not get any error but the diagram file is not created and when I open the editor since there is no diagram file under the given path following message is shown on editor :"No Diagram found for URI 'L/files/NonEmf.diagramNonEmf#/0"

[Updated on: Wed, 07 November 2012 14:17]

Report message to a moderator

Re: Getting started with non EMF Domain Models, need an example [message #981104 is a reply to message #974965] Mon, 12 November 2012 06:47 Go to previous messageGo to next message
Saniya Mirajkar is currently offline Saniya MirajkarFriend
Messages: 31
Registered: August 2012
Member
Hi Nikolai,

I use your example as reference.I just need info on the way you use the xml files and diagram files .Initially do we need to create this files or they are created programatically ??
Re: Getting started with non EMF Domain Models, need an example [message #981570 is a reply to message #974965] Mon, 12 November 2012 14:21 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1931
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Hemlata,

it seems the storing of the file is missing. The editor will need a
persisted file containing the diagram to start. But I wonder why this could
have worked in 0.8, as this should have been a prerequisite there as well...

Michael
Re: Getting started with non EMF Domain Models, need an example [message #983820 is a reply to message #981570] Wed, 14 November 2012 07:07 Go to previous messageGo to next message
Saniya Mirajkar is currently offline Saniya MirajkarFriend
Messages: 31
Registered: August 2012
Member
Hi Michael,

Thanks for reply.Now that some how my editor comes up with a persisted file, I get Nullpointer errors for getEditDomain() when using "addIfPossible()" method.

I use the following code to add my object to diagram:


   AddContext addContext = new AddContext();
        addContext.setNewObject(object);

        addContext.setLocation(x, y);
        addContext.setSize(100, 200);
        addContext.setTargetContainer(diagram);
        final PictogramElement pictogram =
              dtyProvider.getFeatureProvider().addIfPossible(addContext);


Re: Getting started with non EMF Domain Models, need an example [message #985568 is a reply to message #983820] Thu, 15 November 2012 13:57 Go to previous messageGo to next message
Nikolai Raitsev is currently offline Nikolai RaitsevFriend
Messages: 102
Registered: July 2009
Senior Member
Hi Hemlata,

I am happy that my example has helped you.

In fact, the code from the example should be migrated to Graphiti version 0.9.x.

In the Github version of my example (https://github.com/kumarunster/phirea.public/tree/master/test.graphiti.nonemf) you can see the current state of the example, and it runs on 0.9 version of Graphiti, but unfortunately I cannot exactly say (on the fly), what you should change...

In the whole example I'm trying to show, how is it possible to use Graphiti based editors without EMF lock-in of the domain model. If you look at ApplicationWorkbenchWindowAdvisor you have a Tip, how to get the right EditorInput for your Graphiti-Editor.

About my case: In my application I have a datamodel, that is stored in a database and a lot of graphiti-xml-files, that are stored in a database too. The graphiti-xml's are all created programatically from some template-files, and all the referenced objects in that diagram files are drag-n-dropped from my "Repository". That files are copied, if a EditorInput is produced, in a Temp-Folder from my Application every time the new User-Session is started and a diagram is requested. On Save-Actions they are stored in the DB as BLOB.

If you have any questions, so feel free to ask me and look to the github version of my example!

Best regards,

Nikolai
Re: Getting started with non EMF Domain Models, need an example [message #985772 is a reply to message #985568] Fri, 16 November 2012 06:16 Go to previous messageGo to next message
Saniya Mirajkar is currently offline Saniya MirajkarFriend
Messages: 31
Registered: August 2012
Member
Hi Nikolai,

Thanks for that valuable info.

I use the github version of your example which works well with Graphiti 0.9.1 as well.
I do get EditorInput for my Graphiti-Editor the way you get it in ApplicationWorkbenchWindowAdvisor.

In my case I do not want to persist graphiti related info in the database.Right now I am just trying to add the pictogram representation of the domain object to the diagram editor with version 0.9.1

I try to create my own Graphiti diagram as follows:

IWorkbenchPage page = PlatformUI.getWorkbench()
                    .getActiveWorkbenchWindow().getActivePage();

      IEditorInput input = RepositoryUtils.getEditorInput();
     
      // Create the pictogram for selected Functional Variable

      final Diagram diagram = Graphiti.getPeCreateService()
                    .createDiagram(DIAGRAM_TYPE, sourceVariable_.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);


With this blank graphical editor opens up.And now I try to add the buisness object to this diaram using following stuff:

 AddContext addContext = new AddContext();
            addContext.setNewObject(object);

            addContext.setLocation(200, 300);
            addContext.setSize(100, 200);
            addContext.setTargetContainer(diagram);
            DiagramFeatureProvider fp = (DiagramFeatureProvider) dtyProvider
                    .getFeatureProvider();
           
            AddFunctionalVariableFeature feature = (AddFunctionalVariableFeature)  
                     dtyProvider.getFeatureProvider().getAddFeature(addContext);

            dtyProvider.getFeatureProvider().addIfPossible(addContext);


When using this ,internally it gives Nullpointer exception for getEditDomain() in addIfPossible method as follows:

org.eclipse.core.runtime.AssertionFailedException: null argument:
    at org.eclipse.core.runtime.Assert.isNotNull(Assert.java:85)
    at org.eclipse.core.runtime.Assert.isNotNull(Assert.java:73)
    at org.eclipse.graphiti.ui.editor.DiagramEditor.executeFeature(DiagramEditor.java:1946)
    at org.eclipse.graphiti.features.impl.AbstractFeatureProvider.addIfPossible(AbstractFeatureProvider.java:331)


I suppose that is because my editor is not getting initialised properly.
On debugging I see that my Editor has no TransactionalEditingDomain.With version 0.8.2 I created my own TransactionalEditingDomain and passed that to constructor of DiagramEditor. But in version 0.9 there is no constructor which accepts TransactionalEditingDomain.

I am now stuck at point as how to add the pictogram on the diagram with the new version of Graphiti.
Re: Getting started with non EMF Domain Models, need an example [message #985810 is a reply to message #985772] Fri, 16 November 2012 09:07 Go to previous message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1931
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Hemlata,

in case the editing domain is the issue, that is indeed changed between 0.8
and 0.9: instead of passing a domain into the input (FWIW: which caused the
input object to be not as light-weight as it should be - that's the reason
why we removed it) you should now be able to create a special editing domain
in your own subclass of DefaultUpdateBehavior (override
DiagramEditor.createUpdateBehavior to hook in your own instance of that
class). DefaultUpdateBehavior offers a method createEditingDomain you could
override.

HTH,
Michael
Previous Topic:AddFeature (link element)
Next Topic:Create graphical elements by create new diagram
Goto Forum:
  


Current Time: Wed Apr 24 20:50:41 GMT 2024

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

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

Back to the top