Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » Multiple decorators : expected behaviour?
Multiple decorators : expected behaviour? [message #726093] Fri, 16 September 2011 14:31 Go to next message
Hernan Gonzalez is currently offline Hernan GonzalezFriend
Messages: 188
Registered: October 2010
Location: Buenos Aires, Argentina
Senior Member
The method ToolBehaviorProvider.getDecorators() returns an array of Decorators for a pictogram element. What is the expected behaviour when more than one is returned? I expected that they were displayed side by side, but it seems I was too optimistic Razz

For example, in the tutorial:

public class TutorialToolBehaviorProvider extends DefaultToolBehaviorProvider {
 ...
  @Override
  public IDecorator[] getDecorators(PictogramElement pe) {
    IFeatureProvider featureProvider = getFeatureProvider();
    Object bo = featureProvider.getBusinessObjectForPictogramElement(pe);
    if (bo instanceof EClass) {
        IDecorator imageRenderingDecorator1 = new ImageDecorator(IPlatformImageConstants.IMG_ECLIPSE_ERROR);
        imageRenderingDecorator1.setMessage("Error");
        IDecorator imageRenderingDecorator2 = new ImageDecorator(IPlatformImageConstants.IMG_ECLIPSE_INFORMATION);
        imageRenderingDecorator2.setMessage("Info"); 
        return new IDecorator[] { imageRenderingDecorator1,imageRenderingDecorator2};
    }
    return super.getDecorators(pe);
  }


The two images are placed one in top of the other - only the last one is visible. Is this right?
Re: Multiple decorators : expected behaviour? [message #726103 is a reply to message #726093] Fri, 16 September 2011 15:10 Go to previous messageGo to next message
Hernan Gonzalez is currently offline Hernan GonzalezFriend
Messages: 188
Registered: October 2010
Location: Buenos Aires, Argentina
Senior Member
Well, after looking inside the code, (PictogramElementDelegate.decorateFigure) it seems that decorators are just stacked, so that's all

I wonder if some alternative decorators could be implemented, apart from ImageDecorator... specially I'd like to have some "highligting" decorators, either drawing some border or changing the background colour. I'll give it a look.

Another thing: I see that the decorateFigure() is called for every figure refresh (eg, when I move it), and that it instantiates a new DecoratorImageFigure() each time. This extends a ImageFigure (draw2d), which states in its docs: "Note that it is the client's responsibility to dispose the given image. There is no "free" resource management in draw2d." I know little of Draw2d/SWT, can someone who knows better confirm that there is no danger of resource leak here?

[Updated on: Fri, 16 September 2011 15:10]

Report message to a moderator

Re: Multiple decorators : expected behaviour? [message #726544 is a reply to message #726103] Sun, 18 September 2011 15:16 Go to previous messageGo to next message
Andreas Graf is currently offline Andreas GrafFriend
Messages: 211
Registered: July 2009
Senior Member
Hi Hernan,

I haven't tried this, but there is this piece of code int PictogramElementDelegate:

if (decorator instanceof ILocation) {
				ILocation location = (ILocation) decorator;
				boundsForDecoratorFigure.setLocation(location.getX(), location.getY());
			}


which makes me think if you could extend the ImageDecorator, implement ILocation and provide your own location?

That would put the responsibility of decorator layout to you, but at least it might be possible.

Andreas
Re: Multiple decorators : expected behaviour? [message #726658 is a reply to message #726544] Mon, 19 September 2011 07:44 Go to previous messageGo to next message
Felix Velasco is currently offline Felix VelascoFriend
Messages: 43
Registered: July 2009
Member
IImageDecorator already implements ILocation, so you just have to call setX() and setY() as you wish...

        IImageDecorator imageRenderingDecorator1 = new ImageDecorator(IPlatformImageConstants.IMG_ECLIPSE_ERROR);
        imageRenderingDecorator1.setMessage("Error");
        imageRenderingDecorator1.setX(4); //default
        imageRenderingDecorator1.setY(10);
Re: Multiple decorators : expected behaviour? [message #726883 is a reply to message #726658] Mon, 19 September 2011 19:16 Go to previous message
Hernan Gonzalez is currently offline Hernan GonzalezFriend
Messages: 188
Registered: October 2010
Location: Buenos Aires, Argentina
Senior Member
Thanks
Previous Topic:where to add model listeners to refresh property view
Next Topic:Does Graphiti support fill patterns?
Goto Forum:
  


Current Time: Fri Apr 26 01:06:08 GMT 2024

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

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

Back to the top