KickJava   Java API By Example, From Geeks To Geeks.

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


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 public class ToggleSiteOperation
19     extends Operation
20     implements IToggleSiteOperation {
21
22     private IConfiguredSite site;
23
24     public ToggleSiteOperation(IConfiguredSite site) {
25         super();
26         this.site = site;
27     }
28
29     /* (non-Javadoc)
30      * @see org.eclipse.update.operations.IOperation#execute(org.eclipse.core.runtime.IProgressMonitor)
31      */

32     public boolean execute(
33         IProgressMonitor monitor,
34         IOperationListener listener)
35         throws CoreException {
36         if (site == null)
37             return false;
38         boolean oldValue = site.isEnabled();
39         site.setEnabled(!oldValue);
40         IStatus status = OperationsManager.getValidator().validateCurrentState();
41         if (status != null) {
42             // revert
43
site.setEnabled(oldValue);
44             throw new CoreException(status);
45         } else {
46             try {
47                 boolean restartNeeded = SiteManager.getLocalSite().save();
48                 OperationsManager.fireObjectChanged(site, ""); //$NON-NLS-1$
49
return restartNeeded; // will restart only if changes could not be applied to current config
50
} catch (CoreException e) {
51                 //revert
52
site.setEnabled(oldValue);
53                 UpdateUtils.logException(e);
54                 throw e;
55             }
56         }
57     }
58 }
59
Popular Tags