Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » How to have multidecorators
How to have multidecorators [message #631552] Thu, 07 October 2010 22:24 Go to next message
Daniele is currently offline DanieleFriend
Messages: 45
Registered: August 2010
Member
Hi there,
I need to have different decorators on my PE depending on values in the properties panel. I am starting to implement it using the following code:

@Override
public IDecorator[] getDecorators(PictogramElement pe) {
IFeatureProvider featureProvider = getFeatureProvider();
Object bo = featureProvider.getBusinessObjectForPictogramElement(pe);

if (bo instanceof Thing) {
Thing thing = (Thing) bo;
String name = thing.getName();

if (name != null && name.length() > 0 && !(name.charAt(0) >= 'A' && name.charAt(0) <= 'Z')) {

//Image: imageWarning
ImageDecorator imageWarning=new ImageDecorator(IPlatformImageConstants.IMG_ECLIPSE_WARNING_T SK);

return new ImageDecorator[] {imageWarning};

}

else if (name.equals("Vision")) {
//Image: imageWarning
ImageDecorator imageVision=new ImageDecorator(ImageProvider.IMG_VISION);
imageVision.setX(30);
imageVision.setY(30);

return new ImageDecorator[] {imageVision};

}

}

return super.getDecorators(pe);
}

But I have the following problem:


when I add a PE into the diagram it remains stucked at the same location altough I am able to visualize the different decorators by setting different values for the attribute NAME in the properties panel.

I noticed that if I eliminate the "else if" part, it works perfectly but obviously (in this case) I have just one kind of decorator.

Indeed, my final goal is to have a PE that have three decorators each one associated to a different attribute of the BO linked to the PE. These 3 decorators can change their images depending on a specific set of values defined for the three attributes, e.g.:


Attribute 1 --> Decorator 1:
----------------------------------
(Value ---> Image)

"A"---> "ImgA"
"B"---> "ImgB"
"C"---> "ImgC"

Attribute 2 --> Decorator 2:
----------------------------------
(Value ---> Image)

"X"---> "ImgX"
"Y"---> "ImgY"
"Z"---> "ImgZ"

Attribute 3 --> Decorator 3:
----------------------------------
(Value ---> Image)

"K"---> "ImgK"
"L"---> "ImgL"
"M"---> "ImgM"


Thank you in adnvance for any suggestions or help Smile
Daniele


Re: How to have multidecorators [message #631604 is a reply to message #631552] Fri, 08 October 2010 07:41 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1914
Registered: July 2009
Location: Walldorf, Germany
Senior Member
I'm not really sure if I understood your problem correctly. What I tried is
the following: I added your code snippet to the toturial
ToolBehaviorProvider and tried to return first a digfferent decorator, then
two decorators at once. That worked, also the location of the second
decorator changed as expected. This change was triggered via direct editing,
external changes and via the properties view.

A gues what could be wrong (without knowing your coding) is that there is
something going wrong within the notification process: it could be that the
wrong editing domain is used for doing the change or that the diagram
objects are not correctly linked to the domain objects. The root
PictogramElement for your "thing" needs to be linked to the "Thing"
instance.

Besides I not really sure if the decorator is the best solution for your
scenario. Did you think about adding the icons directly to the diagram in
your add feature? My impression is that the icons are rather static and
directly depend on the value of one attribute. An example for this would be
a class object displaying the attributes with an icon for the visibility
state (green circle for public, red for private). Maybe that would be an
alternative as well.

Michael

"Daniele" <barone.daniele@gmail.com> wrote in message
news:i8lh61$tk3$1@news.eclipse.org...
> Hi there, I need to have different decorators on my PE depending on values
> in the properties panel. I am starting to implement it using the following
> code:
>
> @Override
> public IDecorator[] getDecorators(PictogramElement pe) {
> IFeatureProvider featureProvider = getFeatureProvider();
> Object bo = featureProvider.getBusinessObjectForPictogramElement(pe);
>
> if (bo instanceof Thing) {
> Thing thing = (Thing) bo;
> String name = thing.getName();
> if (name != null && name.length() > 0 && !(name.charAt(0) >= 'A' &&
> name.charAt(0) <= 'Z')) {
>
> //Image: imageWarning
> ImageDecorator imageWarning=new
> ImageDecorator(IPlatformImageConstants.IMG_ECLIPSE_WARNING_T SK);
>
> return new ImageDecorator[] {imageWarning};
>
> }
>
> else if (name.equals("Vision")) {
> //Image: imageWarning
> ImageDecorator imageVision=new ImageDecorator(ImageProvider.IMG_VISION);
> imageVision.setX(30);
> imageVision.setY(30);
>
> return new ImageDecorator[] {imageVision};
>
> }
>
> }
>
> return super.getDecorators(pe);
> }
>
> But I have the following problem:
>
>
> when I add a PE into the diagram it remains stucked at the same location
> altough I am able to visualize the different decorators by setting
> different values for the attribute NAME in the properties panel.
>
> I noticed that if I eliminate the "else if" part, it works perfectly but
> obviously (in this case) I have just one kind of decorator.
>
> Indeed, my final goal is to have a PE that have three decorators each one
> associated to a different attribute of the BO linked to the PE. These 3
> decorators can change their images depending on a specific set of values
> defined for the three attributes, e.g.:
>
>
> Attribute 1 --> Decorator 1:
> ----------------------------------
> (Value ---> Image)
>
> "A"---> "ImgA"
> "B"---> "ImgB"
> "C"---> "ImgC"
>
> Attribute 2 --> Decorator 2:
> ----------------------------------
> (Value ---> Image)
>
> "X"---> "ImgX"
> "Y"---> "ImgY"
> "Z"---> "ImgZ"
>
> Attribute 3 --> Decorator 3:
> ----------------------------------
> (Value ---> Image)
>
> "K"---> "ImgK"
> "L"---> "ImgL"
> "M"---> "ImgM"
>
>
> Thank you in adnvance for any suggestions or help :)
> Daniele
>
>
>
Re: How to have multidecorators [message #631782 is a reply to message #631604] Fri, 08 October 2010 17:53 Go to previous messageGo to next message
Daniele is currently offline DanieleFriend
Messages: 45
Registered: August 2010
Member
Hi Michael,

first of all thank you very much for your help, I much appreciated it.

Reading your answer, before adopting in detail some of your suggestions, I just tried to add the following code on the EClass graphiti example (which is updated to the last version in the repository):


@Override
public IDecorator[] getDecorators(PictogramElement pe) {
IFeatureProvider featureProvider = getFeatureProvider();
Object bo = featureProvider.getBusinessObjectForPictogramElement(pe);
if (bo instanceof EClass) {
EClass eClass = (EClass) bo;
String name = eClass.getName();
if (name != null && name.length() > 0 && !(name.charAt(0) >= 'A' && name.charAt(0) <= 'Z')) {
IDecorator imageRenderingDecorator = new ImageDecorator(IPlatformImageConstants.IMG_ECLIPSE_WARNING_T SK);
imageRenderingDecorator.setMessage("Name should start with upper case letter"); //$NON-NLS-1$
return new IDecorator[] { imageRenderingDecorator };
}

// NEW PART
else if(name.equals("Test")){
IDecorator imageRenderingDecorator2 = new ImageDecorator(IPlatformImageConstants.IMG_ECLIPSE_ERROR);
imageRenderingDecorator2.setMessage("Name should start with upper case letter"); //$NON-NLS-1$

// Decorator to a different position
//ImageDecorator imageRenderingDecorator2=new ImageDecorator(IPlatformImageConstants.IMG_ECLIPSE_ERROR);
//imageRenderingDecorator2.setX(30);
//imageRenderingDecorator2.setY(30);

return new IDecorator[] { imageRenderingDecorator2 };

}

Now, If I perform the following steps:

1) create a new project and a new diagram

2) add an EClass

3) Change the decorator of the EClass setting the value of the name either to a string with a non capitalized first letter or to a string equals to "Text)

4) Move the EClass around in the diagram

