KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > actions > CreateFolderAction


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.ui.actions;
12
13 import java.util.Iterator JavaDoc;
14
15 import org.eclipse.core.resources.IResource;
16 import org.eclipse.jface.viewers.IStructuredSelection;
17 import org.eclipse.jface.wizard.WizardDialog;
18 import org.eclipse.swt.widgets.Shell;
19 import org.eclipse.ui.ISharedImages;
20 import org.eclipse.ui.PlatformUI;
21 import org.eclipse.ui.internal.ide.IDEWorkbenchMessages;
22 import org.eclipse.ui.internal.ide.IIDEHelpContextIds;
23 import org.eclipse.ui.wizards.newresource.BasicNewFolderResourceWizard;
24
25 /**
26  * Standard action for creating a folder resource within the currently
27  * selected folder or project.
28  * <p>
29  * This class may be instantiated; it is not intended to be subclassed.
30  * </p>
31  *
32  * @deprecated should use NewWizardMenu to populate a New submenu instead (see Navigator view)
33  */

34 public class CreateFolderAction extends SelectionListenerAction {
35
36     /**
37      * The id of this action.
38      */

39     public static final String JavaDoc ID = PlatformUI.PLUGIN_ID
40             + ".CreateFolderAction";//$NON-NLS-1$
41

42     /**
43      * The shell in which to show any dialogs.
44      */

45     private Shell shell;
46
47     /**
48      * Creates a new action for creating a folder resource.
49      *
50      * @param shell the shell for any dialogs
51      *
52      * @deprecated see deprecated tag on class
53      */

54     public CreateFolderAction(Shell shell) {
55         super(IDEWorkbenchMessages.CreateFolderAction_text);
56         if (shell == null) {
57             throw new IllegalArgumentException JavaDoc();
58         }
59         this.shell = shell;
60         setImageDescriptor(PlatformUI.getWorkbench().getSharedImages()
61                 .getImageDescriptor(ISharedImages.IMG_OBJ_FOLDER));
62         setToolTipText(IDEWorkbenchMessages.CreateFolderAction_toolTip);
63         setId(ID);
64         PlatformUI.getWorkbench().getHelpSystem().setHelp(this,
65                 IIDEHelpContextIds.CREATE_FOLDER_ACTION);
66     }
67
68     /**
69      * The <code>CreateFolderAction</code> implementation of this
70      * <code>IAction</code> method opens a <code>BasicNewFolderResourceWizard</code>
71      * in a wizard dialog under the shell passed to the constructor.
72      */

73     public void run() {
74         BasicNewFolderResourceWizard wizard = new BasicNewFolderResourceWizard();
75         wizard.init(PlatformUI.getWorkbench(), getStructuredSelection());
76         wizard.setNeedsProgressMonitor(true);
77         WizardDialog dialog = new WizardDialog(shell, wizard);
78         dialog.create();
79         dialog.getShell().setText(
80                 IDEWorkbenchMessages.CreateFolderAction_title);
81         PlatformUI.getWorkbench().getHelpSystem().setHelp(dialog.getShell(),
82                 IIDEHelpContextIds.NEW_FOLDER_WIZARD);
83         dialog.open();
84
85     }
86
87     /**
88      * The <code>CreateFolderAction</code> implementation of this
89      * <code>SelectionListenerAction</code> method enables the action only
90      * if the selection contains folders and open projects.
91      */

92     protected boolean updateSelection(IStructuredSelection s) {
93         if (!super.updateSelection(s)) {
94             return false;
95         }
96         Iterator JavaDoc resources = getSelectedResources().iterator();
97         while (resources.hasNext()) {
98             IResource resource = (IResource) resources.next();
99             if (!resourceIsType(resource, IResource.PROJECT | IResource.FOLDER)
100                     || !resource.isAccessible()) {
101                 return false;
102             }
103         }
104         return true;
105     }
106 }
107
Popular Tags