Java Reference
In-Depth Information
menu is applicable for our custom EditPart class added earlier, with 'Display
default image' added to its context menu. Returning to our ViewFactory class,
we'll add the following overrides to decorate the view with our new
CustomStyle .
public class IntermediateEventImageViewFactory extends
Event2ViewFactory {
@Override
protected void decorateView(View containerView, View view, IAdaptable
semanticAdapter, String semanticHint, int index, boolean persisted) {
super .decorateView(containerView, view, semanticAdapter,
semanticHint, index, persisted);
CustomStyle style = (CustomStyle)
view.getStyle(StylePackage.eINSTANCE.getCustomStyle());
style.setDefault( false );
}
@Override
protected List createStyles(View view) {
List styles = super .createStyles(view);
styles.add(StyleFactory.eINSTANCE.createCustomStyle());
return styles;
}
}
Our EditPart must be aware of the new Style element to create the
appropriate figure. Additionally, as our action will set our default:EBoolean
attribute in the CustomStyle , we'll need to respond to this event and update
our model accordingly by overriding handleNotificationEvent() .
public class IntermediateEventImageEditPart extends Event2EditPart {
public IntermediateEventImageEditPart(View view) {
super (view);
}
protected IFigure createNodeShape() {
CustomStyle style = (CustomStyle) getNotationView().getStyle(
StylePackage.eINSTANCE.getCustomStyle());
if (style == null || style.isDefault()) {
return super .createNodeShape();
}
URL url = FileLocator.find(Activator.getDefault().getBundle(),
new Path("images" + IPath.SEPARATOR + "ievent.svg"), null );
return new ScalableImageFigure(
RenderedImageFactory.getInstance(url), true, true, true);
}
protected void handleNotificationEvent(Notification notification) {
Search WWH ::




Custom Search