| /******************************************************************************* |
| * Copyright (c) 2004-2008 Istvan Rath and Daniel Varro |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * Istvan Rath - initial API and implementation |
| *******************************************************************************/ |
| |
| package org.eclipse.viatra2.treeeditor.menu;
|
|
|
|
|
| import java.util.Iterator;
|
| import java.util.List; |
|
|
| import org.eclipse.jface.action.IMenuListener;
|
| import org.eclipse.jface.action.IMenuManager;
|
| import org.eclipse.jface.action.MenuManager; |
| import org.eclipse.jface.action.Separator;
|
| import org.eclipse.jface.viewers.ISelection;
|
| import org.eclipse.jface.viewers.StructuredSelection;
|
| import org.eclipse.swt.widgets.Menu; |
| import org.eclipse.viatra2.core.IEntity;
|
| import org.eclipse.viatra2.core.IRelation;
|
| import org.eclipse.viatra2.treeeditor.ViatraTreeEditor;
|
| import org.eclipse.viatra2.treeeditor.actions.ViatraTreeEditorSelectionAction;
|
| import org.eclipse.viatra2.treeeditor.providers.ViatraContentProvider.TargetRelationDummy; |
|
|
| public class ViatraTreeEditorMenuListener implements IMenuListener {
|
|
|
| private ViatraTreeEditor iVTE;
|
|
|
| public ViatraTreeEditorMenuListener(ViatraTreeEditor vte) {
|
| iVTE = vte;
|
| }
|
|
|
| public void menuAboutToShow(IMenuManager manager) {
|
| manager.removeAll();
|
|
|
| boolean isEntitySelected = false;
|
| boolean isElementSelected = false; |
| boolean isRelationSelected = false; |
| boolean isRelationTargetSelected = false; |
|
|
|
|
| ISelection sel = iVTE.getSite().getSelectionProvider().getSelection();
|
|
|
|
|
| if (sel instanceof StructuredSelection) {
|
|
|
| Iterator it = ((StructuredSelection) sel).iterator();
|
| while (it.hasNext()) {
|
| Object curr = it.next();
|
| if (!isElementSelected) {
|
| if (iVTE.getDeleteAction()!=null)
|
| {
|
| manager.add(iVTE.getDeleteAction());
|
| }
|
| else
|
| {
|
| manager.add(iVTE.getLocalDeleteAction());
|
| }
|
| manager.add(iVTE.getRenameAction());
|
| manager.add(new Separator("new"));
|
| manager.add(iVTE.getNewRelationAction());
|
| manager.add(new Separator("misc"));
|
| manager.add(iVTE.getExportAction());
|
| manager.add(new Separator());
|
| isElementSelected = true;
|
| }
|
| if (curr instanceof IEntity && !isEntitySelected) {
|
| //if (iVTE.getFramework().isRunnable((IModelElement)curr))
|
| //{
|
| // manager.appendToGroup("misc", iVTE.getRunAction());
|
| //}
|
| manager.appendToGroup("new", iVTE.getNewEntityAction());
|
| isEntitySelected = true;
|
| }
|
| if (curr instanceof IRelation && !isRelationSelected)
|
| {
|
| manager.add(iVTE.getNavigateRelationAction()); |
| isRelationSelected = true; // signal that a relation has already been selected |
| // no need to contribute any IRelation-specific action anymore
|
| } |
| if (curr instanceof TargetRelationDummy && !isRelationTargetSelected) |
| { |
| manager.add(iVTE.getNavigateRelationSourceAction()); |
| isRelationTargetSelected = true; // signal that a relation target dummy has already been selected |
| // no need to contribute any relation target-specific action anymore |
| }
|
| } |
| manager.add(new Separator()); |
| // add contributed actions |
| // for (ViatraTreeEditorSelectionAction a : iVTE.getContributedActions()) |
| // { |
| // manager.add(a); |
| // } |
| for (String key : iVTE.getContributedActions().keySet()) { |
| IMenuManager target = manager; |
| List<ViatraTreeEditorSelectionAction> cAs = iVTE.getContributedActions().get(key); |
| if (!"Default".equals( key )) { |
| target = new MenuManager( key ); |
| manager.add(target); |
| } |
| for (ViatraTreeEditorSelectionAction a : cAs) { |
| target.add(a); |
| } |
| } |
|
|
| }
|
|
|
| //manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
|
| }
|
|
|
| }
|