Skip to content
Snippets Groups Projects
Commit 619ae7a6 authored by Dongyue Mou's avatar Dongyue Mou
Browse files

added protection code to avoid crash of whole menu

parent d37b0c04
No related branches found
No related tags found
No related merge requests found
......@@ -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;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment