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.BasicNewFolderResourceWizard; 24 25 34 public class CreateFolderAction extends SelectionListenerAction { 35 36 39 public static final String ID = PlatformUI.PLUGIN_ID 40 + ".CreateFolderAction"; 42 45 private Shell shell; 46 47 54 public CreateFolderAction(Shell shell) { 55 super(IDEWorkbenchMessages.CreateFolderAction_text); 56 if (shell == null) { 57 throw new IllegalArgumentException (); 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 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 92 protected boolean updateSelection(IStructuredSelection s) { 93 if (!super.updateSelection(s)) { 94 return false; 95 } 96 Iterator 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 |