KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > update > internal > ui > views > UninstallFeatureAction


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.update.internal.ui.views;
12
13 import java.lang.reflect.InvocationTargetException JavaDoc;
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 JavaDoc 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 current config is broken, confirm with the user to continue
48
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 JavaDoc e) {
65             // This should not happen
66
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             // check for pending changes (e.g. if the feature has just been disabled)
87
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) //$NON-NLS-1$
92
return false;
93         } catch (CoreException e) {
94             return false;
95         }
96                 
97         return true;
98     }
99 }
100
Popular Tags