Révision 3141
tmp/org.txm.lexicaltable.core/src/org/txm/lexicaltable/core/statsengine/data/ILexicalTable.java (revision 3141) | ||
---|---|---|
89 | 89 |
* @param col the col |
90 | 90 |
* @param checkEmptyLines the check empty lines |
91 | 91 |
*/ |
92 |
public abstract void removeCol(int col, boolean checkEmptyLines); |
|
92 |
public abstract void removeCol(int col, boolean checkEmptyLines) throws StatException;
|
|
93 | 93 |
|
94 | 94 |
/** |
95 | 95 |
* Removes the cols. |
96 | 96 |
* |
97 | 97 |
* @param cols the cols |
98 | 98 |
*/ |
99 |
public abstract void removeCols(List<Integer> cols); |
|
99 |
public abstract void removeCols(List<Integer> cols) throws StatException;
|
|
100 | 100 |
|
101 | 101 |
/** |
102 | 102 |
* Removes the cols. |
103 | 103 |
* |
104 | 104 |
* @param coltodelete the coltodelete |
105 | 105 |
*/ |
106 |
public abstract void removeCols(int[] coltodelete); |
|
106 |
public abstract void removeCols(int[] coltodelete) throws StatException;
|
|
107 | 107 |
|
108 | 108 |
/** |
109 | 109 |
* Removes the row. |
110 | 110 |
* |
111 | 111 |
* @param row the row |
112 | 112 |
*/ |
113 |
public abstract void removeRow(int row); |
|
113 |
public abstract void removeRow(int row) throws StatException;
|
|
114 | 114 |
|
115 | 115 |
/** |
116 | 116 |
* Removes the rows. |
117 | 117 |
* |
118 | 118 |
* @param row the row |
119 | 119 |
*/ |
120 |
public abstract void removeRows(List<Integer> row); |
|
120 |
public abstract void removeRows(List<Integer> row) throws StatException;
|
|
121 | 121 |
|
122 | 122 |
/** |
123 | 123 |
* Removes the rows. |
124 | 124 |
* |
125 | 125 |
* @param selectionIndices the selection indices |
126 | 126 |
*/ |
127 |
public abstract void removeRows(int[] selectionIndices); |
|
127 |
public abstract void removeRows(int[] selectionIndices) throws StatException;
|
|
128 | 128 |
|
129 | 129 |
/** |
130 | 130 |
* Sets the. |
tmp/org.txm.lexicaltable.rcp/src/org/txm/lexicaltable/rcp/editors/LexicalTableEditor.java (revision 3141) | ||
---|---|---|
266 | 266 |
} |
267 | 267 |
} |
268 | 268 |
|
269 |
if (d.doMerge()) {
|
|
269 |
try {
|
|
270 | 270 |
|
271 |
int nrows; |
|
272 |
try { |
|
273 |
nrows = lexicalTable.getNRows(); |
|
274 |
} |
|
275 |
catch (Exception e2) { |
|
276 |
// TODO Auto-generated catch block |
|
277 |
e2.printStackTrace(); |
|
278 |
return; |
|
279 |
} |
|
280 |
String newname = d.getMergeName(); |
|
281 |
|
|
282 |
Log.fine(NLS.bind(LexicalTableUIMessages.mergeColsColonP0, colindices)); |
|
283 |
|
|
284 |
double[] firstcol = cols.get(colindices.get(0)); |
|
285 |
|
|
286 |
// merge selected cols into the first one |
|
287 |
for (int i = 1; i < colindices.size(); i++) { |
|
271 |
if (d.doMerge()) { |
|
272 |
|
|
273 |
int nrows = lexicalTable.getNRows(); |
|
274 |
|
|
275 |
String newname = d.getMergeName(); |
|
276 |
|
|
277 |
Log.fine(NLS.bind(LexicalTableUIMessages.mergeColsColonP0, colindices)); |
|
278 |
|
|
279 |
double[] firstcol = cols.get(colindices.get(0)); |
|
280 |
|
|
281 |
// merge selected cols into the first one |
|
282 |
for (int i = 1; i < colindices.size(); i++) { |
|
283 |
for (int j = 0; j < nrows; j++) { |
|
284 |
firstcol[j] += cols.get(colindices.get(i))[j]; |
|
285 |
} |
|
286 |
} |
|
287 |
|
|
288 |
// update first col of the Lexical table |
|
288 | 289 |
for (int j = 0; j < nrows; j++) { |
289 |
firstcol[j] += cols.get(colindices.get(i))[j];
|
|
290 |
lexicalTable.getData().set(j, colindices.get(0), firstcol[j]);
|
|
290 | 291 |
} |
291 |
} |
|
292 |
|
|
293 |
// update first col of the Lexical table |
|
294 |
for (int j = 0; j < nrows; j++) { |
|
295 |
lexicalTable.getData().set(j, colindices.get(0), firstcol[j]); |
|
296 |
} |
|
297 |
|
|
298 |
// and its name |
|
299 |
lexicalTable.getColNames().setString(colindices.get(0), newname); |
|
300 |
|
|
301 |
// keep only the first col |
|
302 |
List<Integer> coltodelete = colindices.subList(1, colindices.size()); |
|
303 |
lexicalTable.getData().removeCols(coltodelete); |
|
304 |
lexicalTable.setAltered(); |
|
305 |
// refresh stuff |
|
306 |
collist = new ArrayList<>();// update col name |
|
307 |
// list |
|
308 |
try { |
|
292 |
|
|
293 |
// and its name |
|
294 |
lexicalTable.getColNames().setString(colindices.get(0), newname); |
|
295 |
|
|
296 |
// keep only the first col |
|
297 |
List<Integer> coltodelete = colindices.subList(1, colindices.size()); |
|
298 |
lexicalTable.getData().removeCols(coltodelete); |
|
299 |
lexicalTable.setAltered(); |
|
300 |
// refresh stuff |
|
301 |
collist = new ArrayList<>();// update col name |
|
302 |
// list |
|
309 | 303 |
for (String colname : lexicalTable.getColNames().asStringsArray()) { |
310 | 304 |
collist.add(colname); |
311 | 305 |
} |
306 |
|
|
307 |
Collections.sort(colindices);// update table viewer cols |
|
308 |
for (int i = colindices.size() - 1; i >= 1; i--) { |
|
309 |
viewer.getTable().getColumns()[colindices.get(i) + 3].dispose();// +3 = separator, |
|
310 |
// form, freq |
|
311 |
} |
|
312 |
viewer.getTable().getColumns()[colindices.get(0) + 3].setText(newname); |
|
313 |
compute(false); |
|
314 |
|
|
315 |
|
|
312 | 316 |
} |
313 |
catch (StatException e1) { |
|
314 |
org.txm.utils.logger.Log.printStackTrace(e1); |
|
315 |
return; |
|
316 |
} |
|
317 |
|
|
318 |
Collections.sort(colindices);// update table viewer cols |
|
319 |
for (int i = colindices.size() - 1; i >= 1; i--) { |
|
320 |
viewer.getTable().getColumns()[colindices.get(i) + 3].dispose();// +3 = separator, |
|
321 |
// form, freq |
|
322 |
} |
|
323 |
viewer.getTable().getColumns()[colindices.get(0) + 3].setText(newname); |
|
324 |
compute(false); |
|
325 |
} |
|
326 |
// delete |
|
327 |
else { |
|
328 |
Log.fine(NLS.bind(LexicalTableUIMessages.deleteColsColonP0, colindices)); |
|
329 |
|
|
330 |
lexicalTable.getData().removeCols(colindices); |
|
331 |
lexicalTable.setAltered(); |
|
332 |
|
|
333 |
collist = new ArrayList<>(); |
|
334 |
Vector colnames = lexicalTable.getColNames(); |
|
335 |
try { |
|
317 |
// delete |
|
318 |
else { |
|
319 |
Log.fine(NLS.bind(LexicalTableUIMessages.deleteColsColonP0, colindices)); |
|
320 |
|
|
321 |
lexicalTable.getData().removeCols(colindices); |
|
322 |
lexicalTable.setAltered(); |
|
323 |
|
|
324 |
collist = new ArrayList<>(); |
|
325 |
Vector colnames = lexicalTable.getColNames(); |
|
336 | 326 |
for (String colname : colnames.asStringsArray()) { |
337 | 327 |
collist.add(colname); |
338 | 328 |
} |
329 |
Collections.sort(colindices); |
|
330 |
for (int i = colindices.size() - 1; i >= 0; i--) { |
|
331 |
viewer.getTable().getColumns()[colindices.get(i) + 3].dispose(); |
|
332 |
} |
|
333 |
compute(false); |
|
339 | 334 |
} |
340 |
catch (StatException e1) { |
|
341 |
org.txm.utils.logger.Log.printStackTrace(e1); |
|
342 |
return; |
|
343 |
} |
|
344 |
|
|
345 |
Collections.sort(colindices); |
|
346 |
for (int i = colindices.size() - 1; i >= 0; i--) { |
|
347 |
viewer.getTable().getColumns()[colindices.get(i) + 3].dispose(); |
|
348 |
} |
|
349 |
compute(false); |
|
335 |
} catch (Exception e2) { |
|
336 |
// TODO Auto-generated catch block |
|
337 |
e2.printStackTrace(); |
|
338 |
return; |
|
350 | 339 |
} |
351 | 340 |
} |
352 | 341 |
StatusLine.setMessage(""); //$NON-NLS-1$ |
342 |
|
|
353 | 343 |
} |
354 | 344 |
|
355 | 345 |
@Override |
... | ... | |
377 | 367 |
count++; |
378 | 368 |
} |
379 | 369 |
} |
370 |
try { |
|
380 | 371 |
|
381 | 372 |
if (d.doMerge()) { |
382 | 373 |
MergeLines.mergeLines(LexicalTableEditor.this, d.getMergeName(), rowindices); |
... | ... | |
386 | 377 |
compute(false); |
387 | 378 |
} |
388 | 379 |
lexicalTable.setAltered(); |
380 |
} catch(Exception ex) { |
|
381 |
Log.warning(ex.getMessage()); |
|
382 |
Log.printStackTrace(); |
|
383 |
} |
|
389 | 384 |
} |
390 | 385 |
} |
391 | 386 |
|
tmp/org.txm.lexicaltable.rcp/src/org/txm/lexicaltable/rcp/handlers/___MergeCols.java (revision 3141) | ||
---|---|---|
85 | 85 |
int nrows; |
86 | 86 |
try { |
87 | 87 |
nrows = table.getNRows(); |
88 |
} |
|
89 |
catch (Exception e) { |
|
90 |
// TODO Auto-generated catch block |
|
91 |
e.printStackTrace(); |
|
92 |
return null; |
|
93 |
} |
|
94 |
for (int i = 1; i < selectedCols.length; i++) { |
|
88 |
|
|
89 |
for (int i = 1; i < selectedCols.length; i++) { |
|
90 |
for (int j = 0; j < nrows; j++) { |
|
91 |
firstcol[j] += cols.get(selectedCols[i])[j]; |
|
92 |
} |
|
93 |
} |
|
94 |
|
|
95 |
// update table |
|
95 | 96 |
for (int j = 0; j < nrows; j++) { |
96 |
firstcol[j] += cols.get(selectedCols[i])[j];
|
|
97 |
table.getData().set(j, selectedCols[0], firstcol[j]);
|
|
97 | 98 |
} |
98 |
} |
|
99 |
|
|
100 |
// update table |
|
101 |
for (int j = 0; j < nrows; j++) { |
|
102 |
table.getData().set(j, selectedCols[0], firstcol[j]); |
|
103 |
} |
|
104 |
|
|
105 |
// keep only the first col |
|
106 |
int[] coltodelete = new int[selectedCols.length - 1]; |
|
107 |
System.arraycopy(selectedCols, 1, coltodelete, 0, |
|
108 |
selectedCols.length - 1); |
|
109 |
table.getData().removeCols(coltodelete); |
|
110 |
table.setAltered(); |
|
111 |
// reset col name |
|
112 |
table.getColNames().setString(selectedCols[0], newname); |
|
113 |
try { |
|
99 |
|
|
100 |
// keep only the first col |
|
101 |
int[] coltodelete = new int[selectedCols.length - 1]; |
|
102 |
System.arraycopy(selectedCols, 1, coltodelete, 0, selectedCols.length - 1); |
|
103 |
table.getData().removeCols(coltodelete); |
|
104 |
table.setAltered(); |
|
105 |
// reset col name |
|
106 |
table.getColNames().setString(selectedCols[0], newname); |
|
107 |
|
|
114 | 108 |
System.out.println(NLS.bind(TXMUIMessages.namesColon, Arrays.toString(table.getRowNames().asStringsArray()))); |
115 | 109 |
} |
116 | 110 |
catch (Exception e1) { |
117 | 111 |
// TODO Auto-generated catch block |
118 | 112 |
org.txm.utils.logger.Log.printStackTrace(e1); |
113 |
return null; |
|
119 | 114 |
} |
120 |
; |
|
115 |
|
|
121 | 116 |
System.out.println(TXMUIMessages.endOfColumnMerge); |
122 | 117 |
LTeditor.refreshTable(); |
123 | 118 |
} |
tmp/org.txm.lexicaltable.rcp/src/org/txm/lexicaltable/rcp/handlers/MergeLines.java (revision 3141) | ||
---|---|---|
54 | 54 |
|
55 | 55 |
@Override |
56 | 56 |
public Object execute(ExecutionEvent event) throws ExecutionException { |
57 |
Shell shell = HandlerUtil.getActiveWorkbenchWindowChecked(event) |
|
58 |
.getShell(); |
|
57 |
Shell shell = HandlerUtil.getActiveWorkbenchWindowChecked(event).getShell(); |
|
59 | 58 |
|
60 |
IWorkbenchPart editor = HandlerUtil.getActiveWorkbenchWindow(event) |
|
61 |
.getActivePage().getActivePart(); |
|
59 |
IWorkbenchPart editor = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().getActivePart();
|
|
60 |
|
|
62 | 61 |
if (editor instanceof LexicalTableEditor) { |
63 | 62 |
LexicalTableEditor LTeditor = (LexicalTableEditor) editor; |
64 |
int[] selection = LTeditor.getlineTableViewer().getTable() |
|
65 |
.getSelectionIndices(); |
|
66 |
if (selection.length == 0) |
|
63 |
int[] selection = LTeditor.getlineTableViewer().getTable().getSelectionIndices();
|
|
64 |
|
|
65 |
if (selection.length == 0) {
|
|
67 | 66 |
return null; |
68 |
|
|
67 |
} |
|
69 | 68 |
String newname = ""; //$NON-NLS-1$ |
70 | 69 |
InputDialog d = new InputDialog(shell, TXMUIMessages.newName, |
71 | 70 |
TXMUIMessages.editTheNameOfTheNewLineCreatedByTheMergedLines, "", null); //$NON-NLS-1$ |
72 |
if (d.open() == Window.OK) |
|
71 |
|
|
72 |
if (d.open() == Window.OK) { |
|
73 | 73 |
newname = d.getValue(); |
74 |
else
|
|
74 |
} else {
|
|
75 | 75 |
return null; |
76 |
if (newname.trim().equals("")) //$NON-NLS-1$ |
|
76 |
} |
|
77 |
|
|
78 |
if (newname.trim().equals("")) { //$NON-NLS-1$ |
|
77 | 79 |
return null; |
80 |
} |
|
78 | 81 |
|
79 | 82 |
mergeLines(LTeditor, newname, selection); |
80 | 83 |
|
... | ... | |
92 | 95 |
static public void mergeLines(LexicalTableEditor LTeditor, String newname, int[] selection) { |
93 | 96 |
// sum the lines |
94 | 97 |
StatusLine.setMessage(LexicalTableUIMessages.mergingLines); |
95 |
List<double[]> cols = LTeditor.getCols(); |
|
96 |
LexicalTable table = LTeditor.getLexicalTable(); |
|
97 |
TableViewer lineTableViewer = LTeditor.getlineTableViewer(); |
|
98 |
double[] fuz = new double[cols.size()]; |
|
99 |
for (int j = 0; j < cols.size(); j++) |
|
100 |
fuz[j] = 0; |
|
101 |
for (int i : selection) |
|
102 |
for (int j = 0; j < cols.size(); j++) |
|
103 |
fuz[j] += cols.get(j)[i]; |
|
98 |
try { |
|
99 |
List<double[]> cols = LTeditor.getCols(); |
|
100 |
LexicalTable table = LTeditor.getLexicalTable(); |
|
104 | 101 |
|
105 |
// set values in the first row of the selection |
|
106 |
for (int j = 0; j < cols.size(); j++) |
|
107 |
table.getData().set(selection[0], j, fuz[j]); |
|
108 |
|
|
109 |
// keep only the first selected line |
|
110 |
int[] lineToDelete = new int[selection.length - 1]; |
|
111 |
System.arraycopy(selection, 1, lineToDelete, 0, selection.length - 1); |
|
112 |
// System.out.println("Lines to delete : "+Arrays.toString(lineToDelete)); |
|
113 |
table.getData().removeRows(lineToDelete); |
|
114 |
table.setAltered(); |
|
115 |
// reset line name |
|
116 |
try { |
|
102 |
double[] fuz = new double[cols.size()]; |
|
103 |
for (int j = 0; j < cols.size(); j++) { |
|
104 |
fuz[j] = 0; |
|
105 |
} |
|
106 |
for (int i : selection) { |
|
107 |
for (int j = 0; j < cols.size(); j++) { |
|
108 |
fuz[j] += cols.get(j)[i]; |
|
109 |
} |
|
110 |
} |
|
111 |
// set values in the first row of the selection |
|
112 |
for (int j = 0; j < cols.size(); j++) { |
|
113 |
table.getData().set(selection[0], j, fuz[j]); |
|
114 |
} |
|
115 |
|
|
116 |
// keep only the first selected line |
|
117 |
int[] lineToDelete = new int[selection.length - 1]; |
|
118 |
System.arraycopy(selection, 1, lineToDelete, 0, selection.length - 1); |
|
119 |
// System.out.println("Lines to delete : "+Arrays.toString(lineToDelete)); |
|
120 |
table.getData().removeRows(lineToDelete); |
|
121 |
table.setAltered(); |
|
122 |
// reset line name |
|
123 |
|
|
117 | 124 |
table.getRowNames().setString(selection[0], newname); |
118 | 125 |
LTeditor.compute(false); |
119 | 126 |
|
Formats disponibles : Unified diff