Révision 2587

tmp/org.txm.specificities.rcp/src/org/txm/specificities/rcp/editors/SpecificitiesEditor.java (revision 2587)
66 66
 * 
67 67
 * @author mdecorde
68 68
 * @author sjacquot
69
 * @author sloiseau 
69
 * @author sloiseau
70 70
 * 
71 71
 */
72 72
public class SpecificitiesEditor extends TXMEditor<Specificities> {
73

  
73
	
74 74
	public final static String ID = SpecificitiesEditor.class.getName();
75

  
75
	
76 76
	/** The specificities table. */
77 77
	private Table specificitesTable;
78
	
78 79
	private TableViewer viewer;
79

  
80
	
80 81
	/**
81 82
	 * Viewer comparator for sorting.
82 83
	 */
83 84
	protected SpecificitiesLinesViewerComparator viewerComparator;
84

  
85

  
85
	
86
	
86 87
	TableColumn typeFrequencyColumn;
87 88
	
88 89
	
89 90
	/**
90 91
	 * Unit property.
91 92
	 */
92
	@Parameter(key=TXMPreferences.UNIT_PROPERTY)
93
	@Parameter(key = TXMPreferences.UNIT_PROPERTY)
93 94
	protected PropertiesComboViewer unitPropertyComboViewer;
94 95
	
95 96
	/**
96 97
	 * Maximum score.
97 98
	 */
98
	@Parameter(key=SpecificitiesPreferences.MAX_SCORE)
99
	@Parameter(key = SpecificitiesPreferences.MAX_SCORE)
99 100
	protected Spinner maxScoreFilter;
100

  
101
	
101 102
	/**
102 103
	 * Minimum frequency filtering spinner.
103 104
	 */
104
	@Parameter(key=TXMPreferences.F_MIN)
105
	@Parameter(key = TXMPreferences.F_MIN)
105 106
	protected Spinner fMinSpinner;
106

  
107
	
107 108
	/**
108 109
	 * Maximum number of lines filtering.
109 110
	 */
110
	@Parameter(key=TXMPreferences.V_MAX)
111
	@Parameter(key = TXMPreferences.V_MAX)
111 112
	protected Spinner vMaxSpinner;
112 113
	
113 114
	
114 115
	@Override
115 116
	public void _createPartControl() {
116

  
117
		
117 118
		try {
118 119
			// Main parameters
119 120
			GLComposite mainParametersArea = this.getMainParametersComposite();
120 121
			mainParametersArea.getLayout().numColumns = 2;
121 122
			
122 123
			// parent parameters
123
			if (!this.getResult().getParent().isVisible())	{
124
			if (!this.getResult().getParent().isVisible()) {
124 125
				// unit property
125 126
				new Label(mainParametersArea, SWT.NONE).setText(TXMCoreMessages.common_property);
126 127
				this.unitPropertyComboViewer = new PropertiesComboViewer(mainParametersArea, this, false,
......
128 129
						this.getResult().getUnitProperty(), false);
129 130
			}
130 131
			
131

  
132
			
132 133
			// Extended parameters
133 134
			Composite extendedParametersArea = this.getExtendedParametersGroup();
134 135
			
......
137 138
			this.maxScoreFilter = maxScore.getSpinner();
138 139
			this.maxScoreFilter.setMinimum(0);
139 140
			this.maxScoreFilter.setMaximum(100000);
140

  
141
			
141 142
			// Result area
142 143
			GLComposite resultArea = this.getResultArea();
143

  
144
			
144 145
			// create table viewer
145 146
			viewer = new TableViewer(resultArea, SWT.VIRTUAL | SWT.MULTI | SWT.FULL_SELECTION);
146 147
			viewer.getTable().addKeyListener(new TableKeyListener(viewer));
......
154 155
			// creates the viewer comparator
155 156
			this.viewerComparator = new SpecificitiesLinesViewerComparator(Toolbox.getCollator(this.getResult()));
156 157
			viewer.setComparator(this.viewerComparator);
157

  
158

  
158
			
159
			
159 160
			// create 1st column: Unit
160 161
			TableColumn unitColumn = new TableColumn(specificitesTable, SWT.NONE);
161 162
			unitColumn.setText(TXMCoreMessages.common_units);
......
176 177
			// add a separator empty column
177 178
			TableColumn separatorColumn = new TableColumn(specificitesTable, SWT.NONE);
178 179
			separatorColumn.setResizable(false);
179

  
180
			
180 181
			specificitesTable.setHeaderVisible(true);
181

  
182
			
182 183
			// Horizontal bar on second table takes up a little extra space.
183 184
			// To keep vertical scroll bars in sink, force table1 to end above
184 185
			// horizontal scrollbar
......
188 189
			spacerData.heightHint = hBarRight.getSize().y;
189 190
			spacer.setLayoutData(spacerData);
190 191
			spacer.setVisible(false);
191

  
192
			
192 193
			// Register the context menu
193 194
			TXMEditor.initContextMenu(this.specificitesTable, this.getSite(), this.viewer);
194 195
			
......
203 204
				this.vMaxSpinner.setMinimum(1);
204 205
			}
205 206
			
206
		} catch (Exception e) {
207
		}
208
		catch (Exception e) {
207 209
			Log.severe(NLS.bind(SpecificitiesUIMessages.failedToComputeSpecificities, e.getMessage()));
208 210
			Log.printStackTrace(e);
209 211
		}
210 212
	}
211

  
212

  
213 213
	
214
	
215
	
214 216
	@Override
215 217
	public void updateEditorFromResult(boolean update) {
216 218
		try {
217

  
219
			
218 220
			String[] lexicalTableColumnNames = null;
219 221
			int[] lexicalTableColumnTotalFrequencies = null;
220

  
222
			
221 223
			try {
222 224
				lexicalTableColumnNames = this.getResult().getColumnsNames();
223 225
				lexicalTableColumnTotalFrequencies = this.getResult().getColumnsFrequenciesSums();
224
			} catch (Exception e) {
226
			}
227
			catch (Exception e) {
225 228
				Log.severe(NLS.bind(RCoreMessages.error_unexpectedErrorInRStatisticsEngine, e));
226 229
				Log.printStackTrace(e);
227 230
				return;
228 231
			}
229

  
232
			
230 233
			int len = lexicalTableColumnNames.length;
231 234
			if (len == 2) {
232 235
				len--; // show only the first column specifs since they are the same (modulo signus)
233 236
			}
234
			if(!update
235
//					//&& this.getResult().hasBeenComputedOnce()
236
					)	{
237

  
237
			if (!update
238
			// //&& this.getResult().hasBeenComputedOnce()
239
			) {
238 240
				
239 241
				
242
				
240 243
				// remove lexical table columns if already exist
241
//				int columnsCount = specificitesTable.getColumnCount();
242
//				System.out.println("SpecificitiesEditor.updateEditorFromResult(): column count = " + columnsCount);
243
//				for (int firstLexicalTableColumnIndex = 3; firstLexicalTableColumnIndex < columnsCount - 1; firstLexicalTableColumnIndex++) {
244
//					System.err.println("SpecificitiesEditor.updateEditorFromResult() removing column " + firstLexicalTableColumnIndex);
245
//					specificitesTable.getColumn(firstLexicalTableColumnIndex).dispose();
246
//				}
244
				// int columnsCount = specificitesTable.getColumnCount();
245
				// System.out.println("SpecificitiesEditor.updateEditorFromResult(): column count = " + columnsCount);
246
				// for (int firstLexicalTableColumnIndex = 3; firstLexicalTableColumnIndex < columnsCount - 1; firstLexicalTableColumnIndex++) {
247
				// System.err.println("SpecificitiesEditor.updateEditorFromResult() removing column " + firstLexicalTableColumnIndex);
248
				// specificitesTable.getColumn(firstLexicalTableColumnIndex).dispose();
249
				// }
247 250
				
248 251
				// System.out.println("partnames: "+Arrays.toString(partNames));
249
				 // for each lexical table column
250
				for (int i = 0, firstLexicalTableColumnIndex = 3; i < len ; i++, firstLexicalTableColumnIndex += 2) {
251

  
252
					//System.err.println("SpecificitiesEditor.updateEditorFromResult() creating column freq at index " + firstLexicalTableColumnIndex);
252
				// for each lexical table column
253
				for (int i = 0, firstLexicalTableColumnIndex = 3; i < len; i++, firstLexicalTableColumnIndex += 2) {
253 254
					
254
					//FREQ COLUMN
255
					// System.err.println("SpecificitiesEditor.updateEditorFromResult() creating column freq at index " + firstLexicalTableColumnIndex);
256
					
257
					// FREQ COLUMN
255 258
					final TableColumn freqpartTableColumn = new TableColumn(specificitesTable, SWT.NONE);
256
//					freqpartTableColumn.setText(lexicalTableColumnNames[i] + " t=" + lexicalTableColumnTotalFrequencies[i]); //$NON-NLS-1$ 
257
//					freqpartTableColumn.setToolTipText(lexicalTableColumnNames[i] + " t=" + lexicalTableColumnTotalFrequencies[i]); //$NON-NLS-1$ 
258
//					//System.out.println("create column "+lexicalTableColumnNames[i]);
259
//					freqpartTableColumn.setAlignment(SWT.RIGHT);
260
//					freqpartTableColumn.pack();
259
					// freqpartTableColumn.setText(lexicalTableColumnNames[i] + " t=" + lexicalTableColumnTotalFrequencies[i]); //$NON-NLS-1$
260
					// freqpartTableColumn.setToolTipText(lexicalTableColumnNames[i] + " t=" + lexicalTableColumnTotalFrequencies[i]); //$NON-NLS-1$
261
					// //System.out.println("create column "+lexicalTableColumnNames[i]);
262
					// freqpartTableColumn.setAlignment(SWT.RIGHT);
263
					// freqpartTableColumn.pack();
261 264
					
262 265
					viewerComparator.addSelectionAdapter(viewer, freqpartTableColumn, firstLexicalTableColumnIndex);
263

  
264 266
					
265
					//System.err.println("SpecificitiesEditor.updateEditorFromResult() creating column score at index " + (firstLexicalTableColumnIndex + 1));
266 267
					
267
					//SCORE COLUMN
268
					// System.err.println("SpecificitiesEditor.updateEditorFromResult() creating column score at index " + (firstLexicalTableColumnIndex + 1));
269
					
270
					// SCORE COLUMN
268 271
					final TableColumn lexicalTableColumn = new TableColumn(specificitesTable, SWT.NONE);
269
					lexicalTableColumn.setText(SpecificitiesUIMessages.index); 
270
					//lexicalTableColumn.setToolTipText(lexicalTableColumnNames[i] + " t=" + lexicalTableColumnTotalFrequencies[i]); //$NON-NLS-1$ 
272
					lexicalTableColumn.setText(SpecificitiesUIMessages.index);
273
					// lexicalTableColumn.setToolTipText(lexicalTableColumnNames[i] + " t=" + lexicalTableColumnTotalFrequencies[i]); //$NON-NLS-1$
271 274
					// System.out.println("create column "+partNames[i]);
272 275
					lexicalTableColumn.setAlignment(SWT.RIGHT);
273 276
					lexicalTableColumn.pack();
274

  
277
					
275 278
					viewerComparator.addSelectionAdapter(viewer, lexicalTableColumn, (firstLexicalTableColumnIndex + 1));
276 279
				}
277 280
			}
278

  
279
			if(!this.getResult().isDirty())	{
281
			
282
			if (!this.getResult().isDirty()) {
280 283
				
281 284
				// units
282 285
				String[] typeNames = this.getResult().getTypeNames();
......
287 290
				int[][] specFreqs = this.getResult().getFrequencies();
288 291
				
289 292
				// units' total in parts
290
				//final int[] sortedPartIndexes = specificitesResult.getSortedPartIndexes();
291
	
293
				// final int[] sortedPartIndexes = specificitesResult.getSortedPartIndexes();
294
				
292 295
				// Create an array of lines to fill the tables
293
//				Log.finest("len types: " + typeNames.length);
294
//				Log.finest("len freq: " + typeFreq.length);
295
//				Log.finest("len specfreqs: " + specFreqs.length);
296
//				Log.finest("len specidx: " + specIndex.length);
296
				// Log.finest("len types: " + typeNames.length);
297
				// Log.finest("len freq: " + typeFreq.length);
298
				// Log.finest("len specfreqs: " + specFreqs.length);
299
				// Log.finest("len specidx: " + specIndex.length);
297 300
				
298 301
				Object[] tableLines = new Object[typeNames.length];
299 302
				for (int j = 0; j < tableLines.length; j++) {
......
304 307
			else {
305 308
				viewer.setInput(null);
306 309
			}
307

  
310
			
308 311
			// Updating the main frequency table header
309 312
			String text = TXMCoreMessages.common_frequency;
310
			if(this.getResult().hasBeenComputedOnce())	{
313
			if (this.getResult().hasBeenComputedOnce()) {
311 314
				text += " " + SpecificitiesUIMessages.t + " " + this.getResult().getFrequenciesSum();
312 315
			}
313 316
			typeFrequencyColumn.setText(text);
314
			typeFrequencyColumn.setToolTipText(typeFrequencyColumn.getText()); 
317
			typeFrequencyColumn.setToolTipText(typeFrequencyColumn.getText());
315 318
			typeFrequencyColumn.pack();
316 319
			
317 320
			// Updating the table headers from lexical table values
318
			for (int i = 0, firstLexicalTableColumnIndex = 3; i < len ; i++, firstLexicalTableColumnIndex += 2) {
321
			for (int i = 0, firstLexicalTableColumnIndex = 3; i < len; i++, firstLexicalTableColumnIndex += 2) {
319 322
				// frequency columns
320 323
				TableColumn freqpartTableColumn = specificitesTable.getColumn(firstLexicalTableColumnIndex);
321 324
				text = lexicalTableColumnNames[i];
322
				if(this.getResult().hasBeenComputedOnce())	{
325
				if (this.getResult().hasBeenComputedOnce()) {
323 326
					text += " t=" + lexicalTableColumnTotalFrequencies[i];
324 327
				}
325
				freqpartTableColumn.setText(text); 
326
				freqpartTableColumn.setToolTipText(freqpartTableColumn.getText()); 
327
				//System.out.println("create column "+lexicalTableColumnNames[i]);
328
				freqpartTableColumn.setText(text);
329
				freqpartTableColumn.setToolTipText(freqpartTableColumn.getText());
330
				// System.out.println("create column "+lexicalTableColumnNames[i]);
328 331
				freqpartTableColumn.setAlignment(SWT.RIGHT);
329
				freqpartTableColumn.pack();
332
				// freqpartTableColumn.pack();
330 333
			}
331

  
332
			// Pack the columns so the label of the sort column is not truncated due of the sorting order arrow display			
334
			
335
			// Pack the columns so the label of the sort column is not truncated due of the sorting order arrow display
333 336
			TXMEditor.packColumns(viewer);
334 337
			
335
		} catch (Exception e) {
338
		}
339
		catch (Exception e) {
336 340
			// TODO Auto-generated catch block
337 341
			e.printStackTrace();
338 342
		}
339 343
	}
340

  
341

  
344
	
345
	
342 346
	@Override
343 347
	public void setFocus() {
344 348
		this.specificitesTable.setFocus();
345 349
	}
346

  
350
	
347 351
	/**
348 352
	 * Gets the current selected lines in table.
353
	 * 
349 354
	 * @return
350 355
	 */
351
	public ISelection getTableSelection()	{
356
	public ISelection getTableSelection() {
352 357
		return this.viewer.getSelection();
353 358
	}
354 359
	
355

  
360
	
356 361
	@Override
357 362
	public void updateResultFromEditor() {
358 363
		// nothing to do
359 364
	}
360

  
361

  
362

  
363
}
365
	
366
	
367
	
368
}

Formats disponibles : Unified diff