diff --git a/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/views/NavigatorNewMenu.java b/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/views/NavigatorNewMenu.java index a6f64e38a493ef0c970221cfeb01e06ac88e23bc..df69054e5acd08feea35643e934d39c040267aa4 100644 --- a/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/views/NavigatorNewMenu.java +++ b/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/views/NavigatorNewMenu.java @@ -22,16 +22,20 @@ import org.eclipse.emf.ecore.EObject; import org.eclipse.jface.action.Action; import org.eclipse.jface.action.ActionContributionItem; import org.eclipse.jface.action.IContributionItem; +import org.eclipse.jface.resource.ImageDescriptor; import org.fortiss.tooling.kernel.extension.data.Prototype; import org.fortiss.tooling.kernel.service.ICommandStackService; import org.fortiss.tooling.kernel.service.IElementCompositorService; import org.fortiss.tooling.kernel.service.IPrototypeService; +import org.fortiss.tooling.kernel.ui.ToolingKernelUIActivator; import org.fortiss.tooling.kernel.ui.extension.IContextMenuContributor; +import org.fortiss.tooling.kernel.ui.extension.IModelElementHandler; import org.fortiss.tooling.kernel.ui.extension.data.ContextMenuContextProvider; import org.fortiss.tooling.kernel.ui.service.IContextMenuService; import org.fortiss.tooling.kernel.ui.service.IModelEditorBindingService; import org.fortiss.tooling.kernel.ui.service.IModelElementHandlerService; import org.fortiss.tooling.kernel.ui.service.INavigatorService; +import org.fortiss.tooling.kernel.utils.LoggingUtils; /** * The contributor for the dynamic new menu of the navigator view based on model @@ -50,7 +54,12 @@ public class NavigatorNewMenu implements IContextMenuContributor { /** Constructor. */ public NavigatorNewMenu() { for(Prototype prototype : IPrototypeService.INSTANCE.getPrimaryPrototypes()) { - actions.add(new AddPrototypeAction(prototype)); + try { + actions.add(new AddPrototypeAction(prototype)); + } catch(Exception e) { + LoggingUtils.error(ToolingKernelUIActivator.getDefault(), + "Unexpected exception while adding prototypes", e); + } } } @@ -89,11 +98,22 @@ public class NavigatorNewMenu implements IContextMenuContributor { /** Constructor. */ public AddPrototypeAction(Prototype prototype) { - super(prototype.getName(), IModelElementHandlerService.INSTANCE.getModelElementHandler( - prototype.getPrototype()).getIconImageDescriptor()); + super(prototype.getName(), getIcon(prototype)); this.prototype = prototype; } + /** Get the icon of the prototype */ + public static ImageDescriptor getIcon(Prototype prototype) { + IModelElementHandler<EObject> handler = + IModelElementHandlerService.INSTANCE.getModelElementHandler(prototype + .getPrototype()); + + if(handler == null) + return null; + + return handler.getIconImageDescriptor(); + } + /** {@inheritDoc} */ @Override public void run() { @@ -114,9 +134,10 @@ public class NavigatorNewMenu implements IContextMenuContributor { * prototype can be added to it. */ public boolean prepare(EObject container, boolean expert) { - if(!expert && - IModelElementHandlerService.INSTANCE.getModelElementHandler( - prototype.getPrototype()).hiddenInNonExpertView()) { + IModelElementHandler<EObject> handler = + IModelElementHandlerService.INSTANCE.getModelElementHandler(prototype + .getPrototype()); + if(!expert && handler != null && handler.hiddenInNonExpertView()) { this.container = null; return false; }