KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > update > internal > operations > UninstallOperation


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.operations;
12
13 import org.eclipse.core.runtime.*;
14 import org.eclipse.osgi.util.NLS;
15 import org.eclipse.update.configuration.*;
16 import org.eclipse.update.core.*;
17 import org.eclipse.update.internal.core.Messages;
18 import org.eclipse.update.operations.*;
19
20 /**
21  * Configure a feature.
22  * ConfigOperation
23  */

24 public class UninstallOperation extends FeatureOperation implements IUninstallFeatureOperation{
25
26     public UninstallOperation(IConfiguredSite site, IFeature feature) {
27         super(site, feature);
28     }
29
30     public void setTargetSite(IConfiguredSite targetSite) {
31         this.targetSite = targetSite;
32     }
33
34     public boolean execute(IProgressMonitor pm, IOperationListener listener) throws CoreException {
35         
36         if (targetSite == null)
37             targetSite = UpdateUtils.getConfigSite(feature, SiteManager.getLocalSite().getCurrentConfiguration());
38
39         // Restart not needed
40
boolean restartNeeded = false;
41
42         if (targetSite != null) {
43             // if needed, unconfigure the feature first
44
if (targetSite.isConfigured(feature)) {
45                 IStatus status = OperationsManager.getValidator().validatePendingUnconfig(feature);
46                 if (status != null && status.getCode() == IStatus.ERROR)
47                     throw new CoreException(status);
48                 if (unconfigure(feature, targetSite))
49                     restartNeeded = true;
50                 else
51                     throw Utilities.newCoreException(NLS.bind(Messages.OperationsManager_error_uninstall, (new String JavaDoc[] { feature.getVersionedIdentifier().toString() })), null);
52             }
53             targetSite.remove(feature, pm);
54         } else {
55             // we should do something here
56
String JavaDoc message =
57                 NLS.bind(Messages.OperationsManager_error_uninstall, (new String JavaDoc[] { feature.getLabel() }));
58             IStatus status =
59                 new Status(
60                     IStatus.ERROR,
61                     UpdateUtils.getPluginId(),
62                     IStatus.OK,
63                     message,
64                     null);
65             throw new CoreException(status);
66         }
67
68         markProcessed();
69         if (listener != null)
70             listener.afterExecute(this, null);
71
72         restartNeeded = SiteManager.getLocalSite().save() && restartNeeded;
73
74         // notify the model
75
OperationsManager.fireObjectChanged(feature, UNINSTALL);
76         
77         return restartNeeded;
78     }
79
80 }
81
Popular Tags