001: /*******************************************************************************
002: * Copyright (c) 2000, 2005 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.ui.actions;
011:
012: import java.util.Iterator;
013:
014: import org.eclipse.core.resources.IResource;
015: import org.eclipse.jface.viewers.IStructuredSelection;
016: import org.eclipse.jface.wizard.WizardDialog;
017: import org.eclipse.swt.widgets.Shell;
018: import org.eclipse.ui.ISharedImages;
019: import org.eclipse.ui.PlatformUI;
020: import org.eclipse.ui.internal.ide.IDEWorkbenchMessages;
021: import org.eclipse.ui.internal.ide.IIDEHelpContextIds;
022: import org.eclipse.ui.wizards.newresource.BasicNewFolderResourceWizard;
023:
024: /**
025: * Standard action for creating a folder resource within the currently
026: * selected folder or project.
027: * <p>
028: * This class may be instantiated; it is not intended to be subclassed.
029: * </p>
030: *
031: * @deprecated should use NewWizardMenu to populate a New submenu instead (see Navigator view)
032: */
033: public class CreateFolderAction extends SelectionListenerAction {
034:
035: /**
036: * The id of this action.
037: */
038: public static final String ID = PlatformUI.PLUGIN_ID
039: + ".CreateFolderAction";//$NON-NLS-1$
040:
041: /**
042: * The shell in which to show any dialogs.
043: */
044: private Shell shell;
045:
046: /**
047: * Creates a new action for creating a folder resource.
048: *
049: * @param shell the shell for any dialogs
050: *
051: * @deprecated see deprecated tag on class
052: */
053: public CreateFolderAction(Shell shell) {
054: super (IDEWorkbenchMessages.CreateFolderAction_text);
055: if (shell == null) {
056: throw new IllegalArgumentException();
057: }
058: this .shell = shell;
059: setImageDescriptor(PlatformUI.getWorkbench().getSharedImages()
060: .getImageDescriptor(ISharedImages.IMG_OBJ_FOLDER));
061: setToolTipText(IDEWorkbenchMessages.CreateFolderAction_toolTip);
062: setId(ID);
063: PlatformUI.getWorkbench().getHelpSystem().setHelp(this ,
064: IIDEHelpContextIds.CREATE_FOLDER_ACTION);
065: }
066:
067: /**
068: * The <code>CreateFolderAction</code> implementation of this
069: * <code>IAction</code> method opens a <code>BasicNewFolderResourceWizard</code>
070: * in a wizard dialog under the shell passed to the constructor.
071: */
072: public void run() {
073: BasicNewFolderResourceWizard wizard = new BasicNewFolderResourceWizard();
074: wizard
075: .init(PlatformUI.getWorkbench(),
076: getStructuredSelection());
077: wizard.setNeedsProgressMonitor(true);
078: WizardDialog dialog = new WizardDialog(shell, wizard);
079: dialog.create();
080: dialog.getShell().setText(
081: IDEWorkbenchMessages.CreateFolderAction_title);
082: PlatformUI.getWorkbench().getHelpSystem()
083: .setHelp(dialog.getShell(),
084: IIDEHelpContextIds.NEW_FOLDER_WIZARD);
085: dialog.open();
086:
087: }
088:
089: /**
090: * The <code>CreateFolderAction</code> implementation of this
091: * <code>SelectionListenerAction</code> method enables the action only
092: * if the selection contains folders and open projects.
093: */
094: protected boolean updateSelection(IStructuredSelection s) {
095: if (!super .updateSelection(s)) {
096: return false;
097: }
098: Iterator resources = getSelectedResources().iterator();
099: while (resources.hasNext()) {
100: IResource resource = (IResource) resources.next();
101: if (!resourceIsType(resource, IResource.PROJECT
102: | IResource.FOLDER)
103: || !resource.isAccessible()) {
104: return false;
105: }
106: }
107: return true;
108: }
109: }
|