Révision 940

tmp/org.txm.queryindex.rcp/src/queryindexrcp/adapters/AdapterFactory.java (revision 940)
5 5
import org.eclipse.jface.resource.ImageDescriptor;
6 6
import org.eclipse.ui.model.IWorkbenchAdapter;
7 7
import org.eclipse.ui.plugin.AbstractUIPlugin;
8
import org.txm.functions.queryindex.QueryIndex;
8
import org.txm.queryindex.core.functions.QueryIndex;
9 9
import org.txm.rcp.Application;
10 10
import org.txm.rcp.IImageKeys;
11 11

  
tmp/org.txm.queryindex.rcp/src/org/txm/queryindex/core/functions/QueryIndexLine.java (revision 940)
1
package org.txm.queryindex.core.functions;
2

  
3
import org.txm.searchengine.cqp.clientExceptions.CqiClientException;
4
import org.txm.searchengine.cqp.corpus.QueryResult;
5
import org.txm.searchengine.cqp.corpus.query.Query;
6

  
7
public class QueryIndexLine {
8
	String name;
9
	private Query query;
10
	QueryResult[] qresults;
11
	int[] freqs;
12
	int total;
13

  
14

  
15
	public QueryIndexLine(String name, Query query, QueryResult[] qresults) {
16
		this.qresults = qresults;
17
		this.query = query;
18
		this.name = name;
19
	}
20

  
21
	public String getName() {
22
		return name;
23
	}
24

  
25
	public Query getQuery() {
26
		return query;
27
	}
28
	
29
	public int[] getFreqs() {
30
		computeFreqsAndTotal();
31
		return freqs;
32
	}
33
	
34
	private void computeFreqsAndTotal() {
35
		if (freqs == null) {
36
			//System.out.println("compute freqs");
37
			total = 0;
38
			try {
39
				freqs = new int[qresults.length];
40
				for (int i = 0 ; i < freqs.length ; i++) {
41
					//System.out.println("add "+qresults[i].getNMatch());
42
					freqs[i] = qresults[i].getNMatch();
43
					total += freqs[i];
44
					qresults[i].drop();
45
				}
46
				qresults = null;
47
			} catch (CqiClientException e) {
48
				// TODO Auto-generated catch block
49
				org.txm.utils.logger.Log.printStackTrace(e);
50
				freqs = new int[0];
51
			}
52
		} else {
53
			total = 0;
54
			for (int i = 0 ; i < freqs.length ; i++) {
55
				total += freqs[i];
56
			}
57
		}
58
	}
59

  
60
	public int getFrequency() {
61
		computeFreqsAndTotal();
62
		return total;
63
	}
64
	
65
	public int getFrequency(int i) {
66
		computeFreqsAndTotal();
67
		return freqs[i];
68
	}
69
	
70
	public void setFrequencies(int[] freqs) {
71
		this.freqs = freqs;
72
//		total = 0 ;
73
//		for (int f : freqs) total+=f;
74
//		System.out.println("total : "+total);
75
	}
76

  
77
	/*private static void mergeMatches(int from, List<Match> matches, List<Match> tmp) {
78
		int im1 = 0;
79
		for (int im2 = 0 ; im2 < tmp.size() && im1 < matches.size() ;) {
80
			Match m1 = matches.get(im1);
81
			Match m2 = tmp.get(im2);
82

  
83
			if (m1.getStart() < m2.getStart()) {
84
				im1++;
85
			} else if (m1.getStart() >  m2.getStart()) {
86
				im2++;
87
				matches.add(im1,m2);
88
			} else {
89
				if (m1.getEnd() <  m2.getEnd()) {
90
					im1++;
91
				} else if (m1.getEnd() >  m2.getEnd()) {
92
					im2++;
93
					matches.add(im1,m2);
94
				} else {
95
					System.out.println("ERROR while merging : m1 == m2");
96
				}
97
			}
98
		} // end of match merge
99
	}
100

  
101
	public void union(List<QueryIndexLine> lines) throws CqiClientException {
102
		for (QueryIndexLine line : lines) { // process lines	
103
			for (QueryResult qresult : line.getQResult()) {
104

  
105
				List<Match> matches = qresult.getMatches();
106

  
107
				int nmatches = matches.size();
108
				int im1 = 0;
109
				List<Match> matches2 = qresult.getMatches();
110
				int nmatches2 = matches2.size();
111
				ArrayList<Match> tmp = new ArrayList<Match>(); // receive the match to add
112

  
113
				// 1-5 2-5 3-6 7-9
114
				// 1.4 1-5 2-5 3-5 7-8 7-9
115
				// select all without doublons
116
				int im2;
117
				for (im2 = 0 ; im2 < nmatches2 && im1 < nmatches ;) {
118
					Match m1 = matches.get(im1);
119
					Match m2 = matches2.get(im2);
120

  
121
					if (m1.getStart() == m2.getStart() && m1.getEnd() == m2.getEnd()) {
122
						// don't add
123
						im2++; // test next match2
124
					} else {
125
						tmp.add(m2);
126
						if (m1.getStart() <  m2.getStart()) {
127
							im1++;
128
						} else if (m1.getStart() >  m2.getStart()){
129
							im2++;
130
						} else {
131
							if (m1.getEnd() <  m2.getEnd()) {
132
								im1++;
133
							} else {
134
								im2++;
135
							} 
136
						}
137
					}
138
				} // almost end of match selection
139
				for (int i = im2 ; i < nmatches2 ; i++) 
140
					tmp.add(matches2.get(im2)); // get the last ones if any
141

  
142
				// merge
143
				mergeMatches(0, matches, tmp);
144
			} // end of union
145
			freqs = null; // will be recomputed next time
146
		}
147
	}*/
148

  
149
	/*public void inter(List<QueryIndexLine> lines) throws CqiClientException {
150
		List<Match> matches = qresult.getMatches();
151
		for (QueryIndexLine line : lines) {
152
			List<Match> matches2 = line.getQResult().getMatches();
153
		}
154
		freq = -1;
155
	}
156

  
157
	public void minus(List<QueryIndexLine> lines)throws CqiClientException {
158
		List<Match> matches = qresult.getMatches();
159
		for (QueryIndexLine line : lines) {
160
			List<Match> matches2 = line.getQResult().getMatches();
161
		}
162
		freq = -1;
163
	}
164
	 */
165
}
0 166

  
tmp/org.txm.queryindex.rcp/src/org/txm/queryindex/core/functions/Messages.java (revision 940)
1
package org.txm.queryindex.core.functions;
2

  
3
import org.eclipse.osgi.util.NLS;
4
import org.txm.utils.messages.Utf8NLS;
5

  
6

  
7
/**
8
 * QueryIndex messages.
9
 * 
10
 * @author mdecorde
11
 * @author sjacquot
12
 *
13
 */
