1 11 package org.eclipse.update.internal.operations; 12 13 import java.lang.reflect.InvocationTargetException ; 14 15 import org.eclipse.core.runtime.CoreException; 16 import org.eclipse.core.runtime.IProgressMonitor; 17 import org.eclipse.update.configuration.IConfiguredSite; 18 import org.eclipse.update.core.IFeature; 19 import org.eclipse.update.operations.IOperation; 20 import org.eclipse.update.operations.IOperationListener; 21 22 public abstract class BatchFeatureOperation extends Operation implements IBatchFeatureOperation { 23 24 private IFeature[] features; 25 private IConfiguredSite[] targetSites; 26 27 28 public BatchFeatureOperation(IConfiguredSite[] targetSites, IFeature[] features) { 29 super(); 30 this.features = features; 31 this.targetSites = targetSites; 32 } 33 34 public IFeature[] getFeatures() { 35 return features; 36 } 37 38 public IConfiguredSite[] getTargetSites() { 39 return targetSites; 40 } 41 42 public void setTargetSites(IConfiguredSite[] targetSites) { 43 this.targetSites = targetSites; 44 45 } 46 47 public boolean execute(IProgressMonitor pm, IOperationListener listener) 48 throws CoreException, InvocationTargetException { 49 50 if (getFeatures() == null || getFeatures().length == 0) 51 return false; 52 IOperation[] operations = new IOperation[getFeatures().length]; 53 54 for ( int i = 0; i < getFeatures().length; i ++) { 55 operations[i] = createOperation(getTargetSites()[i], getFeatures()[i]); 56 } 57 58 boolean restartNeeded = false; 59 60 for ( int i = 0; i < operations.length; i ++) { 61 try { 62 boolean status = operations[i].execute(pm, listener); 63 if (status) 64 restartNeeded = true; 65 } catch (Throwable t) { 66 t.printStackTrace(); 67 } 68 } 69 70 return restartNeeded; 71 72 } 73 74 protected abstract IOperation createOperation(IConfiguredSite targetSite, IFeature feature); 75 76 } 77 | Popular Tags |