01: /*******************************************************************************
02: * Copyright (c) 2006 Andrei Loskutov.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the BSD License
05: * which accompanies this distribution, and is available at
06: * http://www.opensource.org/licenses/bsd-license.php
07: * Contributor: Andrei Loskutov - initial API and implementation
08: *******************************************************************************/package de.loskutov.bco.ui.actions;
09:
10: import org.eclipse.jface.action.Action;
11: import org.eclipse.jface.preference.IPreferenceStore;
12: import org.eclipse.ui.plugin.AbstractUIPlugin;
13:
14: import de.loskutov.bco.BytecodeOutlinePlugin;
15:
16: /**
17: * Default action which could be used as template for "toggle" action.
18: * Action image, text and tooltip will be initialized by default.
19: * To use it, register IPropertyChangeListener and check for IAction.CHECKED
20: * event name.
21: * @author Andrei
22: */
23: public abstract class DefaultToggleAction extends Action {
24:
25: private static final String ACTION = "action";
26:
27: public DefaultToggleAction(String id) {
28: super ();
29: setId(id);
30: init();
31:
32: IPreferenceStore store = BytecodeOutlinePlugin.getDefault()
33: .getPreferenceStore();
34:
35: boolean isChecked = store.getBoolean(id);
36: setChecked(isChecked);
37: }
38:
39: private void init() {
40: String myId = getId();
41: if (myId != null && myId.startsWith("diff_")) {
42: myId = myId.substring("diff_".length());
43: }
44: setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(
45: BytecodeOutlinePlugin.getDefault().getBundle()
46: .getSymbolicName(), BytecodeOutlinePlugin
47: .getResourceString(ACTION + "." + myId + "."
48: + IMAGE)));
49:
50: setText(BytecodeOutlinePlugin.getResourceString(ACTION + "."
51: + myId + "." + TEXT));
52: setToolTipText(BytecodeOutlinePlugin.getResourceString(ACTION
53: + "." + myId + "." + TOOL_TIP_TEXT));
54: }
55:
56: /**
57: * @see org.eclipse.jface.action.IAction#run()
58: */
59: public final void run() {
60: boolean isChecked = isChecked();
61: IPreferenceStore store = BytecodeOutlinePlugin.getDefault()
62: .getPreferenceStore();
63: store.setValue(getId(), isChecked);
64: run(isChecked);
65: }
66:
67: public abstract void run(boolean newState);
68: }
|