Skip to content
Snippets Groups Projects
Commit 6126cdc7 authored by Vincent Aravantinos's avatar Vincent Aravantinos
Browse files

Context menu to deal with constraints

refs 2353
parent f14600bb
No related branches found
No related tags found
No related merge requests found
......@@ -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">
......
/*-----------------------------------------------------------------------+
| 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() {
//
// }
// });
}
}
}
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