Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Modify palette tool to copy existing resource
Modify palette tool to copy existing resource [message #207425] Tue, 30 September 2008 07:38 Go to next message
Daniel Taylor is currently offline Daniel TaylorFriend
Messages: 2
Registered: July 2009
Junior Member
Hi,

Here's a short explanation of what I'm trying to do:
In my EMF domain, the top level diagram is a Component, which has an
EReference that is a list of components, so you can have components inside
components, etc. They also have other attributes, but that's not
important for now.

What I would like is for all top level Components in the project to be
available to the user in the palette, so they can drop in a component
they've already created in a different diagram into the current one. For
example, a user can make a new diagram and define component A, another new
diagram and define component B, then they can make a new diagram called
component C, and components A and B will be available in the palette to
create as subcomponents. I want it to be a deep copy, and have no
references to the object it was copied from, but just to copy it's
structure and attributes and deep copy the references exactly.

Here's what I've done so far:
I have modified my generated diagram and palette factory so that the
palette factory gets a map of all top level components in the project
(name, IPath to the resource). I know how to access the EMF model with
the IPath.

The strategy I tried to use (which didn't work) is to make a custom
creation tool (I made a copy of
org.eclipse.gmf.runtime.diagram.ui.tools.CreationTool) and I send it the
type I'm creating (Component) and the IPath to the resource I want to
copy. Then, in performCreation(), I attempted to add a method that goes
through the result of the compound creation command (I don't understand
exactly what that does, and that's part of my problem) and modify the
editPart's model element directly.

This didn't work, and I figure it's pretty obvious this isn't the right
way to do it. So what approach should I use to essentially make a copy of
the resource at the given IPath into the current diagram?

Please let me know if any part of my description is not clear. I
appreciate your advice.

Thank you.

-Daniel
Re: Modify palette tool to copy existing resource [message #207572 is a reply to message #207425] Tue, 30 September 2008 20:06 Go to previous message
Daniel Taylor is currently offline Daniel TaylorFriend
Messages: 2
Registered: July 2009
Junior Member
Well, I actually solved it thanks to another post on this newsgroup:
http://dev.eclipse.org/newslists/news.eclipse.modeling.gmf/m sg00843.html

What I did was, from within my custom creation tool, after the command to
create the Component was executed:

Put all of the EStructuralFeature's of the component into a list using my
***Package.Literals.

TransactionalEditingDomain domain =
((IGraphicalEditPart)editPart).getEditingDomain();
where editPart is retrieved the same way it is in the selectAddedObject
method of the creationTool.

Then iterate through my list of features and do the following:
EStructuralFeature f = itr.next();
SetRequest r = new SetRequest(domain, createComp, f, copyComp.eGet(f));
SetValueCommand com = new SetValueCommand(r);
com.execute(null, null);

Where createComp is retrieved from:
Component createComp =
(Component)((IGraphicalEditPart)editPart).resolveSemanticEle ment();

and copyComp was loaded from the IPath.

This is probably a bit of a hack, but it works perfectly. Hope it helps
anyone who's look for something like this.
Previous Topic:How to remove the default diagram toolbar and actions?
Next Topic:Remove the horizontal line in the middle of Compartment?
Goto Forum:
  


Current Time: Wed Jan 27 17:44:28 GMT 2021

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

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

Back to the top