Community
Participate
Working Groups
Build Identifier: Hi, it is useful if the template provides the option to override the getImage method. This would do the job: <%@ include file="ItemProvider/getText.override.javajetinc" fail="alternative" %> <%@ start %> public Object getImage(Object object) { return overlayImage(object, getResourceLocator().getImage("full/obj16/<%=genClass.getName()%>"));<%=genModel.getNonNLS()%> } <%@ end %><%//ItemProvider/getText.override.javajetinc%> Reproducible: Always
Created attachment 203418 [details] patch
Why not just ensure that the image you want is at the location expected? Can you give an example of how you would use this flexibility? (To help motivate why we'd do this.)
Hi, I want to display an image depending on a value of a structural feature of a model element. Hence, one static icon is not enough. (In reply to comment #2) > Why not just ensure that the image you want is at the location expected? > > Can you give an example of how you would use this flexibility? (To help > motivate why we'd do this.)
So that's a general pattern that you'll need to repeat? Can you show what kind of logic you'll put in your template override?
I need to apply this to all providers for subclasses of a model element. These will have something like this: getImage (Object object){ MySuperClass superClass = (MySuperClass)object; if (superClass.a) return imageOK; else if (superClass.b) return imageErrorCause else return imageError }
And that's a general pattern because all your instances have an a and a b feature? What you describe sounds like it could be nicely addressed by a single implementation/override of the overlay method. Normally error indicators are done by decorating the "normal" icon. Note you can specify a class that will be used in place of ItemProviderAdapter as the base class your "root" item will extend, (i.e., ones that don't extend another generated item provider) so an implementation of overlay in that one class could accomplish a lot (assuming you don't have a root class in the model itself, in which case you could do it in that item provider).
Hi Ed, I have a root meta-model element from which all other meta-model elements inherit feature a and feature b. Therefore, all instances have these two features as well. Important for me is that I do not have to do anything after adding new model elements to the meta-model. Hence, I wanted to check in the template if the meta-model element is inheriting from my element which provides a and b and then generate code to do so. What I want is not really an error indicator because the model is OK if the error logo is displayed. It shall be a quick way to see the most important statement about an instance via the icon in the treeview. So I think an overlay is not suitable here as these instances would have no other normal image in the treeview. As far as I understand the "Provider Root Extends Class" is not suitable here as all of my elements do inherit. Changing the code of my base class will not be very nice as all other ItemProviders override the getImageMethod() and I will mix generated with handwritten code. Thank you very much for all of your work in investigating this issue!
Of course if you aren't going to use specialized images at all you'll also not want the images themselves to be generated. On a GenClass you can already set Image to false for that purpose. No image is generated and no getImage is generated either. Such an item provider will reuse/inherit the getImage of the parent item provider. It sounds like that accomplishes exactly what you want, i.e., if you specialize that item provider of the root class to deal with the a and b features for producing the image, you're done. If you don't want to modify generated code, you could write the image logic in a Provider Root Extends Class you write by hand and have the generator insert that. That seems to accomplish exactly the same goal, right?
This works in my case as I do not have model elements with a static image. If one has a model with dynamic and static pictures this can become quite complex. I think of a base class with subclasses that have static images (These will have image set to true) and two classes A and B with subclasses that have dynamic images following a different algorithm. Here, I would need to do a cast first to select the right logic. However, this would still work. But when having situtations where the getImage logic cannot be inherited, because this logic changes within the inheritance tree one gets really ugly source code.
Hi Ed, is there a way to do the same for getText. I could not find something like the no Image. Can this be reached somehow? If not this could be a use case for extending genmodel or the template. Ralph
There is already an override in the template for getText...