KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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  * Configure a feature.
20  * ConfigOperation
21  */

22 public class ConfigOperation
23 extends FeatureOperation
24 implements IConfigFeatureOperation {
25
26     public ConfigOperation(
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().validatePendingConfig(feature);
37         if (status != null && status.getCode() == IStatus.ERROR) {
38             throw new CoreException(status);
39         }
40         try {
41             targetSite.configure(feature);
42             //ensureUnique();
43

44             // Restart not needed
45
boolean restartNeeded = false;
46
47             // Check if this operation is cancelling one that's already pending
48
IOperation pendingOperation =
49                 OperationsManager.findPendingOperation(feature);
50
51             if (pendingOperation instanceof IUnconfigFeatureOperation) {
52                 // no need to do either pending change
53
OperationsManager.removePendingOperation(pendingOperation);
54             } else {
55                 OperationsManager.addPendingOperation(this);
56             }
57
58             markProcessed();
59             if (listener != null)
60                 listener.afterExecute(this, null);
61
62             restartNeeded = SiteManager.getLocalSite().save() && restartNeeded;
63
64             // notify the model
65
OperationsManager.fireObjectChanged(feature, null);
66
67             return restartNeeded;
68         } catch (CoreException e) {
69             undo();
70             UpdateUtils.logException(e);
71             throw e;
72         }
73     }
74
75     public void undo() throws CoreException {
76         targetSite.unconfigure(feature);
77     }
78 }
79
Popular Tags