KickJava   Java API By Example, From Geeks To Geeks.

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


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.update.configuration.*;
15 import org.eclipse.update.core.*;
16 import org.eclipse.update.operations.*;
17
18 /**
19  * Unconfigure a feature.
20  * UnconfigOperation
21  */

22 public class UnconfigOperation
23     extends FeatureOperation
24     implements IUnconfigFeatureOperation {
25
26     public UnconfigOperation(
27         IConfiguredSite site,
28         IFeature feature) {
29         super(site, feature);
30     }
31
32     public boolean execute(IProgressMonitor pm, IOperationListener listener)
33         throws CoreException {
34
35         IStatus status =
36             OperationsManager.getValidator().validatePendingUnconfig(feature);
37         if (status != null && status.getCode() == IStatus.ERROR) {
38             throw new CoreException(status);
39         }
40
41         PatchCleaner cleaner = new PatchCleaner(targetSite, feature);
42         targetSite.unconfigure(feature);
43         cleaner.dispose();
44
45         try {
46             // Restart not needed
47
boolean restartNeeded = false;
48
49             // Check if this operation is cancelling one that's already pending
50
IOperation pendingOperation =
51                 OperationsManager.findPendingOperation(feature);
52
53             if (pendingOperation instanceof IConfigFeatureOperation) {
54                 // no need to do either pending change
55
OperationsManager.removePendingOperation(pendingOperation);
56             } else {
57                 OperationsManager.addPendingOperation(this);
58                 restartNeeded = true;
59             }
60
61             markProcessed();
62             if (listener != null)
63                 listener.afterExecute(this, null);
64
65             restartNeeded = SiteManager.getLocalSite().save() && restartNeeded;
66
67             // notify the model
68
OperationsManager.fireObjectChanged(feature, null);
69
70             return restartNeeded;
71         } catch (CoreException e) {
72             undo();
73             UpdateUtils.logException(e);
74             throw e;
75         }
76     }
77
78     public void undo() throws CoreException {
79         targetSite.configure(feature);
80     }
81
82 }
83
Popular Tags