| Create Diagram Model Programatically [message #708892] |
Wed, 03 August 2011 05:06  |
Murthy Bhat Messages: 137 Registered: July 2009 |
Senior Member |
|
|
Hello,
I have a graphiti editor which i use to create/edit certain domain model. The diagram information is all stored in the same file when saved. However there are some old domain models which do not have the Diagram model within them. So when I load the old files, I want to create corresponding pictogram elements and other graphics programmatically.
I have created the diagram using:
Diagram diagram = Graphiti.getPeCreateService().createDiagram(diagramTypeId, diagramName, true);
Is there any way to create pictogram elements and graphics algorithms programmatically or should I create each element using the create features only?
Thanks in advance for help.
Best Regards,
Murthy
[Updated on: Wed, 03 August 2011 05:11] Report message to a moderator
|
|
|
| Re: Create Diagram Model Programatically [message #708915 is a reply to message #708892] |
Wed, 03 August 2011 05:28   |
Joerg Reichert Messages: 60 Registered: July 2009 Location: Leipzig |
Member |
|
|
Hi Murthy,
sure it is. Economically you can reuse the logic of your add feature implementation:
private void createExampleStructure(
final IDiagramTypeProvider ddtp,
final Diagram diagram, DomainObject domainObject) {
AddDomainObjectFeature add = new AddDomainObjectFeature(
ddtp.getFeatureProvider()) {
public IFeatureProvider getFeatureProvider() {
return ddtp.getFeatureProvider();
}
protected Diagram getDiagram() {
return diagram;
}
};
AddContext context = new AddContext();
context.setNewObject(domainObject);
context.setTargetContainer(diagram);
add.add(context);
}
Depending in which context you want to execute the creation you have to provide the containing diagram and feature provider.
Regards,
Joerg
--
Need professional support for Xtext and EMF?
Go to: http://xtext.itemis.com
|
|
|
|
|
| Re: Create Diagram Model Programatically [message #717737 is a reply to message #717719] |
Mon, 22 August 2011 04:26   |
Joerg Reichert Messages: 60 Registered: July 2009 Location: Leipzig |
Member |
|
|
Hi Murthy,
I just looked into my code once again and noticed that only depend on the feature provider as I use the direct editing support. In any other case you should not depend on that.
I also had two use cases
- Create Diagram file (and content) for existing domain model
- Create initial domain model and associated initial diagram file
My notion was just to reuse the logic of the PictogramElement add(IAddContext context), but you may redefine such logic also outside the add feature class. You only need your loaded domain model and a diagram object as starting point, this can be easily created by
Diagram diagram = Graphiti.getPeCreateService().createDiagram(yourDiagramTypeId, diagramName, true);
The you have the create services:
IPeService peService = Graphiti.getPeService();
IPeCreateService peCreateService = Graphiti.getPeCreateService();
IGaService gaService = Graphiti.getGaService();
and you can as usual create your graphical elements and link them with the corresponding domain model objects.
Regards
Joerg
--
Need professional support for Xtext and EMF?
Go to: http://xtext.itemis.com
|
|
|
|
| Re: Create Diagram Model Programatically [message #719841 is a reply to message #719802] |
Mon, 29 August 2011 03:56   |
Joerg Reichert Messages: 60 Registered: July 2009 Location: Leipzig |
Member |
|
|
Hi Murthy,
I think this is due to the fact, that you had created the anchors without associating them without an org.eclipse.graphiti.mm.pictograms.AnchorContainer and without a referenced GA (see setReferencedGraphicsAlgorithm). An anchor have to belong to a graphical element, that should be an connection end. The anchor itself is only the concept of a connection point of that element (as far as I understand). So e.g. a rectangle has a list of anchors (AnchorContainer.getAnchors()).
Regards,
Joerg
--
Need professional support for Xtext and EMF?
Go to: http://xtext.itemis.com
|
|
|
|
| Re: Create Diagram Model Programatically [message #722908 is a reply to message #722898] |
Wed, 07 September 2011 03:17   |
Joerg Reichert Messages: 60 Registered: July 2009 Location: Leipzig |
Member |
|
|
Hi Murthy,
the decorators of the connection are visible, but the polyline itself is not?
I have had an issue when not setting the source and target pictogram elements at the add connection context beside the the anchors.
Create[DomainObject]AssociationFeature createLink = new Create[DomainObject]AssociationFeature(
getFeatureProvider());
Anchor startAnchor = ...
Anchor endAnchor = ...
if(startAnchor != null && endAnchor != null) {
CreateConnectionContext createContext = new CreateConnectionContext();
createContext.setSourcePictogramElement(startAnchor.getParent());
createContext.setSourceAnchor(startAnchor);
createContext.setTargetPictogramElement(endAnchor.getParent());
createContext.setTargetAnchor(endAnchor);
if(createLink.canCreate(createContext)) {
createLink.create(createContext);
}
}
I used the create connection feature as the domain object for the connection should be created, too. Inside the create connection feature the add connection feature is called. And this code looks identical to yours.
Joerg
--
Need professional support for Xtext and EMF?
Go to: http://xtext.itemis.com
|
|
|
|
|
|
| Re: Create Diagram Model Programatically [message #875708 is a reply to message #717737] |
Wed, 23 May 2012 04:01  |
Joyce Liao Messages: 1 Registered: May 2012 |
Junior Member |
|
|
Hi Joerg, Hi Murthy
I have the same question now. I am a bigger at Graphiti.
Could you please give the code example about "you can as usual create your graphical elements and link them with the corresponding domain model objects"
Thank you very much
Joerg Reichert wrote on Mon, 22 August 2011 04:26Hi Murthy,
I just looked into my code once again and noticed that only depend on the feature provider as I use the direct editing support. In any other case you should not depend on that.
I also had two use cases
- Create Diagram file (and content) for existing domain model
- Create initial domain model and associated initial diagram file
My notion was just to reuse the logic of the PictogramElement add(IAddContext context), but you may redefine such logic also outside the add feature class. You only need your loaded domain model and a diagram object as starting point, this can be easily created by
Diagram diagram = Graphiti.getPeCreateService().createDiagram(yourDiagramTypeId, diagramName, true);
The you have the create services:
IPeService peService = Graphiti.getPeService();
IPeCreateService peCreateService = Graphiti.getPeCreateService();
IGaService gaService = Graphiti.getGaService();
and you can as usual create your graphical elements and link them with the corresponding domain model objects.
Regards
Joerg
|
|
|
Powered by
FUDForum. Page generated in 0.11439 seconds