KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > ide > actions > ToggleAutoBuildAction


1 /*******************************************************************************
2  * Copyright (c) 2004, 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 - Initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.ui.internal.ide.actions;
12
13 import org.eclipse.core.resources.IWorkspace;
14 import org.eclipse.core.resources.IWorkspaceDescription;
15 import org.eclipse.core.resources.ResourcesPlugin;
16 import org.eclipse.core.runtime.CoreException;
17 import org.eclipse.jface.action.Action;
18 import org.eclipse.jface.dialogs.ErrorDialog;
19 import org.eclipse.ui.IWorkbenchWindow;
20 import org.eclipse.ui.actions.ActionFactory;
21 import org.eclipse.ui.internal.ide.IDEWorkbenchMessages;
22
23 /**
24  * Action for toggling autobuild on or off.
25  */

26 public class ToggleAutoBuildAction extends Action implements
27         ActionFactory.IWorkbenchAction {
28     private IWorkbenchWindow window;
29
30     /**
31      * Creates a new ToggleAutoBuildAction
32      * @param window The window for parenting dialogs associated with this action
33      */

34     public ToggleAutoBuildAction(IWorkbenchWindow window) {
35         super(IDEWorkbenchMessages.Workbench_buildAutomatically);
36         this.window = window;
37         setChecked(ResourcesPlugin.getWorkspace().isAutoBuilding());
38     }
39
40     /* (non-Javadoc)
41      * @see org.eclipse.ui.actions.ActionFactory.IWorkbenchAction#dispose()
42      */

43     public void dispose() {
44         //nothing to dispose
45
}
46
47     /* (non-Javadoc)
48      * @see org.eclipse.jface.action.IAction#run()
49      */

50     public void run() {
51         IWorkspace workspace = ResourcesPlugin.getWorkspace();
52         IWorkspaceDescription description = workspace.getDescription();
53         description.setAutoBuilding(!description.isAutoBuilding());
54         try {
55             workspace.setDescription(description);
56         } catch (CoreException e) {
57             ErrorDialog.openError(window.getShell(), null, null, e.getStatus());
58         }
59     }
60 }
61
Popular Tags