14
public class Messages extends NLS {
15

  
16
	private static final String BUNDLE_NAME = "org.txm.queryindex.core.functions.messages"; //$NON-NLS-1$
17
	
18
	public static String QueryIndexEditor_0;
19
	public static String QueryIndexEditor_1;
20
	public static String QueryIndexEditor_10;
21
	public static String QueryIndexEditor_11;
22
	public static String QueryIndexEditor_2;
23
	public static String QueryIndexEditor_3;
24
	public static String QueryIndexEditor_4;
25
	public static String QueryIndexEditor_6;
26
	public static String QueryIndexEditor_7;
27
	public static String QueryIndexEditor_8;
28
	public static String QueryIndexEditor_9;
29
	
30
	static {
31
		// initialize resource bundle
32
		Utf8NLS.initializeMessages(BUNDLE_NAME, Messages.class);
33
	}
34

  
35
	private Messages() {
36
	}
37
}
0 38

  
tmp/org.txm.queryindex.rcp/src/org/txm/queryindex/core/functions/messages_fr.properties (revision 940)
1

  
2
QueryIndexEditor_0  = Index de requête de : 
3
QueryIndexEditor_1  = remplacement des lignes : 
4
QueryIndexEditor_10 = requêtes
5
QueryIndexEditor_11 = 
6
QueryIndexEditor_2  = Erreur lors de l'ajout de la requête : 
7
QueryIndexEditor_3  = Requête ajoutée
8
QueryIndexEditor_4  = Chargement depuis un fichier
9
QueryIndexEditor_6  = Le fichier suivant ne peut être lu : 
10
QueryIndexEditor_7  = Vers les concordances
11
QueryIndexEditor_8  = Vers la progression
12
QueryIndexEditor_9  = Supprimer les lignes
0 13

  
tmp/org.txm.queryindex.rcp/src/org/txm/queryindex/core/functions/QueryIndex.java (revision 940)
1
package org.txm.queryindex.core.functions;
2

  
3
import java.io.BufferedReader;
4
import java.io.File;
5
import java.io.FileInputStream;
6
import java.io.FileOutputStream;
7
import java.io.IOException;
8
import java.io.InputStreamReader;
9
import java.io.OutputStreamWriter;
10
import java.util.ArrayList;
11
import java.util.Arrays;
12
import java.util.Collection;
13
import java.util.Collections;
14
import java.util.Comparator;
15
import java.util.LinkedHashMap;
16
import java.util.List;
17
import java.util.Map;
18

  
19
import org.eclipse.core.runtime.IAdaptable;
20
import org.eclipse.core.runtime.IProgressMonitor;
21
import org.eclipse.jface.resource.ImageDescriptor;
22
import org.eclipse.ui.model.IWorkbenchAdapter;
23
import org.txm.core.messages.TXMCoreMessages;
24
import org.txm.core.results.TXMParameters;
25
import org.txm.core.results.TXMResult;
26
import org.txm.index.core.functions.LineComparator.SortMode;
27
import org.txm.index.core.messages.IndexCoreMessages;
28
import org.txm.lexicaltable.core.functions.LexicalTable;
29
import org.txm.lexicaltable.core.statsengine.r.data.LexicalTableImpl;
30
import org.txm.rcp.IImageKeys;
31
import org.txm.searchengine.cqp.clientExceptions.CqiClientException;
32
import org.txm.searchengine.cqp.corpus.Corpus;
33
import org.txm.searchengine.cqp.corpus.Part;
34
import org.txm.searchengine.cqp.corpus.Partition;
35
import org.txm.searchengine.cqp.corpus.QueryResult;
36
import org.txm.searchengine.cqp.corpus.query.Query;
37
import org.txm.utils.logger.Log;
38

  
39
public class QueryIndex extends TXMResult implements IAdaptable {
40
	
41
	Corpus corpus;
42
	Partition partition;
43

  
44
	LinkedHashMap<String, QueryIndexLine> lines = new LinkedHashMap<String, QueryIndexLine>();
45
	List<String> partnames;
46
	//	private int FilterFmin;
47
	//	private int FilterFmax;
48
	//	private int FilterVmax;
49

  
50
	//	public int getFilterFmin() {
51
	//		return FilterFmin;
52
	//	}
53
	//
54
	//	public int getFilterFmax() {
55
	//		return FilterFmax;
56
	//	}
57
	//
58
	//	public int getFilterVmax() {
59
	//		return FilterVmax;
60
	//	}
61

  
62
	/** The writer. */
63
	private OutputStreamWriter writer;
64

  
65
	public int getT() {
66
		int t = 0;
67
		for (QueryIndexLine line : lines.values()) {
68
			t += line.getFrequency();
69
		}
70
		return t;
71
	}
72

  
73
	public int getFmin() {
74
		int t = 999999999;
75
		for (QueryIndexLine line : lines.values()) {
76
			int f = line.getFrequency();
77
			if (f < t) t = f;
78
		}
79
		return t;
80
	}
81

  
82
	public int getFmax() {
83
		int t = 0;
84
		for (QueryIndexLine line : lines.values()) {
85
			int f = line.getFrequency();
86
			if (f > t) t = f;
87
		}
88
		return t;
89
	}
90

  
91
	public int getV() {
92
		return lines.values().size();
93
	}
94

  
95
	public QueryIndex(Corpus corpus) {
96
		super(corpus);
97
		this.corpus = corpus;
98
		partnames = Arrays.asList(corpus.getName());
99
	}
100

  
101
	public String getName() {
102
		if (partition != null)
103
			return partition.getName();
104
		return corpus.getName();
105
	}
106

  
107
	public QueryIndex(Partition partition) {
108
		super(partition);
109
		this.corpus = partition.getCorpus();
110
		this.partition = partition;
111
		partnames = partition.getPartNames();
112
	}
113

  
114
	public Corpus getCorpus() {
115
		return corpus;
116
	}
117

  
118
	public Partition getPartition() {
119
		return partition;
120
	}
121

  
122
	public Collection<QueryIndexLine> getLines() {
123
		return lines.values();
124
	}
125

  
126
	public LinkedHashMap<String, QueryIndexLine> getLinesHash() {
127
		return lines;
128
	}
129

  
130
	//	public void filterLines(int fmin, int fmax) {
131
	//		System.out.println("filter lines fmin="+fmin +" fmax="+fmax );
132
	//		this.FilterFmin = fmin;
133
	//		this.FilterFmax = fmax;
134
	//	}
135
	int multi = 1;
136
	public void sortLines(SortMode mode, boolean revert) {
137

  
138
		multi = 1;
139
		if (revert) multi = -1;
140
		List<Map.Entry<String, QueryIndexLine>> entries =
141
				new ArrayList<Map.Entry<String, QueryIndexLine>>(lines.entrySet());
142

  
143
		if (mode == SortMode.FREQUNIT) {
144
			Collections.sort(entries, new Comparator<Map.Entry<String, QueryIndexLine>>() {
145
				public int compare(Map.Entry<String, QueryIndexLine> a, Map.Entry<String, QueryIndexLine> b){
146
					int ret = multi * (a.getValue().getFrequency() - b.getValue().getFrequency());
147
					if (ret == 0) {
148
						return multi * a.getValue().getName().compareTo(b.getValue().getName());
149
					}
150
					return ret;
151
				}
152
			});
153
		} else if (mode == SortMode.FREQ) {
154
			Collections.sort(entries, new Comparator<Map.Entry<String, QueryIndexLine>>() {
155
				public int compare(Map.Entry<String, QueryIndexLine> a, Map.Entry<String, QueryIndexLine> b){
156
					return multi * (a.getValue().getFrequency() - b.getValue().getFrequency());
157
				}
158
			});
159
		} else if (mode == SortMode.UNIT) {
160
			Collections.sort(entries, new Comparator<Map.Entry<String, QueryIndexLine>>() {
161
				public int compare(Map.Entry<String, QueryIndexLine> a, Map.Entry<String, QueryIndexLine> b){
162
					return multi * a.getValue().getName().compareTo(b.getValue().getName());
163
				}
164
			});
165
		} else if (mode == SortMode.UNITFREQ) {
166
			Collections.sort(entries, new Comparator<Map.Entry<String, QueryIndexLine>>() {
167
				public int compare(Map.Entry<String, QueryIndexLine> a, Map.Entry<String, QueryIndexLine> b){
168
					int ret = multi * a.getValue().getName().compareTo(b.getValue().getName());
169
					if (ret == 0) {
170
						return multi * (a.getValue().getFrequency() - b.getValue().getFrequency());
171
					}
172
					return ret;
173
				}
174
			});
175
		}
176

  
177
		LinkedHashMap<String, QueryIndexLine> sortedMap = new LinkedHashMap<String, QueryIndexLine>();
178
		for (Map.Entry<String, QueryIndexLine> entry : entries) {
179
			sortedMap.put(entry.getKey(), entry.getValue());
180
		}
181

  
182
		lines = sortedMap;
183
	}
184

  
185
	//	public void cut(int vmax) {
186
	//		System.out.println("TODO cut tmax="+vmax );
187
	//		this.FilterVmax = vmax;
188
	//	}
189

  
190
	public boolean isComputedWithPartition() {
191
		return partition != null;
192
	}
193

  
194
	public void addLinesFromFile(File propFile) throws CqiClientException, IOException {
195
		BufferedReader reader = new BufferedReader(new InputStreamReader(
196
				new FileInputStream(propFile), "UTF-8")); //$NON-NLS-1$
197

  
198
		String line = reader.readLine();
199
		while (line != null) {
200
			String[] split = line.split("=", 2); //$NON-NLS-1$
201
			if (split.length == 2) {
202
				if (hasLine(split[0])) {
203
					System.out.println(TXMCoreMessages.QueryIndex_2+line);
204
				} else {
205
					if (addLine(split[0], new Query(split[1])) == null) {
206
						System.out.println(TXMCoreMessages.QueryIndex_3+line);
207
					}
208
				}
209
			}
210
			line = reader.readLine();
211
		}
212
		reader.close();
213
	}
214

  
215
	/**
216
	 * Write all the lines on a writer.
217
	 *
218
	 * @param outfile the outfile
219
	 * @param encoding the encoding
220
	 * @param colseparator the colseparator
221
	 * @param txtseparator the txtseparator
222
	 * @return true, if successful
223
	 */
224
	public boolean toTxt(File outfile, String encoding, String colseparator, String txtseparator) {
225
		try {
226
			toTxt(outfile, 0, lines.size(), encoding, colseparator, txtseparator);
227
		} catch (Exception e) {
228
			System.err.println(IndexCoreMessages.Index_7 + Log.toString(e));
229
			return false;
230
		}
231
		return true;
232
	}
233

  
234
	/**
235
	 * Write the lines between from and to on a writer.
236
	 *
237
	 * @param outfile the outfile
238
	 * @param from The first line to be written
239
	 * @param to The last line to be writen
240
	 * @param encoding the encoding
241
	 * @param colseparator the colseparator
242
	 * @param txtseparator the txtseparator
243
	 * @throws CqiClientException the cqi client exception
244
	 * @throws IOException Signals that an I/O exception has occurred.
245
	 */
246
	public void toTxt(File outfile, int from, int to, String encoding, String colseparator, String txtseparator)
247
			throws CqiClientException, IOException {
248
		// NK: writer declared as class attribute to perform a clean if the operation is interrupted
249
		this.writer = new OutputStreamWriter(new FileOutputStream(outfile),
250
				encoding); 
251
		String header = "Queries"; //$NON-NLS-1$
252
		header = txtseparator+ header.substring(0, header.length() - 1) +txtseparator;
253
		header += colseparator+ txtseparator+ "F" + txtseparator; //$NON-NLS-1$
254

  
255
		if (partnames.size() > 1)
256
			for (int j = 0; j < partnames.size(); j++)
257
				header += colseparator + txtseparator+ partnames.get(j).replace(txtseparator, txtseparator+txtseparator)+txtseparator; 
258
		header += "\n"; //$NON-NLS-1$
259
		writer.write(header);
260

  
261
		// for(Line ligne: lines)
262
		for (String name : lines.keySet()) {
263
			QueryIndexLine ligne = lines.get(name);
264
			writer.write(txtseparator+ ligne.getName().replace(txtseparator, txtseparator+txtseparator)+ txtseparator + colseparator + ligne.getFrequency()); 
265
			if (partnames.size() > 1)
266
				for (int j = 0; j < partnames.size(); j++)
267
					writer.write(colseparator + ligne.getFrequency(j)); 
268
			writer.write("\n"); //$NON-NLS-1$
269
		}
270
		writer.flush();
271
		writer.close();
272
	}
273

  
274
	public List<String> getPartnames() {
275
		return partnames;
276
	}
277

  
278
	public QueryIndexLine addLine(String name, Query query) throws CqiClientException {
279
		if (lines.containsKey(name)) return null;
280
		QueryResult[] qresults;
281
		if (partition != null) {
282
			qresults = new QueryResult[partition.getNPart()];
283
			List<Part> parts = partition.getParts();
284
			for (int i = 0 ; i < parts.size() ; i++) {
285
				qresults[i] = parts.get(i).query(query, "tmp", true); //$NON-NLS-1$
286
				//qresults[i].drop(); // free mem done later
287
			}
288
		} else {
289
			qresults = new QueryResult[1];
290
			qresults[0] = corpus.query(query, "tmp", true); //$NON-NLS-1$
291
			//qresults[0].drop(); // free mem done later
292
		}
293

  
294
		QueryIndexLine line = new QueryIndexLine(name, query, qresults);
295
		lines.put(name, line);
296
		return line;
297
	}
298

  
299
	public LexicalTable toLexicalTable() {
300
		if (partition == null) return null;
301

  
302
		int npart = partition.getNPart();
303
		int[][] freqs = new int[lines.size()][npart];
304
		String[] rownames = new String[lines.size()];
305
		String[] colnames = new String[npart];
306

  
307
		int i = 0;
308
		for (String key : lines.keySet()) {
309

  
310
			QueryIndexLine line = lines.get(key);
311
			int[] linefreqs = line.getFreqs();
312
			rownames[i] = line.getName();
313
			for (int j = 0 ; j < npart ; j++) {
314
				freqs[i][j] = linefreqs[j];
315
			}
316
			i++;
317
		}
318
		List<Part> parts = partition.getParts();
319
		for (int j = 0 ; j < npart ; j++) {
320
			colnames[j] = parts.get(j).getName();
321
		}
322

  
323
		try {
324
			LexicalTableImpl lt = new LexicalTableImpl(freqs, rownames, colnames);
325
			LexicalTable table = new LexicalTable(partition, partition.getProperty(), 1, this.getV(), lt);
326
			return table;
327
		} catch (Exception e) {
328
			Log.printStackTrace(e);
329
		}
330
		return null;
331
	}
332

  
333
	public boolean removeLine(String name) {
334
		if (lines.containsKey(name)) {
335
			lines.remove(name);
336
			return true;
337
		} else {
338
			return false;
339
		}
340
	}
341

  
342
	public boolean hasLine(String name) {
343
		return lines.containsKey(name);
344
	}
345

  
346
	public ArrayList<QueryIndexLine> getLines(int from, int to) {
347
		if (lines.size() == 0) return new ArrayList<QueryIndexLine>();
348

  
349
		if (from < 0) from = 0;
350
		if (to < 0) to = 0;
351
		if (to > lines.size()) to = lines.size();
352
		if (from > to) from = to - 1;
353
		ArrayList<QueryIndexLine> tmp = new ArrayList<QueryIndexLine>();
354
		int i = 0;
355
		for (QueryIndexLine line : lines.values()) {
356
			if (i >= from && i < to) {
357
				tmp.add(line);
358
			}
359
			i++;
360
		}
361

  
362
		return tmp;
363
	}
364

  
365
	@Override
366
	public void clean() {
367
		try {
368
			this.writer.flush();
369
			this.writer.close();	
370
		} catch (IOException e) {
371
			Log.printStackTrace(e);
372
		}
373
	}
374

  
375
	@Override
376
	public Object getAdapter(Class adapterType) {
377
		if (adapterType == IWorkbenchAdapter.class)
378
			return queryindexAdapter;
379
		return null;
380
	}
381

  
382
	/** The QueryIndex adapter. */
383
	private static IWorkbenchAdapter queryindexAdapter = new IWorkbenchAdapter() {
384

  
385
		@Override
386
		public Object[] getChildren(Object o) {
387
			return new Object[0];
388
		}
389

  
390
		@Override
391
		public ImageDescriptor getImageDescriptor(Object object) {
392
			return IImageKeys.getImageDescriptor(IImageKeys.QUERYINDEX);
393
			//return AbstractUIPlugin.imageDescriptorFromPlugin("QueryIndexRCP", "icons/functions/WordCloud.png"); //$NON-NLS //$NON-NLS-1$
394
			//return null;
395
		}
396

  
397
		@Override
398
		public String getLabel(Object o) {
399
			return ((QueryIndex) o).getName();
400
		}
401

  
402
		@Override
403
		public Object getParent(Object o) {
404
			if (((QueryIndex) o).getPartition() != null) {
405
				return ((QueryIndex) o).getPartition();
406
			} else {
407
				return ((QueryIndex) o).getCorpus();
408
			}
409
		}
410
	};
411

  
412
	@Override
413
	public boolean delete() {
414
		if (partition != null) {
415
			return partition.removeResult(this);
416
		}
417
		else if (corpus != null) {
418
			return corpus.removeResult(this);
419
		}
420
		return false;
421
	}
422

  
423
	@Override
424
	public String getSimpleName() {
425
		return "";
426
	}
427

  
428
	@Override
429
	public String getDetails() {
430
		return "";
431
	}
432

  
433
	@Override
434
	public boolean canCompute() {
435
		return corpus != null || partition != null;
436
	}
437

  
438
	@Override
439
	public boolean _compute() throws Exception {
440
		//FIXME: not yet implemented
441
		System.err.println("QueryIndex.compute(): not yet implemented.");
442
		return false;
443
	}
444

  
445
	@Override
446
	public boolean saveParameters() throws Exception {
447
		//FIXME: not yet implemented
448
		System.err.println("QueryIndex.saveParameters(): not yet implemented.");
449
		return false;
450
	}
451

  
452
	@Override
453
	public boolean loadParameters() throws Exception {
454
		//FIXME: not yet implemented
455
		System.err.println("QueryIndex.loadParameters(): not yet implemented.");
456
		return false;
457
	}
458

  
459
	@Override
460
	public boolean setParameters(TXMParameters parameters) throws Exception {
461
		//FIXME: not yet implemented
462
		System.err.println("QueryIndex.setParameters(): not yet implemented.");
463
		return false;
464
	}
465

  
466
	
467
	@Override
468
	public String getResultype() {
469
		return "Query index";
470
	}
471

  
472
}
0 473

  
tmp/org.txm.queryindex.rcp/src/org/txm/queryindex/core/functions/package.html (revision 940)
1
<html>
2
<body>
3
<p>Prototype of Query index.</p>
4
</body>
5
</html>
0 6

  
tmp/org.txm.queryindex.rcp/src/org/txm/queryindex/core/functions/messages.properties (revision 940)
1

  
2
QueryIndexEditor_0  = Query Index of
3
QueryIndexEditor_1  = replacing line:
4
QueryIndexEditor_10 = queries
5
QueryIndexEditor_11 = 
6
QueryIndexEditor_2  = Failed to add line with query:
7
QueryIndexEditor_3  = Line added.
8
QueryIndexEditor_4  = Load from a file
9
QueryIndexEditor_6  = Cannot read from file:
10
QueryIndexEditor_7  = Link to concordance
11
QueryIndexEditor_8  = Link to progression
12
QueryIndexEditor_9  = delete lines
0 13

  
tmp/org.txm.queryindex.rcp/src/org/txm/queryindex/rcp/editors/queryindex/LineContentProvider.java (revision 940)
1
// Copyright © 2010-2013 ENS de Lyon.
2
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of
3
// Lyon 2, University of Franche-Comté, University of Nice
4
// Sophia Antipolis, University of Paris 3.
5
// 
6
// The TXM platform is free software: you can redistribute it
7
// and/or modify it under the terms of the GNU General Public
8
// License as published by the Free Software Foundation,
9
// either version 2 of the License, or (at your option) any
10
// later version.
11
// 
12
// The TXM platform is distributed in the hope that it will be
13
// useful, but WITHOUT ANY WARRANTY; without even the implied
14
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15
// PURPOSE. See the GNU General Public License for more
16
// details.
17
// 
18
// You should have received a copy of the GNU General
19
// Public License along with the TXM platform. If not, see
20
// http://www.gnu.org/licenses.
21
// 
22
// 
23
// 
24
// $LastChangedDate:$
25
// $LastChangedRevision:$
26
// $LastChangedBy:$ 
27
//
28
package org.txm.queryindex.rcp.editors.queryindex;
29

  
30
import java.util.List;
31

  
32
import org.eclipse.jface.viewers.IStructuredContentProvider;
33
import org.eclipse.jface.viewers.Viewer;
34
import org.txm.queryindex.core.functions.QueryIndexLine;
35

  
36
// TODO: Auto-generated Javadoc
37
/**
38
 * The IStructuredContentProvider used by the reference and line tables.
39
 *
40
 * @author jmague
41
 */
