Révision 773

tmp/org.txm.progression.rcp/src/org/txm/progression/rcp/editors/ProgressionEditor.java (revision 773)
3 3
 */
4 4
package org.txm.progression.rcp.editors;
5 5

  
6
import java.io.File;
7
import java.io.FileNotFoundException;
8
import java.io.IOException;
9
import java.io.UnsupportedEncodingException;
6 10
import java.util.ArrayList;
7 11
import java.util.List;
12
import java.util.Properties;
8 13

  
9 14
import org.eclipse.swt.SWT;
10 15
import org.eclipse.swt.custom.ScrolledComposite;
16
import org.eclipse.swt.events.KeyEvent;
11 17
import org.eclipse.swt.events.SelectionEvent;
12 18
import org.eclipse.swt.events.SelectionListener;
13 19
import org.eclipse.swt.layout.GridData;
......
15 21
import org.eclipse.swt.widgets.Button;
16 22
import org.eclipse.swt.widgets.Composite;
17 23
import org.eclipse.swt.widgets.Event;
24
import org.eclipse.swt.widgets.FileDialog;
18 25
import org.eclipse.swt.widgets.Label;
19 26
import org.eclipse.swt.widgets.Listener;
20 27
import org.eclipse.swt.widgets.Text;
......
30 37
import org.txm.rcp.editors.TXMEditor;
31 38
import org.txm.rcp.editors.listeners.ComputeKeyListener;
32 39
import org.txm.rcp.editors.listeners.ComputeSelectionListener;
40
import org.txm.rcp.messages.TXMUIMessages;
33 41
import org.txm.rcp.swt.widget.AssistedQueryWidget;
34 42
import org.txm.rcp.swt.widget.structures.StructuralUnitPropertiesComboViewer;
35 43
import org.txm.rcp.swt.widget.structures.StructuralUnitsComboViewer;
36 44
import org.txm.rcp.swt.widget.structures.StructuralUnitsCombosGroup;
37 45
import org.txm.searchengine.cqp.corpus.Corpus;
38 46
import org.txm.searchengine.cqp.corpus.query.Query;
47
import org.txm.utils.io.IOUtils;
39 48
import org.txm.utils.logger.Log;
40 49

  
41 50
/**
......
120 129
	@Parameter(key=ProgressionPreferences.REPEAT_SAME_VALUES)
121 130
	protected Button repeatSameValues;
122 131

  
132
	private AssistedQueryWidget queryWidget;
123 133

  
124 134

  
125 135

  
126 136

  
137

  
127 138
	@Override
128 139
	public void __createPartControl(Composite parent) {
129 140

  
......
167 178

  
168 179

  
169 180
		try {
181
			// Query:
182
			getMinimalParametersComposite().getLayout().numColumns = 2;
183
			// make
184
			getMinimalParametersComposite().setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false));
185
			
186
			Label queryLabel = new Label(getMinimalParametersComposite(), SWT.NONE);
187
			queryLabel.setText("Add query");
188
			queryLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
170 189

  
171

  
190
			// [ (v)]
191
			// queryWidget = new QueryWidget(queryArea, SWT.DROP_DOWN);
192
			queryWidget = new AssistedQueryWidget(getMinimalParametersComposite(), SWT.DROP_DOWN, getResult().getCorpus());
193
			queryWidget.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
194
			queryWidget.addKeyListener(new ComputeKeyListener(this) {
195
				@Override
196
				public void keyPressed(KeyEvent e) {
197
					if (e.keyCode == SWT.CR || e.keyCode == SWT.KEYPAD_CR) {
198
						onPlusButtonPressed(null, queryWidget.getQueryString());
199
						super.keyPressed(e);
200
					}
201
				}
202
			});
203
			
172 204
			// System.out.println(parent.getLayout());
173 205
			Composite mainPanel = this.getCommandParametersGroup();
174 206
			GridData gridData = new GridData(GridData.FILL, GridData.FILL, true, true);
......
289 321
			// add query button
290 322
			Button plusButton = new Button(queriesFocusComposite, SWT.NONE);
291 323
			plusButton.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
292
			plusButton.setText(ProgressionUIMessages.ProgressionDialog_9);
324
			plusButton.setText("Add multiple queries...");
293 325

  
294 326
			plusButton.addListener(SWT.Selection, new Listener() {
295 327
				@Override
296 328
				public void handleEvent(Event event) {
297
					if (colors.length > queryWidgets.size()) {
298
						Log.info("add query field");
299
						addFocusQueryField();
300
						sc1.layout(true);
301
						queriesFocusComposite.layout(true);
302
						sc1.setMinSize(queriesFocusComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
329
					FileDialog dialog = new FileDialog(event.display.getActiveShell(), SWT.OPEN);
330
					dialog.setText("Select a UTF-8 property file");
331
					String path = dialog.open();
332
					if (path != null) {
333
						Properties props = new Properties();
334
						try {
335
							props.load(IOUtils.getReader(new File(path)));
336
							for (Object k : props.keySet()) {
337
								onPlusButtonPressed(event, props.get(k).toString());
338
							}
339
						} catch (Exception e) {
340
							// TODO Auto-generated catch block
341
							e.printStackTrace();
342
						}
303 343
					}
304 344
				}
305 345
			});
306 346

  
307

  
308 347
		} catch (Exception e) {
309 348
			Log.printStackTrace(e);
310 349
		}
......
312 351

  
313 352
	}
314 353

  
354
	public void onPlusButtonPressed(Event event, String defaultValue) {
355
		if (colors.length > queryWidgets.size()) {
356
			Log.info("add query field");
357
			QueryField qf = addFocusQueryField();
358
			if (qf != null) qf.setQuery(defaultValue);
359
			sc1.layout(true);
360
			queriesFocusComposite.layout(true);
361
			sc1.setMinSize(queriesFocusComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
362
		}
363
	}
315 364

  
316 365

  
317

  
318 366
	/**
319 367
	 * 
320 368
	 * @author mdecorde
......
426 474

  
427 475
		// create the queries fields
428 476
		if (queries == null) {
429
			addFocusQueryField();
477
			//addFocusQueryField();
430 478
		}
431 479
		else {
432 480
			for (Query q : queries) {

Formats disponibles : Unified diff