1 11 package org.eclipse.ui.actions; 12 13 import java.util.Iterator ; 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 34 public class CreateFileAction extends SelectionListenerAction { 35 36 39 public static final String ID = PlatformUI.PLUGIN_ID + ".CreateFileAction"; 41 44 private Shell shell; 45 46 53 public CreateFileAction(Shell shell) { 54 super(IDEWorkbenchMessages.CreateFileAction_text); 55 if (shell == null) { 56 throw new IllegalArgumentException (); 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 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 90 protected boolean updateSelection(IStructuredSelection s) { 91 if (!super.updateSelection(s)) { 92 return false; 93 } 94 Iterator 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 |