blob: 49d482ccb0f6c19f1cecfde6963d6cc62291fa73 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2000, 2017 IBM Corporation and others.
* 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
*
*******************************************************************************/
package org.eclipse.dltk.internal.ui.actions;
import org.eclipse.core.resources.IResource;
import org.eclipse.dltk.core.IModelElement;
import org.eclipse.dltk.ui.IContextMenuConstants;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.IWorkbenchSite;
import org.eclipse.ui.actions.ActionGroup;
import org.eclipse.ui.actions.NewWizardMenu;
/**
* Action group that adds the 'new' menu to a context menu.
* <p>
* This class may be instantiated; it is not intended to be subclassed.
* </p>
*
*
*/
public class NewWizardsActionGroup extends ActionGroup {
private IWorkbenchSite fSite;
/**
* Creates a new <code>NewWizardsActionGroup</code>. The group requires
* that the selection provided by the part's selection provider is of type <code>
* org.eclipse.jface.viewers.IStructuredSelection</code>.
*
* @param site the view part that owns this action group
*/
public NewWizardsActionGroup(IWorkbenchSite site) {
fSite= site;
}
@Override
public void fillContextMenu(IMenuManager menu) {
super.fillContextMenu(menu);
ISelection selection= getContext().getSelection();
if (selection instanceof IStructuredSelection) {
IStructuredSelection sel= (IStructuredSelection) selection;
if (sel.size() <= 1 && isNewTarget(sel.getFirstElement())) {
MenuManager newMenu = new MenuManager(ActionMessages.NewWizardsActionGroup_new);
menu.appendToGroup(IContextMenuConstants.GROUP_NEW, newMenu);
newMenu.add(new NewWizardMenu(fSite.getWorkbenchWindow()));
}
}
}
private boolean isNewTarget(Object element) {
if (element == null)
return true;
if (element instanceof IResource) {
return true;
}
if (element instanceof IModelElement) {
int type= ((IModelElement)element).getElementType();
return type == IModelElement.SCRIPT_PROJECT ||
type == IModelElement.PROJECT_FRAGMENT ||
type == IModelElement.SCRIPT_FOLDER ||
type == IModelElement.SOURCE_MODULE ||
type == IModelElement.TYPE;
}
return false;
}
}