resize element by listening to model changes [message #513112] |
Mon, 08 February 2010 16:21  |
Eclipse User |
|
|
|
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 03:22   |
Eclipse User |
|
|
|
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
|
|
|
|
Powered by
FUDForum. Page generated in 0.05315 seconds