1 11 package org.eclipse.update.internal.ui.views; 12 13 import java.lang.reflect.InvocationTargetException ; 14 15 import org.eclipse.core.runtime.CoreException; 16 import org.eclipse.core.runtime.IStatus; 17 import org.eclipse.jface.dialogs.ErrorDialog; 18 import org.eclipse.jface.viewers.IStructuredSelection; 19 import org.eclipse.swt.widgets.Shell; 20 import org.eclipse.update.configuration.IConfiguredSite; 21 import org.eclipse.update.core.IFeature; 22 import org.eclipse.update.internal.core.InstallRegistry; 23 import org.eclipse.update.internal.operations.OperationFactory; 24 import org.eclipse.update.internal.operations.UpdateUtils; 25 import org.eclipse.update.internal.ui.UpdateUI; 26 import org.eclipse.update.internal.ui.UpdateUIMessages; 27 import org.eclipse.update.internal.ui.model.ConfiguredFeatureAdapter; 28 import org.eclipse.update.operations.IFeatureOperation; 29 import org.eclipse.update.operations.IOperation; 30 import org.eclipse.update.operations.OperationsManager; 31 32 public class UninstallFeaturesAction extends FeatureAction { 33 34 private ConfiguredFeatureAdapter[] adapters; 35 36 public UninstallFeaturesAction( Shell shell, String text) { 37 super(shell, text); 38 setWindowTitle(UpdateUIMessages.FeatureUninstallAction_dialogTitle); 39 } 40 41 42 public void run() { 43 try { 44 IStatus status = OperationsManager.getValidator().validatePlatformConfigValid(); 45 if (status != null) 46 throw new CoreException(status); 47 48 if (adapters == null || !confirm(UpdateUIMessages.FeatureUninstallAction_uninstallQuestion)) 49 return; 50 51 if (OperationsManager.getValidator().validateCurrentState() != null && 53 !confirm(UpdateUIMessages.Actions_brokenConfigQuestion)) 54 return; 55 56 IFeature[] features = new IFeature[adapters.length]; 57 IConfiguredSite[] configuredSites = new IConfiguredSite[adapters.length]; 58 for( int i = 0; i < adapters.length; i++) { 59 features[i] = adapters[i].getFeature(null); 60 configuredSites[i] = adapters[i].getConfiguredSite(); 61 } 62 63 IOperation uninstallFeaturesOperation = 64 ((OperationFactory)OperationsManager.getOperationFactory()).createUninstallFeaturesOperation( configuredSites, features); 65 66 boolean restartNeeded = uninstallFeaturesOperation.execute(null, null); 67 UpdateUI.requestRestart(restartNeeded); 68 69 } catch (CoreException e) { 70 ErrorDialog.openError(shell, null, null, e.getStatus()); 71 } catch (InvocationTargetException e) { 72 UpdateUtils.logException(e.getTargetException()); 74 } 75 } 76 77 78 public void setSelection(IStructuredSelection selection) { 79 80 this.adapters = (ConfiguredFeatureAdapter[]) selection.toList().toArray(new ConfiguredFeatureAdapter[selection.size()]); 81 setText(UpdateUIMessages.FeatureUninstallAction_uninstall); 82 } 83 84 public boolean canExecuteAction() { 85 86 if (adapters == null || adapters.length == 0) 87 return false; 88 89 for( int i = 0; i < adapters.length; i++) { 90 if (adapters[i].isConfigured()) 91 return false; 92 93 try { 94 IFeatureOperation pendingOperation = OperationsManager.findPendingOperation(adapters[i].getFeature(null)); 96 if (pendingOperation != null) 97 return false; 98 99 if (InstallRegistry.getInstance().get("feature_"+adapters[i].getFeature(null).getVersionedIdentifier()) == null) return false; 101 } catch (CoreException e) { 102 return false; 103 } 104 } 105 106 return true; 107 } 108 } 109 | Popular Tags |