Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: bdea732b0ef33811f33e8432e34d20f55e07f8ae (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*******************************************************************************
 * Copyright (c) 2000, 2015 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *     Alex Blewitt <alex.blewitt@gmail.com> - replace new Boolean with Boolean.valueOf - https://bugs.eclipse.org/470344
 *******************************************************************************/
package org.eclipse.compare.internal;

import java.util.ResourceBundle;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.compare.CompareConfiguration;

/**
 * Toggles a boolean property of an <code>CompareConfiguration</code>.
 */
public class ChangePropertyAction extends Action implements IPropertyChangeListener, DisposeListener {

	private CompareConfiguration fCompareConfiguration;
	private String fPropertyKey;
	private ResourceBundle fBundle;
	private String fPrefix;

	public static ChangePropertyAction createIgnoreWhiteSpaceAction(ResourceBundle bundle, CompareConfiguration compareConfiguration) {
		return new ChangePropertyAction(bundle, compareConfiguration, "action.IgnoreWhiteSpace.", CompareConfiguration.IGNORE_WHITESPACE); //$NON-NLS-1$
	}
	public static ChangePropertyAction createShowPseudoConflictsAction(ResourceBundle bundle, CompareConfiguration compareConfiguration) {
		return new ChangePropertyAction(bundle, compareConfiguration, "action.ShowPseudoConflicts.", CompareConfiguration.SHOW_PSEUDO_CONFLICTS); //$NON-NLS-1$
	}

	public ChangePropertyAction(ResourceBundle bundle, CompareConfiguration cc, String rkey, String pkey) {
		fPropertyKey= pkey;
		fBundle= bundle;
		fPrefix= rkey;
		Utilities.initAction(this, fBundle, fPrefix);
		setCompareConfiguration(cc);
	}

	public void run() {
		boolean b= !Utilities.getBoolean(fCompareConfiguration, fPropertyKey, false);
		setChecked(b);
		if (fCompareConfiguration != null)
			fCompareConfiguration.setProperty(fPropertyKey, Boolean.valueOf(b));
	}

	public void setChecked(boolean state) {
		super.setChecked(state);
		Utilities.initToggleAction(this, fBundle, fPrefix, state);
	}

	public void setCompareConfiguration(CompareConfiguration cc) {
		if (fCompareConfiguration != null)
			fCompareConfiguration.removePropertyChangeListener(this);
		fCompareConfiguration= cc;
		if (fCompareConfiguration != null)
			fCompareConfiguration.addPropertyChangeListener(this);
		setChecked(Utilities.getBoolean(fCompareConfiguration, fPropertyKey, false));
	}

	public void propertyChange(PropertyChangeEvent event) {
		if (event.getProperty().equals(fPropertyKey)) {
			setChecked(Utilities.getBoolean(fCompareConfiguration, fPropertyKey, false));
		}
	}

	public void dispose(){
		if (fCompareConfiguration != null)
			fCompareConfiguration.removePropertyChangeListener(this);
	}

	public void widgetDisposed(DisposeEvent e) {
		dispose();
	}
}

Back to the top