Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Adding existing domain element to the diagram at specific location
icon9.gif  Adding existing domain element to the diagram at specific location [message #1185958] Thu, 14 November 2013 11:27 Go to next message
Vitaly Savickas is currently offline Vitaly SavickasFriend
Messages: 62
Registered: March 2010
Does anyone know how can I add an existing domain element to the diagram at particular location?

I have spent three days figuring it out and debugging the existing implementation of creation tools from the palette, but nothing works. The CreateViewAndElement request is the closest thing to suit me, BUT I don't want a new element to be created. I already have an element with some attributes set, not belonging to the diagram yet. There's a method setResultElement() on the request, but it does not have any effect - still creates a new empty element.

Re: Adding existing domain element to the diagram at specific location [message #1186110 is a reply to message #1185958] Thu, 14 November 2013 13:40 Go to previous message
Vitaly Savickas is currently offline Vitaly SavickasFriend
Messages: 62
Registered: March 2010
*sigh* As always with GMF, scratching your ear has to be done with a foot. Solved it myself, but had to debug and inspect the whole command chain of the creation tool and adapt it to my needs. Anyway, if you have the same problem, here's how I did it:

// requests and adapters
IElementType type = ComponentsElementTypes.Component_2002;
CreateElementRequest createElementRequest = new CreateElementRequest(
		getEditingDomain(), ((View) getModel()).getElement(),
CreateElementRequestAdapter adapter = new CreateElementRequestAdapter(createElementRequest);
ViewAndElementDescriptor descriptor = new ViewAndElementDescriptor(
		((IHintedType) type).getSemanticHint(), 
CreateViewAndElementRequest request = new CreateViewAndElementRequest(descriptor);

// element command (customised to return an existing element)
Command createElementCommand = new ICommandProxy(
		new EventBComponentCreateCommand((CreateElementRequest) descriptor.getCreateElementRequestAdapter().getAdapter(CreateElementRequest.class)) {

			protected CommandResult doExecuteWithResult(
					IProgressMonitor monitor, IAdaptable info)
					throws ExecutionException {
				EventBComponent newElement = (EventBComponent) Platform

				ComponentDiagram owner = (ComponentDiagram) getElementToEdit();

				doConfigure(newElement, monitor, info);

				((CreateElementRequest) getRequest())
				return CommandResult.newOKCommandResult(newElement);

// semantic command
SemanticCreateCommand semanticCommand = new SemanticCreateCommand(adapter, createElementCommand);

// view command
TransactionalEditingDomain editingDomain = ((IGraphicalEditPart) getHost()).getEditingDomain();
CreateCommand viewCommand = new CreateCommand(editingDomain, descriptor, (View) (getHost().getModel()));

// relocate command
Point dropLocation = dropRequest.getLocation().getCopy();
SetBoundsCommand relocateCommand = new SetBoundsCommand(editingDomain, "Set location", request.getViewAndElementDescriptor(), dropLocation);

// compound command
CompositeCommand cc = new CompositeCommand(semanticCommand.getLabel());
return new ICommandProxy(cc);

The resulting command is similar to what you get when you drag a tool from the palette to the diagram, except you can customise the domain element here. For a simple tasks it is however quite a heavy solution, in my opinion. So, if anyone knows a simpler way, you are very welcome to share it.


[Updated on: Thu, 14 November 2013 13:42]

Report message to a moderator

Previous Topic:GMF toolbar actions refresh/update issue
Next Topic:I've got the selection, I need to make invisible old!
Goto Forum:

Current Time: Thu Feb 25 02:50:01 GMT 2021

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

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

Back to the top