42
public class LineContentProvider implements IStructuredContentProvider {
43

  
44
	/*
45
	 * (non-Javadoc)
46
	 * 
47
	 * @see
48
	 * org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java
49
	 * .lang.Object)
50
	 */
51
	@Override
52
	public Object[] getElements(Object inputElement) {
53
		@SuppressWarnings("unchecked")
54
		List<QueryIndexLine> lines = (List<QueryIndexLine>) inputElement;
55
		return lines.toArray();
56
	}
57

  
58
	/*
59
	 * (non-Javadoc)
60
	 * 
61
	 * @see org.eclipse.jface.viewers.IContentProvider#dispose()
62
	 */
63
	@Override
64
	public void dispose() {
65
		// TODO Auto-generated method stub
66

  
67
	}
68

  
69
	/*
70
	 * (non-Javadoc)
71
	 * 
72
	 * @see
73
	 * org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface
74
	 * .viewers.Viewer, java.lang.Object, java.lang.Object)
75
	 */
76
	@Override
77
	public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
78
		// TODO Auto-generated method stub
79
	}
80

  
81
}
0 82

  
tmp/org.txm.queryindex.rcp/src/org/txm/queryindex/rcp/editors/queryindex/LineLabelProvider.java (revision 940)
1
// Copyright © 2010-2013 ENS de Lyon.
2
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of
3
// Lyon 2, University of Franche-Comté, University of Nice
4
// Sophia Antipolis, University of Paris 3.
5
// 
6
// The TXM platform is free software: you can redistribute it
7
// and/or modify it under the terms of the GNU General Public
8
// License as published by the Free Software Foundation,
9
// either version 2 of the License, or (at your option) any
10
// later version.
11
// 
12
// The TXM platform is distributed in the hope that it will be
13
// useful, but WITHOUT ANY WARRANTY; without even the implied
14
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15
// PURPOSE. See the GNU General Public License for more
16
// details.
17
// 
18
// You should have received a copy of the GNU General
19
// Public License along with the TXM platform. If not, see
20
// http://www.gnu.org/licenses.
21
// 
22
// 
23
// 
24
// $LastChangedDate:$
25
// $LastChangedRevision:$
26
// $LastChangedBy:$ 
27
//
28
package org.txm.queryindex.rcp.editors.queryindex;
29

  
30
import org.eclipse.jface.viewers.ILabelProviderListener;
31
import org.eclipse.jface.viewers.ITableLabelProvider;
32
import org.eclipse.swt.graphics.Image;
33
import org.txm.queryindex.core.functions.QueryIndexLine;
34

  
35
// TODO: Auto-generated Javadoc
36
/**
37
 * The Class LineLabelProvider.
38
 */
