KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > compare > internal > ChangePropertyAction


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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.compare.internal;
12
13 import java.util.ResourceBundle JavaDoc;
14
15 import org.eclipse.jface.action.Action;
16 import org.eclipse.jface.util.IPropertyChangeListener;
17 import org.eclipse.jface.util.PropertyChangeEvent;
18 import org.eclipse.swt.events.DisposeEvent;
19 import org.eclipse.swt.events.DisposeListener;
20 import org.eclipse.compare.CompareConfiguration;
21
22 /**
23  * Toggles a boolean property of an <code>CompareConfiguration</code>.
24  */

25 public class ChangePropertyAction extends Action implements IPropertyChangeListener, DisposeListener {
26
27     private CompareConfiguration fCompareConfiguration;
28     private String JavaDoc fPropertyKey;
29     private ResourceBundle JavaDoc fBundle;
30     private String JavaDoc fPrefix;
31
32     public static ChangePropertyAction createIgnoreWhiteSpaceAction(ResourceBundle JavaDoc bundle, CompareConfiguration compareConfiguration) {
33         return new ChangePropertyAction(bundle, compareConfiguration, "action.IgnoreWhiteSpace.", CompareConfiguration.IGNORE_WHITESPACE); //$NON-NLS-1$
34
}
35     public static ChangePropertyAction createShowPseudoConflictsAction(ResourceBundle JavaDoc bundle, CompareConfiguration compareConfiguration) {
36         return new ChangePropertyAction(bundle, compareConfiguration, "action.ShowPseudoConflicts.", CompareConfiguration.SHOW_PSEUDO_CONFLICTS); //$NON-NLS-1$
37
}
38
39     public ChangePropertyAction(ResourceBundle JavaDoc bundle, CompareConfiguration cc, String JavaDoc rkey, String JavaDoc pkey) {
40         fPropertyKey= pkey;
41         fBundle= bundle;
42         fPrefix= rkey;
43         Utilities.initAction(this, fBundle, fPrefix);
44         setCompareConfiguration(cc);
45     }
46
47     public void run() {
48         boolean b= !Utilities.getBoolean(fCompareConfiguration, fPropertyKey, false);
49         setChecked(b);
50         if (fCompareConfiguration != null)
51             fCompareConfiguration.setProperty(fPropertyKey, new Boolean JavaDoc(b));
52     }
53
54     public void setChecked(boolean state) {
55         super.setChecked(state);
56         Utilities.initToggleAction(this, fBundle, fPrefix, state);
57     }
58     
59     public void setCompareConfiguration(CompareConfiguration cc) {
60         if (fCompareConfiguration != null)
61             fCompareConfiguration.removePropertyChangeListener(this);
62         fCompareConfiguration= cc;
63         if (fCompareConfiguration != null)
64             fCompareConfiguration.addPropertyChangeListener(this);
65         setChecked(Utilities.getBoolean(fCompareConfiguration, fPropertyKey, false));
66     }
67
68     public void propertyChange(PropertyChangeEvent event) {
69         if (event.getProperty().equals(fPropertyKey)) {
70             setChecked(Utilities.getBoolean(fCompareConfiguration, fPropertyKey, false));
71         }
72     }
73     
74     public void dispose(){
75         if (fCompareConfiguration != null)
76             fCompareConfiguration.removePropertyChangeListener(this);
77     }
78     
79     public void widgetDisposed(DisposeEvent e) {
80         dispose();
81     }
82 }
83
Popular Tags