Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 7ebfbc8b26adf499c549d67226f1e5796cd390c5 (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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
/*****************************************************************************
 * Copyright (c) 2010, 2017 CEA LIST, Christian W. Damus, 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:
 *  Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
 *  Christian W. Damus (CEA) - bug 402525
 *  Christian W. Damus - bugs 399859, 516526
 *  Mickael ADAM (ALL4TEC) mickael.adam@all4tec.net - manage buttons visibility and enable. 
 *  Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Bug 515808, 522564
 *
 *****************************************************************************/
package org.eclipse.papyrus.infra.widgets.editors;

import org.eclipse.core.databinding.observable.list.IObservableList;
import org.eclipse.jface.viewers.IBaseLabelProvider;
import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.papyrus.infra.widgets.providers.TreeCollectionContentProvider;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Tree;

/**
 * An editor for multivalued fields.
 *
 * @author Camille Letavernier
 * @param <T>
 *
 */
public class MultipleValueEditor<T extends IElementSelector> extends AbstractMultipleValueEditor<T> {

	private final int style;

	/**
	 * The viewer displaying the current values from
	 * the model
	 */
	protected TreeViewer treeViewer;

	/**
	 * The tree associated to the viewer
	 */
	protected Tree tree;

	/**
	 *
	 * Constructor.
	 * 
	 * @param <T>
	 *
	 * @param parent
	 *            The Composite in which this Editor should be displayed
	 * @param style
	 *            This editor's tree style
	 * @param selector
	 *            The element selector for this editor's dialog
	 * @param ordered
	 *            Specify if the observed collection is ordered. If true, Up and Down controls are displayed.
	 * @param unique
	 *            Specify if the observed collection values are unique.
	 * @param label
	 *            The label for this editor. If null, the label isn't created.
	 */
	public MultipleValueEditor(Composite parent, int style, T selector, boolean ordered, boolean unique, String label) {
		super(parent, selector, ordered, unique, label);

		this.style = style;

		createContents();
	}

	/**
	 *
	 * Constructor.
	 *
	 * @param parent
	 *            The Composite in which this Editor should be displayed
	 * @param style
	 *            This editor's tree style
	 * @param selector
	 *            The element selector for this editor's dialog
	 * @param ordered
	 *            Specify if the observed collection is ordered. If true, Up and Down controls are displayed
	 */
	public MultipleValueEditor(Composite parent, int style, T selector, boolean ordered) {
		this(parent, style, selector, ordered, false, null);
	}

	/**
	 *
	 * Constructor.
	 *
	 * @param parent
	 *            The Composite in which this Editor should be displayed
	 * @param style
	 *            This editor's tree style
	 * @param selector
	 *            The element selector for this editor's dialog
	 */
	public MultipleValueEditor(Composite parent, int style, T selector) {
		this(parent, style, selector, false, false, null);
	}

	/**
	 *
	 * Constructor.
	 *
	 * @param parent
	 *            The Composite in which this Editor should be displayed
	 * @param style
	 *            This editor's tree style
	 * @param selector
	 *            The element selector for this editor's dialog
	 * @param label
	 *            The label for this Editor
	 */
	public MultipleValueEditor(Composite parent, int style, T selector, String label) {
		this(parent, style, selector, false, false, label);
	}

	/**
	 *
	 * Constructor.
	 *
	 * @param parent
	 *            The Composite in which this Editor should be displayed
	 * @param style
	 *            This editor's tree style
	 * @param selector
	 *            The element selector for this editor's dialog
	 * @param ordered
	 *            Specify if the observed collection is ordered. If true, Up and Down controls are displayed.
	 * @param unique
	 *            Specify if the observed collection values are unique.
	 * @param label
	 *            The label for this editor. If null, the label isn't created.
	 * @param upperBound
	 *            The maximum number of values that must appear.
	 */
	public MultipleValueEditor(Composite parent, int style, T selector, boolean ordered, boolean unique, String label, int upperBound) {
		super(parent, selector, ordered, unique, label, upperBound);

		this.style = style;

		createContents();
	}

	@Override
	protected Control createContents(Composite parent) {
		tree = new Tree(parent, style | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER | SWT.FULL_SELECTION);

		tree.addSelectionListener(this);

		treeViewer = new TreeViewer(tree);
		treeViewer.setContentProvider(TreeCollectionContentProvider.instance);

		return tree;
	}

	@Override
	protected ISelectionProvider getSelectionProvider(Control contentControl) {
		return treeViewer;
	}

	@Override
	protected void setInput(IObservableList modelProperty) {
		treeViewer.setInput(modelProperty);
	}

	/**
	 * Sets the label provider for this editor
	 *
	 * @param labelProvider
	 *            The label provider for this editor
	 */
	@Override
	public void setLabelProvider(IBaseLabelProvider labelProvider) {
		treeViewer.setLabelProvider(labelProvider);
	}

	@Override
	public IBaseLabelProvider getLabelProvider() {
		return treeViewer.getLabelProvider();
	}

	/**
	 * Gets the tree viewer associated to this editor
	 *
	 * @return the tree viewer associated to this editor
	 */
	public TreeViewer getViewer() {
		return treeViewer;
	}

	@Override
	public void dispose() {
		if (null != tree && !this.tree.isDisposed()) {
			this.tree.removeSelectionListener(this);
		}
		super.dispose();
	}

	@Override
	public void refreshValue() {
		treeViewer.refresh();
	}

}

Back to the top