1 11 package org.eclipse.compare.internal; 12 13 import java.util.ResourceBundle ; 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 25 public class ChangePropertyAction extends Action implements IPropertyChangeListener, DisposeListener { 26 27 private CompareConfiguration fCompareConfiguration; 28 private String fPropertyKey; 29 private ResourceBundle fBundle; 30 private String fPrefix; 31 32 public static ChangePropertyAction createIgnoreWhiteSpaceAction(ResourceBundle bundle, CompareConfiguration compareConfiguration) { 33 return new ChangePropertyAction(bundle, compareConfiguration, "action.IgnoreWhiteSpace.", CompareConfiguration.IGNORE_WHITESPACE); } 35 public static ChangePropertyAction createShowPseudoConflictsAction(ResourceBundle bundle, CompareConfiguration compareConfiguration) { 36 return new ChangePropertyAction(bundle, compareConfiguration, "action.ShowPseudoConflicts.", CompareConfiguration.SHOW_PSEUDO_CONFLICTS); } 38 39 public ChangePropertyAction(ResourceBundle bundle, CompareConfiguration cc, String rkey, String 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 (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 |