Revision 1413

tmp/org.txm.ahc.rcp/src/org/txm/ahc/rcp/editors/AHCChartEditor.java (revision 1413)
105 105
		this.rendering2D.setText("2D");//$NON-NLS-1$
106 106
		this.chartToolBar.addControl(this.rendering2D);
107 107
		this.rendering2D.addSelectionListener(computeSelectionListener);
108
		
109
		
110
		// FIXME: temporary fix, later must enable the font, rendering mode, etc. in R calls
111
		// disable all component of the rendering tool bar
112
		this.advancedChartToolBar.setEnabled(false);
108 113

  
114

  
109 115
	}
110 116

  
111 117

  
tmp/org.txm.specificities.rcp/src/org/txm/specificities/rcp/handlers/ComputeSpecifictiesSelectionChart.java (revision 1413)
61 61
				}
62 62

  
63 63
				final String[] selectedTypeNames = new String[tableLines.length];
64
				String[] partNames = specificities.getPartShortNames();
64
				String[] partNames = specificities.getColumnsNames();
65 65
				final double[][] selectedSpecificitiesIndices = new double[tableLines.length][partNames.length];
66 66
				for (int i = 0; i < tableLines.length; i++) {
67 67
					selectedTypeNames[i] = (String) ((Object[]) tableLines[i])[0];
tmp/org.txm.specificities.rcp/src/org/txm/specificities/rcp/editors/SpecificitiesEditor.java (revision 1413)
46 46
import org.txm.core.results.Parameter;
47 47
import org.txm.rcp.editors.TXMEditor;
48 48
import org.txm.rcp.editors.TableKeyListener;
49
import org.txm.rcp.editors.listeners.ComputeKeyListener;
50
import org.txm.rcp.editors.listeners.ComputeSelectionListener;
49 51
import org.txm.rcp.swt.GLComposite;
50 52
import org.txm.rcp.swt.widget.structures.PropertiesComboViewer;
51 53
import org.txm.searchengine.cqp.corpus.CQPCorpus;
......
119 121
			gridLayout.numColumns = 2;
120 122
			extendedParametersArea.setLayout(gridLayout);
121 123
			
124
			// Computing listeners
125
			ComputeSelectionListener computeSelectionListener = new ComputeSelectionListener(this);
126
			ComputeKeyListener computeKeyListener = new ComputeKeyListener(this);
127
			
122 128
			// max score
123 129
			Label maxScoreLabel = new Label(extendedParametersArea, SWT.NONE);
124 130
			maxScoreLabel.setText("Maximum score");
......
127 133
			this.maxScoreFilter.setToolTipText("The maximum score to display");
128 134
			this.maxScoreFilter.setMinimum(0);
129 135
			
136
			this.maxScoreFilter.addKeyListener(computeKeyListener);
137
			this.maxScoreFilter.addSelectionListener(computeSelectionListener);
138

  
130 139
			
131 140
			
132 141
			// Result area
......
199 208
	@Override
200 209
	public void updateEditorFromResult(boolean update) {
201 210
		try {
211

  
212
			String[] lexicalTableColumnNames = null;
213
			int[] lexicalTableColumnTotalFrequencies = null;
214

  
215

  
216
			try {
217
				lexicalTableColumnNames = this.getResult().getColumnsNames();
218
				lexicalTableColumnTotalFrequencies = this.getResult().getColumnsFrequenciesSums();
219
			} catch (Exception e) {
220
				Log.severe(NLS.bind(RCoreMessages.error_unexpectedErrorInRStatisticsEngine, e));
221
				Log.printStackTrace(e);
222
				return;
223
			}
224

  
202 225
			
203 226
			if(!update
204 227
//					//&& this.getResult().hasBeenComputedOnce()
205 228
					)	{
206
				String[] lexicalTableColumnNames = null;
207
				int[] lexicalTableColumnTotalFrequencies = null;
208
				try {
209
					lexicalTableColumnNames = this.getResult().getPartShortNames();
210
					lexicalTableColumnTotalFrequencies = this.getResult().getPartSizes();
211
				} catch (Exception e) {
212
					Log.severe(NLS.bind(RCoreMessages.error_unexpectedErrorInRStatisticsEngine, e));
213
					Log.printStackTrace(e);
214
					return;
215
				}
216 229

  
217 230
				// remove lexical table columns if already exist
218 231
//				int columnsCount = specificitesTable.getColumnCount();
......
226 239
				 // for each lexical table column
227 240
				for (int i = 0, firstLexicalTableColumnIndex = 3; i < lexicalTableColumnNames.length ; i++, firstLexicalTableColumnIndex += 2) {
228 241

  
229
					System.err.println("SpecificitiesEditor.updateEditorFromResult() creating column freq at index " + firstLexicalTableColumnIndex);
242
					//System.err.println("SpecificitiesEditor.updateEditorFromResult() creating column freq at index " + firstLexicalTableColumnIndex);
230 243
					
231 244
					//FREQ COLUMN
232 245
					final TableColumn freqpartTableColumn = new TableColumn(specificitesTable, SWT.NONE);
233
					freqpartTableColumn.setText(lexicalTableColumnNames[i] + " t=" + lexicalTableColumnTotalFrequencies[i]); //$NON-NLS-1$ 
234
					freqpartTableColumn.setToolTipText(lexicalTableColumnNames[i] + " t=" + lexicalTableColumnTotalFrequencies[i]); //$NON-NLS-1$ 
235
					//System.out.println("create column "+lexicalTableColumnNames[i]);
236
					freqpartTableColumn.setAlignment(SWT.RIGHT);
237
					freqpartTableColumn.pack();
246
//					freqpartTableColumn.setText(lexicalTableColumnNames[i] + " t=" + lexicalTableColumnTotalFrequencies[i]); //$NON-NLS-1$ 
247
//					freqpartTableColumn.setToolTipText(lexicalTableColumnNames[i] + " t=" + lexicalTableColumnTotalFrequencies[i]); //$NON-NLS-1$ 
248
//					//System.out.println("create column "+lexicalTableColumnNames[i]);
249
//					freqpartTableColumn.setAlignment(SWT.RIGHT);
250
//					freqpartTableColumn.pack();
238 251
					
239 252
					viewerComparator.addSelectionAdapter(viewer, freqpartTableColumn, firstLexicalTableColumnIndex);
240 253

  
241 254
					
242
					System.err.println("SpecificitiesEditor.updateEditorFromResult() creating column score at index " + (firstLexicalTableColumnIndex + 1));
255
					//System.err.println("SpecificitiesEditor.updateEditorFromResult() creating column score at index " + (firstLexicalTableColumnIndex + 1));
243 256
					
244 257
					//SCORE COLUMN
245 258
					final TableColumn lexicalTableColumn = new TableColumn(specificitesTable, SWT.NONE);
246 259
					lexicalTableColumn.setText("score"); 
247
					lexicalTableColumn.setToolTipText(lexicalTableColumnNames[i] + " t=" + lexicalTableColumnTotalFrequencies[i]); //$NON-NLS-1$ 
260
					//lexicalTableColumn.setToolTipText(lexicalTableColumnNames[i] + " t=" + lexicalTableColumnTotalFrequencies[i]); //$NON-NLS-1$ 
248 261
					// System.out.println("create column "+partNames[i]);
249 262
					lexicalTableColumn.setAlignment(SWT.RIGHT);
250 263
					lexicalTableColumn.pack();
......
252 265
					viewerComparator.addSelectionAdapter(viewer, lexicalTableColumn, (firstLexicalTableColumnIndex + 1));
253 266
				}
254 267
			}
255
			
268

  
256 269
			if(!this.getResult().isDirty())	{
257 270
				
258
				typeFrequencyColumn.setText(TXMCoreMessages.common_frequency + " " + SpecificitiesUIMessages.t + " " + this.getResult().getCorpusSize()); //$NON-NLS-1$ //$NON-NLS-2$
259
				typeFrequencyColumn.setToolTipText(typeFrequencyColumn.getText()); 
260
				typeFrequencyColumn.pack();
261

  
262 271
				// units
263 272
				String[] typeNames = this.getResult().getTypeNames();
264 273
				// units' total freq
265 274
				int[] typeFreq = this.getResult().getFormFrequencies();
266
				// units' index fr each part
275
				// units' index for each part
267 276
				double[][] specIndex = this.getResult().getSpecificitesIndex();
268
				int[][] specFreqs = this.getResult().getFrequency();
277
				int[][] specFreqs = this.getResult().getFrequencies();
269 278
				
270 279
				// units' total in parts
271 280
				//final int[] sortedPartIndexes = specificitesResult.getSortedPartIndexes();
272 281
	
273 282
				// Create an array of lines to fill the tables
274
				Log.finest("len types: "+typeNames.length);
275
				Log.finest("len freq: "+typeFreq.length);
276
				Log.finest("len specfreqs: "+specFreqs.length);
277
				Log.finest("len specidx: "+specIndex.length);
283
				Log.finest("len types: " + typeNames.length);
284
				Log.finest("len freq: " + typeFreq.length);
285
				Log.finest("len specfreqs: " + specFreqs.length);
286
				Log.finest("len specidx: " + specIndex.length);
278 287
				
279 288
				Object[] tableLines = new Object[typeNames.length];
280 289
				for (int j = 0; j < tableLines.length; j++) {
......
286 295
				viewer.setInput(null);
287 296
			}
288 297

  
298
			
299
			// Updating the main frequency table header
300
			String text = TXMCoreMessages.common_frequency;
301
			if(this.getResult().hasBeenComputedOnce())	{
302
				text += " " + SpecificitiesUIMessages.t + " " + this.getResult().getFrequenciesSum();
303
			}
304
			typeFrequencyColumn.setText(text);
305
			typeFrequencyColumn.setToolTipText(typeFrequencyColumn.getText()); 
306
			typeFrequencyColumn.pack();
307
			
308
			// Updating the table headers from lexical table values
309
			for (int i = 0, firstLexicalTableColumnIndex = 3; i < lexicalTableColumnNames.length ; i++, firstLexicalTableColumnIndex += 2) {
310
				// frequency columns
311
				TableColumn freqpartTableColumn = specificitesTable.getColumn(firstLexicalTableColumnIndex);
312
				text = lexicalTableColumnNames[i];
313
				if(this.getResult().hasBeenComputedOnce())	{
314
					text += " t=" + lexicalTableColumnTotalFrequencies[i];
315
				}
316
				freqpartTableColumn.setText(text); 
317
				freqpartTableColumn.setToolTipText(freqpartTableColumn.getText()); 
318
				//System.out.println("create column "+lexicalTableColumnNames[i]);
319
				freqpartTableColumn.setAlignment(SWT.RIGHT);
320
				freqpartTableColumn.pack();
321
			}
322
			
323
			
324
			
289 325
			// Pack the columns so the label of the sort column is not truncated due of the sorting order arrow display			
290 326
			TXMEditor.packColumns(viewer);
291 327
			
tmp/org.txm.specificities.core/src/org/txm/specificities/core/functions/SpecificitiesSelection.java (revision 1413)
80 80
	protected boolean _compute() throws Exception {
81 81
		Specificities specificities = this.getParent();
82 82
		double[][] tableLines = specificities.getSpecificitesIndex();
83
		String[] partNames = specificities.getPartShortNames();
83
		String[] partNames = specificities.getColumnsNames();
84 84
		String[] rowNames = specificities.getTypeNames();
85 85

  
86 86
		selectedSpecificitiesIndex = new double[selectedTypeNames.size()][partNames.length];
......
153 153
	 */
154 154
	public String[] getSelectedPartNames() {
155 155
		try {
156
			return ((Specificities)this.parent).getPartShortNames();
156
			return ((Specificities)this.parent).getColumnsNames();
157 157
		}
158 158
		catch (StatException e) {
159 159
			// TODO Auto-generated catch block
tmp/org.txm.specificities.core/src/org/txm/specificities/core/functions/Specificities.java (revision 1413)
356 356
	}
357 357

  
358 358
	/**
359
	 * Gets the nbr part.
359
	 * Gets the number of columns of the lexical table.
360 360
	 *
361 361
	 * @return the nbr part
362 362
	 * @throws StatException the stat exception
363 363
	 */
364
	public int getNbrPart() throws StatException {
364
	public int getColumnsCount() throws StatException {
365 365
		if (lexicalTable != null)
366 366
			try {
367 367
				return lexicalTable.getNColumns();
......
371 371
				return 0;
372 372
			}
373 373
		else
374
			return getPartShortNames().length;
374
			return getColumnsNames().length;
375 375
	}
376 376

  
377 377
	/**
378
	 * Gets the corpus size.
378
	 * Gets the sum of all the columns frequencies.
379 379
	 *
380 380
	 * @return the corpus size
381 381
	 * @throws StatException the stat exception
382 382
	 */
383
	public int getCorpusSize() throws StatException {
383
	public int getFrequenciesSum() throws StatException {
384 384
		if (lexicalTable.getData() != null) {
385 385
			return lexicalTable.getData().getTotal();
386
		} else if (lexicon != null){
386
		}
387
		else if (lexicon != null) {
387 388
			return lexicon.nbrOfToken();
388
		} else {
389
		}
390
		else {
389 391
			return 0;
390 392
		}
391 393
	}
392 394

  
393 395
	/**
396
	 * Gets the sums of each columns frequencies.
397
	 *
398
	 * @return the sums of each columns frequencies
399
	 * @throws StatException the stat exception
400
	 * @throws CqiClientException 
401
	 */
402
	public int[] getColumnsFrequenciesSums() throws StatException, CqiClientException {
403
		
404
		if(
405
				//this.lexicalTable != null && 
406
				this.lexicalTable.hasBeenComputedOnce())	{
407
			Vector colsSizes = lexicalTable.getColMarginsVector();
408
			if (colindex != null) {
409
				colsSizes = colsSizes.get(colindex);
410
			}
411
			return colsSizes.asIntArray();
412
		}
413
		else if(this.lexicalTable.getPartition() != null)	{
414
			return ((Partition)this.lexicalTable.getPartition()).getPartSizes();
415
		}
416
		else	{
417
			return new int[] {0, 0};
418
		}
419
//		if (lexicalTable != null && this.subCorpus == null
420
//				|| 
421
//				) {
422
//			try {
423
//				Vector partSizes = lexicalTable.getColMarginsVector();
424
//				if (colindex != null) {
425
//					partSizes = partSizes.get(colindex);
426
//				}
427
//				return partSizes.asIntArray();
428
//			}
429
//			catch (Exception e) {
430
//				return ((Partition)this.lexicalTable.getParent()).getPartSizes();
431
//			}
432
//		}
433
//		else {
434
//			try {
435
//				return new int[] { subLexicon.nbrOfToken(), lexicon.nbrOfToken() - subLexicon.nbrOfToken() };
436
//			}
437
//			// case of Subcorpus specificities (the lexicons has not yet been computed)
438
//			catch (Exception e) {
439
//				return new int[] {0, 0};
440
//			}
441
//		}
442
	}
443
	
444
	/**
394 445
	 * Gets the specificities index.
395 446
	 * 
396 447
	 * @return the specificities index
......
414 465
	}
415 466

  
416 467
	/**
417
	 * Names of the part for which specificities are computed.
468
	 * Gets the names of the lexical table columns.
418 469
	 *
419
	 * @return the part short names
470
	 * @return 
420 471
	 * @throws StatException the stat exception
421 472
	 */
422
	public String[] getPartShortNames() throws StatException {
473
	public String[] getColumnsNames() throws StatException {
423 474
		//		System.out.println("get col names: "+table);
424 475
		//		System.out.println("colnames: "+colnames);
425 476
		if (colnames != null && colnames.size() > 0) {
......
449 500
	}
450 501

  
451 502
	/**
452
	 * Gets the frequency.
503
	 * Gets the frequencies of all columns.
453 504
	 *
454
	 * @return the frequency
505
	 * @return the frequencies
455 506
	 * @throws StatException the stat exception
456 507
	 */
457
	public int[][] getFrequency() throws StatException {
508
	public int[][] getFrequencies() throws StatException {
458 509
		//System.out.println("GET FREQUENCIES");
459 510
		if (frequencies == null) {
460 511
			//System.out.println("no frequencies");
......
507 558
		return lexicon;
508 559
	}
509 560

  
510
	/**
511
	 * Gets the part size.
512
	 *
513
	 * @return the part size
514
	 * @throws StatException the stat exception
515
	 * @throws CqiClientException 
516
	 */
517
	public int[] getPartSizes() throws StatException, CqiClientException {
518
		if (lexicalTable != null && this.subCorpus == null) {
519
			
520
			try {
521
				Vector partSizes = lexicalTable.getColMarginsVector();
522
				if (colindex != null) {
523
					partSizes = partSizes.get(colindex);
524
				}
525
				return partSizes.asIntArray();
526
			}
527
			catch (Exception e) {
528
				return ((Partition)this.lexicalTable.getParent()).getPartSizes();
529
			}
530
			
531
			
532
		}
533
		else {
534
			try {
535
				return new int[] { subLexicon.nbrOfToken(), lexicon.nbrOfToken() - subLexicon.nbrOfToken() };
536
			}
537
			// case of Subcorpus specificities (the lexicons has not yet been computed)
538
			catch (Exception e) {
539
				return new int[] {0, 0};
540
			}
541
		}
542
	}
543 561

  
562

  
544 563
	/**
545 564
	 * The frequency in the whole corpus.
546 565
	 *
......
579 598
		//int[] T = getPartSize();
580 599
		acquireSemaphore();
581 600
		try {
582
			getFrequency();
601
			getFrequencies();
583 602
			getFormFrequencies();
584 603
			getLexicon();
585
			String[] names = getPartShortNames();
604
			String[] names = getColumnsNames();
586 605
			// if ("UTF-8".equals(encoding)) writer.write('\ufeff'); // UTF-8 BOM
587 606
			//write column header
588 607
			String txt = SpecificitiesCoreMessages.unit+colseparator+"F"; //$NON-NLS-1$
tmp/org.txm.wordcloud.rcp/src/org/txm/wordcloud/rcp/editors/WordCloudEditor.java (revision 1413)
69 69
		randomPositions.setText(WordCloudUIMessages.randomizePositions);
70 70
		
71 71

  
72
		// FIXME: temporary fix, later must will to enable the font, rendering mode, etc. in WordCloud R calls
72
		// FIXME: temporary fix, later must enable the font, rendering mode, etc. in WordCloud R calls
73 73
		// disable all component of the rendering tool bar
74 74
		this.advancedChartToolBar.setEnabled(false);
75 75
		
tmp/org.txm.lexicaltable.core/src/org/txm/lexicaltable/core/functions/LexicalTable.java (revision 1413)
488 488
	}
489 489

  
490 490
	@Override
491
	public String getSimpleName() {
492
//		if (statsData != null) {
493
			StringBuilder strb = new StringBuilder();
494
			if (property != null) {
495
				strb.append(property.getName() + " ");
496
				try {
497
					//strb.append(this.getFMin() + " / " + this.getNRows());
498
					strb.append(this.fMinFilter + " / " + this.vMaxFilter);
499
				} catch (Exception e) {
500
					// TODO Auto-generated catch block
501
					e.printStackTrace();
502
					return this.getEmptyName();
503
				}
504
				return strb.toString();
505
			}
506
			
507
//		}
508
		else	{
509
			return this.getEmptyName();	
510
		}
511
	}
512

  
513
	
514
	@Override
491 515
	public String getName() {
492 516
		try {
493
			return this.getPartition().getSimpleName() + ":" + this.getSimpleName(); //$NON-NLS-1$
517
			return this.getParent().getSimpleName() + ":" + this.getSimpleName(); //$NON-NLS-1$
494 518
		}
495 519
		catch(Exception e) {
496 520
		}
......
570 594
		}
571 595
	}
572 596

  
573
	@Override
574
	public String getSimpleName() {
575
//		if (statsData != null) {
576
			StringBuilder strb = new StringBuilder();
577
			if (property != null) {
578
				strb.append(property.getName() + " ");
579
				try {
580
					//strb.append(this.getFMin() + " / " + this.getNRows());
581
					strb.append(this.fMinFilter + " / " + this.vMaxFilter);
582
				} catch (Exception e) {
583
					// TODO Auto-generated catch block
584
					e.printStackTrace();
585
					return this.getEmptyName();
586
				}
587
				return strb.toString();
588
			}
589
			
590
//		}
591
		else	{
592
			return this.getEmptyName();	
593
		}
594
	}
595 597

  
596 598
	/**
597 599
	 * Gets the maximum number of lines filter.
tmp/org.txm.core/src/java/org/txm/core/results/TXMResult.java (revision 1413)
797 797
	 * This method is also recursively called on all the children branch to mark them as dirty.
798 798
	 */
799 799
	public void setDirty() {
800
		this.dirty = true;
800
		this.setDirty(true);
801
	}
802

  
803
	/**
804
	 *  Sets the result dirty state so editors or others will know the TXMResult needs to be recomputed or not.
805
	 *  This method is also recursively called on all the children branch sets the new dirty state.
806
	 * @param dirty
807
	 */
808
	public void setDirty(boolean dirty) {
809
		this.dirty = dirty;
801 810
		for (int i = 0; i < this.children.size(); i++) {
802
			this.children.get(i).setDirty();
811
			this.children.get(i).setDirty(dirty);
803 812
		}
804 813
	}
814
	
805 815

  
806

  
807 816
	/**
808 817
	 * Gets the value of the specified key in parameters, local result node or
809 818
	 * default preferences nodes.
tmp/org.txm.lexicaltable.rcp/src/org/txm/lexicaltable/rcp/editors/LexicalTableEditor.java (revision 1413)
293 293
							// keep only the first col
294 294
							List<Integer> coltodelete = colindices.subList(1, colindices.size());
295 295
							lexicalTable.getData().removeCols(coltodelete);
296
							lexicalTable.setAltered();
296

  
297 297
							// refresh stuff
298 298
							collist = new ArrayList<Object>();// update col name
299 299
							// list
......
370 370
							MergeLines.mergeLines(LexicalTableEditor.this, d.getMergeName(), rowindices);
371 371
						} else {
372 372
							lexicalTable.getData().removeRows(rowindices);
373
							lexicalTable.setAltered();
374 373
							refreshTable(true);
375 374
							viewer.getTable().deselectAll();
376 375
						}
......
668 667
	public void importData(File file) {
669 668
		try {
670 669
			if (lexicalTable.getData().importData(file)) {
671
				lexicalTable.setAltered();
672 670
				// fix col names
673 671
				String[] colnames = lexicalTable.getColNames().asStringsArray();
674 672
				TableColumn[] cols = viewer.getTable().getColumns();
......
693 691
		}
694 692
	}
695 693

  
694
	 
695

  
696 696
		/**
697 697
		 * Sort.
698 698
		 *
......
702 702
	 // FIXME: try to use a ViewerSorter instead of this but also manage the result sorting for export
703 703
		public void sort(TableViewerColumn col, int index) {
704 704

  
705
			if (lexicalTable.getData() == null) return;
706
			
707 705
			if (index == previousSortedCol) {
708 706
				reverse = !reverse;
709 707
			} else {
tmp/org.txm.rcp/src/main/java/org/txm/rcp/handlers/BaseAbstractHandler.java (revision 1413)
136 136
	 * @return
137 137
	 */
138 138
	public static TXMEditor getActiveEditor(ExecutionEvent event)	{
139
		if(event != null)	{
140
			return (TXMEditor) HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().getActivePart();
139
		try {
140
			if(event != null)	{
141
				return (TXMEditor) HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().getActivePart();
142
			}
143
			else	{
144
				return (TXMEditor) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
145
			}
141 146
		}
142
		else	{
143
			return (TXMEditor) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
147
		catch (Exception e) {
144 148
		}
149
		return null;
145 150
	}
146 151
	
147 152
	/**
tmp/org.txm.rcp/src/main/java/org/txm/rcp/adapters/TXMResultAdapter.java (revision 1413)
12 12
import org.txm.core.preferences.TBXPreferences;
13 13
import org.txm.core.results.TXMResult;
14 14
import org.txm.rcp.handlers.BaseAbstractHandler;
15
import org.txm.rcp.utils.SWTEditorsUtils;
15 16

  
16 17
/**
17 18
 * Base adapter for TXM result objects.
......
36 37

  
37 38
	@Override
38 39
	public String getLabel(Object result) {
39
		return ((TXMResult) result).getCurrentName();
40
		// FIXME: SJ: dirty tests
41
		String label = ((TXMResult) result).getCurrentName();
42

  
43
		if(((TXMResult) result).isDirty() && ((TXMResult) result).hasBeenComputedOnce())	{
44
			label += " *";
45
		}
46
		return label;
40 47
	}
41 48

  
42 49
	@Override
tmp/org.txm.rcp/src/main/java/org/txm/rcp/testers/CurrentEditorIsDirty.java (revision 1413)
1
package org.txm.rcp.testers;
2

  
3
import org.eclipse.core.expressions.PropertyTester;
4
import org.txm.rcp.editors.TXMEditor;
5
import org.txm.rcp.handlers.BaseAbstractHandler;
6

  
7
/**
8
 * Checks if the results persistence is enabled.
9
 * 
10
 * @author sjacquot
11
 *
12
 */
13
public class CurrentEditorIsDirty extends PropertyTester {
14

  
15
	//public static final String PROPERTY_NAMESPACE = "org.txm.rcp.testers"; //$NON-NLS-1$
16
//	
17
//	public static final String PROPERTY_STATE_ENGINE_READY = "CurrentEditorIsDirty"; //$NON-NLS-1$
18

  
19

  
20
	@Override
21
	public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
22

  
23
		TXMEditor editor = BaseAbstractHandler.getActiveEditor(null);
24
		
25
		boolean dirty = false;
26
		
27
		if(editor != null)	{
28
			dirty = editor.isDirty();
29
		}
30
		
31
		// DEbug
32
		//System.err.println("Current editor is dirty: " + dirty);
33
		
34
		return dirty;
35
	}
36

  
37
}
0 38

  
tmp/org.txm.rcp/src/main/java/org/txm/rcp/testers/AutoPersistenceDisabled.java (revision 1413)
21 21
	public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
22 22

  
23 23
		boolean enabled = RCPPreferences.getInstance().getBoolean(TBXPreferences.AUTO_PERSISTENCE_ENABLED);
24
		//System.err.println("IS results persistence enabled: " + enabled);
24
		System.err.println("IS results persistence enabled: " + enabled);
25 25
		return !enabled;
26 26
	}
27 27

  
tmp/org.txm.rcp/src/main/java/org/txm/rcp/editors/TXMEditor.java (revision 1413)
173 173
	 * debug purpose variable -> easier to fetch information that the getResult() method
174 174
	 */
175 175
	private T result;
176
	
177
	/**
178
	 * To store or edit the dirty state of the editor from widget.
179
	 */
180
	protected boolean dirty;
176 181

  
182
	
183
	
184
	
185

  
177 186
	@Override
178 187
	public void init(IEditorSite site, IEditorInput input) throws PartInitException {
179 188
		this.setSite(site);
......
440 449
	}
441 450

  
442 451
	/**
443
	 * 
452
	 * Gets the top toolbar.
444 453
	 * @return the default Top toolbar of TXMEditors
445 454
	 */
446 455
	public TXMEditorToolBar getTopToolbar() {
......
448 457
	}
449 458

  
450 459
	/**
451
	 * The user must configure its layout
460
	 * Gets the result display area.
461
	 * The user must configure its layout.
452 462
	 * @return
453 463
	 */
454 464
	public GLComposite getResultArea() {
......
456 466
	}
457 467

  
458 468
	/**
459
	 * 
469
	 * Gets the bottom toolbar.
460 470
	 * @return the default bottom toolbar of editors
461 471
	 */
462 472
	public TXMEditorToolBar getBottomToolbar() {
......
464 474
	}
465 475

  
466 476
	/**
467
	 * Crates the parent layout with some configuration to make children composite visible/invisible.
477
	 * Creates the parent layout with some configuration to make children composite visible/invisible.
468 478
	 * 
469 479
	 * @param colSpan
470 480
	 */
......
474 484
	}
475 485

  
476 486
	/**
477
	 * @return the commandParametersComposite. Put here you main parameter widgets using RowData data layout
487
	 * Gets the extended parameters Group widget.
488
	 * Put here you main parameter widgets using RowData data layout.
489
	 * 
490
	 * @return the extendedParametersGroup 
478 491
	 */
479 492
	public Group getExtendedParametersGroup() {
480 493
		return this.extendedParametersGroup;
......
487 500
		//			getResult().saveParameters();
488 501
		//		}
489 502

  
503
		/// FIXME: SJ: dirty state tests
504
		//this.compute(true);
505
		this.setDirty(false);
506

  
507
		
490 508
		notifyExtensions("notifyDoSave"); //$NON-NLS-1$
491 509
		firePropertyChange(IEditorPart.PROP_DIRTY);
492 510
	}
......
496 514
		// TODO Auto-generated method stub
497 515
	}
498 516

  
517
	@Override
499 518
	public void dispose() {
500 519
		notifyExtensions("notifyDispose"); //$NON-NLS-1$
501 520
		super.dispose();
502 521
	}
503 522

  
523
	/**
524
	 * Sets the dirty state of the editor.
525
	 * Also sets the result dirty state to true if editor is dirty.
526
	 * Then refreshes the corpora view result node to reflect the dirty state.
527
	 * 
528
	 * @param dirty
529
	 */
530
	public void setDirty(boolean dirty) {
531
		this.dirty = dirty;
532
        
533
		//this.result.setDirty(dirty);
534
        
535
        firePropertyChange(IEditorPart.PROP_DIRTY);
536
        CorporaView.refreshObject(this.result);
537
    }
538
	
504 539
	@Override
505 540
	public boolean isDirty() {
506 541

  
507
		boolean dirty = false;
542
		boolean dirty = this.dirty;
543
		
544
		//boolean dirty = false;
508 545

  
509 546
		//		if (this.getResult() != null) { //TODO see what to do with dirty results in TXMEditor
510 547
		//			// if the result has never been computed, the editor is not dirty ->  no * shown
511 548
		//			//dirty = this.getResult().isDirty() && this.getResult().hasBeenComputedOnce();
512 549
		//		}
513 550

  
551
		// FIXME: SJ: tests
552
		//dirty = this.getResult().isDirty() && this.getResult().hasBeenComputedOnce();
553
		
514 554

  
515 555
		for (TXMEditorExtension<T> b : extensions) {
516 556
			try {
......
531 571

  
532 572
	@Override
533 573
	public void setFocus() {
534
		if (mainParametersComposite != null && !mainParametersComposite.isDisposed()) {
535
			mainParametersComposite.setFocus();
536
		}
537
		CorporaView.focus(getResult());
574
		// FIXME SJ: this code leads to a bug, the focus must not be regiven to the main parameter after each computing
575
//		if (mainParametersComposite != null && !mainParametersComposite.isDisposed()) {
576
//			mainParametersComposite.setFocus();
577
//		}
578
		CorporaView.focus(this.getResult());
538 579
	}
539 580

  
540 581
	@SuppressWarnings("unchecked")
......
666 707

  
667 708
					notifyExtensions("notifyStartOfCompute"); //$NON-NLS-1$	
668 709
					
669
					//if (!update || RCPPreferences.getInstance().getBoolean(RCPPreferences.AUTO_UPDATE_EDITOR)) {
670
						if (!TXMEditor.this.getResult().compute(monitor)) {
671
							Log.finest("TXMEditor.compute(): " + TXMEditor.this.getClass().getSimpleName() + ": computing failed.");
672
						}
673
					//}
710
					if (!TXMEditor.this.getResult().compute(monitor)) {
711
						Log.finest("TXMEditor.compute(): " + TXMEditor.this.getClass().getSimpleName() + ": computing failed.");
712
					}
713

  
674 714
					notifyExtensions("notifyEndOfCompute"); //$NON-NLS-1$
675 715

  
676 716
					monitor.worked(50);
......
680 720
						@Override
681 721
						public void run() {
682 722
							try {
723
								/// FIXME: SJ: dirty state tests
724
//								setDirty(false);
725
								
683 726
								refresh(update);
684 727
							} catch (Exception e) {
685 728
								Log.finest("TXMEditor.compute(): " + TXMEditor.this.getClass().getSimpleName() + ": Error while refreshing the editor: " + e); //$NON-NLS-1$
......
804 847
		// focus in the main widget 
805 848
		this.setFocus();
806 849

  
850
		/// FIXME: SJ: dirty state tests
851
		this.setDirty(false);
852

  
853
		
807 854
		// FIXME: update all open editors of the children result
808 855
		// FIXME: prob here is that updateEditorFromResult() doesn't enough because the compute() method does some other stuff
809 856
		// so the cascade computing may be done here rather than in TXMResult.compute() or we need to move some stuff from TXMEditor.compute() to
tmp/org.txm.rcp/src/main/java/org/txm/rcp/editors/listeners/ComputeSelectionListener.java (revision 1413)
33 33
		if(RCPPreferences.getInstance().getBoolean(RCPPreferences.AUTO_UPDATE_EDITOR) && (!(e.getSource() instanceof Spinner) || e.stateMask != 0))	{
34 34
			this.editor.compute(true);
35 35
		}
36
		else	{
37
			this.editor.setDirty(true);
38
		}
36 39
	}
37 40

  
38 41
	@Override
......
46 49
	@Override
47 50
	public void selectionChanged(SelectionChangedEvent event) {
48 51
		// to skip programmatically setSelection() calls on some widgets or if auto-compute preference is false
49
		if(!mustIgnoreEvent(event)
50
				&& RCPPreferences.getInstance().getBoolean(RCPPreferences.AUTO_UPDATE_EDITOR))	{
51
			this.editor.compute(true);
52
//		if(!mustIgnoreEvent(event)
53
//				&& RCPPreferences.getInstance().getBoolean(RCPPreferences.AUTO_UPDATE_EDITOR))	{
54
//			this.editor.compute(true);
55
//		}
56

  
57
		// FIXME: SJ: dirty tests
58
		// to skip programmatically setSelection() calls on some widgets or if auto-compute preference is false
59
		if(!mustIgnoreEvent(event)) {
60
			if(RCPPreferences.getInstance().getBoolean(RCPPreferences.AUTO_UPDATE_EDITOR))	{
61
				this.editor.compute(true);
62
			}
63
			else	{
64
				this.editor.setDirty(true);
65
			}
52 66
		}
67

  
68
		
69
		
53 70
	}
54 71
}
tmp/org.txm.rcp/src/main/java/org/txm/rcp/editors/listeners/ComputeKeyListener.java (revision 1413)
32 32
		if (e.keyCode == SWT.CR || e.keyCode == SWT.KEYPAD_CR) {
33 33
			this.editor.compute(true);
34 34
		}
35
		// if other key than Return is pressed then makes the editor and result dirty in manual-computing mode
36
		else if(!RCPPreferences.getInstance().getBoolean(RCPPreferences.AUTO_UPDATE_EDITOR))	{
37
			//this.editor.setDirty(true);
38
		}
35 39
		// FIXME: update the result from the widget
36 40
		// purpose here is, for example, to enable the compute command button when a query is typed
37 41
		// the code below doesn't work as expected
tmp/org.txm.rcp/plugin.xml (revision 1413)
2963 2963
                  </test>
2964 2964
               </adapt>
2965 2965
            </definition>
2966
            <definition
2967
                  id="TXMEditorActive">
2968
               <with
2969
                     variable="activePart">
2970
                  <instanceof
2971
                        value="org.txm.rcp.editors.TXMEditor">
2972
                  </instanceof>
2973
               </with>
2974
            </definition>
2966 2975
   </extension>
2967 2976
  
2968 2977
   <extension
......
3035 3044
            properties="IsParentHidden"
3036 3045
            type="java.lang.Object">
3037 3046
      </propertyTester>
3047
      <propertyTester
3048
            class="org.txm.rcp.testers.CurrentEditorIsDirty"
3049
            id="org.txm.rcp.testers.CurrentEditorIsDirty"
3050
            namespace="org.txm.rcp.testers"
3051
            properties="CurrentEditorIsDirty"
3052
            type="java.lang.Object">
3053
      </propertyTester>
3038 3054
   </extension>
3039 3055
   <extension
3040 3056
         point="org.eclipse.ui.bindings">
......
3167 3183
            natureId="org.txm.core.CorpusNature">
3168 3184
      </image>
3169 3185
   </extension>
3186
   <extension
3187
         point="org.eclipse.ui.handlers">
3188
      <handler
3189
            class="org.txm.rcp.handlers.results.ComputeTXMResult"
3190
            commandId="org.txm.rcp.handlers.ComputeTXMResult">
3191
         <enabledWhen>
3192
            <test
3193
                  property="org.txm.rcp.testers.CurrentEditorIsDirty"
3194
                  value="false">
3195
            </test>
3196
         </enabledWhen>
3197
         <activeWhen>
3198
            <reference
3199
                  definitionId="TXMEditorActive">
3200
            </reference>
3201
         </activeWhen>
3202
      </handler>
3203
   </extension>
3170 3204
</plugin>

Also available in: Unified diff