Saturday, April 11, 2009

Providing custom images for the outline view in Xtext/TMF

Recently I asked a question on the openArchitectureWare forum, how I can change the default image in the outline view of Xtext/TMF. Christian Dietrich was able to give me the correct hints. You can follow the discussion there, and below is a working example of the implementation of my LabelProvider. As you can see it works slightly different. The nice thing is, that due to the generated DSL classes, it is easier now to access the information from the model and static polymorphism more efficiently.


public class AnalysisLabelProvider extends DefaultLabelProvider {

public Image image(Actor actor) {
String image = (actor.isSystem() ? "/icons/Node.gif"
: "/icons/Actor.gif");
return new Image(Display.getDefault(), AnalysisLabelProvider.class
.getResourceAsStream(image));
}

public Image image(UseCase useCase) {

return new Image(Display.getDefault(), AnalysisLabelProvider.class
.getResourceAsStream("/icons/UseCase.gif"));
}

public Image image(Information information) {
return new Image(Display.getDefault(), AnalysisLabelProvider.class
.getResourceAsStream("/icons/Class.gif"));
}

public Image image(Analysis analysis) {
return new Image(Display.getDefault(), AnalysisLabelProvider.class
.getResourceAsStream("/icons/Model.gif"));
}

public Image image(Issue issue) {
return new Image(Display.getDefault(), AnalysisLabelProvider.class
.getResourceAsStream("/icons/Comment.gif"));
}

public Image image(Step step) {
return new Image(Display.getDefault(), AnalysisLabelProvider.class
.getResourceAsStream("/icons/StructuredActivityNode.gif"));
}
}

That's it. The rest can be seen from the discussion. Link provided above. Oh, one more thing: you need to add the icons folder to your plugin resources! The implementation could also be made more efficient (prevent loading of images again and again).

No comments:

Post a Comment