Switching Diagram Label Icon during runtime on/off [message #1032956] |
Wed, 03 April 2013 17:21 |
Phil H 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 #1033614 is a reply to message #1032956] |
Thu, 04 April 2013 12:40 |
Phil H 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 |
Thomas Beyer 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 |
Phil H 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.
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.
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 1009 times) -
Attachment: red.JPG
(Size: 8.32KB, Downloaded 1062 times)
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.05333 seconds