1 /*******************************************************************************
2  * Copyright (c) 2000, 2011 IBM Corporation and others.
3  *
4  * This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License 2.0
6  * which accompanies this distribution, and is available at
7  * https://www.eclipse.org/legal/epl-2.0/
8  *
9  * SPDX-License-Identifier: EPL-2.0
10  *
11  * Contributors:
12  *     IBM Corporation - initial API and implementation
13  *******************************************************************************/
14 package org.eclipse.team.internal.ccvs.ui;
15 
16 import org.eclipse.compare.CompareUI;
17 import org.eclipse.jface.preference.*;
18 import org.eclipse.jface.util.PropertyChangeEvent;
19 import org.eclipse.swt.SWT;
20 import org.eclipse.swt.layout.GridData;
21 import org.eclipse.swt.widgets.Event;
22 import org.eclipse.team.internal.ui.SWTUtils;
23 import org.eclipse.ui.preferences.IWorkbenchPreferenceContainer;
24 
25 /**
26  * Preference page for configuring CVS comparisons
27  */
28 public class ComparePreferencePage extends CVSFieldEditorPreferencePage {
29 	private BooleanFieldEditor contents;
30 	private StringFieldEditor regex;
31 
32 	@Override
getPageHelpContextId()33 	protected String getPageHelpContextId() {
34 		return IHelpContextIds.COMPARE_PREFERENCE_PAGE;
35 	}
36 
37 	@Override
getPageDescription()38 	protected String getPageDescription() {
39 		return CVSUIMessages.ComparePreferencePage_0;
40 	}
41 
42 	@Override
createFieldEditors()43 	protected void createFieldEditors() {
44 		IPreferenceStore store = getPreferenceStore();
45 
46 		contents = new BooleanFieldEditor(ICVSUIConstants.PREF_CONSIDER_CONTENTS,
47 				CVSUIMessages.ComparePreferencePage_4,
48 				BooleanFieldEditor.DEFAULT, getFieldEditorParent()) {
49 			private Event selectionEvent = createSelectionEvent();
50 			private Event createSelectionEvent() {
51 				Event event = new Event();
52 				event.type = SWT.Selection;
53 				return event;
54 			}
55 			// invert the UI
56 			@Override
57 			protected void doLoad() {
58 				super.doLoad();
59 				getChangeControl(getFieldEditorParent()).setSelection(!getBooleanValue());
60 				getChangeControl(getFieldEditorParent()).notifyListeners(SWT.Selection,
61 						selectionEvent);
62 			}
63 			@Override
64 			protected void doLoadDefault() {
65 				super.doLoadDefault();
66 				getChangeControl(getFieldEditorParent()).setSelection(!getBooleanValue());
67 				getChangeControl(getFieldEditorParent()).notifyListeners(SWT.Selection,
68 						selectionEvent);
69 			}
70 			@Override
71 			protected void doStore() {
72 				getPreferenceStore().setValue(getPreferenceName(), !getBooleanValue());
73 			}
74 		};
75 		addField(contents);
76 		regex = new StringFieldEditor(ICVSUIConstants.PREF_SYNCVIEW_REGEX_FILTER_PATTERN,
77 				CVSUIMessages.ComparePreferencePage_5,
78 				getFieldEditorParent());
79 		addField(regex);
80 		GridData data = new GridData();
81 		data.horizontalIndent = 20;
82 		regex.getLabelControl(getFieldEditorParent()).setLayoutData(data);
83 		regex.setEnabled(store.getBoolean(ICVSUIConstants.PREF_CONSIDER_CONTENTS), getFieldEditorParent());
84 		addField(new BooleanFieldEditor(
85 				ICVSUIConstants.PREF_SHOW_COMPARE_REVISION_IN_DIALOG,
86 				CVSUIMessages.ComparePreferencePage_3,
87 				BooleanFieldEditor.DEFAULT,
88 				getFieldEditorParent()));
89 		addField(new BooleanFieldEditor(
90 				ICVSUIConstants.PREF_COMMIT_SET_DEFAULT_ENABLEMENT,
91 				CVSUIMessages.ComparePreferencePage_2,
92 				BooleanFieldEditor.DEFAULT,
93 				getFieldEditorParent()));
94 		addField(new BooleanFieldEditor(
95 				ICVSUIConstants.PREF_ENABLE_MODEL_SYNC,
96 				CVSUIMessages.ComparePreferencePage_7,
97 				BooleanFieldEditor.DEFAULT,
98 				getFieldEditorParent()));
99 		addField(new BooleanFieldEditor(
100 				ICVSUIConstants.PREF_OPEN_COMPARE_EDITOR_FOR_SINGLE_FILE,
101 				CVSUIMessages.ComparePreferencePage_8,
102 				BooleanFieldEditor.DEFAULT,
103 				getFieldEditorParent()));
104 
105 		IPreferencePageContainer container = getContainer();
106 		if (container instanceof IWorkbenchPreferenceContainer) {
107 			IWorkbenchPreferenceContainer workbenchContainer = (IWorkbenchPreferenceContainer) container;
108 			SWTUtils.createPreferenceLink(workbenchContainer, getFieldEditorParent(),
109 					CompareUI.PREFERENCE_PAGE_ID, CVSUIMessages.ComparePreferencePage_6);
110 		}
111 	}
112 
113 	@Override
propertyChange(PropertyChangeEvent event)114 	public void propertyChange(PropertyChangeEvent event) {
115 		super.propertyChange(event);
116 		regex.setEnabled(!contents.getBooleanValue(), getFieldEditorParent());
117 	}
118 }
119