39
public class LineLabelProvider implements ITableLabelProvider {
40

  
41
	/* (non-Javadoc)
42
	 * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnImage(java.lang.Object, int)
43
	 */
44
	@Override
45
	public Image getColumnImage(Object element, int columnIndex) {
46
		return null;
47
	}
48

  
49
	/* (non-Javadoc)
50
	 * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang.Object, int)
51
	 */
52
	@Override
53
	public String getColumnText(Object element, int columnIndex) {
54
		QueryIndexLine line = (QueryIndexLine) element;
55
		switch (columnIndex) {
56
		case 0:
57
			return ""; //$NON-NLS-1$
58
		case 1:
59
			return line.getName();
60
		case 2:
61
			return "" + line.getFrequency(); //$NON-NLS-1$
62
		default:
63
			if (line.getFreqs().length > 1
64
					&& columnIndex - 3 < line.getFreqs().length)
65
				return "" + line.getFrequency(columnIndex - 3); //$NON-NLS-1$
66
			else
67
				return "";//$NON-NLS-1$
68
		}
69
	}
70

  
71
	/* (non-Javadoc)
72
	 * @see org.eclipse.jface.viewers.IBaseLabelProvider#addListener(org.eclipse.jface.viewers.ILabelProviderListener)
73
	 */
74
	@Override
75
	public void addListener(ILabelProviderListener listener) {
76
		// TODO Auto-generated method stub
77
	}
78

  
79
	/* (non-Javadoc)
80
	 * @see org.eclipse.jface.viewers.IBaseLabelProvider#dispose()
81
	 */
82
	@Override
83
	public void dispose() {
84
		// TODO Auto-generated method stub
85
	}
86

  
87
	/* (non-Javadoc)
88
	 * @see org.eclipse.jface.viewers.IBaseLabelProvider#isLabelProperty(java.lang.Object, java.lang.String)
89
	 */
90
	@Override
91
	public boolean isLabelProperty(Object element, String property) {
92
		// TODO Auto-generated method stub
93
		return false;
94
	}
95

  
96
	/* (non-Javadoc)
97
	 * @see org.eclipse.jface.viewers.IBaseLabelProvider#removeListener(org.eclipse.jface.viewers.ILabelProviderListener)
98
	 */
99
	@Override
100
	public void removeListener(ILabelProviderListener listener) {
101
		// TODO Auto-generated method stub
102
	}
103
}
0 104

  
tmp/org.txm.queryindex.rcp/src/org/txm/queryindex/rcp/editors/queryindex/QueryIndexEditor.java (revision 940)
1
// Copyright © 2010-2013 ENS de Lyon.
2
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of
3
// Lyon 2, University of Franche-Comté, University of Nice
4
// Sophia Antipolis, University of Paris 3.
5
// 
6
// The TXM platform is free software: you can redistribute it
7
// and/or modify it under the terms of the GNU General Public
8
// License as published by the Free Software Foundation,
9
// either version 2 of the License, or (at your option) any
10
// later version.
11
// 
12
// The TXM platform is distributed in the hope that it will be
13
// useful, but WITHOUT ANY WARRANTY; without even the implied
14
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15
// PURPOSE. See the GNU General Public License for more
16
// details.
17
// 
18
// You should have received a copy of the GNU General
19
// Public License along with the TXM platform. If not, see
20
// http://www.gnu.org/licenses.
21
// 
22
// 
23
// 
24
// $LastChangedDate:$
25
// $LastChangedRevision:$
26
// $LastChangedBy:$ 
27
//
28
package org.txm.queryindex.rcp.editors.queryindex;
29

  
30
import java.io.File;
31
import java.io.IOException;
32
import java.util.ArrayList;
33
import java.util.List;
34

  
35
import org.eclipse.core.runtime.IProgressMonitor;
36
import org.eclipse.core.runtime.IStatus;
37
import org.eclipse.core.runtime.Status;
38
import org.eclipse.jface.action.MenuManager;
39
import org.eclipse.jface.viewers.ISelection;
40
import org.eclipse.jface.viewers.StructuredSelection;
41
import org.eclipse.jface.viewers.TableViewer;
42
import org.eclipse.swt.SWT;
43
import org.eclipse.swt.events.KeyEvent;
44
import org.eclipse.swt.events.KeyListener;
45
import org.eclipse.swt.events.MouseAdapter;
46
import org.eclipse.swt.events.MouseEvent;
47
import org.eclipse.swt.events.SelectionEvent;
48
import org.eclipse.swt.events.SelectionListener;
49
import org.eclipse.swt.graphics.Font;
50
import org.eclipse.swt.graphics.FontData;
51
import org.eclipse.swt.graphics.Point;
52
import org.eclipse.swt.layout.FormAttachment;
53
import org.eclipse.swt.layout.FormData;
54
import org.eclipse.swt.layout.FormLayout;
55
import org.eclipse.swt.layout.GridData;
56
import org.eclipse.swt.layout.GridLayout;
57
import org.eclipse.swt.widgets.Button;
58
import org.eclipse.swt.widgets.Composite;
59
import org.eclipse.swt.widgets.Display;
60
import org.eclipse.swt.widgets.FileDialog;
61
import org.eclipse.swt.widgets.Label;
62
import org.eclipse.swt.widgets.Menu;
63
import org.eclipse.swt.widgets.Spinner;
64
import org.eclipse.swt.widgets.TableColumn;
65
import org.eclipse.ui.IEditorInput;
66
import org.eclipse.ui.IEditorSite;
67
import org.eclipse.ui.PartInitException;
68
import org.txm.core.messages.TXMCoreMessages;
69
import org.txm.index.core.functions.LineComparator.SortMode;
70
import org.txm.index.rcp.messages.IndexUIMessages;
71
import org.txm.queryindex.core.functions.Messages;
72
import org.txm.queryindex.core.functions.QueryIndex;
73
import org.txm.queryindex.core.functions.QueryIndexLine;
74
import org.txm.queryindex.rcp.editors.input.QueryIndexEditorInput;
75
import org.txm.rcp.JobsTimer;
76
import org.txm.rcp.StatusLine;
77
import org.txm.rcp.editors.TXMEditor;
78
import org.txm.rcp.editors.TableKeyListener;
79
import org.txm.rcp.messages.TXMUIMessages;
80
import org.txm.rcp.swt.dialog.LastOpened;
81
import org.txm.rcp.swt.widget.NamedAssistedQueryWidget;
82
import org.txm.rcp.swt.widget.NavigationWidget;
83
import org.txm.rcp.utils.JobHandler;
84
import org.txm.rcp.views.QueriesView;
85
import org.txm.rcp.views.corpora.CorporaView;
86
import org.txm.searchengine.cqp.CQPSearchEngine;
87
import org.txm.searchengine.cqp.clientExceptions.CqiClientException;
88
import org.txm.searchengine.cqp.corpus.Corpus;
89
import org.txm.searchengine.cqp.corpus.Partition;
90
import org.txm.searchengine.cqp.corpus.Property;
91
import org.txm.searchengine.cqp.corpus.query.Query;
92
import org.txm.statsengine.r.rcp.views.RVariablesView;
93
import org.txm.utils.logger.Log;
94

  
95
/**
96
 * display the query index parameters and result.
97
 * 
98
 * @author mdecorde
99
 */
