Revision 2385
tmp/org.txm.lexicaltable.rcp/src/org/txm/lexicaltable/rcp/editors/LexicalTableEditor.java (revision 2385) | ||
---|---|---|
69 | 69 |
import org.txm.statsengine.core.data.Vector; |
70 | 70 |
import org.txm.statsengine.r.rcp.views.RVariablesView; |
71 | 71 |
import org.txm.utils.logger.Log; |
72 |
|
|
72 | 73 |
/** |
73 | 74 |
* display the lexical table tools to merge/delete lines or columns and display |
74 | 75 |
* the lexical table too |
75 | 76 |
* |
76 | 77 |
* @author mdecorde |
77 | 78 |
*/ |
78 |
public class LexicalTableEditor extends TXMEditor<LexicalTable> { |
|
79 |
|
|
79 |
public class LexicalTableEditor extends TXMEditor<LexicalTable> { |
|
80 | 80 |
|
81 |
|
|
81 | 82 |
public static final String ID = LexicalTableEditor.class.getName(); |
82 | 83 |
|
83 | 84 |
/** The table. */ |
... | ... | |
86 | 87 |
// params |
87 | 88 |
/** The line table viewer. */ |
88 | 89 |
TableViewer viewer; |
89 |
|
|
90 |
|
|
90 | 91 |
/** The form column. */ |
91 | 92 |
TableViewerColumn unitColumn; |
92 |
|
|
93 |
|
|
93 | 94 |
/** The freq column. */ |
94 | 95 |
TableViewerColumn freqColumn; |
95 |
|
|
96 |
|
|
96 | 97 |
/** The cols. */ |
97 | 98 |
private List<double[]> cols; |
98 |
|
|
99 |
|
|
99 | 100 |
/** The rows. */ |
100 | 101 |
private List<String> rows; |
101 |
|
|
102 |
|
|
102 | 103 |
/** The collist. */ |
103 | 104 |
List<Object> collist; |
104 |
|
|
105 |
|
|
105 | 106 |
/** The previous sorted col. */ |
106 | 107 |
private int previousSortedCol; |
108 |
|
|
107 | 109 |
boolean DEFAULTREVERSE = false; |
110 |
|
|
108 | 111 |
boolean reverse = DEFAULTREVERSE; |
109 |
|
|
110 |
|
|
112 |
|
|
113 |
|
|
111 | 114 |
private Label infoLine; |
112 |
|
|
115 |
|
|
113 | 116 |
/** |
114 | 117 |
* Button to merge or delete some rows. |
115 | 118 |
*/ |
... | ... | |
119 | 122 |
* Button to merge or delete some columns. |
120 | 123 |
*/ |
121 | 124 |
protected Button mergeDeleteColumnsButton; |
122 |
|
|
123 | 125 |
|
124 |
|
|
125 |
// FIXME: SJ: viewer comparator tests |
|
126 |
// /** |
|
127 |
// * Viewer comparator for sorting. |
|
128 |
// */ |
|
129 |
// protected LexicalTableLinesViewerComparator viewerComparator; |
|
130 |
|
|
131 | 126 |
|
132 | 127 |
|
128 |
// FIXME: SJ: viewer comparator tests |
|
129 |
// /** |
|
130 |
// * Viewer comparator for sorting. |
|
131 |
// */ |
|
132 |
// protected LexicalTableLinesViewerComparator viewerComparator; |
|
133 |
|
|
134 |
|
|
135 |
|
|
133 | 136 |
/** |
134 | 137 |
* Unit property. |
135 | 138 |
*/ |
136 |
@Parameter(key=LexicalTablePreferences.UNIT_PROPERTY)
|
|
139 |
@Parameter(key = LexicalTablePreferences.UNIT_PROPERTY)
|
|
137 | 140 |
protected PropertiesComboViewer unitPropertyComboViewer; |
138 |
|
|
139 | 141 |
|
142 |
|
|
140 | 143 |
/** |
141 | 144 |
* Minimum frequency filter spinner. |
142 | 145 |
*/ |
143 |
@Parameter(key=LexicalTablePreferences.F_MIN)
|
|
146 |
@Parameter(key = LexicalTablePreferences.F_MIN)
|
|
144 | 147 |
protected Spinner fMinSpinner; |
145 |
|
|
148 |
|
|
146 | 149 |
/** |
147 | 150 |
* Maximum numbers of lines spinner. |
148 | 151 |
*/ |
149 |
@Parameter(key=LexicalTablePreferences.V_MAX)
|
|
152 |
@Parameter(key = LexicalTablePreferences.V_MAX)
|
|
150 | 153 |
protected Spinner vMaxSpinner; |
151 | 154 |
|
152 | 155 |
/** |
... | ... | |
164 | 167 |
// Main parameters |
165 | 168 |
GLComposite mainParametersArea = this.getMainParametersComposite(); |
166 | 169 |
mainParametersArea.getLayout().numColumns = 2; |
167 |
|
|
170 |
|
|
168 | 171 |
// unit property |
169 | 172 |
new Label(mainParametersArea, SWT.NONE).setText(TXMCoreMessages.common_property); |
170 | 173 |
this.unitPropertyComboViewer = new PropertiesComboViewer( |
... | ... | |
174 | 177 |
CQPCorpus.getFirstParentCorpus(this.getResult()).getOrderedProperties(), |
175 | 178 |
this.getResult().getProperty(), |
176 | 179 |
false); |
177 |
|
|
178 |
// disable the property selection on Lexical table created from partition index
|
|
180 |
|
|
181 |
// disable the property selection on Lexical table created from partition index |
|
179 | 182 |
if (this.getResult().getParent() instanceof PartitionIndex) { |
180 | 183 |
this.unitPropertyComboViewer.getCombo().setEnabled(false); |
181 | 184 |
} |
... | ... | |
185 | 188 |
Composite extendedParametersArea = this.getExtendedParametersGroup(); |
186 | 189 |
|
187 | 190 |
// FIXME: SJ: became useless? Apply button |
188 |
// Button keepTop = new Button(extendedParametersArea, SWT.PUSH); |
|
189 |
// keepTop.setText(LexicalTableUIMessages.LexicalTableEditor_4); |
|
190 |
// keepTop.addSelectionListener(new SelectionListener() { |
|
191 |
// @Override |
|
192 |
// public void widgetSelected(SelectionEvent e) { |
|
193 |
// StatusLine.setMessage(LexicalTableUIMessages.LexicalTableEditor_16); |
|
194 |
// System.out.println(NLS.bind(LexicalTableUIMessages.LexicalTableEditor_5, vMaxFilterSpinner.getSelection(), fMinFilterSpinner.getSelection())); |
|
195 |
// |
|
196 |
// MessageBox messageBox = new MessageBox(e.display.getActiveShell(), SWT.ICON_QUESTION | SWT.YES | SWT.NO); |
|
197 |
// messageBox.setMessage(TXMUIMessages.common_areYouSure); |
|
198 |
// int response = messageBox.open(); |
|
199 |
// if (response != SWT.YES) { |
|
200 |
// return; |
|
201 |
// } |
|
202 |
// |
|
203 |
// try { |
|
204 |
//// updateResultFromEditor(); |
|
205 |
//// refresh(false); |
|
206 |
// // force the recomputing |
|
207 |
// getResult().setDirty(); |
|
208 |
// compute(true); |
|
209 |
// } catch (Exception e1) { |
|
210 |
// // TODO Auto-generated catch block |
|
211 |
// org.txm.utils.logger.Log.printStackTrace(e1); |
|
212 |
// StatusLine.setMessage("LexicalTable: sorting error."); //$NON-NLS-1$ |
|
213 |
// } |
|
214 |
// } |
|
215 |
// |
|
216 |
// @Override |
|
217 |
// public void widgetDefaultSelected(SelectionEvent e) { |
|
218 |
// } |
|
219 |
// }); |
|
220 |
|
|
191 |
// Button keepTop = new Button(extendedParametersArea, SWT.PUSH); |
|
192 |
// keepTop.setText(LexicalTableUIMessages.LexicalTableEditor_4); |
|
193 |
// keepTop.addSelectionListener(new SelectionListener() { |
|
194 |
// @Override |
|
195 |
// public void widgetSelected(SelectionEvent e) { |
|
196 |
// StatusLine.setMessage(LexicalTableUIMessages.LexicalTableEditor_16); |
|
197 |
// System.out.println(NLS.bind(LexicalTableUIMessages.LexicalTableEditor_5, vMaxFilterSpinner.getSelection(), fMinFilterSpinner.getSelection())); |
|
198 |
// |
|
199 |
// MessageBox messageBox = new MessageBox(e.display.getActiveShell(), SWT.ICON_QUESTION | SWT.YES | SWT.NO); |
|
200 |
// messageBox.setMessage(TXMUIMessages.common_areYouSure); |
|
201 |
// int response = messageBox.open(); |
|
202 |
// if (response != SWT.YES) { |
|
203 |
// return; |
|
204 |
// } |
|
205 |
// |
|
206 |
// try { |
|
207 |
//// updateResultFromEditor(); |
|
208 |
//// refresh(false); |
|
209 |
// // force the recomputing |
|
210 |
// getResult().setDirty(); |
|
211 |
// compute(true); |
|
212 |
// } catch (Exception e1) { |
|
213 |
// // TODO Auto-generated catch block |
|
214 |
// org.txm.utils.logger.Log.printStackTrace(e1); |
|
215 |
// StatusLine.setMessage("LexicalTable: sorting error."); //$NON-NLS-1$ |
|
216 |
// } |
|
217 |
// } |
|
218 |
// |
|
219 |
// @Override |
|
220 |
// public void widgetDefaultSelected(SelectionEvent e) { |
|
221 |
// } |
|
222 |
// }); |
|
221 | 223 |
|
224 |
|
|
222 | 225 |
// thresholds |
223 | 226 |
ThresholdsGroup thresholdsGroup = new ThresholdsGroup(this.getExtendedParametersGroup(), SWT.NONE, this, true, false); |
224 | 227 |
this.fMinSpinner = thresholdsGroup.getFMinSpinner(); |
... | ... | |
229 | 232 |
mergeDeleteColumnsButton = new Button(extendedParametersArea, SWT.PUSH); |
230 | 233 |
mergeDeleteColumnsButton.setText(LexicalTableUIMessages.mergeOrDeleteColumns); |
231 | 234 |
mergeDeleteColumnsButton.addSelectionListener(new SelectionListener() { |
235 |
|
|
232 | 236 |
@Override |
233 | 237 |
public void widgetSelected(SelectionEvent e) { |
234 | 238 |
StatusLine.setMessage(LexicalTableUIMessages.mergingLines); |
235 | 239 |
ArrayList<Object> selection = new ArrayList<Object>(); |
236 | 240 |
MergeDeleteDialog d = new MergeDeleteDialog(e.display.getActiveShell(), new ArrayList<Object>(collist), selection, -1); |
237 |
|
|
241 |
|
|
238 | 242 |
if (d.open() == Window.OK) { |
239 | 243 |
List<Integer> colindices = new ArrayList<Integer>(); |
240 | 244 |
for (int i = 0; i < collist.size(); i++) { |
... | ... | |
242 | 246 |
colindices.add(i); |
243 | 247 |
} |
244 | 248 |
} |
245 |
|
|
249 |
|
|
246 | 250 |
if (d.doMerge()) { |
247 | 251 |
|
248 | 252 |
int nrows; |
249 | 253 |
try { |
250 | 254 |
nrows = lexicalTable.getNRows(); |
251 |
} catch (Exception e2) { |
|
255 |
} |
|
256 |
catch (Exception e2) { |
|
252 | 257 |
// TODO Auto-generated catch block |
253 | 258 |
e2.printStackTrace(); |
254 | 259 |
return; |
255 | 260 |
} |
256 | 261 |
String newname = d.getMergeName(); |
257 |
|
|
262 |
|
|
258 | 263 |
Log.fine(NLS.bind(LexicalTableUIMessages.mergeColsColonP0, colindices)); |
259 | 264 |
|
260 | 265 |
double[] firstcol = cols.get(colindices.get(0)); |
261 |
|
|
266 |
|
|
262 | 267 |
// merge selected cols into the first one |
263 | 268 |
for (int i = 1; i < colindices.size(); i++) { |
264 | 269 |
for (int j = 0; j < nrows; j++) { |
265 | 270 |
firstcol[j] += cols.get(colindices.get(i))[j]; |
266 | 271 |
} |
267 | 272 |
} |
268 |
|
|
273 |
|
|
269 | 274 |
// update first col of the Lexical table |
270 | 275 |
for (int j = 0; j < nrows; j++) { |
271 | 276 |
lexicalTable.getData().set(j, colindices.get(0), firstcol[j]); |
272 | 277 |
} |
273 |
|
|
278 |
|
|
274 | 279 |
// and its name |
275 | 280 |
lexicalTable.getColNames().setString(colindices.get(0), newname); |
276 |
|
|
281 |
|
|
277 | 282 |
// keep only the first col |
278 | 283 |
List<Integer> coltodelete = colindices.subList(1, colindices.size()); |
279 | 284 |
lexicalTable.getData().removeCols(coltodelete); |
... | ... | |
285 | 290 |
for (String colname : lexicalTable.getColNames().asStringsArray()) { |
286 | 291 |
collist.add(colname); |
287 | 292 |
} |
288 |
} catch (StatException e1) { |
|
293 |
} |
|
294 |
catch (StatException e1) { |
|
289 | 295 |
org.txm.utils.logger.Log.printStackTrace(e1); |
290 | 296 |
return; |
291 | 297 |
} |
292 |
|
|
298 |
|
|
293 | 299 |
Collections.sort(colindices);// update table viewer cols |
294 | 300 |
for (int i = colindices.size() - 1; i >= 1; i--) { |
295 | 301 |
viewer.getTable().getColumns()[colindices.get(i) + 3].dispose();// +3 = separator, |
... | ... | |
311 | 317 |
for (String colname : colnames.asStringsArray()) { |
312 | 318 |
collist.add(colname); |
313 | 319 |
} |
314 |
} catch (StatException e1) { |
|
320 |
} |
|
321 |
catch (StatException e1) { |
|
315 | 322 |
org.txm.utils.logger.Log.printStackTrace(e1); |
316 | 323 |
return; |
317 | 324 |
} |
318 |
|
|
325 |
|
|
319 | 326 |
Collections.sort(colindices); |
320 | 327 |
for (int i = colindices.size() - 1; i >= 0; i--) { |
321 | 328 |
viewer.getTable().getColumns()[colindices.get(i) + 3].dispose(); |
... | ... | |
325 | 332 |
} |
326 | 333 |
StatusLine.setMessage(""); //$NON-NLS-1$ |
327 | 334 |
} |
328 |
|
|
335 |
|
|
329 | 336 |
@Override |
330 |
public void widgetDefaultSelected(SelectionEvent e) { |
|
331 |
} |
|
337 |
public void widgetDefaultSelected(SelectionEvent e) {} |
|
332 | 338 |
}); |
333 |
|
|
339 |
|
|
334 | 340 |
// Merge or delete lines button |
335 | 341 |
mergeDeleteRowsButton = new Button(extendedParametersArea, SWT.PUSH); |
336 | 342 |
mergeDeleteRowsButton.setText(LexicalTableUIMessages.mergeOrDeleteRows); |
337 | 343 |
mergeDeleteRowsButton.addSelectionListener(new SelectionListener() { |
344 |
|
|
338 | 345 |
@Override |
339 | 346 |
public void widgetSelected(SelectionEvent e) { |
340 |
|
|
347 |
|
|
341 | 348 |
ArrayList<Object> selection = new ArrayList<Object>(); |
342 | 349 |
MergeDeleteDialog d = new MergeDeleteDialog(e.display |
343 | 350 |
.getActiveShell(), new ArrayList<Object>(rows), |
... | ... | |
351 | 358 |
count++; |
352 | 359 |
} |
353 | 360 |
} |
354 |
|
|
361 |
|
|
355 | 362 |
if (d.doMerge()) { |
356 | 363 |
MergeLines.mergeLines(LexicalTableEditor.this, d.getMergeName(), rowindices); |
357 |
} else { |
|
364 |
} |
|
365 |
else { |
|
358 | 366 |
lexicalTable.getData().removeRows(rowindices); |
359 | 367 |
compute(false); |
360 | 368 |
} |
361 | 369 |
lexicalTable.setAltered(); |
362 | 370 |
} |
363 | 371 |
} |
364 |
|
|
372 |
|
|
365 | 373 |
@Override |
366 |
public void widgetDefaultSelected(SelectionEvent e) { |
|
367 |
} |
|
374 |
public void widgetDefaultSelected(SelectionEvent e) {} |
|
368 | 375 |
}); |
369 | 376 |
|
370 | 377 |
// Result area |
... | ... | |
373 | 380 |
GridData gd = new GridData(GridData.FILL_BOTH); |
374 | 381 |
gd.grabExcessVerticalSpace = true; |
375 | 382 |
gd.grabExcessHorizontalSpace = true; |
376 |
//gd.horizontalSpan = 2; |
|
383 |
// gd.horizontalSpan = 2;
|
|
377 | 384 |
resultArea.setLayoutData(gd); |
378 | 385 |
|
379 | 386 |
viewer = new TableViewer(resultArea, SWT.VIRTUAL | SWT.MULTI | SWT.FULL_SELECTION | SWT.BORDER); |
380 | 387 |
viewer.getTable().addKeyListener(new TableKeyListener(viewer)); |
381 | 388 |
viewer.getTable().setLinesVisible(true); |
382 | 389 |
viewer.getTable().setHeaderVisible(true); |
383 |
|
|
384 | 390 |
|
385 |
//viewer.setContentProvider(ArrayContentProvider.getInstance()); |
|
386 |
|
|
391 |
|
|
392 |
// viewer.setContentProvider(ArrayContentProvider.getInstance()); |
|
393 |
|
|
387 | 394 |
// FIXME: viewer comparator tests |
388 | 395 |
// creates the viewer comparator |
389 |
// this.viewerComparator = new LexicalTableLinesViewerComparator(Toolbox.getCollator(this.getResult()));
|
|
390 |
// viewer.setComparator(this.viewerComparator);
|
|
391 |
|
|
396 |
// this.viewerComparator = new LexicalTableLinesViewerComparator(Toolbox.getCollator(this.getResult()));
|
|
397 |
// viewer.setComparator(this.viewerComparator);
|
|
398 |
|
|
392 | 399 |
// FIXME: we must use this line rather than the LineContentProvider class |
393 |
//viewer.setContentProvider(ArrayContentProvider.getInstance()); |
|
400 |
// viewer.setContentProvider(ArrayContentProvider.getInstance());
|
|
394 | 401 |
viewer.setContentProvider(new LineContentProvider()); |
395 |
|
|
396 | 402 |
|
403 |
|
|
397 | 404 |
viewer.getTable().setLayoutData(new GridData(GridData.FILL_BOTH)); |
398 | 405 |
|
399 | 406 |
// first dummy column |
... | ... | |
404 | 411 |
unitColumn = new TableViewerColumn(viewer, SWT.LEFT); |
405 | 412 |
unitColumn.getColumn().addSelectionListener(new ColumnSelectionListener(this, unitColumn, -2)); |
406 | 413 |
// FIXME: viewer comparator tests |
407 |
//viewerComparator.addSelectionAdapter(viewer, unitColumn.getColumn(), 1); |
|
414 |
// viewerComparator.addSelectionAdapter(viewer, unitColumn.getColumn(), 1);
|
|
408 | 415 |
|
409 | 416 |
// frequency column |
410 | 417 |
freqColumn = new TableViewerColumn(viewer, SWT.LEFT); |
411 | 418 |
freqColumn.getColumn().setText(TXMCoreMessages.common_frequency); |
412 | 419 |
freqColumn.getColumn().addSelectionListener(new ColumnSelectionListener(this, freqColumn, -1)); |
413 | 420 |
// FIXME: viewer comparator tests |
414 |
//viewerComparator.addSelectionAdapter(viewer, freqColumn.getColumn(), 2); |
|
415 |
|
|
421 |
// viewerComparator.addSelectionAdapter(viewer, freqColumn.getColumn(), 2);
|
|
422 |
|
|
416 | 423 |
// Register the context menu |
417 | 424 |
TXMEditor.initContextMenu(this.viewer.getTable(), this.getSite(), this.viewer); // $NON-NLS-1$ |
418 |
|
|
425 |
|
|
419 | 426 |
// adjust UI to the original sorting |
420 | 427 |
viewer.getTable().setSortColumn(unitColumn.getColumn()); |
421 | 428 |
viewer.getTable().setSortDirection(SWT.UP); |
422 |
|
|
429 |
|
|
423 | 430 |
infoLine = new Label(getBottomToolbar().getParent(), SWT.NONE); |
424 | 431 |
} |
425 | 432 |
catch (Exception e) { |
... | ... | |
427 | 434 |
e.printStackTrace(); |
428 | 435 |
} |
429 | 436 |
} |
430 |
|
|
431 |
|
|
437 |
|
|
438 |
|
|
432 | 439 |
/** |
433 | 440 |
* |
434 | 441 |
* @throws StatException |
... | ... | |
437 | 444 |
private void refreshColNames() throws StatException, CqiClientException { |
438 | 445 |
TableColumn[] cols = viewer.getTable().getColumns(); |
439 | 446 |
String[] colnames = lexicalTable.getColNames().asStringsArray(); |
440 |
|
|
441 |
for (int i = 0 ; i < cols.length ; i++) {
|
|
442 |
cols[i].setText(colnames[i]+ "T="+lexicalTable.getPartition().getParts().get(i).getSize()); //$NON-NLS-1$
|
|
447 |
|
|
448 |
for (int i = 0; i < cols.length; i++) {
|
|
449 |
cols[i].setText(colnames[i] + "T=" + lexicalTable.getPartition().getParts().get(i).getSize()); //$NON-NLS-1$
|
|
443 | 450 |
} |
444 | 451 |
} |
445 |
|
|
452 |
|
|
446 | 453 |
public void setContentDescription(String desc) { |
447 | 454 |
infoLine.setText(desc); |
448 | 455 |
infoLine.update(); |
... | ... | |
454 | 461 |
*/ |
455 | 462 |
public void refreshInfos() { |
456 | 463 |
try { |
457 |
this.setContentDescription(TXMCoreMessages.bind(LexicalTableUIMessages.tP0vP1fminP2fmaxP3, lexicalTable.getData().getTotal(), lexicalTable.getData().getNRows(), lexicalTable.getData().getFMin(), lexicalTable.getData().getFMax())); |
|
458 |
} catch (Exception e3) { |
|
464 |
this.setContentDescription(TXMCoreMessages.bind(LexicalTableUIMessages.tP0vP1fminP2fmaxP3, lexicalTable.getData().getTotal(), lexicalTable.getData().getNRows(), lexicalTable.getData() |
|
465 |
.getFMin(), lexicalTable.getData().getFMax())); |
|
466 |
} |
|
467 |
catch (Exception e3) { |
|
459 | 468 |
org.txm.utils.logger.Log.printStackTrace(e3); |
460 | 469 |
} |
461 | 470 |
} |
462 |
|
|
471 |
|
|
463 | 472 |
public void refreshTable() { |
464 | 473 |
this.refreshTable(false); |
465 | 474 |
} |
... | ... | |
470 | 479 |
// FIXME: SJ: not optimized, need to mix the update/not update code and do not remove column each computing, only when needed |
471 | 480 |
// FIXME: SJ: + usine à gaz... virer la variable "collist" |
472 | 481 |
public void refreshTable(boolean update) { |
473 |
|
|
474 | 482 |
|
483 |
|
|
475 | 484 |
this.viewer.getControl().setRedraw(false); |
476 | 485 |
|
477 | 486 |
// removing old columns |
... | ... | |
483 | 492 |
|
484 | 493 |
collist = new ArrayList<Object>(); |
485 | 494 |
|
486 |
if(this.lexicalTable.getProperty() != null) {
|
|
495 |
if (this.lexicalTable.getProperty() != null) {
|
|
487 | 496 |
unitColumn.getColumn().setText(this.lexicalTable.getProperty().getName()); |
488 | 497 |
} |
489 | 498 |
|
... | ... | |
492 | 501 |
String[] colNames; |
493 | 502 |
int[] colMargins = null; |
494 | 503 |
// from lexical table if they exist |
495 |
if (lexicalTable.getData() != null) {
|
|
504 |
if (lexicalTable.getData() != null) {
|
|
496 | 505 |
colNames = lexicalTable.getColNames().asStringsArray(); |
497 | 506 |
colMargins = lexicalTable.getColMarginsVector().asIntArray(); |
498 | 507 |
} |
499 | 508 |
// otherwise from partition parts names |
500 |
else {
|
|
509 |
else {
|
|
501 | 510 |
colNames = this.getResult().getPartition().getPartNames().toArray(new String[0]); |
502 | 511 |
} |
503 | 512 |
|
... | ... | |
505 | 514 |
TableViewerColumn column = new TableViewerColumn(viewer, SWT.RIGHT); |
506 | 515 |
column.getColumn().addSelectionListener(new ColumnSelectionListener(this, column, i)); |
507 | 516 |
// FIXME: viewer comparator tests |
508 |
//viewerComparator.addSelectionAdapter(viewer, column.getColumn(), i + 2); |
|
517 |
// viewerComparator.addSelectionAdapter(viewer, column.getColumn(), i + 2);
|
|
509 | 518 |
|
510 | 519 |
String colName = colNames[i]; |
511 | 520 |
column.getColumn().setToolTipText(colName); |
512 | 521 |
collist.add(colName); |
513 | 522 |
|
514 |
if(colMargins != null) {
|
|
523 |
if (colMargins != null) {
|
|
515 | 524 |
colName += " t=" + colMargins[i]; //$NON-NLS-1$ |
516 | 525 |
} |
517 | 526 |
|
... | ... | |
523 | 532 |
// TODO Auto-generated catch block |
524 | 533 |
e.printStackTrace(); |
525 | 534 |
} |
526 |
|
|
527 |
|
|
528 |
if(this.lexicalTable.hasBeenComputedOnce()) {
|
|
535 |
|
|
536 |
|
|
537 |
if (this.lexicalTable.hasBeenComputedOnce()) {
|
|
529 | 538 |
LineLabelProvider labelprovider = new LineLabelProvider(this.lexicalTable); |
530 | 539 |
this.viewer.setLabelProvider(labelprovider); |
531 | 540 |
this.cols = labelprovider.getCols(); |
... | ... | |
533 | 542 |
this.viewer.setInput(this.lexicalTable); |
534 | 543 |
|
535 | 544 |
// initial sorting |
536 |
if(!update) {
|
|
545 |
if (!update) {
|
|
537 | 546 |
this.sort(unitColumn, -2); |
538 | 547 |
} |
539 | 548 |
} |
540 |
|
|
541 | 549 |
|
550 |
|
|
542 | 551 |
this.viewer.getControl().setRedraw(true); |
543 |
|
|
544 | 552 |
|
553 |
|
|
545 | 554 |
// Refresh and pack the columns |
546 | 555 |
TXMEditor.packColumns(this.viewer); |
547 | 556 |
|
... | ... | |
550 | 559 |
|
551 | 560 |
|
552 | 561 |
} |
553 |
|
|
554 | 562 |
|
563 |
|
|
555 | 564 |
/** |
556 | 565 |
* Sets the col comparator. |
557 | 566 |
* |
... | ... | |
571 | 580 |
* currentComparator.initialize(cooc.getCorpus()); |
572 | 581 |
*/ |
573 | 582 |
} |
574 |
|
|
583 |
|
|
575 | 584 |
/** |
576 | 585 |
* Gets the corpus. |
577 | 586 |
* |
... | ... | |
580 | 589 |
public CQPCorpus getCorpus() { |
581 | 590 |
return null; |
582 | 591 |
} |
583 |
|
|
584 |
|
|
585 |
|
|
592 |
|
|
593 |
|
|
594 |
|
|
586 | 595 |
/** |
587 | 596 |
* Gets the line table viewer. |
588 | 597 |
* |
... | ... | |
591 | 600 |
public TableViewer getlineTableViewer() { |
592 | 601 |
return viewer; |
593 | 602 |
} |
594 |
|
|
603 |
|
|
595 | 604 |
/** |
596 | 605 |
* Gets the lexical table. |
597 | 606 |
* |
... | ... | |
600 | 609 |
public LexicalTable getLexicalTable() { |
601 | 610 |
return lexicalTable; |
602 | 611 |
} |
603 |
|
|
612 |
|
|
604 | 613 |
/** |
605 | 614 |
* Gets the cols. |
606 | 615 |
* |
... | ... | |
609 | 618 |
public List<double[]> getCols() { |
610 | 619 |
return cols; |
611 | 620 |
} |
612 |
|
|
621 |
|
|
613 | 622 |
/** |
614 | 623 |
* Export data. |
615 | 624 |
* |
616 | 625 |
* @param file the file |
617 | 626 |
*/ |
618 |
@Deprecated
|
|
627 |
@Deprecated |
|
619 | 628 |
public void exportData(File file) { |
620 |
lexicalTable.getData().toTxt(file, TXMPreferences.DEFAULT_ENCODING, "\t", ""); //$NON-NLS-1$
|
|
629 |
lexicalTable.getData().toTxt(file, TXMPreferences.DEFAULT_ENCODING, "\t", ""); //$NON-NLS-1$ |
|
621 | 630 |
} |
622 |
|
|
631 |
|
|
623 | 632 |
/** |
624 | 633 |
* Import data. |
625 | 634 |
* |
626 | 635 |
* @param file the file |
627 | 636 |
*/ |
628 |
@Deprecated
|
|
637 |
@Deprecated |
|
629 | 638 |
public void importData(File file) { |
630 | 639 |
try { |
631 | 640 |
String encoding = TBXPreferences.getInstance().getString(TBXPreferences.EXPORT_ENCODING); |
... | ... | |
639 | 648 |
TableColumn[] cols = viewer.getTable().getColumns(); |
640 | 649 |
int ncol = cols.length - 3; |
641 | 650 |
if (colnames.length != ncol) { |
642 |
//Log.severe(LexicalTableUIMessages.bind(LexicalTableUIMessages.errorColonDifferentColumnsNumberColonBeforeP0AfterP1, ncol, colnames.length)); |
|
651 |
// Log.severe(LexicalTableUIMessages.bind(LexicalTableUIMessages.errorColonDifferentColumnsNumberColonBeforeP0AfterP1, ncol, colnames.length));
|
|
643 | 652 |
LexicalTable r = getResult(); |
644 | 653 |
close(); |
645 | 654 |
TXMEditor.openEditor(r, LexicalTableEditor.ID); |
646 | 655 |
return; |
647 | 656 |
} |
648 |
for (int i = 0; i < colnames.length ; i++) {
|
|
649 |
//System.out.println("set col name "+colnames[i]); |
|
657 |
for (int i = 0; i < colnames.length; i++) { |
|
658 |
// System.out.println("set col name "+colnames[i]);
|
|
650 | 659 |
cols[3 + i].setText(colnames[i]); |
651 | 660 |
} |
652 | 661 |
viewer.refresh(); |
653 | 662 |
viewer.setInput(lexicalTable); |
654 | 663 |
viewer.getTable().getParent().layout(); |
655 | 664 |
refreshTable(false); |
656 |
} else { |
|
665 |
} |
|
666 |
else { |
|
657 | 667 |
Log.severe(LexicalTableUIMessages.failedToImportLexicalTable); |
658 | 668 |
} |
659 |
} catch(Exception e) { |
|
669 |
} |
|
670 |
catch (Exception e) { |
|
660 | 671 |
Log.severe(LexicalTableUIMessages.bind(LexicalTableUIMessages.errorWhileImportingDataColonP0, e)); |
661 | 672 |
org.txm.utils.logger.Log.printStackTrace(e); |
662 | 673 |
} |
663 | 674 |
} |
664 |
|
|
665 |
|
|
666 |
|
|
667 |
/** |
|
668 |
* Sort. |
|
669 |
* |
|
670 |
* @param col the col |
|
671 |
* @param index the index |
|
672 |
*/ |
|
673 |
// FIXME: SJ: try to use a ViewerSorter instead of this but also manage the result sorting for export |
|
674 |
public void sort(TableViewerColumn col, int index) { |
|
675 |
|
|
676 |
if (index == previousSortedCol) { |
|
677 |
reverse = !reverse; |
|
678 |
} else { |
|
679 |
reverse = DEFAULTREVERSE; |
|
675 |
|
|
676 |
|
|
677 |
|
|
678 |
/** |
|
679 |
* Sort. |
|
680 |
* |
|
681 |
* @param col the col |
|
682 |
* @param index the index |
|
683 |
*/ |
|
684 |
// FIXME: SJ: try to use a ViewerSorter instead of this but also manage the result sorting for export |
|
685 |
public void sort(TableViewerColumn col, int index) { |
|
686 |
|
|
687 |
if (index == previousSortedCol) { |
|
688 |
reverse = !reverse; |
|
689 |
} |
|
690 |
else { |
|
691 |
reverse = DEFAULTREVERSE; |
|
692 |
} |
|
693 |
|
|
694 |
if (index == -2) {// rownames |
|
695 |
lexicalTable.getData().sortRowNames(reverse); |
|
696 |
} |
|
697 |
else if (index == -1) { // freqs |
|
698 |
try { |
|
699 |
lexicalTable.getData().sortByFreqs(reverse); |
|
700 |
StatusLine.setMessage(TXMUIMessages.sortDone); |
|
680 | 701 |
} |
681 |
|
|
682 |
if (index == -2) {// rownames |
|
683 |
lexicalTable.getData().sortRowNames(reverse); |
|
684 |
} else if (index == -1) { // freqs |
|
685 |
try { |
|
686 |
lexicalTable.getData().sortByFreqs(reverse); |
|
687 |
StatusLine.setMessage(TXMUIMessages.sortDone); |
|
688 |
} catch (Exception e2) { |
|
689 |
org.txm.utils.logger.Log.printStackTrace(e2); |
|
690 |
} |
|
691 |
} else if (index >= 0) { |
|
692 |
lexicalTable.getData().sort(index, reverse); |
|
702 |
catch (Exception e2) { |
|
703 |
org.txm.utils.logger.Log.printStackTrace(e2); |
|
693 | 704 |
} |
694 |
|
|
695 |
previousSortedCol = index; |
|
696 |
|
|
697 |
refreshTable(true); |
|
698 |
|
|
699 |
//viewer.getTable().setSortColumn(col.getColumn()); |
|
700 |
viewer.getTable().setSortColumn(viewer.getTable().getColumn(index + 3)); |
|
701 |
|
|
702 |
if (reverse) { |
|
703 |
viewer.getTable().setSortDirection(SWT.DOWN); |
|
704 |
} |
|
705 |
else { |
|
706 |
viewer.getTable().setSortDirection(SWT.UP); |
|
707 |
} |
|
708 |
|
|
709 |
// Refresh and pack the columns |
|
710 |
TXMEditor.packColumns(this.viewer); |
|
711 |
|
|
712 | 705 |
} |
706 |
else if (index >= 0) { |
|
707 |
lexicalTable.getData().sort(index, reverse); |
|
708 |
} |
|
713 | 709 |
|
714 |
|
|
715 |
@Override |
|
710 |
previousSortedCol = index; |
|
711 |
|
|
712 |
refreshTable(true); |
|
713 |
|
|
714 |
// viewer.getTable().setSortColumn(col.getColumn()); |
|
715 |
viewer.getTable().setSortColumn(viewer.getTable().getColumn(index + 3)); |
|
716 |
|
|
717 |
if (reverse) { |
|
718 |
viewer.getTable().setSortDirection(SWT.DOWN); |
|
719 |
} |
|
720 |
else { |
|
721 |
viewer.getTable().setSortDirection(SWT.UP); |
|
722 |
} |
|
723 |
|
|
724 |
// Refresh and pack the columns |
|
725 |
TXMEditor.packColumns(this.viewer); |
|
726 |
|
|
727 |
} |
|
728 |
|
|
729 |
|
|
730 |
@Override |
|
716 | 731 |
public void updateEditorFromResult(boolean update) { |
717 |
|
|
718 |
// enable/disable the edition buttons according to the computed state
|
|
732 |
|
|
733 |
// enable/disable the edition buttons according to the computed state |
|
719 | 734 |
if (this.lexicalTable.getData() != null) { |
720 | 735 |
this.mergeDeleteColumnsButton.setEnabled(true); |
721 | 736 |
this.mergeDeleteRowsButton.setEnabled(true); |
722 |
|
|
737 |
|
|
723 | 738 |
this.refreshInfos(); |
724 | 739 |
} |
725 | 740 |
else { |
726 | 741 |
this.mergeDeleteColumnsButton.setEnabled(false); |
727 | 742 |
this.mergeDeleteRowsButton.setEnabled(false); |
728 | 743 |
} |
729 |
|
|
744 |
|
|
730 | 745 |
this.refreshTable(update); |
731 |
|
|
746 |
|
|
732 | 747 |
QueriesView.refresh(); |
733 | 748 |
RVariablesView.refresh(); |
734 | 749 |
} |
735 |
|
|
736 |
|
|
750 |
|
|
751 |
|
|
737 | 752 |
@Override |
738 | 753 |
public void updateResultFromEditor() { |
739 |
//FIXME: SJ: needs to manage here the merge/deletion of rows and columns |
|
754 |
// FIXME: SJ: needs to manage here the merge/deletion of rows and columns
|
|
740 | 755 |
} |
741 |
} |
|
756 |
} |
Also available in: Unified diff