KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2005, 2006 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.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 JavaDoc 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 current config is broken, confirm with the user to continue
49
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 JavaDoc e) {
62             // This should not happen
63
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             // check for pending changes (e.g. if the feature has just been disabled)
85
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) //$NON-NLS-1$
90
return false;
91         } catch (CoreException e) {
92             return false;
93         }
94                 
95         return true;
96     }
97 }
98
Popular Tags