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 UnconfigureAndUninstallFeaturesAction extends FeatureAction { 33 34 private ConfiguredFeatureAdapter[] adapters; 35 36 public UnconfigureAndUninstallFeaturesAction( Shell shell, String text) { 37 super(shell, text); 38 setWindowTitle(UpdateUIMessages.FeatureUnconfigureAndUninstallAction_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.FeatureUnconfigureAndUninstallAction_question)) 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()).createUnconfigureAndUninstallFeaturesOperation( 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 public void setSelection(IStructuredSelection selection) { 78 79 this.adapters = (ConfiguredFeatureAdapter[]) selection.toList().toArray(new ConfiguredFeatureAdapter[selection.size()]); 80 setText(UpdateUIMessages.FeatureUnconfigureAndUninstallAction_uninstall); 81 } 82 83 public boolean canExecuteAction() { 84 85 if (adapters == null || adapters.length == 0) 86 return false; 87 88 for( int i = 0; i < adapters.length; i++) { 89 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 } 110 | Popular Tags |