100
public class QueryIndexEditor extends TXMEditor<QueryIndex> {
101

  
102
	/** The Constant ID. */
103
	public static final String ID = "org.txm.rcp.editors.queryindex.QueryIndexEditor"; //$NON-NLS-1$
104

  
105
	/** The corpus. */
106
	protected Corpus corpus;
107
	protected Partition partition; // can be null
108

  
109
	/** The index. */
110
	protected QueryIndex queryindex;
111
	boolean stored = false; // start storing at first line added
112
	// protected boolean saveQueryIndex = true;
113

  
114
	// params
115
	/** The query label. */
116
	protected Label queryLabel;
117

  
118
	/** The query widget. */
119
	protected NamedAssistedQueryWidget queryWidget;
120

  
121
	/** The N ligne p page spinner. */
122
	protected Spinner NLignePPageSpinner;
123
	// infos
124
	/** The navigation area. */
125
	protected NavigationWidget navigationArea;
126

  
127
	/** The l fmin info. */
128
	protected Label lFminInfo;
129

  
130
	/** The l fmax info. */
131
	protected Label lFmaxInfo;
132

  
133
	/** The l v info. */
134
	protected Label lVInfo;
135

  
136
	/** The l t info. */
137
	protected Label lTInfo;
138
	// result
139
	/** The line table viewer. */
140
	protected TableViewer viewer;
141

  
142
	/** The n column. */
143
	protected TableColumn nColumn;
144

  
145
	/** The unit column. */
146
	protected TableColumn unitColumn;
147

  
148
	/** The freq column. */
149
	protected TableColumn freqColumn;
150

  
151
	/** The separator column. */
152
	protected TableColumn separatorColumn;
153

  
154
	/** The top line. */
155
	protected int topLine;
156

  
157
	/** The bottom line. */
158
	protected int bottomLine;
159

  
160
	/** The nblinesperpage. */
161
	protected int nblinesperpage;
162

  
163
	/** The nblinesmax. */
164
	protected int nblinesmax;
165

  
166
//	/** The scroll composite. */
167
//	private ScrolledComposite scrollComposite;
168
//
169
//	/** The head composite. */
170
//	private Composite headComposite;
171

  
172
	/** The title. */
173
	String title;
174

  
175
	/**
176
	 * Instantiates a new index editor.
177
	 */
178
	public QueryIndexEditor() {
179
		super();
180
	}
181

  
182
	/**
183
	 * Do save.
184
	 * 
185
	 * @param arg0
186
	 *            the arg0
187
	 * @see org.eclipse.ui.part.EditorPart#doSave(org.eclipse.core.runtime.IProgressMonitor)
188
	 */
189
	@Override
190
	public void doSave(IProgressMonitor arg0) {
191
		// TODO Auto-generated method stub
192
	}
193

  
194
	/**
195
	 * Do save as.
196
	 * 
197
	 * @see org.eclipse.lyon gournd zeroui.part.EditorPart#doSaveAs()
198
	 */
199
	@Override
200
	public void doSaveAs() {
201
		// TODO Auto-generated method stub
202
	}
203

  
204
	/**
205
	 * Inits the.
206
	 * 
207
	 * @param site
208
	 *            the site
209
	 * @param input
210
	 *            the input
211
	 * @throws PartInitException
212
	 *             the part init exception
213
	 * @see org.eclipse.ui.part.EditorPart#init(org.eclipse.ui.IEditorSite,
214
	 *      org.eclipse.ui.IEditorInput)
215
	 */
216
	@Override
217
	public void init(IEditorSite site, IEditorInput input)
218
			throws PartInitException {
219
		setSite(site);
220
		setInput(input);
221

  
222
		this.corpus = ((QueryIndexEditorInput) input).getCorpus();
223
		this.partition = ((QueryIndexEditorInput) input).getPartition();
224
		this.queryindex = ((QueryIndexEditorInput) input).getQueryIndex();
225
	}
226

  
227
	/**
228
	 * Checks if is dirty.
229
	 * 
230
	 * @return true, if is dirty
231
	 * @see org.eclipse.ui.part.EditorPart#isDirty()
232
	 */
233
	@Override
234
	public boolean isDirty() {
235
		return false;
236
	}
237

  
238
	/**
239
	 * Checks if is save as allowed.
240
	 * 
241
	 * @return true, if is save as allowed
242
	 * @see org.eclipse.ui.part.EditorPart#isSaveAsAllowed()
243
	 */
244
	@Override
245
	public boolean isSaveAsAllowed() {
246
		return false;
247
	}
248

  
249
	private QueryIndex createQueryIndex() {
250
		if (queryindex == null) {
251
			if (partition != null) {
252
				queryindex = new QueryIndex(partition);
253
				title = Messages.QueryIndexEditor_0 + partition.getName();
254
			} else {
255
				queryindex = new QueryIndex(corpus);
256
				title = Messages.QueryIndexEditor_0 + corpus;
257
			}
258
		}
259
		return queryindex;
260
	}
261

  
262
	/**
263
	 * Compute index.
264
	 */
265
	public void compute() {
266

  
267
		createQueryIndex();
268

  
269
		StatusLine.setMessage(IndexUIMessages.IndexEditor_33);
270
		final Query query; // if the query is empty then we put "[]" instead
271
		if (!queryWidget.getQueryString().equals("\"\"")) {//$NON-NLS-1$
272
			query = new Query(queryWidget.getQueryString());
273
		} else {
274
			System.err.println(IndexUIMessages.IndexEditor_0);
275
			return;
276
		}
277

  
278
		final String name;
279
		if (queryWidget.getQueryName().length() == 0) {
280
			name = query.toString();
281
		} else {
282
			name = queryWidget.getQueryName();
283
		}
284

  
285
		try {
286
			JobHandler jobhandler = new JobHandler(title,
287
					queryWidget.getParent()) {
288
				@Override
289
				protected IStatus run(IProgressMonitor monitor) {
290
					this.runInit(monitor);
291
					JobsTimer.start();
292
					final QueryIndexLine line;
293
					try {
294
						try {
295
							if (queryindex.hasLine(name)) {
296
								System.out.println(Messages.QueryIndexEditor_1 + name);
297
								queryindex.removeLine(name);
298
							}
299
							line = queryindex.addLine(name, query);
300
						} catch (CqiClientException e2) {
301
							System.out
302
									.println(Messages.QueryIndexEditor_2
303
											+ query);
304
							Log.printStackTrace(e2);
305
							return Status.CANCEL_STATUS;
306
						}
307

  
308
						if (line == null) {
309
							System.out
310
									.println(Messages.QueryIndexEditor_2
311
											+ query);
312
							return Status.CANCEL_STATUS;
313
						}
314

  
315
						if (monitor.isCanceled())
316
							return Status.CANCEL_STATUS;
317

  
318
						queryindex.sortLines(SortMode.FREQUNIT, true);
319

  
320
						if (monitor.isCanceled())
321
							return Status.CANCEL_STATUS;
322

  
323
						this.acquireSemaphore();
324
						this.releaseSemaphore();
325

  
326
						final String message = Messages.QueryIndexEditor_3;
327

  
328
						if (monitor.isCanceled())
329
							return Status.CANCEL_STATUS;
330

  
331
						monitor.worked(95);
332
						// refresh ui
333
						syncExec(new Runnable() {
334
							@Override
335
							public void run() {
336

  
337
								System.out.println(message);
338
								StatusLine.setMessage(message);
339

  
340
								CorporaView.refresh();
341
								CorporaView.expand(queryindex.getParent());
342
								QueriesView.refresh();
343
								RVariablesView.refresh();
344

  
345
								setPartName(title);
346

  
347
								queryWidget.memorize();
348
								nblinesperpage = NLignePPageSpinner
349
										.getSelection();
350

  
351
								fillDisplayArea(0,
352
										NLignePPageSpinner.getSelection());
353

  
354
								if (line != null) {
355
									queryWidget.setText(""); //$NON-NLS-1$
356
									queryWidget.setName(""); //$NON-NLS-1$
357
									queryWidget.focus();
358
								}
359
							}
360
						});
361
					} catch (Exception e) {
362
						System.out.println(e.getLocalizedMessage());
363
						try {
364
							System.out.println(TXMUIMessages.LastCQPError
365
									+ CQPSearchEngine.getCqiClient().getLastCQPError());
366
						} catch (Exception e1) {
367
							System.out.println(IndexUIMessages.IndexEditor_10
368
									+ e1);
369
							Log.printStackTrace(e1);
370
						}
371
						Log.severe("Error while computing QueryIndex: "+e.getLocalizedMessage());
372
					} catch (ThreadDeath td) {
373
						return Status.CANCEL_STATUS;
374
					} finally {
375
						monitor.done();
376
						JobsTimer.stopAndPrint();
377
					}
378
					return Status.OK_STATUS;
379
				}
380
			};
381
			jobhandler.startJob();
382

  
383
		} catch (Exception e1) {
384
			Log.printStackTrace(e1);
385
		}
386
	}
387

  
388
	/**
389
	 * Creates the part control.
390
	 * 
391
	 * @param parent
392
	 *            the parent
393
	 * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
394
	 */
395
	@Override
396
	public void _createPartControl() {
397

  
398
		// create scrollable area
399
//		scrollComposite = new ScrolledComposite(parent, SWT.H_SCROLL | SWT.NONE);
400
//		FormData headLayoutData = new FormData();
401
//		headLayoutData.top = new FormAttachment(0, 0);
402
//		headLayoutData.left = new FormAttachment(0);
403
//		headLayoutData.right = new FormAttachment(100);
404
//		scrollComposite.setLayoutData(headLayoutData);
405
//		scrollComposite.setLayout(new FormLayout());
406
//
407
//		headComposite = new Composite(scrollComposite, SWT.NONE);
408
//		headLayoutData = new FormData();
409
//		headLayoutData.top = new FormAttachment(0);
410
//		headLayoutData.bottom = new FormAttachment(100);
411
//		headLayoutData.left = new FormAttachment(0);
412
//		headLayoutData.right = new FormAttachment(100);
413
//		headComposite.setLayoutData(headLayoutData);
414
//		headComposite.setLayout(new FormLayout());
415
//
416
//		scrollComposite.setContent(headComposite);
417
//		scrollComposite.setExpandVertical(true);
418
//		scrollComposite.setExpandHorizontal(true);
419
//		scrollComposite.addControlListener(new ControlAdapter() {
420
//			@Override
421
//			public void controlResized(ControlEvent e) {
422
//				Rectangle r = scrollComposite.getClientArea();
423
//				scrollComposite.setMinSize(headComposite.computeSize(
424
//						SWT.DEFAULT, SWT.DEFAULT));
425
//			}
426
//		});
427

  
428
		final Composite paramArea = getExtendedParametersComposite();
429

  
430
		// info&navigation panel
431
		// final Composite infosArea = new Composite(headComposite, SWT.NONE);
432
		// FormData infosLayoutData = new FormData();
433
		// infosLayoutData.top = new FormAttachment(paramArea, 0);
434
		// infosLayoutData.left = new FormAttachment(0);
435
		// infosLayoutData.right = new FormAttachment(100);
436
		// infosArea.setLayoutData(infosLayoutData);
437

  
438
		Composite resultArea = getResultArea();
439

  
440
		// compose paramArea
441
		FormLayout paramLayout = new FormLayout();
442
		paramArea.setLayout(paramLayout);
443

  
444
		// on créé une Query, ici le pivot de la concordance est "[]"
445
		// Query Area: query itself + view properties
446
		Composite queryArea = new Composite(paramArea, SWT.NONE);
447

  
448
		FormData queryLayoutData = new FormData();
449
		queryLayoutData.top = new FormAttachment(0);
450
		queryLayoutData.left = new FormAttachment(0);
451
		queryLayoutData.right = new FormAttachment(100);
452
		queryArea.setLayoutData(queryLayoutData);
453

  
454
		queryArea.setLayout(new GridLayout(4, false));
455

  
456
		// | Query: [ (v)] [Search] |
457
		// Query:
458
		// queryLabel = new Label(queryArea, SWT.NONE);
459
		// queryLabel.setText(RCPMessages.IndexEditor_3);
460
		// queryLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false,
461
		// true));
462

  
463
		// [ (v)]
464
		queryWidget = new NamedAssistedQueryWidget(queryArea, SWT.DROP_DOWN,
465
				this.corpus);
466
		GridData layoutData = new GridData(GridData.VERTICAL_ALIGN_CENTER);
467
		layoutData.horizontalAlignment = GridData.FILL;
468
		layoutData.grabExcessHorizontalSpace = true;
469
		queryWidget.setLayoutData(layoutData);
470
		queryWidget.addKeyListener(new KeyListener() {
471
			@Override
472
			public void keyPressed(KeyEvent e) {
473
				// System.out.println("key pressed : "+e.keyCode);
474
				if (e.keyCode == SWT.CR || e.keyCode == SWT.KEYPAD_CR) {
475
					compute();
476
				}
477
			}
478

  
479
			@Override
480
			public void keyReleased(KeyEvent e) {
481
			}
482
		});
483

  
484
		Button loadFromFile = new Button(queryArea, SWT.BOLD);
485
		loadFromFile.setEnabled(true);
486
		loadFromFile.setText(Messages.QueryIndexEditor_4);
487
		loadFromFile
488
				.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_CENTER));
489
		loadFromFile.addSelectionListener(new SelectionListener() {
490
			@Override
491
			public void widgetSelected(SelectionEvent e) {
492
				File propFile = null;
493
				if (LastOpened.getFile(ID) != null)
494
					propFile = new File(LastOpened.getFolder(ID));
495

  
496
				FileDialog dialog = new FileDialog(getShell(), SWT.OPEN);
497
				String[] exts = { "*.properties" }; //$NON-NLS
498
				dialog.setFilterExtensions(exts);
499
				if (propFile != null) {
500
					dialog.setFilterPath(propFile.getParent());
501
					dialog.setFileName(propFile.getName());
502
				}
503
				String path = dialog.open();
504
				if (path != null) {
505
					propFile = new File(path);
506
					// compute();
507
					// System.out.println("TODO: load from file "+propFile);
... Ce différentiel a été tronqué car il excède la taille maximale pouvant être affichée.

Formats disponibles : Unified diff