Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » Adding Root Domain Object on Diagram Creation
Adding Root Domain Object on Diagram Creation [message #1001959] Thu, 17 January 2013 16:02 Go to next message
Dan Simkins is currently offline Dan SimkinsFriend
Messages: 38
Registered: December 2012
Member
Hi,

I have created a custom Diagram Editor by extending DiagramEditor.

I have created a custom New Diagram Wizard by extending BasicNewResourceWizard.

I am struggling to determine the correct place to automatically add the root domain object on diagram creation. I have tried after opening the newly created diagram as follows:

try
{
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor( editorInput, editorID );

ModelPackageImpl.init();
Model model = ControlFactory.eINSTANCE.createModel();
diagram.eResource().getContents().add( model );
}

and whilst I get no exception, the resultant new diagram file does not contain the root domain object.

Any pointers would be greatly appreciated.

Thanks

Dan
Re: Adding Root Domain Object on Diagram Creation [message #1001973 is a reply to message #1001959] Thu, 17 January 2013 16:22 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1931
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Dan,

why don't you add your domain root object along with the diagram within your
wizard?

Michael
Re: Adding Root Domain Object on Diagram Creation [message #1001985 is a reply to message #1001973] Thu, 17 January 2013 16:52 Go to previous messageGo to next message
Dan Simkins is currently offline Dan SimkinsFriend
Messages: 38
Registered: December 2012
Member
Hi Michael,

That's what I'm trying to do, but failing miserably - I seem to have 'code' blindness!!

I am trying to add it (as per above) in the performFinish method. I have tried in a number of places. For instance, after creating the diagram (using - Diagram diagram = Graphiti.getPeCreateService().createDiagram( diagramTypeId, diagramName, true ) ), if I attempt to create and add the root domain at that point, I get a null pointer exception on execution at:

diagram.eResource().getContents().add( model );

I'm sure I must be doing something really dumb!

Dan

[Updated on: Thu, 17 January 2013 18:03]

Report message to a moderator

Re: Adding Root Domain Object on Diagram Creation [message #1002080 is a reply to message #1001985] Thu, 17 January 2013 22:23 Go to previous messageGo to next message
Hallvard Traetteberg is currently offline Hallvard TraettebergFriend
Messages: 673
Registered: July 2009
Location: Trondheim, Norway
Senior Member
On 17.01.13 08.52, Dan Simkins wrote:
> Hi Michael,
>
> That's what I'm trying to do, but failing miserably - I seem to have
> 'code' blindness!!
>
> I am trying to add it (as per above) in the performFinish method. I have
> tried in a number of places. For instance, after creating the diagram
> (using - Diagram diagram = Graphiti.getPeCreateService().createDiagram(
> diagramTypeId, diagramName, true ) ), if I attempt to create and add the
> root domain at that point, I get a null pointer exception on execution of:
>
> diagram.eResource().getContents().add( model );

It seems diagram is not inside a resource, hence eResource() returns
null. Have you created a ResourceSet and a Resource and added the
diagram? Below I've pasted code from
org.eclipse.graphiti.examples.common.FileService that does that. Insert
a call to it before the line that gives an NPE.

Hallvard

package org.eclipse.graphiti.examples.common;

public class FileService {

/**
* @since 0.9
*/
public static void createEmfFileForDiagram(URI diagramResourceUri,
final Diagram diagram) {

// Create a resource set and EditingDomain
final TransactionalEditingDomain editingDomain =
GraphitiUiInternal.getEmfService()
.createResourceSetAndEditingDomain();
final ResourceSet resourceSet = editingDomain.getResourceSet();
// Create a resource for this file.
final Resource resource = resourceSet.createResource(diagramResourceUri);
final CommandStack commandStack = editingDomain.getCommandStack();
commandStack.execute(new RecordingCommand(editingDomain) {

@Override
protected void doExecute() {
resource.setTrackingModification(true);
resource.getContents().add(diagram);

}
});

save(editingDomain, Collections.<Resource, Map<?, ?>> emptyMap());
editingDomain.dispose();
}

Hallvard
Re: Adding Root Domain Object on Diagram Creation [message #1002090 is a reply to message #1002080] Thu, 17 January 2013 22:59 Go to previous messageGo to next message
Dan Simkins is currently offline Dan SimkinsFriend
Messages: 38
Registered: December 2012
Member
Hi Hallvard,

Thanks for your response.

In my initial post, I had tried to add the root domain object after the call to createEmfFileForDiagram. My apologies - my subsequent post was misleading in that I tried adding the root domain object before the call to createEmfFileForDiagram and as you correctly noted, no resource had been created and thus I got a NPE.

My problem still remains the same - the essential sequence is as below, however, the resultant diagram file (which is fine in all other respects) does not contain my root domain object:

Diagram diagram = Graphiti.getPeCreateService().createDiagram( diagramTypeId, diagramName, true );

IFile diagramFile = diagramFolder.getFile( diagramName + "." + editorExtension );

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

FileService.createEmfFileForDiagram( uri, diagram );

String providerId = GraphitiUi.getExtensionManager().getDiagramTypeProviderId( diagram.getDiagramTypeId() );

DiagramEditorInput editorInput = new DiagramEditorInput( EcoreUtil.getURI( diagram ), providerId );

try
{
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor( editorInput, editorID );

ModelPackageImpl.init();
Model model = ControlFactory.eINSTANCE.createModel();
diagram.eResource().getContents().add( model );
}
...

Apologies for the misleading NPE post.

I would really appreciate any ideas.

Thanks

Dan

Re: Adding Root Domain Object on Diagram Creation [message #1002522 is a reply to message #1002090] Fri, 18 January 2013 19:01 Go to previous messageGo to next message
Hallvard Traetteberg is currently offline Hallvard TraettebergFriend
Messages: 673
Registered: July 2009
Location: Trondheim, Norway
Senior Member
Dan,

You must link the diagram to it, too.

Hallvard

On 17.01.13 14.59, Dan Simkins wrote:
> Hi Hallvard,
>
> Thanks for your response.
>
> In my initial post, I had tried to add the root domain object after the
> call to createEmfFileForDiagram. My apologies - my subsequent post was
> misleading in that I tried adding the root domain object before the call
> to createEmfFileForDiagram and as you correctly noted, no resource had
> been created and thus I got a NPE.
>
> My problem still remains the same - the essential sequence is as below,
> however, the resultant diagram file (which is fine in all other
> respects) does not contain my root domain object:
>
> Diagram diagram = Graphiti.getPeCreateService().createDiagram(
> diagramTypeId, diagramName, true );
>
> IFile diagramFile = diagramFolder.getFile( diagramName + "." +
> editorExtension );
> URI uri = URI.createPlatformResourceURI(
> diagramFile.getFullPath().toString(), true );
>
> FileService.createEmfFileForDiagram( uri, diagram );
>
> String providerId =
> GraphitiUi.getExtensionManager().getDiagramTypeProviderId(
> diagram.getDiagramTypeId() );
>
> DiagramEditorInput editorInput = new DiagramEditorInput(
> EcoreUtil.getURI( diagram ), providerId );
>
> try
> {
>
> PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(
> editorInput, editorID );
>
> ModelPackageImpl.init();
> Model model = ControlFactory.eINSTANCE.createModel();
> diagram.eResource().getContents().add( model );
> }
> ..
>
> Apologies for the misleading NPE post.
>
> I would really appreciate any ideas.
>
> Thanks
>
> Dan
>
>
Re: Adding Root Domain Object on Diagram Creation [message #1004001 is a reply to message #1002522] Tue, 22 January 2013 11:56 Go to previous message
Dan Simkins is currently offline Dan SimkinsFriend
Messages: 38
Registered: December 2012
Member
Hi Hallvard,

Thanks for your response.

The problem was solved by utilising the "Dark Feature Processing" as set-out in the help.

Dan
Previous Topic:Custom Save
Next Topic:Multiple ImageProviders in separate plug-ins
Goto Forum:
  


Current Time: Sun Sep 22 21:38:29 GMT 2024

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

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

Back to the top