KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > views > console > ShowWhenContentChangesAction


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.debug.internal.ui.views.console;
12
13 import org.eclipse.debug.internal.ui.DebugUIPlugin;
14 import org.eclipse.jface.action.Action;
15 import org.eclipse.jface.action.IAction;
16 import org.eclipse.jface.preference.IPreferenceStore;
17 import org.eclipse.jface.util.IPropertyChangeListener;
18 import org.eclipse.jface.util.PropertyChangeEvent;
19
20 /**
21  * Abstract action for toggling preference to automatically show
22  * the console when a streams content changes.
23  *
24  * @since 3.3
25  */

26 public abstract class ShowWhenContentChangesAction extends Action implements IPropertyChangeListener{
27     
28     /**
29      * Constructs an action to toggle console auto activation preferences
30      */

31     public ShowWhenContentChangesAction(String JavaDoc name) {
32         super(name, IAction.AS_CHECK_BOX);
33         setToolTipText(name);
34         getPreferenceStore().addPropertyChangeListener(this);
35         update();
36     }
37
38     /* (non-Javadoc)
39      * @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent)
40      */

41     public void propertyChange(PropertyChangeEvent event) {
42         String JavaDoc property = event.getProperty();
43         if (property.equals(getKey())) {
44              update();
45         }
46     }
47     
48     protected abstract String JavaDoc getKey();
49     
50     private void update() {
51         IPreferenceStore store = getPreferenceStore();
52         if (store.getBoolean(getKey())) {
53             // on
54
setChecked(true);
55          } else {
56             // off
57
setChecked(false);
58          }
59     }
60
61     /**
62      * @return
63      */

64     private IPreferenceStore getPreferenceStore() {
65         return DebugUIPlugin.getDefault().getPreferenceStore();
66     }
67
68     /* (non-Javadoc)
69      * @see org.eclipse.jface.action.Action#run()
70      */

71     public void run() {
72         IPreferenceStore store = getPreferenceStore();
73         boolean show = isChecked();
74         store.removePropertyChangeListener(this);
75         store.setValue(getKey(), show);
76         store.addPropertyChangeListener(this);
77     }
78     
79     /**
80      * Must be called to dispose this action.
81      */

82     public void dispose() {
83         getPreferenceStore().removePropertyChangeListener(this);
84     }
85
86 }
87
Popular Tags