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.internal.core.InstallRegistry; 21 import org.eclipse.update.internal.operations.OperationFactory; 22 import org.eclipse.update.internal.operations.UpdateUtils; 23 import org.eclipse.update.internal.ui.UpdateUI; 24 import org.eclipse.update.internal.ui.UpdateUIMessages; 25 import org.eclipse.update.internal.ui.model.ConfiguredFeatureAdapter; 26 import org.eclipse.update.operations.IFeatureOperation; 27 import org.eclipse.update.operations.IOperation; 28 import org.eclipse.update.operations.OperationsManager; 29 30 public class UnconfigureAndUninstallFeatureAction extends FeatureAction { 31 32 private ConfiguredFeatureAdapter adapter; 33 34 public UnconfigureAndUninstallFeatureAction(Shell shell, String text) { 35 super(shell, text); 36 setWindowTitle(UpdateUIMessages.FeatureUnconfigureAndUninstallAction_dialogTitle); 37 } 38 39 public void run() { 40 try { 41 IStatus status = OperationsManager.getValidator().validatePlatformConfigValid(); 42 if (status != null) 43 throw new CoreException(status); 44 45 if (adapter == null || !confirm(UpdateUIMessages.FeatureUnconfigureAndUninstallAction_question)) 46 return; 47 48 if (OperationsManager.getValidator().validateCurrentState() != null && 50 !confirm(UpdateUIMessages.Actions_brokenConfigQuestion)) 51 return; 52 53 IOperation operation = 54 ((OperationFactory)OperationsManager.getOperationFactory()).createUnconfigureAndUninstallFeatureOperation( adapter.getConfiguredSite(), adapter.getFeature(null)); 55 56 boolean restartNeeded = operation.execute(null, null); 57 UpdateUI.requestRestart(restartNeeded); 58 59 } catch (CoreException e) { 60 ErrorDialog.openError(shell, null, null, e.getStatus()); 61 } catch (InvocationTargetException e) { 62 UpdateUtils.logException(e.getTargetException()); 64 } 65 } 66 67 68 69 public void setSelection(IStructuredSelection selection) { 70 71 this.adapter = (ConfiguredFeatureAdapter) selection.getFirstElement(); 72 setText(UpdateUIMessages.FeatureUnconfigureAndUninstallAction_uninstall); 73 } 74 75 76 public boolean canExecuteAction() { 77 if (adapter == null) 78 return false; 79 80 if (!adapter.isConfigured()) 81 return false; 82 83 try { 84 IFeatureOperation pendingOperation = OperationsManager.findPendingOperation(adapter.getFeature(null)); 86 if (pendingOperation != null) 87 return false; 88 89 if (InstallRegistry.getInstance().get("feature_"+adapter.getFeature(null).getVersionedIdentifier()) == null) return false; 91 } catch (CoreException e) { 92 return false; 93 } 94 95 return true; 96 } 97 } 98 | Popular Tags |