29 |
29 |
|
30 |
30 |
import java.io.File;
|
31 |
31 |
import java.util.ArrayList;
|
|
32 |
import java.util.Arrays;
|
32 |
33 |
import java.util.Collections;
|
33 |
34 |
import java.util.Comparator;
|
|
35 |
import java.util.HashSet;
|
34 |
36 |
import java.util.List;
|
35 |
37 |
|
|
38 |
import org.eclipse.jface.viewers.ISelectionChangedListener;
|
|
39 |
import org.eclipse.jface.viewers.SelectionChangedEvent;
|
|
40 |
import org.eclipse.jface.viewers.StructuredSelection;
|
36 |
41 |
import org.eclipse.jface.viewers.TableViewer;
|
37 |
42 |
import org.eclipse.jface.viewers.TableViewerColumn;
|
38 |
43 |
import org.eclipse.jface.window.Window;
|
... | ... | |
80 |
85 |
* @author mdecorde
|
81 |
86 |
*/
|
82 |
87 |
public class LexicalTableEditor extends TXMEditor<LexicalTable> {
|
83 |
|
|
84 |
|
|
|
88 |
|
|
89 |
|
85 |
90 |
public static final String ID = LexicalTableEditor.class.getName();
|
86 |
|
|
|
91 |
|
87 |
92 |
/** The table. */
|
88 |
93 |
LexicalTable lexicalTable;
|
89 |
|
|
|
94 |
|
90 |
95 |
// params
|
91 |
96 |
/** The line table viewer. */
|
92 |
97 |
TableViewer viewer;
|
93 |
|
|
|
98 |
|
94 |
99 |
/** The form column. */
|
95 |
100 |
TableViewerColumn unitColumn;
|
96 |
|
|
|
101 |
|
97 |
102 |
/** The freq column. */
|
98 |
103 |
TableViewerColumn freqColumn;
|
99 |
|
|
|
104 |
|
100 |
105 |
/** The cols. */
|
101 |
106 |
private List<double[]> cols;
|
102 |
|
|
|
107 |
|
103 |
108 |
/** The rows. */
|
104 |
109 |
private List<String> rows;
|
105 |
|
|
|
110 |
|
106 |
111 |
/** The collist. */
|
107 |
112 |
List<Object> collist;
|
108 |
|
|
|
113 |
|
109 |
114 |
/** The previous sorted col. */
|
110 |
115 |
private int previousSortedCol;
|
111 |
|
|
|
116 |
|
112 |
117 |
boolean DEFAULTREVERSE = false;
|
113 |
|
|
|
118 |
|
114 |
119 |
boolean reverse = DEFAULTREVERSE;
|
115 |
|
|
116 |
|
|
|
120 |
|
|
121 |
|
117 |
122 |
private Label infoLine;
|
118 |
|
|
|
123 |
|
119 |
124 |
/**
|
120 |
125 |
* Button to merge or delete some rows.
|
121 |
126 |
*/
|
122 |
127 |
protected Button mergeDeleteRowsButton;
|
123 |
|
|
|
128 |
|
124 |
129 |
/**
|
125 |
130 |
* Button to merge or delete some columns.
|
126 |
131 |
*/
|
127 |
132 |
protected Button mergeDeleteColumnsButton;
|
128 |
|
|
129 |
|
|
130 |
|
|
|
133 |
|
|
134 |
|
|
135 |
|
131 |
136 |
// FIXME: SJ: viewer comparator tests
|
132 |
137 |
// /**
|
133 |
138 |
// * Viewer comparator for sorting.
|
134 |
139 |
// */
|
135 |
140 |
// protected LexicalTableLinesViewerComparator viewerComparator;
|
136 |
|
|
137 |
|
|
138 |
|
|
|
141 |
|
|
142 |
|
|
143 |
|
139 |
144 |
/**
|
140 |
145 |
* Unit property.
|
141 |
146 |
*/
|
142 |
147 |
@Parameter(key = TXMPreferences.UNIT_PROPERTY)
|
143 |
148 |
protected PropertiesComboViewer unitPropertyComboViewer;
|
144 |
|
|
145 |
|
|
|
149 |
|
|
150 |
|
146 |
151 |
/**
|
147 |
152 |
* Minimum frequency filter spinner.
|
148 |
153 |
*/
|
149 |
154 |
@Parameter(key = TXMPreferences.F_MIN)
|
150 |
155 |
protected Spinner fMinSpinner;
|
151 |
|
|
|
156 |
|
152 |
157 |
/**
|
153 |
158 |
* Minimum frequency filter spinner.
|
154 |
159 |
*/
|
155 |
160 |
@Parameter(key = TXMPreferences.F_MAX)
|
156 |
161 |
protected Spinner fMaxSpinner;
|
157 |
|
|
|
162 |
|
158 |
163 |
/**
|
159 |
164 |
* Maximum numbers of lines spinner.
|
160 |
165 |
*/
|
161 |
166 |
@Parameter(key = TXMPreferences.V_MAX)
|
162 |
167 |
protected Spinner vMaxSpinner;
|
163 |
|
|
|
168 |
|
164 |
169 |
/**
|
165 |
170 |
* Creates the part control.
|
166 |
171 |
*
|
... | ... | |
169 |
174 |
*/
|
170 |
175 |
@Override
|
171 |
176 |
public void _createPartControl() {
|
172 |
|
|
|
177 |
|
173 |
178 |
try {
|
174 |
179 |
lexicalTable = this.getResult();
|
175 |
|
|
|
180 |
|
176 |
181 |
// Main parameters
|
177 |
182 |
GLComposite mainParametersArea = this.getMainParametersComposite();
|
178 |
183 |
mainParametersArea.getLayout().numColumns = 2;
|
179 |
|
|
|
184 |
|
180 |
185 |
// unit property
|
181 |
186 |
new Label(mainParametersArea, SWT.NONE).setText(TXMCoreMessages.common_property);
|
182 |
187 |
ArrayList<WordProperty> availablesProperties = new ArrayList<>();
|
... | ... | |
189 |
194 |
availablesProperties,
|
190 |
195 |
this.getResult().getProperty(),
|
191 |
196 |
false);
|
192 |
|
|
|
197 |
|
193 |
198 |
// disable the property selection on Lexical table created from partition index
|
194 |
199 |
if (this.getResult().getParent() instanceof PartitionIndex) {
|
195 |
200 |
this.unitPropertyComboViewer.getCombo().setEnabled(false);
|
196 |
201 |
}
|
197 |
|
|
198 |
|
|
|
202 |
|
|
203 |
|
199 |
204 |
// Extended parameters
|
200 |
205 |
Composite extendedParametersArea = this.getExtendedParametersGroup();
|
201 |
|
|
|
206 |
|
202 |
207 |
// FIXME: SJ: became useless? Apply button
|
203 |
208 |
// Button keepTop = new Button(extendedParametersArea, SWT.PUSH);
|
204 |
209 |
// keepTop.setText(LexicalTableUIMessages.LexicalTableEditor_4);
|
... | ... | |
232 |
237 |
// public void widgetDefaultSelected(SelectionEvent e) {
|
233 |
238 |
// }
|
234 |
239 |
// });
|
235 |
|
|
236 |
|
|
|
240 |
|
|
241 |
|
237 |
242 |
// thresholds
|
238 |
243 |
ThresholdsGroup thresholdsGroup = new ThresholdsGroup(this.getExtendedParametersGroup(), SWT.NONE, this, true, true);
|
239 |
244 |
this.fMinSpinner = thresholdsGroup.getFMinSpinner();
|
240 |
245 |
this.fMaxSpinner = thresholdsGroup.getFMaxSpinner();
|
241 |
246 |
this.vMaxSpinner = thresholdsGroup.getVMaxSpinner();
|
242 |
247 |
this.vMaxSpinner.setMinimum(2); // LT won't work with 1 line only
|
243 |
|
|
|
248 |
|
244 |
249 |
CQPCorpus corpus = getResult().getFirstParent(MainCorpus.class);
|
245 |
250 |
if (corpus != null) {
|
246 |
251 |
this.vMaxSpinner.setMaximum(corpus.getSize());
|
247 |
252 |
this.fMaxSpinner.setMaximum(corpus.getSize());
|
248 |
253 |
this.fMinSpinner.setMaximum(corpus.getSize());
|
249 |
254 |
}
|
250 |
|
|
|
255 |
|
251 |
256 |
// Merge or delete columns button
|
252 |
257 |
mergeDeleteColumnsButton = new Button(extendedParametersArea, SWT.PUSH);
|
253 |
258 |
mergeDeleteColumnsButton.setText(LexicalTableUIMessages.mergeOrDeleteColumns);
|
254 |
259 |
mergeDeleteColumnsButton.addSelectionListener(new SelectionListener() {
|
255 |
|
|
|
260 |
|
256 |
261 |
@Override
|
257 |
262 |
public void widgetSelected(SelectionEvent e) {
|
258 |
263 |
StatusLine.setMessage(LexicalTableUIMessages.mergingLines);
|
259 |
264 |
ArrayList<Object> selection = new ArrayList<>();
|
260 |
265 |
MergeDeleteDialog d = new MergeDeleteDialog(e.display.getActiveShell(), new ArrayList<>(collist), selection, -1);
|
261 |
|
|
|
266 |
|
262 |
267 |
if (d.open() == Window.OK) {
|
263 |
268 |
List<Integer> colindices = new ArrayList<>();
|
264 |
269 |
for (int i = 0; i < collist.size(); i++) {
|
... | ... | |
266 |
271 |
colindices.add(i);
|
267 |
272 |
}
|
268 |
273 |
}
|
269 |
|
|
|
274 |
|
270 |
275 |
try {
|
271 |
|
|
|
276 |
|
272 |
277 |
if (d.doMerge()) {
|
273 |
|
|
|
278 |
|
274 |
279 |
int nrows = lexicalTable.getNRows();
|
275 |
|
|
|
280 |
|
276 |
281 |
String newname = d.getMergeName();
|
277 |
|
|
|
282 |
|
278 |
283 |
Log.fine(NLS.bind(LexicalTableUIMessages.mergeColsColonP0, colindices));
|
279 |
|
|
|
284 |
|
280 |
285 |
double[] firstcol = cols.get(colindices.get(0));
|
281 |
|
|
|
286 |
|
282 |
287 |
// merge selected cols into the first one
|
283 |
288 |
for (int i = 1; i < colindices.size(); i++) {
|
284 |
289 |
for (int j = 0; j < nrows; j++) {
|
285 |
290 |
firstcol[j] += cols.get(colindices.get(i))[j];
|
286 |
291 |
}
|
287 |
292 |
}
|
288 |
|
|
|
293 |
|
289 |
294 |
// update first col of the Lexical table
|
290 |
295 |
for (int j = 0; j < nrows; j++) {
|
291 |
296 |
lexicalTable.getData().set(j, colindices.get(0), firstcol[j]);
|
292 |
297 |
}
|
293 |
|
|
|
298 |
|
294 |
299 |
// and its name
|
295 |
300 |
lexicalTable.getColNames().setString(colindices.get(0), newname);
|
296 |
|
|
|
301 |
|
297 |
302 |
// keep only the first col
|
298 |
303 |
List<Integer> coltodelete = colindices.subList(1, colindices.size());
|
299 |
304 |
lexicalTable.getData().removeCols(coltodelete);
|
... | ... | |
304 |
309 |
for (String colname : lexicalTable.getColNames().asStringsArray()) {
|
305 |
310 |
collist.add(colname);
|
306 |
311 |
}
|
307 |
|
|
|
312 |
|
308 |
313 |
Collections.sort(colindices);// update table viewer cols
|
309 |
314 |
for (int i = colindices.size() - 1; i >= 1; i--) {
|
310 |
315 |
viewer.getTable().getColumns()[colindices.get(i) + 3].dispose();// +3 = separator,
|
... | ... | |
312 |
317 |
}
|
313 |
318 |
viewer.getTable().getColumns()[colindices.get(0) + 3].setText(newname);
|
314 |
319 |
compute(false);
|
315 |
|
|
316 |
|
|
|
320 |
|
|
321 |
|
317 |
322 |
}
|
318 |
323 |
// delete
|
319 |
324 |
else {
|
320 |
325 |
Log.fine(NLS.bind(LexicalTableUIMessages.deleteColsColonP0, colindices));
|
321 |
|
|
|
326 |
|
322 |
327 |
lexicalTable.getData().removeCols(colindices);
|
323 |
328 |
lexicalTable.setAltered();
|
324 |
|
|
|
329 |
|
325 |
330 |
collist = new ArrayList<>();
|
326 |
331 |
Vector colnames = lexicalTable.getColNames();
|
327 |
332 |
for (String colname : colnames.asStringsArray()) {
|
... | ... | |
340 |
345 |
}
|
341 |
346 |
}
|
342 |
347 |
StatusLine.setMessage(""); //$NON-NLS-1$
|
343 |
|
|
|
348 |
|
344 |
349 |
}
|
345 |
|
|
|
350 |
|
346 |
351 |
@Override
|
347 |
352 |
public void widgetDefaultSelected(SelectionEvent e) {}
|
348 |
353 |
});
|
349 |
|
|
|
354 |
|
350 |
355 |
// Merge or delete lines button
|
351 |
356 |
mergeDeleteRowsButton = new Button(extendedParametersArea, SWT.PUSH);
|
352 |
357 |
mergeDeleteRowsButton.setText(LexicalTableUIMessages.mergeOrDeleteRows);
|
353 |
358 |
mergeDeleteRowsButton.addSelectionListener(new SelectionListener() {
|
354 |
|
|
|
359 |
|
355 |
360 |
@Override
|
356 |
361 |
public void widgetSelected(SelectionEvent e) {
|
357 |
|
|
|
362 |
|
358 |
363 |
ArrayList<Object> selection = new ArrayList<>();
|
359 |
364 |
MergeDeleteDialog d = new MergeDeleteDialog(e.display
|
360 |
365 |
.getActiveShell(), new ArrayList<Object>(rows),
|
... | ... | |
369 |
374 |
}
|
370 |
375 |
}
|
371 |
376 |
try {
|
372 |
|
|
373 |
|
if (d.doMerge()) {
|
374 |
|
MergeLines.mergeLines(LexicalTableEditor.this, d.getMergeName(), rowindices);
|
375 |
|
}
|
376 |
|
else {
|
377 |
|
lexicalTable.getData().removeRows(rowindices);
|
378 |
|
compute(false);
|
379 |
|
}
|
380 |
|
lexicalTable.setAltered();
|
|
377 |
|
|
378 |
if (d.doMerge()) {
|
|
379 |
MergeLines.mergeLines(LexicalTableEditor.this, d.getMergeName(), rowindices);
|
|
380 |
}
|
|
381 |
else {
|
|
382 |
lexicalTable.getData().removeRows(rowindices);
|
|
383 |
compute(false);
|
|
384 |
}
|
|
385 |
lexicalTable.setAltered();
|
381 |
386 |
} catch(Exception ex) {
|
382 |
387 |
Log.warning(ex.getMessage());
|
383 |
388 |
Log.printStackTrace();
|
384 |
389 |
}
|
385 |
390 |
}
|
386 |
391 |
}
|
387 |
|
|
|
392 |
|
388 |
393 |
@Override
|
389 |
394 |
public void widgetDefaultSelected(SelectionEvent e) {}
|
390 |
395 |
});
|
391 |
|
|
|
396 |
|
392 |
397 |
// Result area
|
393 |
398 |
Composite resultArea = this.getResultArea();
|
394 |
|
|
|
399 |
|
395 |
400 |
GridData gd = new GridData(GridData.FILL_BOTH);
|
396 |
401 |
gd.grabExcessVerticalSpace = true;
|
397 |
402 |
gd.grabExcessHorizontalSpace = true;
|
398 |
403 |
// gd.horizontalSpan = 2;
|
399 |
404 |
resultArea.setLayoutData(gd);
|
400 |
|
|
|
405 |
|
401 |
406 |
viewer = new TableViewer(resultArea, SWT.VIRTUAL | SWT.MULTI | SWT.FULL_SELECTION | SWT.BORDER);
|
402 |
407 |
viewer.getTable().addKeyListener(new TableKeyListener(viewer));
|
403 |
408 |
viewer.getTable().setLinesVisible(true);
|
404 |
409 |
viewer.getTable().setHeaderVisible(true);
|
405 |
|
|
406 |
|
|
|
410 |
|
|
411 |
viewer.addSelectionChangedListener(new ISelectionChangedListener() {
|
|
412 |
|
|
413 |
@Override
|
|
414 |
public void selectionChanged(SelectionChangedEvent event) {
|
|
415 |
System.out.println("sel="+viewer.getStructuredSelection().toList());
|
|
416 |
}
|
|
417 |
});
|
|
418 |
|
|
419 |
|
407 |
420 |
// viewer.setContentProvider(ArrayContentProvider.getInstance());
|
408 |
|
|
|
421 |
|
409 |
422 |
// FIXME: viewer comparator tests
|
410 |
423 |
// creates the viewer comparator
|
411 |
424 |
// this.viewerComparator = new LexicalTableLinesViewerComparator(Toolbox.getCollator(this.getResult()));
|
412 |
425 |
// viewer.setComparator(this.viewerComparator);
|
413 |
|
|
|
426 |
|
414 |
427 |
// FIXME: we must use this line rather than the LineContentProvider class
|
415 |
428 |
// viewer.setContentProvider(ArrayContentProvider.getInstance());
|
416 |
429 |
viewer.setContentProvider(new LineContentProvider());
|
417 |
|
|
418 |
|
|
|
430 |
|
|
431 |
|
419 |
432 |
viewer.getTable().setLayoutData(new GridData(GridData.FILL_BOTH));
|
420 |
|
|
|
433 |
|
421 |
434 |
// first dummy column
|
422 |
435 |
TableViewerColumn nColumn = new TableViewerColumn(viewer, SWT.RIGHT);
|
423 |
436 |
nColumn.getColumn().setText(" "); //$NON-NLS-1$
|
424 |
|
|
|
437 |
|
425 |
438 |
// property column
|
426 |
439 |
unitColumn = new TableViewerColumn(viewer, SWT.LEFT);
|
427 |
440 |
unitColumn.getColumn().addSelectionListener(new ColumnSelectionListener(this, unitColumn, -3));
|
428 |
441 |
// FIXME: viewer comparator tests
|
429 |
442 |
// viewerComparator.addSelectionAdapter(viewer, unitColumn.getColumn(), 1);
|
430 |
|
|
|
443 |
|
431 |
444 |
// frequency column
|
432 |
445 |
freqColumn = new TableViewerColumn(viewer, SWT.LEFT);
|
433 |
446 |
freqColumn.getColumn().setText(TXMCoreMessages.common_frequency);
|
434 |
447 |
freqColumn.getColumn().addSelectionListener(new ColumnSelectionListener(this, freqColumn, -2));
|
435 |
448 |
// FIXME: viewer comparator tests
|
436 |
449 |
// viewerComparator.addSelectionAdapter(viewer, freqColumn.getColumn(), 2);
|
437 |
|
|
|
450 |
|
438 |
451 |
// add a separator empty column
|
439 |
452 |
TableViewerColumn separatorColumn = new TableViewerColumn(viewer, SWT.NONE);
|
440 |
453 |
separatorColumn.getColumn().setResizable(false);
|
441 |
|
|
|
454 |
|
442 |
455 |
// Register the context menu
|
443 |
456 |
TXMEditor.initContextMenu(this.viewer.getTable(), this.getSite(), this.viewer); // $NON-NLS-1$
|
444 |
|
|
|
457 |
|
445 |
458 |
// adjust UI to the original sorting
|
446 |
459 |
viewer.getTable().setSortColumn(unitColumn.getColumn());
|
447 |
460 |
viewer.getTable().setSortDirection(SWT.UP);
|
448 |
|
|
|
461 |
|
449 |
462 |
infoLine = new Label(getBottomToolbar().getParent(), SWT.NONE);
|
450 |
463 |
}
|
451 |
464 |
catch (Exception e) {
|
... | ... | |
453 |
466 |
e.printStackTrace();
|
454 |
467 |
}
|
455 |
468 |
}
|
456 |
|
|
457 |
|
|
|
469 |
|
|
470 |
|
458 |
471 |
/**
|
459 |
472 |
*
|
460 |
473 |
* @throws StatException
|
... | ... | |
463 |
476 |
private void refreshColNames() throws StatException, CqiClientException {
|
464 |
477 |
TableColumn[] cols = viewer.getTable().getColumns();
|
465 |
478 |
String[] colnames = lexicalTable.getColNames().asStringsArray();
|
466 |
|
|
|
479 |
|
467 |
480 |
for (int i = 0; i < cols.length; i++) {
|
468 |
481 |
cols[i].setText(colnames[i] + "T=" + lexicalTable.getPartition().getParts().get(i).getSize()); //$NON-NLS-1$
|
469 |
482 |
}
|
470 |
483 |
}
|
471 |
|
|
|
484 |
|
472 |
485 |
@Override
|
473 |
486 |
public void setContentDescription(String desc) {
|
474 |
487 |
infoLine.setText(desc);
|
475 |
488 |
infoLine.update();
|
476 |
489 |
infoLine.getParent().layout();
|
477 |
490 |
}
|
478 |
|
|
|
491 |
|
479 |
492 |
/**
|
480 |
493 |
* Refreshes the description area.
|
481 |
494 |
*/
|
... | ... | |
488 |
501 |
org.txm.utils.logger.Log.printStackTrace(e3);
|
489 |
502 |
}
|
490 |
503 |
}
|
491 |
|
|
|
504 |
|
492 |
505 |
public void refreshTable() {
|
493 |
506 |
this.refreshTable(false);
|
494 |
507 |
}
|
495 |
|
|
|
508 |
|
496 |
509 |
/**
|
497 |
510 |
* Refreshes table.
|
498 |
511 |
*/
|
499 |
512 |
// FIXME: SJ: not optimized, need to mix the update/not update code and do not remove column each computing, only when needed
|
500 |
513 |
// FIXME: SJ: + usine à gaz... virer la variable "collist"
|
501 |
514 |
public void refreshTable(boolean update) {
|
502 |
|
|
|
515 |
|
503 |
516 |
this.viewer.getControl().setRedraw(false);
|
504 |
|
|
|
517 |
|
505 |
518 |
// removing old columns
|
506 |
519 |
for (int i = viewer.getTable().getColumnCount() - 2; i >= 3; i--) {
|
507 |
520 |
viewer.getTable().getColumns()[i].dispose();
|
508 |
521 |
}
|
509 |
|
|
|
522 |
|
510 |
523 |
try {
|
511 |
|
|
|
524 |
|
512 |
525 |
collist = new ArrayList<>();
|
513 |
|
|
|
526 |
|
514 |
527 |
if (this.lexicalTable.getProperty() != null) {
|
515 |
528 |
unitColumn.getColumn().setText(this.lexicalTable.getProperty().getName());
|
516 |
529 |
}
|
517 |
|
|
518 |
|
|
|
530 |
|
|
531 |
|
519 |
532 |
// creating the columns
|
520 |
533 |
String[] colNames;
|
521 |
534 |
int[] colMargins = null;
|
... | ... | |
528 |
541 |
else {
|
529 |
542 |
colNames = this.getResult().getPartition().getPartNames().toArray(new String[0]);
|
530 |
543 |
}
|
531 |
|
|
532 |
|
|
|
544 |
|
|
545 |
|
533 |
546 |
int MAX_NUMBER_OF_COLUMNS = RCPPreferences.getInstance().getInt(RCPPreferences.MAX_NUMBER_OF_COLUMNS);
|
534 |
547 |
for (int i = 0; i < colNames.length; i++) {
|
535 |
|
|
|
548 |
|
536 |
549 |
if (i >= MAX_NUMBER_OF_COLUMNS) {
|
537 |
550 |
Log.warning(NLS.bind("Warning The number of columns exceeds {0} ({1}). the table has been cut. You can, change the maximum in the TXM > User preference page", MAX_NUMBER_OF_COLUMNS, colNames.length));
|
538 |
551 |
break;
|
... | ... | |
541 |
554 |
column.getColumn().addSelectionListener(new ColumnSelectionListener(this, column, i));
|
542 |
555 |
// FIXME: viewer comparator tests
|
543 |
556 |
// viewerComparator.addSelectionAdapter(viewer, column.getColumn(), i + 2);
|
544 |
|
|
|
557 |
|
545 |
558 |
String colName = colNames[i];
|
546 |
559 |
column.getColumn().setToolTipText(colName);
|
547 |
560 |
collist.add(colName);
|
548 |
|
|
|
561 |
|
549 |
562 |
if (colMargins != null) {
|
550 |
563 |
colName += " t=" + colMargins[i]; //$NON-NLS-1$
|
551 |
564 |
}
|
552 |
|
|
|
565 |
|
553 |
566 |
column.getColumn().setText(colName);
|
554 |
|
|
555 |
|
|
|
567 |
|
|
568 |
|
556 |
569 |
}
|
557 |
|
|
|
570 |
|
558 |
571 |
// add a separator empty column
|
559 |
572 |
TableViewerColumn separatorColumn = new TableViewerColumn(viewer, SWT.NONE);
|
560 |
573 |
separatorColumn.getColumn().setResizable(false);
|
561 |
|
|
|
574 |
|
562 |
575 |
}
|
563 |
576 |
catch (StatException e) {
|
564 |
577 |
// TODO Auto-generated catch block
|
565 |
578 |
e.printStackTrace();
|
566 |
579 |
}
|
567 |
|
|
568 |
|
|
|
580 |
|
|
581 |
|
569 |
582 |
if (this.lexicalTable.hasBeenComputedOnce()) {
|
570 |
583 |
LineLabelProvider labelprovider = new LineLabelProvider(this.lexicalTable, viewer.getTable());
|
571 |
584 |
this.viewer.setLabelProvider(labelprovider);
|
572 |
585 |
this.cols = labelprovider.getCols();
|
573 |
586 |
this.rows = labelprovider.getRows();
|
574 |
587 |
this.viewer.setInput(this.lexicalTable);
|
575 |
|
|
|
588 |
|
576 |
589 |
// initial sorting
|
577 |
590 |
if (!update) {
|
578 |
|
this.sort(unitColumn, -2);
|
|
591 |
try {
|
|
592 |
this.sort(unitColumn, -2);
|
|
593 |
} catch (Exception e) {
|
|
594 |
// TODO Auto-generated catch block
|
|
595 |
e.printStackTrace();
|
|
596 |
}
|
579 |
597 |
}
|
580 |
598 |
}
|
581 |
|
|
582 |
|
|
|
599 |
|
|
600 |
|
583 |
601 |
this.viewer.getControl().setRedraw(true);
|
584 |
|
|
585 |
|
|
|
602 |
|
|
603 |
|
586 |
604 |
// Refresh and pack the columns
|
587 |
605 |
TXMEditor.packColumns(this.viewer);
|
588 |
|
|
|
606 |
|
589 |
607 |
this.viewer.getTable().deselectAll();
|
590 |
608 |
this.viewer.getTable().setFocus();
|
591 |
|
|
592 |
|
|
|
609 |
|
|
610 |
|
593 |
611 |
}
|
594 |
|
|
595 |
|
|
|
612 |
|
|
613 |
|
596 |
614 |
/**
|
597 |
615 |
* Sets the col comparator.
|
598 |
616 |
*
|
... | ... | |
612 |
630 |
* currentComparator.initialize(cooc.getCorpus());
|
613 |
631 |
*/
|
614 |
632 |
}
|
615 |
|
|
|
633 |
|
616 |
634 |
/**
|
617 |
635 |
* Gets the corpus.
|
618 |
636 |
*
|
... | ... | |
621 |
639 |
public CQPCorpus getCorpus() {
|
622 |
640 |
return null;
|
623 |
641 |
}
|
624 |
|
|
625 |
|
|
626 |
|
|
|
642 |
|
|
643 |
|
|
644 |
|
627 |
645 |
/**
|
628 |
646 |
* Gets the line table viewer.
|
629 |
647 |
*
|
... | ... | |
632 |
650 |
public TableViewer getlineTableViewer() {
|
633 |
651 |
return viewer;
|
634 |
652 |
}
|
635 |
|
|
|
653 |
|
636 |
654 |
/**
|
637 |
655 |
* Gets the lexical table.
|
638 |
656 |
*
|
... | ... | |
641 |
659 |
public LexicalTable getLexicalTable() {
|
642 |
660 |
return lexicalTable;
|
643 |
661 |
}
|
644 |
|
|
|
662 |
|
645 |
663 |
/**
|
646 |
664 |
* Gets the cols.
|
647 |
665 |
*
|
... | ... | |
650 |
668 |
public List<double[]> getCols() {
|
651 |
669 |
return cols;
|
652 |
670 |
}
|
653 |
|
|
|
671 |
|
654 |
672 |
/**
|
655 |
673 |
* Export data.
|
656 |
674 |
*
|
... | ... | |
660 |
678 |
public void exportData(File file) {
|
661 |
679 |
lexicalTable.getData().toTxt(file, TXMPreferences.DEFAULT_ENCODING, "\t", ""); //$NON-NLS-1$ //$NON-NLS-2$
|
662 |
680 |
}
|
663 |
|
|
|
681 |
|
664 |
682 |
/**
|
665 |
683 |
* Import data.
|
666 |
684 |
*
|
... | ... | |
672 |
690 |
String encoding = TBXPreferences.getInstance().getString(TBXPreferences.EXPORT_ENCODING);
|
673 |
691 |
String colseparator = TBXPreferences.getInstance().getString(TBXPreferences.EXPORT_COL_SEPARATOR);
|
674 |
692 |
String txtseparator = TBXPreferences.getInstance().getString(TBXPreferences.EXPORT_TXT_SEPARATOR);
|
675 |
|
|
|
693 |
|
676 |
694 |
if (lexicalTable.getData().importData(file, encoding, colseparator, txtseparator)) {
|
677 |
695 |
lexicalTable.setAltered();
|
678 |
696 |
// fix col names
|
... | ... | |
704 |
722 |
org.txm.utils.logger.Log.printStackTrace(e);
|
705 |
723 |
}
|
706 |
724 |
}
|
707 |
|
|
708 |
|
|
709 |
|
|
|
725 |
|
|
726 |
|
|
727 |
|
710 |
728 |
/**
|
711 |
729 |
* Sort.
|
712 |
730 |
*
|
713 |
731 |
* @param col the col
|
714 |
732 |
* @param index the index
|
|
733 |
* @throws Exception
|
|
734 |
* @throws StatException
|
715 |
735 |
*/
|
716 |
736 |
// FIXME: SJ: try to use a ViewerSorter instead of this but also manage the result sorting for export
|
717 |
|
public void sort(TableViewerColumn col, int index) {
|
718 |
|
|
|
737 |
public void sort(TableViewerColumn col, int index) throws StatException, Exception {
|
|
738 |
|
|
739 |
List currentSelection = viewer.getStructuredSelection().toList();
|
|
740 |
HashSet<String> selectedEntries = new HashSet<String>();
|
|
741 |
String[] rowNames = this.getResult().getRowNames().asStringsArray();
|
|
742 |
for (Object o : currentSelection) {
|
|
743 |
int i = (int) o;
|
|
744 |
selectedEntries.add(rowNames[i]);
|
|
745 |
}
|
|
746 |
System.out.println("selection before sort: "+currentSelection);
|
|
747 |
System.out.println("selection entries before sort: "+selectedEntries);
|
|
748 |
|
719 |
749 |
if (index == previousSortedCol) {
|
720 |
750 |
reverse = !reverse;
|
721 |
751 |
}
|
722 |
752 |
else {
|
723 |
753 |
reverse = DEFAULTREVERSE;
|
724 |
754 |
}
|
725 |
|
|
|
755 |
|
726 |
756 |
if (index == -3) {// rownames
|
727 |
757 |
lexicalTable.getData().sortRowNames(reverse);
|
728 |
758 |
}
|
... | ... | |
738 |
768 |
else if (index >= 0) {
|
739 |
769 |
lexicalTable.getData().sort(index, reverse);
|
740 |
770 |
}
|
741 |
|
|
|
771 |
|
|
772 |
rowNames = this.getResult().getRowNames().asStringsArray(); // get updated rowNames (new order)
|
|
773 |
List<Integer> newSelection = new ArrayList<Integer>();
|
|
774 |
if (selectedEntries.size() > 0) {
|
|
775 |
for (int i = 0 ; i < rowNames.length ; i++) {
|
|
776 |
if (selectedEntries.contains(rowNames[i])) {
|
|
777 |
newSelection.add(i);
|
|
778 |
System.out.println("found: "+rowNames[i]);
|
|
779 |
}
|
|
780 |
}
|
|
781 |
}
|
|
782 |
|
742 |
783 |
previousSortedCol = index;
|
743 |
|
|
|
784 |
|
744 |
785 |
refreshTable(true);
|
745 |
|
|
|
786 |
|
746 |
787 |
// viewer.getTable().setSortColumn(col.getColumn());
|
747 |
788 |
viewer.getTable().setSortColumn(viewer.getTable().getColumn(index + 4));
|
748 |
|
|
|
789 |
|
749 |
790 |
if (reverse) {
|
750 |
791 |
viewer.getTable().setSortDirection(SWT.DOWN);
|
751 |
792 |
}
|
752 |
793 |
else {
|
753 |
794 |
viewer.getTable().setSortDirection(SWT.UP);
|
754 |
795 |
}
|
755 |
|
|
|
796 |
|
756 |
797 |
// Refresh and pack the columns
|
757 |
798 |
TXMEditor.refreshColumns(this.viewer);
|
758 |
|
|
|
799 |
|
|
800 |
viewer.setSelection(new StructuredSelection(newSelection));
|
|
801 |
|
759 |
802 |
}
|
760 |
|
|
761 |
|
|
|
803 |
|
|
804 |
|
762 |
805 |
@Override
|
763 |
806 |
public void updateEditorFromResult(boolean update) {
|
764 |
|
|
|
807 |
|
765 |
808 |
// enable/disable the edition buttons according to the computed state
|
766 |
809 |
if (this.lexicalTable.getData() != null) {
|
767 |
810 |
this.mergeDeleteColumnsButton.setEnabled(true);
|
768 |
811 |
this.mergeDeleteRowsButton.setEnabled(true);
|
769 |
|
|
|
812 |
|
770 |
813 |
this.refreshInfos();
|
771 |
814 |
}
|
772 |
815 |
else {
|
773 |
816 |
this.mergeDeleteColumnsButton.setEnabled(false);
|
774 |
817 |
this.mergeDeleteRowsButton.setEnabled(false);
|
775 |
818 |
}
|
776 |
|
|
|
819 |
|
777 |
820 |
this.refreshTable(update);
|
778 |
|
|
|
821 |
|
779 |
822 |
QueriesView.refresh();
|
780 |
823 |
RVariablesView.refresh();
|
781 |
824 |
}
|
782 |
|
|
783 |
|
|
|
825 |
|
|
826 |
|
784 |
827 |
@Override
|
785 |
828 |
public void updateResultFromEditor() {
|
786 |
829 |
// FIXME: SJ: needs to manage here the merge/deletion of rows and columns
|