Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: d0b629bfe35ac035458beb5745b6c9c79cfbe24a (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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/*******************************************************************************
.
. This
 * program and the accompanying materials are made available under the terms of
 * the Eclipse Public License 2.0 which accompanies this distribution, and is
t https://www.eclipse.org/legal/epl-2.0/
t
t SPDX-License-Identifier: EPL-2.0
 *
 * Contributors: Steven Spungin <steven@spungin.tv> - initial API and implementation, Bug 432555
 *******************************************************************************/
package org.eclipse.e4.tools.emf.ui.internal.common.component.tabs.empty;

import org.eclipse.e4.tools.emf.ui.internal.common.component.tabs.Messages;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Shell;

/**
 * A standard ElementListSelectionDialog with additional options for including,
 * excluding, and selecting empty values.
 *
 * @author Steven Spungin
 *
 */
public class TitleAreaFilterDialogWithEmptyOptions extends TitleAreaFilterDialog {
	private Button btnExcludeEmptyValues;
	private Button btnOnlyEmptyValues;
	private Button btnIncludeEmptyValues;
	private EmptyFilterOption emptyFilterOption;
	private boolean bShowEmptyOptions = true;
	private Composite compOptions;
	private Composite parent;

	public TitleAreaFilterDialogWithEmptyOptions(Shell parent, ILabelProvider renderer) {
		super(parent, renderer);
	}

	@Override
	protected org.eclipse.swt.widgets.Control createDialogArea(Composite parent) {
		this.parent = parent;
		Composite comp = (Composite) super.createDialogArea(parent);

		// Label labelEmptyInfo = new Label(comp, SWT.NONE);
		// labelEmptyInfo.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER,
		// false, false));
		// labelEmptyInfo.setText("An empty value is defined as a null object, an empty string, or an empty collection.");

		compOptions = new Composite(comp, SWT.NONE);
		compOptions.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
		compOptions.setLayout(new RowLayout());

		// labelEmptyInfo.moveAbove(getText());
		compOptions.moveAbove(getText());

		btnExcludeEmptyValues = new Button(compOptions, SWT.RADIO);
		btnExcludeEmptyValues.setText(Messages.TitleAreaFilterDialogWithEmptyOptions_excludeEmptyValues);
		btnExcludeEmptyValues.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				setEmptyFilterOption(EmptyFilterOption.EXCLUDE);
			}
		});

		btnIncludeEmptyValues = new Button(compOptions, SWT.RADIO);
		btnIncludeEmptyValues.setText(Messages.TitleAreaFilterDialogWithEmptyOptions_includeEmptyValues);
		btnIncludeEmptyValues.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				setEmptyFilterOption(EmptyFilterOption.INCLUDE);
			}
		});

		btnOnlyEmptyValues = new Button(compOptions, SWT.RADIO);
		btnOnlyEmptyValues.setText(Messages.TitleAreaFilterDialogWithEmptyOptions_onlyEmptyValues);
		btnOnlyEmptyValues.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				setEmptyFilterOption(EmptyFilterOption.ONLY);
			}
		});

		String toolTip = Messages.TitleAreaFilterDialogWithEmptyOptions_emptyValueDescription;
		btnExcludeEmptyValues.setToolTipText(toolTip);
		btnIncludeEmptyValues.setToolTipText(toolTip);
		btnOnlyEmptyValues.setToolTipText(toolTip);

		setEmptyFilterOption(EmptyFilterOption.EXCLUDE);

		updateEmptyOptionState();

		parent.pack();
		return comp;
	}

	@Override
	public boolean close() {
		return super.close();
	}

	public EmptyFilterOption getEmptyFilterOption() {
		return emptyFilterOption;
	}

	public void setEmptyFilterOption(EmptyFilterOption emptyFilterOption) {
		this.emptyFilterOption = emptyFilterOption;
		updateUi();
	}

	private void updateUi() {
		if (btnExcludeEmptyValues == null) {
			return;
		}
		switch (emptyFilterOption) {
		case EXCLUDE:
			btnExcludeEmptyValues.setSelection(true);
			btnIncludeEmptyValues.setSelection(false);
			btnOnlyEmptyValues.setSelection(false);
			break;
		case INCLUDE:
			btnExcludeEmptyValues.setSelection(false);
			btnIncludeEmptyValues.setSelection(true);
			btnOnlyEmptyValues.setSelection(false);
			break;
		case ONLY:
			btnExcludeEmptyValues.setSelection(false);
			btnIncludeEmptyValues.setSelection(false);
			btnOnlyEmptyValues.setSelection(true);
			break;
		default:
			break;
		}
	}

	public void setShowEmptyOptions(boolean bShow) {
		this.bShowEmptyOptions = bShow;
		updateEmptyOptionState();
	}

	private void updateEmptyOptionState() {
		if (compOptions == null) {
			return;
		}
		compOptions.setVisible(bShowEmptyOptions);
		((GridData) compOptions.getLayoutData()).exclude = bShowEmptyOptions == false;
		parent.layout();
	}
}

Back to the top