1 11 12 package org.eclipse.jdt.internal.corext.buildpath; 13 14 import java.lang.reflect.InvocationTargetException ; 15 import java.util.List ; 16 17 import org.eclipse.core.runtime.CoreException; 18 import org.eclipse.core.runtime.IProgressMonitor; 19 20 import org.eclipse.jdt.core.IClasspathEntry; 21 import org.eclipse.jdt.core.IJavaProject; 22 import org.eclipse.jdt.core.JavaModelException; 23 24 import org.eclipse.jdt.internal.ui.wizards.NewWizardMessages; 25 import org.eclipse.jdt.internal.ui.wizards.buildpaths.newsourcepage.DialogPackageExplorerActionGroup; 26 27 34 public class ResetOperation extends ClasspathModifierOperation { 35 36 47 public ResetOperation(IClasspathModifierListener listener, IClasspathInformationProvider informationProvider) { 48 super(listener, informationProvider, NewWizardMessages.NewSourceContainerWorkbookPage_ToolBar_Reset_tooltip, IClasspathInformationProvider.RESET); 49 } 50 51 58 public void run(IProgressMonitor monitor) throws InvocationTargetException { 59 List result= null; 60 fException= null; 61 try { 62 List selection= getSelectedElements(); 63 IJavaProject project= fInformationProvider.getJavaProject(); 64 result= reset(selection, project, monitor); 65 } catch (CoreException e) { 66 fException= e; 67 result= null; 68 } 69 super.handleResult(result, monitor); 70 } 71 72 86 public boolean isValid(List elements, int[] types) throws JavaModelException { 87 if (elements.size() == 0) 88 return false; 89 IJavaProject project= fInformationProvider.getJavaProject(); 90 boolean hasResetableFragmentRoot= false; 91 boolean hasOutputFolder= false; 92 boolean hasResetableProject= false; 93 101 for(int i= 0; i < elements.size(); i++) { 102 switch(types[i]) { 103 case DialogPackageExplorerActionGroup.JAVA_PROJECT: hasResetableProject= isValidProject(project); break; case DialogPackageExplorerActionGroup.PACKAGE_FRAGMENT_ROOT: break; case DialogPackageExplorerActionGroup.MODIFIED_FRAGMENT_ROOT: hasResetableFragmentRoot= true; break; case DialogPackageExplorerActionGroup.OUTPUT: hasOutputFolder= true; break; case DialogPackageExplorerActionGroup.DEFAULT_OUTPUT: break; default: return false; } 110 111 } 112 return hasResetableFragmentRoot || hasOutputFolder || hasResetableProject; 113 } 114 115 123 private boolean isValidProject(IJavaProject project) throws JavaModelException { 124 if (project.isOnClasspath(project)) { 125 IClasspathEntry entry= ClasspathModifier.getClasspathEntryFor(project.getPath(), project, IClasspathEntry.CPE_SOURCE); 126 if (entry.getInclusionPatterns().length != 0 || entry.getExclusionPatterns().length != 0) 127 return true; 128 } 129 return false; 130 } 131 132 144 public String getDescription(int type) { 145 if (type == DialogPackageExplorerActionGroup.OUTPUT || 146 type == (DialogPackageExplorerActionGroup.OUTPUT | DialogPackageExplorerActionGroup.MULTI)) 147 return NewWizardMessages.PackageExplorerActionGroup_FormText_SetOutputToDefault; 148 if (type == DialogPackageExplorerActionGroup.MODIFIED_FRAGMENT_ROOT || 149 type == (DialogPackageExplorerActionGroup.MODIFIED_FRAGMENT_ROOT | DialogPackageExplorerActionGroup.MULTI)) 150 return NewWizardMessages.PackageExplorerActionGroup_FormText_ResetFilters; 151 return NewWizardMessages.PackageExplorerActionGroup_FormText_Default_Reset; 152 } 153 } 154 | Popular Tags |