From 6126cdc7270fac9ab8c8313abec92f627dab8590 Mon Sep 17 00:00:00 2001 From: Vincent Aravantinos <aravantinos@fortiss.org> Date: Tue, 12 Apr 2016 14:18:49 +0000 Subject: [PATCH] Context menu to deal with constraints refs 2353 --- .../trunk/plugin.xml | 5 +- .../ui/internal/views/ConstraintMenu.java | 114 ++++++++++++++++++ 2 files changed, 118 insertions(+), 1 deletion(-) create mode 100644 org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/views/ConstraintMenu.java diff --git a/org.fortiss.tooling.kernel.ui/trunk/plugin.xml b/org.fortiss.tooling.kernel.ui/trunk/plugin.xml index 951c33d73..fdbedcb54 100644 --- a/org.fortiss.tooling.kernel.ui/trunk/plugin.xml +++ b/org.fortiss.tooling.kernel.ui/trunk/plugin.xml @@ -121,7 +121,7 @@ state="true"> <enablement> <objectClass - name="org.fortiss.tooling.kernel.model.constraints.IConstrained"> + name="org.eclipse.emf.ecore.EObject"> </objectClass> </enablement> </decorator> @@ -131,6 +131,9 @@ <contextMenuContribution contributor="org.fortiss.tooling.kernel.ui.internal.views.NavigatorNewMenu"> </contextMenuContribution> + <contextMenuContribution + contributor="org.fortiss.tooling.kernel.ui.internal.views.ConstraintMenu"> + </contextMenuContribution> </extension> <extension point="org.eclipse.ui.perspectives"> diff --git a/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/views/ConstraintMenu.java b/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/views/ConstraintMenu.java new file mode 100644 index 000000000..40460c433 --- /dev/null +++ b/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/internal/views/ConstraintMenu.java @@ -0,0 +1,114 @@ +/*-----------------------------------------------------------------------+ + | org.fortiss.tooling.kernel.ui.internal.views + | | + $Id$ + | | + | Copyright (c) 2004-2008 Technische Universitaet Muenchen | + | | + | Technische Universitaet Muenchen ######### ########## | + | Institut fuer Informatik - Lehrstuhl IV ## ## ## ## ## | + | Prof. Dr. Manfred Broy ## ## ## ## ## | + | Boltzmannstr. 3 ## ## ## ## ## | + | 85748 Garching bei Muenchen ## ## ## ## ## | + | Germany ## ###### ## ## | + +-----------------------------------------------------------------------*/ +package org.fortiss.tooling.kernel.ui.internal.views; + +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; + +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.eclipse.jface.viewers.DecorationOverlayIcon; +import org.eclipse.jface.viewers.IDecoration; +import org.eclipse.swt.graphics.Image; +import org.fortiss.tooling.kernel.model.constraints.IConstrained; +import org.fortiss.tooling.kernel.model.constraints.IConstraint; +import org.fortiss.tooling.kernel.model.constraints.OutdatedVerificationStatus; +import org.fortiss.tooling.kernel.ui.ESharedImages; +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.IModelElementHandlerService; + +/** + * The contributor for the dynamic new menu of the navigator view based on model + * element composition. + * + * @author hoelzl + * @author $Author$ + * @version $Rev$ + * @ConQAT.Rating GREEN Hash: 49C26BBDB13EC81195004EDDE740E2C3 + */ +public class ConstraintMenu implements IContextMenuContributor { + + /** {@inheritDoc} */ + @Override + public List<IContributionItem> getContributedItems(EObject selectedObject, + ContextMenuContextProvider contextProvider) { + if(!(selectedObject instanceof IConstrained)) { + return Collections.emptyList(); + } + return ((IConstrained)selectedObject).getConstraints().stream() + .filter(c -> c.getVerificationStatus() instanceof OutdatedVerificationStatus) + .map(c -> new ActionContributionItem(new CheckOutdatedConstraintAction(c))) + .collect(Collectors.toList()); + } + + /** {@inheritDoc} */ + @Override + public String getMenuSectionID() { + return IContextMenuService.TOP_MOST_MENU_SECTION_ID; + } + + /** Action for creating a new prototype. */ + private static class CheckOutdatedConstraintAction extends Action { + + /** Constructor. */ + public CheckOutdatedConstraintAction(IConstraint c) { + super(getName(c), getIcon(c)); + } + + /** Get the icon of the prototype. */ + public static String getName(IConstraint c) { + IModelElementHandler<EObject> handler = + IModelElementHandlerService.INSTANCE.getModelElementHandler(c); + + return handler == null ? "[Outdated constraint]" : handler.getName(c); + } + + /** Get the icon of the prototype. */ + public static ImageDescriptor getIcon(IConstraint c) { + IModelElementHandler<EObject> handler = + IModelElementHandlerService.INSTANCE.getModelElementHandler(c); + if(handler == null) { + return null; + } + Image img = handler.getIcon(c); + if(img == null) { + return null; + } + ImageDescriptor overlay = ESharedImages.WARNING_OVERLAY.getImageDescriptor(); + ImageDescriptor[] descriptors = new ImageDescriptor[5]; + descriptors[IDecoration.BOTTOM_LEFT] = overlay; + return new DecorationOverlayIcon(img, descriptors); + } + + /** {@inheritDoc} */ + @Override + public void run() { + // ICommandStackService.INSTANCE.runAsCommand(container, new Runnable() { + // + // @Override + // public void run() { + // + // } + // }); + } + } +} -- GitLab