BUT when I try to move the EClass on the diagram it is stucked and you cannot move it.

If in the code you set a different location for the second decorator (as shown by the commented code part) you will able to add an Eclass and move it, but the second class you add to the schema is stucked

I hope that I am more clear now

Therefore, Am I doing something wrong Sad ?
Thank you in advance for you valuable time in helping me

[Updated on: Fri, 08 October 2010 19:33]

Report message to a moderator

Re: How to have multidecorators [message #631997 is a reply to message #631782] Mon, 11 October 2010 07:23 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1914
Registered: July 2009
Location: Walldorf, Germany
Senior Member
There's a null check missing. Changing the else to
// NEW PART

else if (name != null && name.equals("Test")) {

solved this. The NPE thrown there simply killed the further eventing...


Michael



"Daniele" <barone.daniele@gmail.com> wrote in message
news:i8nlks$ag9$1@news.eclipse.org...
> Hi Michael,
>
> first of all thank you very much for your help, I much appreciate it.
>
> Before going in details on your answer I just tried to add the following
> code on the EClass graphiti example (which is updated to the last version
> in the repository):
>
>
> @Override
> public IDecorator[] getDecorators(PictogramElement pe) {
> IFeatureProvider featureProvider = getFeatureProvider();
> Object bo = featureProvider.getBusinessObjectForPictogramElement(pe);
> if (bo instanceof EClass) {
> EClass eClass = (EClass) bo;
> String name = eClass.getName();
> if (name != null && name.length() > 0 && !(name.charAt(0) >= 'A' &&
> name.charAt(0) <= 'Z')) {
> IDecorator imageRenderingDecorator = new
> ImageDecorator(IPlatformImageConstants.IMG_ECLIPSE_WARNING_T SK);
> imageRenderingDecorator.setMessage("Name should start with upper case
> letter"); //$NON-NLS-1$
> return new IDecorator[] { imageRenderingDecorator };
> }
>
> // NEW PART
> else if(name.equals("Test")){
> IDecorator imageRenderingDecorator2 = new
> ImageDecorator(IPlatformImageConstants.IMG_ECLIPSE_ERROR);
> imageRenderingDecorator2.setMessage("Name should start with upper case
> letter"); //$NON-NLS-1$
>
> // Decorator to a different position
> //ImageDecorator imageRenderingDecorator2=new
> ImageDecorator(IPlatformImageConstants.IMG_ECLIPSE_ERROR);
> //imageRenderingDecorator2.setX(30);
> //imageRenderingDecorator2.setY(30);
>
> return new IDecorator[] { imageRenderingDecorator2 };
>
> }
>
> Now, If I following these steps:
>
> 1) create a new project and a new diagram
>
> 2) add an EClass
>
> 3) I can change the decorator of the EClass setting the value of the name
> either to a string with a non capitalized first letter or to a string
> equals to "Text)
>
> Now if you try to move the EClass on the diagram it is stucked, you cannot
> move it.
> If in the code you set a different location for the second decorator (as
> shown by the commented code part) you will able to add an Eclass and move
> it, but the second class you add to the schema is stucked
> I hope that I am more clear now
>
> Therefore, Am I doing something wrong :( ?
> Thank you in advance for you valuable time in helping me
>
>
Re: How to have multidecorators [message #632090 is a reply to message #631997] Mon, 11 October 2010 14:18 Go to previous messageGo to next message
Daniele is currently offline DanieleFriend
Messages: 45
Registered: August 2010
Member
Thank you Michael, it works perfectly Laughing !!!
Much appreciated it
D.
Re: How to have multidecorators [message #632103 is a reply to message #631997] Mon, 11 October 2010 15:08 Go to previous messageGo to next message
Daniele is currently offline DanieleFriend
Messages: 45
Registered: August 2010
Member
Hi Micheal,

I just noticed that when I change the value in the properties panel the PE is not automatically refreshed. Only when I move the PE the decorator change reflecting the value in the properties panel.

In the EClass example there is not this issue since (I suppose) the name of the EClass is directly linked to the PE, therefore some event is triggered when its value changes.


But when the attribute appears just in the properties panel (and it is not visualized on the PE), how can I force the refreshing of the PE element?

Thanks

---- this is my actual code for the ELSE part in which the typeIntention is a value that I can change in the properties panel; when this value changes a different image for the Decorator appears on the PE----

else if (typeIntention != null && typeIntention.equals("Vision")) {

ImageDecorator imageVision=new ImageDecorator(ImageProvider.IMG_VISION);
imageVision.setMessage("This is our Vision"); //$NON-NLS-1$

return new ImageDecorator[] {imageVision};

}

[Updated on: Mon, 11 October 2010 15:47]

Report message to a moderator

Re: How to have multidecorators [message #632214 is a reply to message #632103] Tue, 12 October 2010 06:44 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1914
Registered: July 2009
Location: Walldorf, Germany
Senior Member
The registration happens on the level of an object not on attributes. Is the
object which name you change linked to any PE? What I assume is that it
might be a referenced object inside an object that is linked. For perormance
reasons the framework only checks the changed object and not its containment
hierarchy for triggering the editor refresh.

You might force a refresh with the refresh method of DiagramEditor.

Michael


"Daniele" <barone.daniele@gmail.com> wrote in message
news:i8v92t$7kv$1@news.eclipse.org...
> Hi Micheal,
>
> I just noticed that when I change the value in the properties panel
> the PE is not automatically refreshed. Only when I move the PE the
> decorator change reflecting the value in the properties panel.
> In the EClass example there is not this issue since (I suppose) the name
> of the EClass is directly linked to the PE, therefore some event is
> triggered when its value change.
>
>
> But when the attribute appear just in the properties panel (and is not
> visualized on the PE), how I can force the refreshing of the PE element?
>
> Thanks
>
> ---- this is my actual code for the ELSE part in which the typeIntention
> is a value that I can change in the properties panel that when changes a
> different imageDecorator appear on the PE----
>
> else if (typeIntention != null && typeIntention.equals("Vision")) {
>
> ImageDecorator imageVision=new ImageDecorator(ImageProvider.IMG_VISION);
> imageVision.setMessage("This is our Vision"); //$NON-NLS-1$
>
> return new ImageDecorator[] {imageVision};
>
> }
Re: How to have multidecorators [message #632427 is a reply to message #632214] Tue, 12 October 2010 20:38 Go to previous message
Daniele is currently offline DanieleFriend
Messages: 45
Registered: August 2010
Member
Hi Michael,

(again thank you for your help and support)

--> "Is the object which name you change linked to any PE?"

Yes it is linked. The PE is connected to a BO which has two attributes, namely NAME and TYPE (that is an enumeration attribute). The NAME is visualized on the PE and it can be modified with direct editing or trough the properties panel; instead, the TYPE is not part of the PE definition (i.e., not in the addXFeature.java) but appears in the properties panel(using a Combo widget). The user can change the TYPE's value and the decorator's image on the PE changes in accordance.

Anyway, for now I am using your suggestion where each time I change the TYPE 's value in the properties panel I am forcing the refresh of the diagram (in the listener associated to the combo TYPE widget) with the following code:

private ModifyListener listenerIntentionTypeWidget = new ModifyListener(){

public void modifyText (ModifyEvent arg0){
...
IDiagramEditor digramEditor = getDiagramEditor();
digramEditor.refresh();
...
}

Now it seems work Smile
Thank you again for your support
Daniele

[Updated on: Tue, 12 October 2010 20:43]

Report message to a moderator

Previous Topic:Best way to rotate an object
Next Topic:Property sheet integration when domain objects not emf based
Goto Forum:
  


Current Time: Mon Apr 06 19:08:21 GMT 2020

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

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

Back to the top