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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
|
/*******************************************************************************
* Copyright (c) 2004, 2007 BitMethods Inc 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:
* BitMethods Inc - Initial API and implementation
* ARM Ltd. - basic tooltip support
*******************************************************************************/
package org.eclipse.cdt.managedbuilder.ui.properties;
import java.util.ArrayList;
import java.util.StringTokenizer;
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
import org.eclipse.cdt.managedbuilder.core.IHoldsOptions;
import org.eclipse.cdt.managedbuilder.core.IOption;
import org.eclipse.cdt.managedbuilder.internal.macros.OptionContextData;
import org.eclipse.cdt.managedbuilder.macros.IBuildMacroProvider;
import org.eclipse.cdt.utils.ui.controls.FileListControl;
import org.eclipse.cdt.utils.ui.controls.IFileListChangeListener;
import org.eclipse.core.resources.IResource;
import org.eclipse.jface.preference.FieldEditor;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.swt.SWT;
import org.eclipse.swt.SWTException;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.List;
/**
* Field editor that uses FileListControl for user input.
*/
public class FileListControlFieldEditor extends FieldEditor {
// file list control
private FileListControl list;
private int browseType;
private GridLayout layout;
private static final String DEFAULT_SEPERATOR = ";"; //$NON-NLS-1$
//values
// private String[] values = null;
/**
* Creates a file list control field editor.
* @param name the name of the preference this field editor works on
* @param labelText the label text of the field editor
* @param parent the parent of the field editor's control
* @param type the browseType of the file list control
*/
public FileListControlFieldEditor(
String name,
String labelText,
Composite parent,
int type) {
super(name, labelText, parent);
browseType = type;
// Set the browse strategy for the list editor
list.setType(type);
}
/**
* Creates a file list control field editor.
* @param name the name of the preference this field editor works on
* @param labelText the label text of the field editor
* @param tooltip the tooltip text of the field editor
* @param parent the parent of the field editor's control
* @param type the browseType of the file list control
*/
public FileListControlFieldEditor(
String name,
String labelText,
String tooltip,
Composite parent,
int type) {
this(name, labelText, parent, type);
// can't use setToolTip(tooltip) as label not created yet
getLabelControl(parent).setToolTipText(tooltip);
}
/**
* Sets the field editor's tool tip text to the argument, which
* may be null indicating that no tool tip text should be shown.
*
* @param string the new tool tip text (or null)
*
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the field editor has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the field editor</li>
* </ul>
*/
public void setToolTip(String tooltip) {
// Currently just the label has the tooltip
getLabelControl().setToolTipText(tooltip);
}
/**
* Returns the field editor's tool tip text, or null if it has
* not been set.
*
* @return the field editor's tool tip text
*
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the field editor has been disposed</li>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the field editor</li>
* </ul>
*/
public String getToolTipText() {
return getLabelControl().getToolTipText();
}
/**
* Creates a file list control field editor.
* @param name the name of the preference this field editor works on
* @param labelText the label text of the field editor
* @param parent the parent of the field editor's control
* @param value the field editor's value
* @param type the browseType of the file list control
*/
public FileListControlFieldEditor(
String name,
String labelText,
Composite parent,
String value,
int type) {
this(name, labelText, parent, type);
browseType = type;
// this.values = parseString(value);
}
/**
* Fills this field editor's basic controls into the given parent.
*/
protected void doFillIntoGrid(Composite parent, int numColumns) {
Composite topLayout = new Composite(parent, SWT.NONE);
layout = new GridLayout();
layout.numColumns = numColumns;
layout.marginWidth = 7;
layout.marginHeight = 5;
layout.makeColumnsEqualWidth = false;
topLayout.setLayout(layout);
GridData gddata = new GridData(GridData.FILL_HORIZONTAL);
gddata.horizontalSpan = 2;
topLayout.setLayoutData(gddata);
// file list control
list =
new FileListControl(
topLayout,
getLabelText(),
getType());
list.addChangeListener(new IFileListChangeListener(){
public void fileListChanged(FileListControl fileList, String oldValue[], String newValue[]) {
handleFileListChange(fileList,oldValue,newValue);
}
});
topLayout.setLayout(layout);
}
private void handleFileListChange(FileListControl fileList, String oldValue[], String newValue[]){
// values = fileList.getItems();
fireValueChanged(
VALUE,
createList(oldValue),
createList(newValue));
}
/**
* Returns the browseType of this field editor's file list control
* @return
*/
private int getType() {
return browseType;
}
/**
* Returns the file list control
* @return
*/
protected List getListControl() {
return list.getListControl();
}
/* (non-Javadoc)
* @see org.eclipse.jface.preference.FieldEditor#doLoad()
*/
protected void doLoad() {
if (list != null) {
IPreferenceStore store = getPreferenceStore();
if (store != null) {
String s = store.getString(getPreferenceName());
String[] array = parseString(s);
list.setList(array);
list.setSelection(0);
// Set the resource the editor works for
if (store instanceof ToolSettingsPrefStore) {
IConfiguration config = ((ToolSettingsPrefStore)store).getSelectedConfig();
if (config != null) {
IResource project = config.getOwner();
if (project != null) {
/* Enable workspace support for list and set project */
list.setWorkspaceSupport(true);
if (store instanceof ToolSettingsPrefStore){
ToolSettingsPrefStore btsStore = ((ToolSettingsPrefStore)store);
Object[] option = btsStore.getOption(getPreferenceName());
if(option != null){
list.setContext(
btsStore.obtainMacroProvider().getMacroContextInfo(
IBuildMacroProvider.CONTEXT_OPTION,
new OptionContextData((IOption)option[1],
(IHoldsOptions)option[0])));
}
}
}
}
}
}
}
list.selectionChanged();
}
/* (non-Javadoc)
* @see org.eclipse.jface.preference.FieldEditor#doLoadDefault()
*/
protected void doLoadDefault() {
if (list != null) {
list.removeAll();
String s =
getPreferenceStore().getDefaultString(getPreferenceName());
String[] array = parseString(s);
list.setList(array);
list.selectionChanged();
}
}
/* (non-Javadoc)
* @see org.eclipse.jface.preference.FieldEditor#doStore()
*/
protected void doStore() {
String s = createList(list.getItems());
if (s != null)
getPreferenceStore().setValue(getPreferenceName(), s);
}
public String[] getStringListValue(){
return list.getItems();
}
/**
* Returns the number of basic controls this field editor consists of.
*
* @return the number of controls
*/
public int getNumberOfControls() {
return 1;
}
/**
* Answers a <code>String</code> containing the strings passed in the
* argument separated by the DEFAULT_SEPERATOR
*
* @param items An array of strings
* @return
*/
private String createList(String[] items) {
StringBuffer path = new StringBuffer(""); //$NON-NLS-1$
for (int i = 0; i < items.length; i++) {
path.append(items[i]);
if (i < (items.length - 1)) {
path.append(DEFAULT_SEPERATOR);
}
}
return path.toString();
}
/**
* Parse the string with the separator and returns the string array.
* @param stringList
* @return
*/
private String[] parseString(String stringList) {
StringTokenizer tokenizer =
new StringTokenizer(stringList, DEFAULT_SEPERATOR);
ArrayList list = new ArrayList();
while (tokenizer.hasMoreElements()) {
list.add(tokenizer.nextElement());
}
return (String[]) list.toArray(new String[list.size()]);
}
/**
* Set style
*/
public void setStyle() {
layout.marginWidth = 0;
}
/* (non-Javadoc)
* @see org.eclipse.jface.preference.FieldEditor#adjustForNumColumns(int)
*/
protected void adjustForNumColumns(int numColumns) {
}
public Label getLabelControl(Composite parent) {
return list.getLabelControl();
}
public void setEnabled(boolean enabled, Composite parent) {
list.setEnabled(enabled);
}
}
|