blob: fef880b8b2cfe8be6a14aadf30cbe6a4d00a26ec [file] [log] [blame]
david_williamscfdb2cd2004-11-11 08:37:49 +00001/*******************************************************************************
amywuecebb042007-04-10 20:07:35 +00002 * Copyright (c) 2001, 2005 IBM Corporation and others.
david_williamscfdb2cd2004-11-11 08:37:49 +00003 * 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
amywuecebb042007-04-10 20:07:35 +00007 *
david_williamscfdb2cd2004-11-11 08:37:49 +00008 * Contributors:
9 * IBM Corporation - initial API and implementation
10 * Jens Lukowski/Innoopract - initial renaming/restructuring
11 *
12 *******************************************************************************/
nitindbca26632005-03-30 18:13:32 +000013package org.eclipse.wst.sse.ui.internal.contentoutline;
david_williamscfdb2cd2004-11-11 08:37:49 +000014
15import org.eclipse.jface.action.Action;
16import org.eclipse.jface.action.IAction;
17import org.eclipse.jface.preference.IPreferenceStore;
18import org.eclipse.ui.texteditor.IUpdate;
19
20/**
21 * An IAction.AS_CHECK_BOX action that sets and gets its checked state along
22 * with a value from a preference store. Should be used with
23 * PropertyChangeUpdateActionContributionItem to listen to changes in the
nitind56dbcb72004-11-30 04:07:19 +000024 * store and update the checked state from PropertyChangeEvents.
david_williamscfdb2cd2004-11-11 08:37:49 +000025 */
26public class PropertyChangeUpdateAction extends Action implements IUpdate {
27 private String fPreferenceKey;
28 private IPreferenceStore fStore;
29 private boolean fUpdateFromPropertyChange = true;
30
31 public PropertyChangeUpdateAction(String text, IPreferenceStore store, String preferenceKey, boolean defaultValue) {
32 super(text, IAction.AS_CHECK_BOX);
33 fPreferenceKey = preferenceKey;
34 fStore = store;
35 fStore.setDefault(getPreferenceKey(), defaultValue);
nitind22def7a2005-01-28 03:09:21 +000036 setId(getPreferenceKey());
david_williamscfdb2cd2004-11-11 08:37:49 +000037 setChecked(getPreferenceStore().getBoolean(getPreferenceKey()));
38 }
39
40 /**
41 * @return Returns the orderPreferenceKey.
42 */
43 public String getPreferenceKey() {
44 return fPreferenceKey;
45 }
46
47 /**
48 * @return Returns the store.
49 */
50 public IPreferenceStore getPreferenceStore() {
51 return fStore;
52 }
53
54 /**
55 * @return Returns the updateFromPropertyChange.
56 */
57 public boolean isUpdateFromPropertyChange() {
58 return fUpdateFromPropertyChange;
59 }
60
61 public final void run() {
62 super.run();
63 fStore.setValue(getPreferenceKey(), isChecked());
64 if (!isUpdateFromPropertyChange())
65 update();
66 }
67
68 /**
69 * @param updateFromPropertyChange
70 * The updateFromPropertyChange to set.
71 */
72 public void setUpdateFromPropertyChange(boolean updateFromPropertyChange) {
73 fUpdateFromPropertyChange = updateFromPropertyChange;
74 }
75
76 public void update() {
77 setChecked(fStore.getBoolean(getPreferenceKey()));
78 }
79
80}