Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » how to add a node in sub - diagram programmatically
how to add a node in sub - diagram programmatically [message #547473] Sat, 17 July 2010 11:02 Go to next message
AlexejS Mising name is currently offline AlexejS Mising nameFriend
Messages: 25
Registered: May 2010
Junior Member
Hello @ all,

until now for me it is possible to add a node in my main diagram like:



		        				Petrinet owner = (Petrinet) ((View) part.getModel()).getElement();
		        				owner.getNodes().get(2).getNodes().add(newElement);	
		                    	
		        				CreateViewRequest.ViewDescriptor viewDescriptor = new CreateViewRequest.ViewDescriptor(new EObjectAdapter(
		        						newElement), Node.class, ((IHintedType) PetrinetsElementTypes
		        						.getElementType(PlaceEditPart.VISUAL_ID)).getSemanticHint(), true, part
		        						.getDiagramPreferencesHint());
		        				viewDescriptor.setPersisted(true);
		        				CreateViewRequest createViewRequest = new CreateViewRequest(viewDescriptor);
		        				Command createViewCommand = part.getCommand(createViewRequest);
		        				createViewCommand.execute();




my problem is to add it in a sub - diagram (partition diagram).

When i doublecklick on a node, a new tab with my subdiagram appear, an there i want to place a new node programmatically.

can anybody help me,

thx


Re: how to add a node in sub - diagram programmatically [message #548421 is a reply to message #547473] Wed, 21 July 2010 18:34 Go to previous messageGo to next message
AlexejS Mising name is currently offline AlexejS Mising nameFriend
Messages: 25
Registered: May 2010
Junior Member
A smal hint is enough Smile
Re: how to add a node in sub - diagram programmatically [message #548583 is a reply to message #547473] Thu, 22 July 2010 11:51 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: marius.groeger.googlemail.com

Am 17.07.2010 13:02, schrieb AlexejS:
> Command createViewCommand = part.getCommand(createViewRequest);
> createViewCommand.execute();
>
> my problem is to add it in a sub - diagram (partition diagram).
>
> When i doublecklick on a node, a new tab with my subdiagram appear, an
> there i want to place a new node programmatically.

The "part" in your code determines where your new View will be created.
You should pass the DiagramEditPart of your sub diagram.

Regards
Marius
Re: how to add a node in sub - diagram programmatically [message #548584 is a reply to message #547473] Thu, 22 July 2010 11:51 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: marius.groeger.googlemail.com

Am 17.07.2010 13:02, schrieb AlexejS:
> Command createViewCommand = part.getCommand(createViewRequest);
> createViewCommand.execute();
>
> my problem is to add it in a sub - diagram (partition diagram).
>
> When i doublecklick on a node, a new tab with my subdiagram appear, an
> there i want to place a new node programmatically.

The "part" in your code determines where your new View will be created.
You should pass the DiagramEditPart of your sub diagram.

Regards
Marius
Re: how to add a node in sub - diagram programmatically [message #548585 is a reply to message #547473] Thu, 22 July 2010 11:51 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: marius.groeger.googlemail.com

Am 17.07.2010 13:02, schrieb AlexejS:
> Command createViewCommand = part.getCommand(createViewRequest);
> createViewCommand.execute();
>
> my problem is to add it in a sub - diagram (partition diagram).
>
> When i doublecklick on a node, a new tab with my subdiagram appear, an
> there i want to place a new node programmatically.

The "part" in your code determines where your new View will be created.
You should pass the DiagramEditPart of your sub diagram.

Regards
Marius
Re: how to add a node in sub - diagram programmatically [message #548586 is a reply to message #547473] Thu, 22 July 2010 11:51 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: marius.groeger.googlemail.com

Am 17.07.2010 13:02, schrieb AlexejS:
> Command createViewCommand = part.getCommand(createViewRequest);
> createViewCommand.execute();
>
> my problem is to add it in a sub - diagram (partition diagram).
>
> When i doublecklick on a node, a new tab with my subdiagram appear, an
> there i want to place a new node programmatically.

The "part" in your code determines where your new View will be created.
You should pass the DiagramEditPart of your sub diagram.

Regards
Marius
Re: how to add a node in sub - diagram programmatically [message #548588 is a reply to message #548583] Thu, 22 July 2010 12:02 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: marius.groeger.googlemail.com

Sorry for the multiple posts, I had mail server issues with the OP and
didn't realize that the news version went out on each retry...

Regards
Marius
Re: how to add a node in sub - diagram programmatically [message #548600 is a reply to message #548586] Thu, 22 July 2010 12:39 Go to previous messageGo to next message
AlexejS Mising name is currently offline AlexejS Mising nameFriend
Messages: 25
Registered: May 2010
Junior Member
Eclipse User wrote on Thu, 22 July 2010 07:51
Originally posted by: marius.groeger.googlemail.com

Am 17.07.2010 13:02, schrieb AlexejS:
> Command createViewCommand = part.getCommand(createViewRequest);
> createViewCommand.execute();
>
> my problem is to add it in a sub - diagram (partition diagram).
>
> When i doublecklick on a node, a new tab with my subdiagram appear, an
> there i want to place a new node programmatically.

The "part" in your code determines where your new View will be created.
You should pass the DiagramEditPart of your sub diagram.

Regards
Marius


Thx for your Reply! I understand what you mean.

		protected CommandResult doExecuteWithResult(IProgressMonitor monitor,
				IAdaptable info) throws ExecutionException {
			try {
				Diagram diagram = getDiagramToOpen();
				if (diagram == null) {
					diagram = intializeNewDiagram();
				}
				URI uri = EcoreUtil.getURI(diagram);
				String editorName = uri.lastSegment()
						+ "#" + diagram.eResource().getContents().indexOf(diagram); //$NON-NLS-1$
				IEditorInput editorInput = new URIEditorInput(uri, editorName);
				IWorkbenchPage page = PlatformUI.getWorkbench()
						.getActiveWorkbenchWindow().getActivePage();
				page.openEditor(editorInput, getEditorID());
				//diagram.insertChild((View) targetEditPart.getParent().getModel());
			

				Place newElement = PetrinetsFactory.eINSTANCE.createPlace();
				newElement.setMarkCount(0);
				newElement.setCapacity(-1);
				Petrinet owner = (Petrinet) ((View) targetEditPart.getParent().getModel()).getElement();
				owner.getNodes().get(0).getNodes().add(newElement);	
				CreateViewRequest.ViewDescriptor viewDescriptor = new CreateViewRequest.ViewDescriptor(new EObjectAdapter(
						newElement), Node.class, ((IHintedType) PetrinetsElementTypes
						.getElementType(PlaceEditPart.VISUAL_ID)).getSemanticHint(), true, ??????);
				viewDescriptor.setPersisted(true);
				CreateViewRequest createViewRequest = new CreateViewRequest(viewDescriptor);
				Command createViewCommand =  ????????.getCommand(createViewRequest);
				createViewCommand.execute();



Here the subdiagram is created. Now my aim is to use the Object diagram, to get the EditPart of them. But how?
I really don't want to disturb you. Smile But my nerves are down by now. Smile
Re: how to add a node in sub - diagram programmatically [message #548623 is a reply to message #548600] Thu, 22 July 2010 13:41 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: marius.groeger.googlemail.com

Am 22.07.2010 14:39, schrieb AlexejS:
> protected CommandResult doExecuteWithResult(IProgressMonitor monitor,
> IAdaptable info) throws ExecutionException {
> try {
> Diagram diagram = getDiagramToOpen();
> if (diagram == null) {
> diagram = intializeNewDiagram();
> }
> URI uri = EcoreUtil.getURI(diagram);
> String editorName = uri.lastSegment()
> + "#" + diagram.eResource().getContents().indexOf(diagram); //$NON-NLS-1$
> IEditorInput editorInput = new URIEditorInput(uri, editorName);
> IWorkbenchPage page = PlatformUI.getWorkbench()
> .getActiveWorkbenchWindow().getActivePage();
> page.openEditor(editorInput, getEditorID());
> //diagram.insertChild((View) targetEditPart.getParent().getModel());
>
>
> Place newElement = PetrinetsFactory.eINSTANCE.createPlace();
> newElement.setMarkCount(0);
> newElement.setCapacity(-1);
> Petrinet owner = (Petrinet) ((View)
> targetEditPart.getParent().getModel()).getElement();
> owner.getNodes().get(0).getNodes().add(newElement);
> CreateViewRequest.ViewDescriptor viewDescriptor = new
> CreateViewRequest.ViewDescriptor(new EObjectAdapter(
> newElement), Node.class, ((IHintedType) PetrinetsElementTypes
> .getElementType(PlaceEditPart.VISUAL_ID)).getSemanticHint(), true, ??????);
> viewDescriptor.setPersisted(true);
> CreateViewRequest createViewRequest = new
> CreateViewRequest(viewDescriptor);
> Command createViewCommand = ????????.getCommand(createViewRequest);
> createViewCommand.execute();
>
>
>
> Here the subdiagram is created. Now my aim is to use the Object diagram,
> to get the EditPart of them. But how?

Try this:

:
IEditorPart ep = page.openEditor(editorInput, getEditorID());
DiagramEditPart dep = ((DiagramEditor)ep).getDiagramEditPart();
:
Command createViewCommand = dep.getCommand(createViewRequest);

> I really don't want to disturb you. :) But my nerves are down by now. :)

No worries... I know how it feels like ;-)

Regards
Marius
Re: how to add a node in sub - diagram programmatically [message #548627 is a reply to message #548623] Thu, 22 July 2010 14:01 Go to previous message
AlexejS Mising name is currently offline AlexejS Mising nameFriend
Messages: 25
Registered: May 2010
Junior Member
Yes, thats it!!!
It solves my Problem. Best regards!
I'm very happy now! Smile

Super! Thx!

Previous Topic:How to enable logging in WME?
Next Topic:Question about xsi:schemaLocation in models with different packages
Goto Forum:
  


Current Time: Sat May 25 23:50:07 GMT 2024

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

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

Back to the top