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.jface.operation.IRunnableWithProgress; 21 22 import org.eclipse.jdt.core.JavaModelException; 23 24 import org.eclipse.jdt.internal.ui.wizards.buildpaths.newsourcepage.DialogPackageExplorerActionGroup; 25 26 27 31 public abstract class ClasspathModifierOperation extends ClasspathModifier implements IRunnableWithProgress { 32 protected IClasspathInformationProvider fInformationProvider; 33 protected CoreException fException; 34 private int fType; 35 38 private String fName; 39 40 54 public ClasspathModifierOperation(IClasspathModifierListener listener, IClasspathInformationProvider informationProvider, String name, int type) { 55 super(listener); 56 fInformationProvider= informationProvider; 57 fException= null; 58 fName= name; 59 fType= type; 60 } 61 62 protected void handleResult(List result, IProgressMonitor monitor) throws InvocationTargetException { 63 74 if (monitor == null || fException == null) 75 fInformationProvider.handleResult(result, fException, fType); 76 else 77 throw new InvocationTargetException (fException); 78 fException= null; 79 } 80 81 86 public abstract void run(IProgressMonitor monitor) throws InvocationTargetException , InterruptedException ; 87 88 93 public String getId() { 94 return Integer.toString(fType); 95 } 96 97 112 public abstract boolean isValid(List elements, int[] types) throws JavaModelException; 113 114 126 public abstract String getDescription(int type); 127 128 public String getName() { 129 return fName; 130 } 131 132 public List getSelectedElements() { 133 return fInformationProvider.getSelection().toList(); 134 } 135 136 public int getTypeId() { 137 return fType; 138 } 139 140 public boolean isValid() throws JavaModelException { 141 List selectedElements= getSelectedElements(); 142 int[] types= new int[selectedElements.size()]; 143 for(int i= 0; i < types.length; i++) { 144 types[i]= DialogPackageExplorerActionGroup.getType(selectedElements.get(i), fInformationProvider.getJavaProject()); 145 } 146 return isValid(selectedElements, types); 147 } 148 } 149 | Popular Tags |