Skip to main content



      Home
Home » Modeling » GMF (Graphical Modeling Framework) » Change object properties when clicked
Change object properties when clicked [message #69354] Wed, 25 October 2006 10:29 Go to next message
Eclipse UserFriend
Originally posted by: seliva.gmail.com

Hi!

I am working in the creation of a gmf editor, and I would like to be able
to change an attribute of an object when it is clicked, for example the
color.

I have read the topics related:
http://dev.eclipse.org/newslists/news.eclipse.technology.gmf /msg03725.html
http://dev.eclipse.org/newslists/news.eclipse.modeling.gmf/m sg01089.html

and added a new class extending OpenEditPolicy, and also installed that
EditPolicy in the appropiate EditPart file, but it does not seem to work.

I am not sure OpenEditPolicy is the class I should extend for my case. I
would really glad if someone could give me a hint.

Thanks!
Re: Change object properties when clicked [message #69743 is a reply to message #69354] Thu, 26 October 2006 05:34 Go to previous messageGo to next message
Eclipse UserFriend
Hello Noelia,

To handle double-click you should install custom subclass of OpenEditPolicy
for the desired editpart:

protected void createDefaultEditPolicies() {

installEditPolicy(EditPolicyRoles.OPEN_ROLE, new SubclassOfOpenEditPolicy());
}

As a result, SubclassOfOpenEditPolicy.getOpenCommand(Request request) will
be called and corresponding command will be executed on double-clicking to
the diagram node. Be careful – you should select whole node first (selection
frame around the node should be visible) and only then double-click to the
node. If you double-click on node without selection there is a big chance
to hit inner compartment or label and then corresponding child element will
be selected instead of Double-click command execution.

-----------------
Alex Shatalin
Re: Change object properties when clicked [message #69968 is a reply to message #69743] Thu, 26 October 2006 07:27 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: seliva.gmail.com

Hi again!

thank you very much for your reply. I have already installed my custom
subclass of OpenEditPolicy in my ObjectEditPart and I have added code to
the function SubclassOfOpenEditPolicy.getOpenCommand(Request request) in
this way:

protected Command getOpenCommand(Request request) {
EditPart targetEditPart = getTargetEditPart(request);
if (targetEditPart instanceof IGraphicalEditPart) {
IGraphicalEditPart editPart =
(IGraphicalEditParttargetEditPart;

editPart.getContentPane().setBackgroundColor(ColorConstants. red);
.....

So, as expected, when the node is double-clicked it turns red. My problem
now is how to access the attributes of the object related with that node.

For example, the object has an attribute "state" and I want to change its
value from "free" to "occupy" when the node is clicked. I have tried to
access the attribute using:
YardPackage.eINSTANCE.getObject_ObjectStatus()
but I haven't been able from the function getOpenCommand, so maybe it is
not the right scope for doing this.
Any suggestions for this problem? Thanks a lot!
Re: Change object properties when clicked [message #69988 is a reply to message #69968] Thu, 26 October 2006 07:33 Go to previous messageGo to next message
Eclipse UserFriend
Hello Noelia,

((View) EditPart.getModel()).getElement() is a correct way to access underlying
domain model element.

-----------------
Alex Shatalin
Re: Change object properties when clicked [message #70051 is a reply to message #69988] Thu, 26 October 2006 08:01 Go to previous message
Eclipse UserFriend
Originally posted by: seliva.gmail.com

Thank you very much! It works!
Previous Topic:Updating models
Next Topic:question on MultiClientContext implementation- includes() true only if ALL children return true?
Goto Forum:
  


Current Time: Mon May 05 19:46:35 EDT 2025

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

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

Back to the top