KickJava   Java API By Example, From Geeks To Geeks.

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


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.BasicNewFileResourceWizard;
24
25 /**
26  * Standard action for creating a file 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 CreateFileAction extends SelectionListenerAction {
35
36     /**
37      * The id of this action.
38      */

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

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

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

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

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

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