Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » resize element by listening to model changes
resize element by listening to model changes [message #513112] Mon, 08 February 2010 21:21 Go to next message
Antonis  is currently offline Antonis Friend
Messages: 2
Registered: February 2010
Junior Member
Hi, I m new to GMF and I need your precious help!

I want to have an element (called Button) listen to model changes from the properties view in the editor. Once its width or height property changes it has to be automatically resized.

The Button element is within a List compartment and I have included the following code in the Button EditPart.

In handleNotificationEvent(Notification notification):
Dimension dim = this.getPrimaryShape().getSize();
if(((Button)Button2EditPart.this.getNotationView().getElemen t()).getWidth()!=dim.width ||
((Button)Button2EditPart.this.getNotationView().getElement() ).getWidth()!=dim.height){
refreshVisuals();
}

In refreshVisuals:
Button button = (Button) resolveSemanticElement();
this.getPrimaryShape().setSize(button.getWidth(), button.getHeight());
this.getPrimaryShape().setBounds(new Rectangle(new Point(this.getPrimaryShape().getLocation()), new Dimension(button.getWidth(), button.getHeight())));
this.getContentPane().setSize(button.getWidth(), button.getHeight());
this.getContentPane().setBounds(new Rectangle(new Point(this.getPrimaryShape().getLocation()), new Dimension(button.getWidth(), button.getHeight())));

In ButtonFigure.setSize(w,h) I set the size of the button figure and its button name (WrappingLabel).

The result is that the rectangle shape is resized but its not visible outside the initial bounds of the button (the ones it had once it was created). The label also remains at the same place and is not visible if the button's size is adequately reduced.

Can you tell me what I m doing wrong? Or if there is another more appropriate way to achieve my goal?

Thanks in advance,
anthony
Re: resize element by listening to model changes [message #513519 is a reply to message #513112] Wed, 10 February 2010 08:22 Go to previous messageGo to next message
Romain Bioteau is currently offline Romain BioteauFriend
Messages: 65
Registered: August 2009
Location: Grenoble
Member
Le 08/02/2010 22:21, Antonis a écrit :
> Hi, I m new to GMF and I need your precious help!
>
> I want to have an element (called Button) listen to model changes from
> the properties view in the editor. Once its width or height property
> changes it has to be automatically resized.
>
> The Button element is within a List compartment and I have included the
> following code in the Button EditPart.
>
> In handleNotificationEvent(Notification notification):
> Dimension dim = this.getPrimaryShape().getSize();
> if(((Button)Button2EditPart.this.getNotationView().getElemen
> t()).getWidth()!=dim.width ||
> ((Button)Button2EditPart.this.getNotationView().getElement()
> ).getWidth()!=dim.height){
> refreshVisuals();
> }
>
> In refreshVisuals:
> Button button = (Button) resolveSemanticElement();
> this.getPrimaryShape().setSize(button.getWidth(), button.getHeight());
> this.getPrimaryShape().setBounds(new Rectangle(new
> Point(this.getPrimaryShape().getLocation()), new
> Dimension(button.getWidth(), button.getHeight())));
> this.getContentPane().setSize(button.getWidth(), button.getHeight());
> this.getContentPane().setBounds(new Rectangle(new
> Point(this.getPrimaryShape().getLocation()), new
> Dimension(button.getWidth(), button.getHeight())));
>
> In ButtonFigure.setSize(w,h) I set the size of the button figure and its
> button name (WrappingLabel).
>
> The result is that the rectangle shape is resized but its not visible
> outside the initial bounds of the button (the ones it had once it was
> created). The label also remains at the same place and is not visible if
> the button's size is adequately reduced.
>
> Can you tell me what I m doing wrong? Or if there is another more
> appropriate way to achieve my goal?
>
> Thanks in advance,
> anthony
>

Hi Anthony,
I think you should use the command framework and use a
ChangeBoundRequest instead of overriding your editparts like this.

You could try something like in a widget listener of the property :

ChangeBoundsRequest req = new
ChangeBoundsRequest(RequestConstants.REQ_RESIZE);
req.setSizeDelta(SIZE_DELTA);
req.setResizeDirection(PositionConstants.EAST);

ediPartToResize.getDiagramEditDomain().getDiagramCommandStac k().execute(ediPartToResize.getCommand(req));

This way you are sure everything will be notified correctly
Do the same for the container edit part if you want it to be resize also.

Regars,
Romain


R&D Engineer at BonitaSoft
Re: resize element by listening to model changes [message #513678 is a reply to message #513519] Wed, 10 February 2010 19:22 Go to previous message
Antonis  is currently offline Antonis Friend
Messages: 2
Registered: February 2010
Junior Member

Romain,

Thanks a lot for your answer.
I will give it a try via the command framework.

Anthony
Previous Topic:Change the default Polyline Decoration for the target of a Polyline connection
Next Topic:Note gets model element after load
Goto Forum:
  


Current Time: Mon Sep 23 15:34:55 GMT 2024

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

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

Back to the top