Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: ef80cc46954f435ad74488f46b0260eac1fa8330 (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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*****************************************************************************
 * Copyright (c) 2016 CEA LIST, ALL4TEC 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:
 *  Mickael ADAM (ALL4TEC) mickael.adam@all4tec.net - Initial API and implementation
 *****************************************************************************/

package org.eclipse.papyrus.views.modelexplorer.preferences;

import org.eclipse.jface.dialogs.DialogPage;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.preference.BooleanFieldEditor;
import org.eclipse.jface.preference.FieldEditor;
import org.eclipse.jface.preference.IntegerFieldEditor;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.papyrus.infra.ui.preferences.AbstractPreferenceGroup;
import org.eclipse.papyrus.views.modelexplorer.Activator;
import org.eclipse.papyrus.views.modelexplorer.Messages;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;

/**
 * Preference group for model explorer Search Field.
 */
public class FilterFieldPreferencesGroup extends AbstractPreferenceGroup {

	/** The property change listener on validation delay field. */
	private IPropertyChangeListener listener = event -> refreshDelayField(event);

	/** The field editor for the delay value. */
	private IntegerFieldEditor delayFieldEditor;

	/** The group. */
	private Group fieldGroup;

	/** The field editor for the lave validation preference. */
	private FieldEditor liveValidationfieldEditor;

	/**
	 * 
	 * Constructor.
	 *
	 * @param parent
	 *            The parent.
	 * @param title
	 *            The group title.
	 * @param dialogPage
	 *            The dialog page.
	 */
	public FilterFieldPreferencesGroup(final Composite parent, final String title, final DialogPage dialogPage) {
		super(parent, title, dialogPage);
		createContent(parent);
	}

	/**
	 * Creates the content.
	 *
	 * @param parent
	 *            the parent
	 */
	public void createContent(final Composite parent) {
		fieldGroup = new Group(parent, SWT.SCROLL_PAGE);
		GridLayout layout = new GridLayout();
		layout.numColumns = 2;
		fieldGroup.setLayout(layout);
		fieldGroup.setText(Messages.FilterFieldPreferencesGroup_groupTitle);

		GridDataFactory.fillDefaults().grab(true, false).applyTo(fieldGroup);

		liveValidationfieldEditor = new BooleanFieldEditor(IFilterPreferenceConstants.PREF_FILTER_LIVE_VALIDATION, Messages.FilterFieldPreferencesGroup_UseValidationPreferenceLabel, fieldGroup);
		liveValidationfieldEditor.setPage(dialogPage);
		addFieldEditor(liveValidationfieldEditor);

		// Composite use to manage layout
		Composite composite = new Composite(fieldGroup, SWT.NONE);
		GridDataFactory.fillDefaults().hint(5, 5).applyTo(composite);

		liveValidationfieldEditor.setPropertyChangeListener(listener);

		delayFieldEditor = new IntegerFieldEditor(IFilterPreferenceConstants.PREF_FILTER_VALIDATION_DELAY, Messages.FilterFieldPreferencesGroup_ValidationDelayPreferenceLabel, fieldGroup);
		delayFieldEditor.setPage(dialogPage);
		addFieldEditor(delayFieldEditor);

		delayFieldEditor.setEnabled(Activator.getDefault().getPreferenceStore().getBoolean(IFilterPreferenceConstants.PREF_FILTER_LIVE_VALIDATION), fieldGroup);
	}

	/**
	 * Enable of delay field editor when the live validation is set to true.
	 */
	private void refreshDelayField(final PropertyChangeEvent event) {
		if (null != delayFieldEditor && null != liveValidationfieldEditor && event.getSource().equals(liveValidationfieldEditor)) {
			delayFieldEditor.setEnabled((boolean) event.getNewValue(), fieldGroup);
		}
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see org.eclipse.swt.widgets.Widget#dispose()
	 */
	@Override
	public void dispose() {
		// dispose listener
		liveValidationfieldEditor.setPropertyChangeListener(null);
		super.dispose();
	}
}

Back to the top