KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > texteditor > BooleanPreferenceToggleAction


1 /*******************************************************************************
2  * Copyright (c) 2006 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.ui.internal.texteditor;
12
13 import java.util.ResourceBundle JavaDoc;
14
15 import org.eclipse.core.runtime.Assert;
16
17 import org.eclipse.jface.preference.IPreferenceStore;
18 import org.eclipse.ui.texteditor.IUpdate;
19 import org.eclipse.ui.texteditor.ResourceAction;
20
21 /**
22  *
23  * @since 3.3
24  */

25 public class BooleanPreferenceToggleAction extends ResourceAction implements IUpdate {
26
27     private final String JavaDoc fKey;
28     private final IPreferenceStore fPreferences;
29
30     public BooleanPreferenceToggleAction(ResourceBundle JavaDoc bundle, String JavaDoc prefix, int style, IPreferenceStore preferences, String JavaDoc key) {
31         super(bundle, prefix, style);
32         Assert.isLegal(preferences != null);
33         Assert.isLegal(key != null);
34         fPreferences= preferences;
35         fKey= key;
36         
37         update();
38     }
39
40     /*
41      * @see org.eclipse.ui.texteditor.IUpdate#update()
42      */

43     public void update() {
44         setChecked(fPreferences.getBoolean(fKey));
45     }
46     
47     /*
48      * @see org.eclipse.jface.action.Action#run()
49      */

50     public void run() {
51         boolean state= fPreferences.getBoolean(fKey);
52         fPreferences.setValue(fKey, !state);
53     }
54 }
55
Popular Tags