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