1 11 package org.eclipse.update.internal.operations; 12 13 import org.eclipse.core.runtime.*; 14 import org.eclipse.update.core.*; 15 import org.eclipse.update.operations.*; 16 17 21 public class ReplaceFeatureVersionOperation 22 extends FeatureOperation 23 implements IConfigFeatureOperation { 24 25 private IFeature anotherFeature; 26 27 public ReplaceFeatureVersionOperation( 28 IFeature feature, 29 IFeature anotherFeature) { 30 super(feature.getSite().getCurrentConfiguredSite(), feature); 31 this.anotherFeature = anotherFeature; 32 } 33 34 public boolean execute(IProgressMonitor pm, IOperationListener listener) 35 throws CoreException { 36 37 IStatus status = 38 OperationsManager.getValidator().validatePendingReplaceVersion(feature, anotherFeature); 39 if (status != null) { 40 throw new CoreException(status); 41 } 42 43 45 PatchCleaner cleaner = new PatchCleaner(targetSite, feature); 46 targetSite.unconfigure(feature); 47 cleaner.dispose(); 48 49 targetSite.configure(anotherFeature); 50 52 try { 53 boolean restartNeeded = false; 55 56 IOperation pendingOperation = 58 OperationsManager.findPendingOperation(feature); 59 60 if (pendingOperation instanceof IConfigFeatureOperation) { 61 OperationsManager.removePendingOperation(pendingOperation); 63 } else { 64 OperationsManager.addPendingOperation(this); 65 restartNeeded = true; 66 } 67 68 pendingOperation = 69 OperationsManager.findPendingOperation(anotherFeature); 70 71 if (pendingOperation instanceof IUnconfigFeatureOperation) { 72 OperationsManager.removePendingOperation(pendingOperation); 74 } else { 75 OperationsManager.addPendingOperation(this); 76 restartNeeded = true; 77 } 78 79 markProcessed(); 80 if (listener != null) 81 listener.afterExecute(this, null); 82 83 restartNeeded = SiteManager.getLocalSite().save() && restartNeeded; 84 85 OperationsManager.fireObjectChanged(feature, null); 87 88 return restartNeeded; 89 } catch (CoreException e) { 90 undo(); 91 UpdateUtils.logException(e); 92 throw e; 93 } 94 } 95 96 public void undo() throws CoreException { 97 targetSite.unconfigure(anotherFeature); 98 targetSite.configure(feature); 99 } 100 } 101 | Popular Tags |