Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Switching Diagram Label Icon during runtime on/off
Switching Diagram Label Icon during runtime on/off [message #1032956] Wed, 03 April 2013 17:21 Go to next message
Phil H is currently offline Phil HFriend
Messages: 267
Registered: November 2012
Senior Member
Hi,

by default my diagram labels have no icon. But when the user change a specific property of the label node, the diagram label icon should appear. In my code, I've got access to the EditPart of the label as you can see below. I'm wondering now how I can change the element icon attribute from false to true - Is this possible?


if (graphicalEditPart.getChildren().get(0) instanceof FeatureName2EditPart) {										FeatureName2EditPart featureLabel = (FeatureName2EditPart) graphicalEditPart										.getChildren().get(0);
......

[Updated on: Wed, 03 April 2013 17:21]

Report message to a moderator

Re: Switching Diagram Label Icon during runtime on/off [message #1033091 is a reply to message #1032956] Wed, 03 April 2013 21:05 Go to previous messageGo to next message
Thomas Beyer is currently offline Thomas BeyerFriend
Messages: 55
Registered: February 2013
Member
Hi Phil,

you can listen to notation and semantic changes in your editpart-class and invoke the display/hide or even change the icon of the underlying wrappinglabel.

Check generated
protected void handleNotificationEvent(Notification event)

and start from there to get the appropriate Notification.

Regards
Thomas
Re: Switching Diagram Label Icon during runtime on/off [message #1033106 is a reply to message #1033091] Wed, 03 April 2013 21:24 Go to previous messageGo to next message
Phil H is currently offline Phil HFriend
Messages: 267
Registered: November 2012
Senior Member
Ok, thx so far, but my problem is that I don't know how to display/hide the icon respectively which method I can use. Can you give me a hint?
Re: Switching Diagram Label Icon during runtime on/off [message #1033416 is a reply to message #1033106] Thu, 04 April 2013 08:02 Go to previous messageGo to next message
Ralph Gerbig is currently offline Ralph GerbigFriend
Messages: 697
Registered: November 2009
Senior Member
Hi,

you can call getLabelIcon() and getLabelIconHelper() on the edit part of the lable. This should help you to manipulate the figure of the edit part to show/hide the label.

Ralph
Re: Switching Diagram Label Icon during runtime on/off [message #1033614 is a reply to message #1032956] Thu, 04 April 2013 12:40 Go to previous messageGo to next message
Phil H is currently offline Phil HFriend
Messages: 267
Registered: November 2012
Senior Member
I tried the following code, but then I get an ExecutionException. Unfortunately I've not much knowledge about the swt.graphic stuff. I think the problem is the Image object which I defnining. Is it the right way or am I completely wrong?

Feature featureNode = (Feature) this.resolveSemanticElement();
Device device = Display.getCurrent();
Image image = new Image(device,"platform:/org.ite.amal.model.variability/images/icons/Feature.gif");
if (featureNode.getFilePath() != null) {
   IFigure figure = getFigure();
   if (!featureNode.getFilePath().isEmpty()) {
      setLabelIconHelper(figure, image);
   } else {
      setLabelIconHelper(figure, null);
   }
}

[Updated on: Thu, 04 April 2013 12:41]

Report message to a moderator

Re: Switching Diagram Label Icon during runtime on/off [message #1033805 is a reply to message #1033614] Thu, 04 April 2013 17:01 Go to previous messageGo to next message
Thomas Beyer is currently offline Thomas BeyerFriend
Messages: 55
Registered: February 2013
Member
Hi Phil,

not sure, if the URI you are creating is correct.

Let Eclipse do the work and try the following:
ImageDescriptor myImage = ImageDescriptor.createFromURL(
FileLocator.find(Activator.getDefault().getBundle(),
new Path("icons/myicon.gif"),null));

where Activator is your AbstractUIPlugin-class and the Path-String is relative to your Plugin-root or use the more generic
ImageDescriptor.createFromURL(FileLocator.find(Platform.getBundle(plugin_id), new Path("icons/imageFileName.xxx"),null);


However the ExecutionException can also be a wrapped Exception, that results from possible other resources.
If the examples above don't work, please provide the wrapping code, where you embed the image update.

Regards
Thomas
Re: Switching Diagram Label Icon during runtime on/off [message #1034011 is a reply to message #1033805] Thu, 04 April 2013 23:05 Go to previous messageGo to next message
Phil H is currently offline Phil HFriend
Messages: 267
Registered: November 2012
Senior Member
Hi Thomas,

you're right about the URI. I implemented the following code and got no exception anymore:

FileLocator.find(Platform.getBundle(PldDiagramEditorPlugin.ID),new Path("icons/Feature.gif"), null)).createImage();
if (featureNode.getFilePath() != null) {
   IFigure figure = getFigure();
   if (!featureNode.getFilePath().isEmpty()) {
     setLabelIconHelper(figure, image);	


Unfortunately the icon isn't displayed in the diagram (I generated an editor with eugenia and tested the icon there and it worked - so the icon can't be the problem).

In case of the "Icon event", I noticed that the label went a little bit to the right (like the width of the icon). It seems that the icon is there, but invisible.

index.php/fa/14255/0/

Furthermore, I manipulate the icon path so that it point to a non existing icon. Then a small red rectangle is displayed instead of the icon.

index.php/fa/14256/0/

Maybe the setLabelIconHelper isn't the right method to set an icon? But I couldn't find any other method for this case.

Cheers,
Phil
  • Attachment: feature.png
    (Size: 0.51KB, Downloaded 201 times)
  • Attachment: red.JPG
    (Size: 8.32KB, Downloaded 194 times)
Re: Switching Diagram Label Icon during runtime on/off [message #1036452 is a reply to message #1034011] Mon, 08 April 2013 12:02 Go to previous message
Thomas Beyer is currently offline Thomas BeyerFriend
Messages: 55
Registered: February 2013
Member
Hi Phil,

setLabelIconHelper(...) is only accessing the Figure (which is likely to be a WrappingLabel) and calling the setIcon/Image method on it. Since you achieved to display a red square, you're propably still having an issue with resolving the proper image.
Try using a SharedImage from the Eclipse Workbench to test the display of an icon in your figure.

Do the image creating for testing something like:
PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FILE);

as these images should be created correctly by the workbench.

If this works, you might want to check, if the build-properties of your projects are setup ok and you are using an image, that gmf resp. gef can display correctly.
There might be some restrictions on image types.

Regards
Thomas
Previous Topic:How to edit a label mapped by ExpressionLabelMapping?
Next Topic:Empty runtime Outline
Goto Forum:
  


Current Time: Mon Dec 22 06:31:16 GMT 2014

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

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