01: /*******************************************************************************
02: * Copyright (c) 2004, 2005 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM - Initial API and implementation
10: *******************************************************************************/package org.eclipse.ui.internal.ide.actions;
11:
12: import org.eclipse.core.resources.IWorkspace;
13: import org.eclipse.core.resources.IWorkspaceDescription;
14: import org.eclipse.core.resources.ResourcesPlugin;
15: import org.eclipse.core.runtime.CoreException;
16: import org.eclipse.jface.action.Action;
17: import org.eclipse.jface.dialogs.ErrorDialog;
18: import org.eclipse.ui.IWorkbenchWindow;
19: import org.eclipse.ui.actions.ActionFactory;
20: import org.eclipse.ui.internal.ide.IDEWorkbenchMessages;
21:
22: /**
23: * Action for toggling autobuild on or off.
24: */
25: public class ToggleAutoBuildAction extends Action implements
26: ActionFactory.IWorkbenchAction {
27: private IWorkbenchWindow window;
28:
29: /**
30: * Creates a new ToggleAutoBuildAction
31: * @param window The window for parenting dialogs associated with this action
32: */
33: public ToggleAutoBuildAction(IWorkbenchWindow window) {
34: super (IDEWorkbenchMessages.Workbench_buildAutomatically);
35: this .window = window;
36: setChecked(ResourcesPlugin.getWorkspace().isAutoBuilding());
37: }
38:
39: /* (non-Javadoc)
40: * @see org.eclipse.ui.actions.ActionFactory.IWorkbenchAction#dispose()
41: */
42: public void dispose() {
43: //nothing to dispose
44: }
45:
46: /* (non-Javadoc)
47: * @see org.eclipse.jface.action.IAction#run()
48: */
49: public void run() {
50: IWorkspace workspace = ResourcesPlugin.getWorkspace();
51: IWorkspaceDescription description = workspace.getDescription();
52: description.setAutoBuilding(!description.isAutoBuilding());
53: try {
54: workspace.setDescription(description);
55: } catch (CoreException e) {
56: ErrorDialog.openError(window.getShell(), null, null, e
57: .getStatus());
58: }
59: }
60: }
|