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.)
Getting started with non EMF Domain Models, need an example [message #765844] Wed, 14 December 2011 18:59 Go to next message
Nikolai Raitsev is currently offline Nikolai RaitsevFriend
Messages: 102
Registered: July 2009
Senior Member
I am trying desperately to make a very simple example with POJO classes and Graphiti. (Based on the EMF tutorial in the documentation).

It looks to me that Graphiti can only work with EMF:(

I have two very simple Domain Objects: BusinessClass and Association.


public class BusinessClass {
	
	private String name;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	
	
}

public class Association {
	
	private BusinessClass fromClass;
	
	private BusinessClass toClass;
	
	private String name;

	public BusinessClass getFromClass() {
		return fromClass;
	}

	public void setFromClass(BusinessClass fromClass) {
		this.fromClass = fromClass;
	}

	public BusinessClass getToClass() {
		return toClass;
	}

	public void setToClass(BusinessClass toClass) {
		this.toClass = toClass;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

}




In the CreateBusinessClassFeature I have following code:


	@Override
	public Object[] create(ICreateContext context) {
	// ask user for BusinessClass name
        String newClassName = ExampleUtil.askString(TITLE, USER_QUESTION, "");
        if (newClassName == null || newClassName.trim().length() == 0) {
            return EMPTY;
        }
        // create EClass
        BusinessClass newClass = new BusinessClass();
        // Add model element to resource.
        // We add the model element to the resource of the diagram for
        // simplicity's sake. Normally, a customer would use its own
        // model persistence layer for storing the business model separately.
//        getDiagram().eResource().getContents().add(newClass);
        newClass.setName(newClassName);

        // do the add
        addGraphicalRepresentation(context, newClass);

        // return newly created business object(s)
        return new Object[] { newClass };		
	}




If I start the Editor and create a new BusinessClass, then an exception happens:

java.lang.ClassCastException: test.graphiti.nonemf.domainmodel.BusinessClass cannot be cast to org.eclipse.emf.ecore.EObject
	at org.eclipse.graphiti.features.impl.AbstractFeatureProvider.link(AbstractFeatureProvider.java:668)
..
...
	at org.eclipse.graphiti.features.impl.AbstractFeature.addGraphicalRepresentation(AbstractFeature.java:108)
	at test.graphiti.nonemf.diagram.features.CreateBusinessClassFeature.create(CreateBusinessClassFeature.java:49)


The reason is that the linkage of the diagramm can only work with EObjects ...

EObject bo = (EObject) businessObjects[i]; // KABUMM!!


It is very frustrating for me, to create without prior knowledge a small and clear example.

So please, can someone help me create such an example with only pojo objects?

It would also help a lot for Graphiti distribution. The world is not just about EMF ...
Re: Getting started with non EMF Domain Models, need an example [message #766111 is a reply to message #765844] Thu, 15 December 2011 08:40 Go to previous messageGo to next message
Tim Kaiser is currently offline Tim KaiserFriend
Messages: 118
Registered: July 2009
Senior Member
Hi Nikolai,

did your FeatureProvider supply an IndependenceSolver?

Best, Tim
Re: Getting started with non EMF Domain Models, need an example [message #766352 is a reply to message #766111] Thu, 15 December 2011 15:50 Go to previous messageGo to next message
Nikolai Raitsev is currently offline Nikolai RaitsevFriend
Messages: 102
Registered: July 2009
Senior Member
Hello Tim,

many thanks for that tip! Should it eventually be mentioned here: http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.graphiti.doc%2Fresources%2Fdocu%2Fgfw%2FNon-EMF+domain+objects.htm ?


My implementation now looks like this (first try, I'm happy, because I can draw after hours of despair a rectangle Smile


import org.eclipse.graphiti.features.impl.IIndependenceSolver;

public class POJOIndependenceSolver implements IIndependenceSolver {
	
	private static Map<String, Object> objectMap = new HashMap<String, Object>();

	@Override
	public String getKeyForBusinessObject(Object bo) {
		String result = null;
		if(bo != null) {
			result = String.valueOf(bo.hashCode());
			
			if(!objectMap.containsKey(result))
				objectMap.put(result, bo);
		}
		return result;
	}

	@Override
	public Object getBusinessObjectForKey(String key) {
		return objectMap.get(key);
	}

}


public class DiagramFeatureProvider extends DefaultFeatureProvider {
	
	POJOIndependenceSolver pojoIndependenceSolver;

	public DiagramFeatureProvider(IDiagramTypeProvider dtp) {
		super(dtp);
		pojoIndependenceSolver = new POJOIndependenceSolver();
		setIndependenceSolver(pojoIndependenceSolver);
	}

	@Override
	public IAddFeature getAddFeature(IAddContext context) {
		// is object for add request a TermClass?
        if (context.getNewObject() instanceof BusinessClass) {
            return new AddBusinessClassFeature(this);
        }

        return super.getAddFeature(context);
	}

	@Override
	public ICreateFeature[] getCreateFeatures() {
		return new ICreateFeature[] { new CreateBusinessClassFeature(this) };
	}

}



I keep trying. I'll also post my further questions on this topic, if you don't mind.

Best regards,

Nikolai
Re: Getting started with non EMF Domain Models, need an example [message #809443 is a reply to message #766352] Tue, 28 February 2012 22:08 Go to previous messageGo to next message
Nikolai Raitsev is currently offline Nikolai RaitsevFriend
Messages: 102
Registered: July 2009
Senior Member
After months of break, I have now found little bit of time to make this example "complete".

I can now save my own POJO's (non-EMF objects) with XStream in a "repository" file and when opening the editor, its load the objects from a "repository" file.

I think it is a good simple example of how to use Graphiti without EMF.

The project is attached and how to get it run, see the README.txt including in the project.

Best regards,

Nikolai

P.S.

surprising when one googling for "graphiti example with non emf" he will find this forum as the first entry...

[Updated on: Tue, 28 February 2012 22:10]

Report message to a moderator

Re: Getting started with non EMF Domain Models, need an example [message #862635 is a reply to message #765844] Sun, 29 April 2012 04:40 Go to previous messageGo to next message
richi arora is currently offline richi aroraFriend
Messages: 5
Registered: April 2012
Junior Member
Hi

Where can I find DomainModelChangeListener class as mentioned in graphiti help for non-emf models.

I want to achieve following:
drag a java class and drop on diagram editor.
I only want to use add feature of grahiti as for now
Re: Getting started with non EMF Domain Models, need an example [message #862640 is a reply to message #809443] Sun, 29 April 2012 04:41 Go to previous messageGo to next message
richi arora is currently offline richi aroraFriend
Messages: 5
Registered: April 2012
Junior Member
hi where can i find DomainModelChangeListener class as mentioned in graphiti help for using diagram editor for non-emf domain.
I want to drag drop any java class (pojos) in diagram editor and make associations.
Re: Getting started with non EMF Domain Models, need an example [message #862652 is a reply to message #765844] Sun, 29 April 2012 04:40 Go to previous messageGo to next message
Eclipse UserFriend
Hi

Where can I find DomainModelChangeListener class as mentioned in graphiti help for non-emf models.

I want to achieve following:
drag a java class and drop on diagram editor.
I only want to use add feature of grahiti as for now
Re: Getting started with non EMF Domain Models, need an example [message #862653 is a reply to message #809443] Sun, 29 April 2012 04:41 Go to previous messageGo to next message
Eclipse UserFriend
hi where can i find DomainModelChangeListener class as mentioned in graphiti help for using diagram editor for non-emf domain.
I want to drag drop any java class (pojos) in diagram editor and make associations.
Re: Getting started with non EMF Domain Models, need an example [message #862665 is a reply to message #765844] Sun, 29 April 2012 04:40 Go to previous messageGo to next message
Eclipse UserFriend
Hi

Where can I find DomainModelChangeListener class as mentioned in graphiti help for non-emf models.

I want to achieve following:
drag a java class and drop on diagram editor.
I only want to use add feature of grahiti as for now
Re: Getting started with non EMF Domain Models, need an example [message #862666 is a reply to message #809443] Sun, 29 April 2012 04:41 Go to previous messageGo to next message
Eclipse UserFriend
hi where can i find DomainModelChangeListener class as mentioned in graphiti help for using diagram editor for non-emf domain.
I want to drag drop any java class (pojos) in diagram editor and make associations.
Re: Getting started with non EMF Domain Models, need an example [message #862678 is a reply to message #765844] Sun, 29 April 2012 04:40 Go to previous messageGo to next message
Eclipse UserFriend
Hi

Where can I find DomainModelChangeListener class as mentioned in graphiti help for non-emf models.

I want to achieve following:
drag a java class and drop on diagram editor.
I only want to use add feature of grahiti as for now
Re: Getting started with non EMF Domain Models, need an example [message #862679 is a reply to message #809443] Sun, 29 April 2012 04:41 Go to previous messageGo to next message
Eclipse UserFriend
hi where can i find DomainModelChangeListener class as mentioned in graphiti help for using diagram editor for non-emf domain.
I want to drag drop any java class (pojos) in diagram editor and make associations.
Re: Getting started with non EMF Domain Models, need an example [message #862691 is a reply to message #765844] Sun, 29 April 2012 04:40 Go to previous messageGo to next message
Eclipse UserFriend
Hi

Where can I find DomainModelChangeListener class as mentioned in graphiti help for non-emf models.

I want to achieve following:
drag a java class and drop on diagram editor.
I only want to use add feature of grahiti as for now
Re: Getting started with non EMF Domain Models, need an example [message #862692 is a reply to message #809443] Sun, 29 April 2012 04:41 Go to previous messageGo to next message
Eclipse UserFriend
hi where can i find DomainModelChangeListener class as mentioned in graphiti help for using diagram editor for non-emf domain.
I want to drag drop any java class (pojos) in diagram editor and make associations.
Re: Getting started with non EMF Domain Models, need an example [message #862704 is a reply to message #765844] Sun, 29 April 2012 04:40 Go to previous messageGo to next message
Eclipse UserFriend
Hi

Where can I find DomainModelChangeListener class as mentioned in graphiti help for non-emf models.

I want to achieve following:
drag a java class and drop on diagram editor.
I only want to use add feature of grahiti as for now
Re: Getting started with non EMF Domain Models, need an example [message #862705 is a reply to message #809443] Sun, 29 April 2012 04:41 Go to previous messageGo to next message
Eclipse UserFriend
hi where can i find DomainModelChangeListener class as mentioned in graphiti help for using diagram editor for non-emf domain.
I want to drag drop any java class (pojos) in diagram editor and make associations.
Re: Getting started with non EMF Domain Models, need an example [message #862718 is a reply to message #765844] Sun, 29 April 2012 04:40 Go to previous messageGo to next message
Eclipse UserFriend
Hi

Where can I find DomainModelChangeListener class as mentioned in graphiti help for non-emf models.

I want to achieve following:
drag a java class and drop on diagram editor.
I only want to use add feature of grahiti as for now
Re: Getting started with non EMF Domain Models, need an example [message #862719 is a reply to message #809443] Sun, 29 April 2012 04:41 Go to previous messageGo to next message
Eclipse UserFriend
hi where can i find DomainModelChangeListener class as mentioned in graphiti help for using diagram editor for non-emf domain.
I want to drag drop any java class (pojos) in diagram editor and make associations.
Re: Getting started with non EMF Domain Models, need an example [message #862731 is a reply to message #765844] Sun, 29 April 2012 04:40 Go to previous messageGo to next message
Eclipse UserFriend
Hi

Where can I find DomainModelChangeListener class as mentioned in graphiti help for non-emf models.

I want to achieve following:
drag a java class and drop on diagram editor.
I only want to use add feature of grahiti as for now
Re: Getting started with non EMF Domain Models, need an example [message #862732 is a reply to message #809443] Sun, 29 April 2012 04:41 Go to previous messageGo to next message
Eclipse UserFriend
hi where can i find DomainModelChangeListener class as mentioned in graphiti help for using diagram editor for non-emf domain.
I want to drag drop any java class (pojos) in diagram editor and make associations.
Re: Getting started with non EMF Domain Models, need an example [message #862745 is a reply to message #765844] Sun, 29 April 2012 04:40 Go to previous messageGo to next message
Eclipse UserFriend
Hi

Where can I find DomainModelChangeListener class as mentioned in graphiti help for non-emf models.

I want to achieve following:
drag a java class and drop on diagram editor.
I only want to use add feature of grahiti as for now
Re: Getting started with non EMF Domain Models, need an example [message #862746 is a reply to message #809443] Sun, 29 April 2012 04:41 Go to previous messageGo to next message
Eclipse UserFriend
hi where can i find DomainModelChangeListener class as mentioned in graphiti help for using diagram editor for non-emf domain.
I want to drag drop any java class (pojos) in diagram editor and make associations.
Re: Getting started with non EMF Domain Models, need an example [message #862759 is a reply to message #765844] Sun, 29 April 2012 04:40 Go to previous messageGo to next message
Eclipse UserFriend
Hi

Where can I find DomainModelChangeListener class as mentioned in graphiti help for non-emf models.

I want to achieve following:
drag a java class and drop on diagram editor.
I only want to use add feature of grahiti as for now
Re: Getting started with non EMF Domain Models, need an example [message #862760 is a reply to message #809443] Sun, 29 April 2012 04:41 Go to previous messageGo to next message
Eclipse UserFriend
hi where can i find DomainModelChangeListener class as mentioned in graphiti help for using diagram editor for non-emf domain.
I want to drag drop any java class (pojos) in diagram editor and make associations.
Re: Getting started with non EMF Domain Models, need an example [message #862773 is a reply to message #765844] Sun, 29 April 2012 04:40 Go to previous messageGo to next message
Eclipse UserFriend
Hi

Where can I find DomainModelChangeListener class as mentioned in graphiti help for non-emf models.

I want to achieve following:
drag a java class and drop on diagram editor.
I only want to use add feature of grahiti as for now
Re: Getting started with non EMF Domain Models, need an example [message #862774 is a reply to message #809443] Sun, 29 April 2012 04:41 Go to previous messageGo to next message
Eclipse UserFriend
hi where can i find DomainModelChangeListener class as mentioned in graphiti help for using diagram editor for non-emf domain.
I want to drag drop any java class (pojos) in diagram editor and make associations.
Re: Getting started with non EMF Domain Models, need an example [message #862787 is a reply to message #765844] Sun, 29 April 2012 04:40 Go to previous messageGo to next message
Eclipse UserFriend
Hi

Where can I find DomainModelChangeListener class as mentioned in graphiti help for non-emf models.

I want to achieve following:
drag a java class and drop on diagram editor.
I only want to use add feature of grahiti as for now
Re: Getting started with non EMF Domain Models, need an example [message #862788 is a reply to message #809443] Sun, 29 April 2012 04:41 Go to previous messageGo to next message
Eclipse UserFriend
hi where can i find DomainModelChangeListener class as mentioned in graphiti help for using diagram editor for non-emf domain.
I want to drag drop any java class (pojos) in diagram editor and make associations.
Re: Getting started with non EMF Domain Models, need an example [message #862800 is a reply to message #765844] Sun, 29 April 2012 04:40 Go to previous messageGo to next message
Eclipse UserFriend
Hi

Where can I find DomainModelChangeListener class as mentioned in graphiti help for non-emf models.

I want to achieve following:
drag a java class and drop on diagram editor.
I only want to use add feature of grahiti as for now
Re: Getting started with non EMF Domain Models, need an example [message #862801 is a reply to message #809443] Sun, 29 April 2012 04:41 Go to previous messageGo to next message
Eclipse UserFriend
hi where can i find DomainModelChangeListener class as mentioned in graphiti help for using diagram editor for non-emf domain.
I want to drag drop any java class (pojos) in diagram editor and make associations.
Re: Getting started with non EMF Domain Models, need an example [message #862811 is a reply to message #765844] Sun, 29 April 2012 04:40 Go to previous messageGo to next message
richi arora is currently offline richi aroraFriend
Messages: 5
Registered: April 2012
Junior Member
Hi

Where can I find DomainModelChangeListener class as mentioned in graphiti help for non-emf models.

I want to achieve following:
drag a java class and drop on diagram editor.
I only want to use add feature of grahiti as for now
Re: Getting started with non EMF Domain Models, need an example [message #862812 is a reply to message #809443] Sun, 29 April 2012 04:41 Go to previous messageGo to next message
richi arora is currently offline richi aroraFriend
Messages: 5
Registered: April 2012
Junior Member
hi where can i find DomainModelChangeListener class as mentioned in graphiti help for using diagram editor for non-emf domain.
I want to drag drop any java class (pojos) in diagram editor and make associations.
Re: Getting started with non EMF Domain Models, need an example [message #865065 is a reply to message #862812] Mon, 30 April 2012 08:01 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1637
Registered: July 2009
Location: Walldorf, Germany
Senior Member
This listener only depends on the domain you are using, so in this case it
would be a listener to JDT. In general Graphiti relies on being notified
when any of the domain objects shown on a diagram changes; an according
update needs to be triggered then. Unfortunatly I'm not familiar with JDT to
know what exactly you would need to register.

Michael
Re: Getting started with non EMF Domain Models, need an example [message #865252 is a reply to message #865065] Mon, 30 April 2012 10:01 Go to previous messageGo to next message
richi arora is currently offline richi aroraFriend
Messages: 5
Registered: April 2012
Junior Member
How can I drag drop an custom class in diagram editor rather than adding from a pallete
Re: Getting started with non EMF Domain Models, need an example [message #868573 is a reply to message #865252] Wed, 02 May 2012 08:38 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1637
Registered: July 2009
Location: Walldorf, Germany
Senior Member
There's an example on how to do dupport drag&drop from the project explorer
in the tutorial. Did you have a look at that?

Michael
Re: Getting started with non EMF Domain Models, need an example [message #900268 is a reply to message #868573] Mon, 06 August 2012 09:26 Go to previous messageGo to next message
Saniya Mirajkar is currently offline Saniya MirajkarFriend
Messages: 30
Registered: August 2012
Member
Hi,

We are using the example attached in this post as a reference for creating graphical representations of non-EMF models.

In my case, I do not want to drag and drop the domain objects from pallete. I have an context menu action in the Jface tree-viewer.I want the graphical representation of the object to be added in the diagram editor on click of this particular action.

Any pointers around this?
Re: Getting started with non EMF Domain Models, need an example [message #900272 is a reply to message #900268] Mon, 06 August 2012 09:50 Go to previous messageGo to next message
Nikolai Raitsev is currently offline Nikolai RaitsevFriend
Messages: 102
Registered: July 2009
Senior Member
Hi,

I get it done in a follow way (with drag & drop): I have a TreeView with my custom, Non-EMF Objects and an editor. If I drag & drop an object from the TreeView into the editor, I create a new "Binding" with AddFeature to the diagram.

Unfortunately, my "Example" does not work anymore, after updating Graphiti to the 0.9x version. I need some time, to correct the code and test it. After that, I will upload it here.

Best regards,

Nikolai
Re: Getting started with non EMF Domain Models, need an example [message #900278 is a reply to message #900272] Mon, 06 August 2012 10:23 Go to previous messageGo to next message
Saniya Mirajkar is currently offline Saniya MirajkarFriend
Messages: 30
Registered: August 2012
Member
In my context menu action class I do the following to open up the editor.

final String diagramTypeId = "test.graphiti.nonemf.diagram.DiagramType";

			final Diagram diagram = Graphiti.getPeCreateService()
					.createDiagram(diagramTypeId,
							"test.graphiti.nonemf.diagram.DiagramType", false);

			final String editorID = NonEmfDiagramEditor.DIAGRAM_EDITOR_ID;

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

			URI uri = URI.createPlatformResourceURI(diagramFile.getFullPath()
					.toString(), true);

			TransactionalEditingDomain editingDomain = FileService
					.createEmfFileForDiagram(uri, diagram);
			String providerId = "test.graphiti.nonemf.diagram.DiagramTypeProvider";
			DiagramEditorInput editorInput = new DiagramEditorInput(
					EcoreUtil.getURI(diagram), editingDomain, providerId, true);

			IDiagramTypeProvider dtyProvider = ExtensionManager.getSingleton()
					.createDiagramTypeProvider(providerId);

			PlatformUI.getWorkbench().getActiveWorkbenchWindow()
					.getActivePage().openEditor(editorInput, editorID);
this.createExampleStructure(dtyProvider, editingDomain, diagram,
					doaminObject);


And in the createExampleStructure function, I call the Add feature for the domain object as follows:

private void createExampleStructure(final IDiagramTypeProvider ddtp,
			final TransactionalEditingDomain editingDomain,
			final Diagram diagram, DomainObject domainObject) {

		int x = 20;
		int y = 20;

		AddContext addcontext = new AddContext();
		IFeatureProvider featureprovider = ddtp.getFeatureProvider();

		AddDomainClassFeature addFvFeature = new AddDomainClassFeature(
				featureprovider);

		addcontext.setNewObject(domainObject);
		addcontext.setTargetContainer(diagram);

		addcontext.setX(x);
		addcontext.setY(y);

		if (addFvFeature.canAdd(addcontext)) {
			addFvFeature.add(addcontext);
		}

	}


With this I get an Error "Cannot modify resource set without a write transaction"

Is this the right way to do or am I missing something?

[Updated on: Thu, 09 August 2012 09:11]

Report message to a moderator

Re: Getting started with non EMF Domain Models, need an example [message #900315 is a reply to message #900272] Mon, 06 August 2012 13:03 Go to previous messageGo to next message
Saniya Mirajkar is currently offline Saniya MirajkarFriend
Messages: 30
Registered: August 2012
Member
Hi Nikolai,

Can you please post the example.
Re: Getting started with non EMF Domain Models, need an example [message #900565 is a reply to message #900315] Tue, 07 August 2012 14:50 Go to previous messageGo to previous message
Nikolai Raitsev is currently offline Nikolai RaitsevFriend
Messages: 102
Registered: July 2009
Senior Member
Hi Hemlata,

I have uploaded my example to github: https://github.com/kumarunster/phirea.public/tree/master/test.graphiti.nonemf

please check it out and look at two dnd-packages/classes (Drag/Drop-Listener).

Best regards,

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


Current Time: Fri Nov 28 13:43:20 GMT 2014

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

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