Revision 1437

tmp/org.txm.ca.rcp/src/org/txm/ca/rcp/editors/SingularValuesEditor.java (revision 1437)
1
// Copyright © 2010-2013 ENS de Lyon.
2
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of
3
// Lyon 2, University of Franche-Comté, University of Nice
4
// Sophia Antipolis, University of Paris 3.
5
//
6
// The TXM platform is free software: you can redistribute it
7
// and/or modify it under the terms of the GNU General Public
8
// License as published by the Free Software Foundation,
9
// either version 2 of the License, or (at your option) any
10
// later version.
11
//
12
// The TXM platform is distributed in the hope that it will be
13
// useful, but WITHOUT ANY WARRANTY; without even the implied
14
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15
// PURPOSE. See the GNU General Public License for more
16
// details.
17
//
18
// You should have received a copy of the GNU General
19
// Public License along with the TXM platform. If not, see
20
// http://www.gnu.org/licenses.
21
//
22
//
23
//
24
// $LastChangedDate:$
25
// $LastChangedRevision:$
26
// $LastChangedBy:$
27
//
28
package org.txm.ca.rcp.editors;
29

  
30
import java.text.DecimalFormat;
31
import java.util.ArrayList;
32
import java.util.List;
33

  
34
import org.eclipse.jface.action.MenuManager;
35
import org.eclipse.jface.viewers.ArrayContentProvider;
36
import org.eclipse.jface.viewers.IStructuredContentProvider;
37
import org.eclipse.jface.viewers.ITableLabelProvider;
38
import org.eclipse.jface.viewers.LabelProvider;
39
import org.eclipse.jface.viewers.TableViewer;
40
import org.eclipse.jface.viewers.TableViewerColumn;
41
import org.eclipse.jface.viewers.Viewer;
42
import org.eclipse.swt.SWT;
43
import org.eclipse.swt.events.SelectionAdapter;
44
import org.eclipse.swt.events.SelectionEvent;
45
import org.eclipse.swt.graphics.Image;
46
import org.eclipse.swt.layout.FillLayout;
47
import org.eclipse.swt.widgets.Event;
48
import org.eclipse.swt.widgets.Listener;
49
import org.eclipse.swt.widgets.Menu;
50
import org.eclipse.swt.widgets.Table;
51
import org.eclipse.swt.widgets.TableItem;
52
import org.txm.ca.core.functions.CA;
53
import org.txm.ca.rcp.messages.CAUIMessages;
54
import org.txm.core.results.TXMResult;
55
import org.txm.rcp.StatusLine;
56
import org.txm.rcp.editors.ITablableEditorInput;
57
import org.txm.rcp.editors.TXMEditor;
58
import org.txm.rcp.editors.TableKeyListener;
59
import org.txm.rcp.editors.TableSorter;
60
import org.txm.rcp.editors.input.AbstractTablableEditorInput;
61
import org.txm.rcp.messages.TXMUIMessages;
62
// TODO: Auto-generated Javadoc
63
/**
64
 * show the singular values and compute some stats.
65
 *
66
 * @author mdecorde
67
 */
68
public class SingularValuesEditor extends TXMEditor<CA> {
69

  
70

  
71

  
72
	/** The ID. */
73
	static public String ID = "org.txm.rcp.editors.TableEditor"; //$NON-NLS-1$
74

  
75
	/** The viewer. */
76
	private TableViewer viewer;
77

  
78
	/** The table input. */
79
	//private ITablableEditorInput tableInput;
80

  
81
	/** The columns. */
82
	List<TableViewerColumn> columns = new ArrayList<TableViewerColumn>();
83

  
84
	/** The table sorter. */
85
	private TableSorter tableSorter;
86

  
87

  
88

  
89
	/**
90
	 * 
91
	 * @param result
92
	 */
93
	public SingularValuesEditor(TXMResult result) {
94
		super(result);
95
		
96
//		// Editor input
97
//		ITablableEditorInput table = new AbstractTablableEditorInput() {
98
//			@Override
99
//			public String[] getColumnTitles() {
100
//				return new String[] {
101
//						CAUIMessages.CorrespondanceAnalysisEditorInput_4,
102
//						CAUIMessages.eigenvalue,
103
//						"%", CAUIMessages.CorrespondanceAnalysisEditorInput_11, "", ""}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
104
//			}
105
//
106
//			@Override
107
//			public String[] getColumnTypes() {
108
//				return new String[] {
109
//						TXMUIMessages.integer,
110
//						CAEditor.COL_TYPE,
111
//						CAEditor.COL_TYPE,
112
//						CAEditor.COL_TYPE,
113
//						CAEditor.COL_TYPE,
114
//						CAEditor.SEPARATOR};
115
//			}
116
//
117
//			@Override
118
//			public IStructuredContentProvider getContentProvider() {
119
//				return new IStructuredContentProvider() {
120
//					@Override
121
//					public Object[] getElements(Object inputElement) {
122
//						CA ca = (CA) inputElement;
123
//						List<List<Object>> tabledata = ca.getSingularValuesInfos();
124
//						return tabledata.toArray();
125
//					}
126
//
127
//					@Override
128
//					public void dispose() {
129
//						// TODO Auto-generated method stub
130
//					}
131
//
132
//					@Override
133
//					public void inputChanged(Viewer viewer, Object oldInput,
134
//							Object newInput) {
135
//						// TODO Auto-generated method stub
136
//					}
137
//				};
138
//			}
139
//
140
//			@Override
141
//			public Object getInput() {
142
//				return SingularValuesEditor.this.getResult();
143
//			}
144
//
145
//			@Override
146
//			public LabelProvider getLabelProvider() {
147
//				return new CASingularValueLabelProvider();
148
//			}
149
//		};
150
//
151

  
152
	}
153

  
154
	
155
	/**
156
	 * The Class CASingularValueLabelProvider.
157
	 */
158
	private class CASingularValueLabelProvider extends LabelProvider implements	ITableLabelProvider {
159

  
160
		/**
161
		 * Percent values number format.
162
		 */
163
		protected DecimalFormat percentValuesNumberFormat = new DecimalFormat(new String("0.00")); //$NON-NLS-1$
164

  
165

  
166
		/* (non-Javadoc)
167
		 * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnImage(java.lang.Object, int)
168
		 */
169
		@Override
170
		public Image getColumnImage(Object element, int columnIndex) {
171
			// TODO Auto-generated method stub
172
			return null;
173
		}
174

  
175
		/* (non-Javadoc)
176
		 * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang.Object, int)
177
		 */
178
		@Override
179
		@SuppressWarnings("unchecked") //$NON-NLS-1$
180
		public String getColumnText(Object element, int columnIndex) {
181
			DecimalFormat f;
182
			Object o = ((List<Object>) element).get(columnIndex);
183
			switch (columnIndex) {
184
			case 0: // factor
185
				return o.toString();
186
			case 1: // eigenvalue
187
				if ((Double) o < 1) {
188
					if ((Double) o < 0.0001)
189
						f = new DecimalFormat("0.0000E00"); //$NON-NLS-1$
190
					else
191
						f = new DecimalFormat("0.0000"); //$NON-NLS-1$
192
				} else {
193
					f = new DecimalFormat("##########0.0000"); //$NON-NLS-1$
194
				}
195
				// FIXME: printf syntax tests
196
				//return String.format("%.4f", o);
197
				return f.format(o);
198
			case 2: // percent
199
			case 3: // cumul
200
				return percentValuesNumberFormat.format(o);
201
			default:
202
				return ""; //$NON-NLS-1$
203
			}
204
		}
205
	}
206
	
207

  
208
	@Override
209
	public void _createPartControl() throws Exception {
210
		
211
		this.parent.setLayout(new FillLayout());
212

  
213
		//tableInput = (ITablableEditorInput) this.getEditorInput();
214

  
215
		viewer = new TableViewer(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI | SWT.FULL_SELECTION);
216
		viewer.getTable().addKeyListener(new TableKeyListener(viewer));
217

  
218
		Table table = viewer.getTable();
219
		table.setHeaderVisible(true);
220
		table.setLinesVisible(true);
221

  
222
		String[] titles = new String[] {
223
				CAUIMessages.CorrespondanceAnalysisEditorInput_4,
224
				CAUIMessages.eigenvalue,
225
				"%", CAUIMessages.CorrespondanceAnalysisEditorInput_11, "", ""}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$;
226

  
227
		
228
		for (int i = 0; i < titles.length; i++) {
229
			final int index = i;
230
			final TableViewerColumn column;
231

  
232
			int alignment = SWT.RIGHT;
233
			// Align the bar plot to the left
234
			if(i == 4)	{
235
				alignment = SWT.LEFT;
236
			}
237

  
238
			column = new TableViewerColumn(viewer, alignment);
239

  
240
			column.getColumn().setText(titles[i]);
241
			column.getColumn().setWidth(100);
242
			column.getColumn().setResizable(true);
243
			column.getColumn().setMoveable(true);
244
			columns.add(column);
245

  
246
			column.getColumn().addSelectionListener(new SelectionAdapter() {
247
				@Override
248
				public void widgetSelected(SelectionEvent e) {
249
					StatusLine.setMessage(TXMUIMessages.sortingColumn);
250
					tableSorter.setColumn(index);
251
					int dir = viewer.getTable().getSortDirection();
252
					if (viewer.getTable().getSortColumn() == column.getColumn()) {
253
						dir = dir == SWT.UP ? SWT.DOWN : SWT.UP;
254
					} else {
255
						dir = SWT.DOWN;
256
					}
257
					viewer.getTable().setSortDirection(dir);
258
					viewer.getTable().setSortColumn(column.getColumn());
259
					viewer.refresh();
260
					StatusLine.setMessage(TXMUIMessages.sortDone);
261
				}
262
			});
263
		}
264

  
265

  
266
		// To draw the bar plot column
267
		viewer.getTable().addListener(SWT.EraseItem, new Listener() {
268
		      public void handleEvent(Event event) {
269

  
270
		    	   if(event.index == 4)	{
271
		    		   int itemIndex = viewer.getTable().indexOf((TableItem)event.item);
272
		    		   double percent = Double.parseDouble(((ArrayList)viewer.getElementAt(itemIndex)).get(2).toString().replaceAll(",",".")); // comma replacement according to the locale //$NON-NLS-1$ //$NON-NLS-2$
273

  
274
		    		   int maxPercentItemIndex = 0;
275
		    		   double maxPercent = Double.parseDouble(viewer.getTable().getItem(0).getText(2).replaceAll(",",".")); //$NON-NLS-1$ //$NON-NLS-2$
276
		    		   double tmpMaxPercent;
277

  
278
		    		   // Get the max percent despite of the current row sorting
279
		    		   for(int i = 0; i < viewer.getTable().getItemCount(); i++) {
280
		    			   tmpMaxPercent =  Double.parseDouble(viewer.getTable().getItem(i).getText(2).replaceAll(",",".")); //$NON-NLS-1$ //$NON-NLS-2$
281
		    			   if(tmpMaxPercent > maxPercent)	{
282
		    				   maxPercent = tmpMaxPercent;
283
		    				   maxPercentItemIndex = i;
284
		    			   }
285
		    		   }
286

  
287
		    		   event.gc.setBackground(viewer.getTable().getDisplay().getSystemColor(SWT.COLOR_DARK_GRAY));
288
		    		   event.gc.fillRectangle(event.x, event.y, (int) (event.width * percent / Double.parseDouble(viewer.getTable().getItem(maxPercentItemIndex).getText(2).replaceAll(",","."))), event.height); //$NON-NLS-1$ //$NON-NLS-2$
289
		    	   }
290
		      }
291
		    });
292

  
293

  
294
		
295
		
296

  
297
		//viewer.setContentProvider(tableInput.getContentProvider());
298
		
299
		
300
		viewer.setContentProvider(ArrayContentProvider.getInstance());
301
//		viewer.setContentProvider(new IStructuredContentProvider() {
302
//			@Override
303
//			public Object[] getElements(Object inputElement) {
304
//				return ((CA) inputElement).getSingularValuesInfos().toArray();
305
//			}
306
//
307
//			@Override
308
//			public void dispose() {
309
//				// TODO Auto-generated method stub
310
//			}
311
//
312
//			@Override
313
//			public void inputChanged(Viewer viewer, Object oldInput,
314
//					Object newInput) {
315
//				// TODO Auto-generated method stub
316
//			}
317
//		}
318
//);
319
		
320
		
321
		viewer.setLabelProvider(new CASingularValueLabelProvider());
322
		
323
		
324
		
325

  
326
		tableSorter = new TableSorter();
327
		
328
		//tableSorter.setColumnTypes(tableInput.getColumnTypes());
329
		
330
		
331
		tableSorter.setColumnTypes(new String[] {
332
				TXMUIMessages.integer,
333
				CAEditor.COL_TYPE,
334
				CAEditor.COL_TYPE,
335
				CAEditor.COL_TYPE,
336
				CAEditor.COL_TYPE,
337
				CAEditor.SEPARATOR});
338
		
339
		
340
		viewer.setSorter(tableSorter);
341

  
342
		// Register the context menu
343
		TXMEditor.initContextMenu(this.viewer.getTable(), this.getSite(), this.viewer);
344

  
345
//		createContextMenu(viewer);
346

  
347
		tableSorter.setColumn(0);
348
		int dir = viewer.getTable().getSortDirection();
349
		if (viewer.getTable().getSortColumn() == columns.get(0).getColumn()) {
350
			dir = dir == SWT.UP ? SWT.DOWN : SWT.UP;
351
		} else {
352
			dir = SWT.DOWN;
353
		}
354
		viewer.getTable().setSortDirection(dir);
355
		viewer.getTable().setSortColumn(columns.get(0).getColumn());
356

  
357
		
358
	}
359

  
360

  
361
	@Override
362
	public void updateEditorFromResult(boolean update) throws Exception {
363

  
364
		try {
365
			this.viewer.setInput(((CA)this.getResult()).getSingularValuesInfos().toArray());
366
		}
367
		catch (Exception e) {
368
			// TODO Auto-generated catch block
369
			e.printStackTrace();
370
			this.viewer.setInput(null);
371
		}
372
		
373
		this.viewer.refresh();
374
		
375
		// Pack the columns except the bar plot column
376
		for(int i = 0; i < viewer.getTable().getColumnCount(); i++)	{
377
			if(i != 4)	{
378
				this.viewer.getTable().getColumn(i).pack();
379
			}
380
		}
381
	}
382
	
383

  
384
	
385
	@Override
386
	public void setFocus() {
387
		viewer.getControl().setFocus();
388
	}
389

  
390

  
391
	@Override
392
	public void updateResultFromEditor() {
393
		// TODO Auto-generated method stub
394
		
395
	}
396

  
397

  
398
}
tmp/org.txm.ca.rcp/src/org/txm/ca/rcp/editors/CAEditor.java (revision 1437)
27 27
//
28 28
package org.txm.ca.rcp.editors;
29 29

  
30
import java.awt.Component;
31
import java.awt.event.ComponentEvent;
32
import java.awt.event.ComponentListener;
30 33
import java.util.ArrayList;
31 34
import java.util.Arrays;
32 35
import java.util.List;
33 36

  
34 37
import org.eclipse.jface.viewers.ISelectionChangedListener;
35
import org.eclipse.jface.viewers.IStructuredContentProvider;
36
import org.eclipse.jface.viewers.LabelProvider;
37 38
import org.eclipse.jface.viewers.SelectionChangedEvent;
38 39
import org.eclipse.jface.viewers.TableViewer;
39
import org.eclipse.jface.viewers.Viewer;
40 40
import org.eclipse.osgi.util.NLS;
41 41
import org.eclipse.swt.SWT;
42 42
import org.eclipse.swt.events.SelectionEvent;
......
55 55
import org.eclipse.ui.IEditorInput;
56 56
import org.eclipse.ui.IEditorSite;
57 57
import org.eclipse.ui.IPropertyListener;
58
import org.eclipse.ui.PartInitException;
59 58
import org.eclipse.ui.part.EditorPart;
60 59
import org.txm.ca.core.chartsengine.base.CAChartCreator;
61 60
import org.txm.ca.core.functions.CA;
62 61
import org.txm.ca.core.functions.Eigenvalues;
63 62
import org.txm.ca.rcp.messages.CAUIMessages;
64
import org.txm.chartsengine.rcp.SWTChartsComponentsProvider;
65 63
import org.txm.chartsengine.rcp.editors.ChartEditor;
66 64
import org.txm.chartsengine.rcp.editors.ChartEditorInput;
67 65
import org.txm.core.results.TXMResult;
68
import org.txm.rcp.editors.ITablableEditorInput;
69 66
import org.txm.rcp.editors.SplitedGenericMultiPageEditor;
70 67
import org.txm.rcp.editors.TXMMultiPageEditor;
71 68
import org.txm.rcp.editors.TXMResultEditorInput;
72
import org.txm.rcp.editors.input.AbstractTablableEditorInput;
73 69
import org.txm.rcp.messages.TXMUIMessages;
74 70

  
75 71
// TODO: Auto-generated Javadoc
......
82 78
public class CAEditor extends TXMMultiPageEditor implements SplitedGenericMultiPageEditor {
83 79

  
84 80

  
85
	/** The ca. */
81
	/**
82
	 * The CA.
83
	 */
86 84
	private CA ca;
87 85

  
88 86
	/**
......
91 89
	protected EditorPart mainEditor;
92 90

  
93 91

  
94
	public static String SEPARATOR = "SEPARATOR"; //$NON-NLS-1$
92
	//public static String SEPARATOR = "SEPARATOR"; //$NON-NLS-1$
93
	public static String SEPARATOR = ""; //$NON-NLS-1$
95 94

  
96 95
	public static String COL_TYPE = "Double"; //$NON-NLS-1$
97 96

  
......
161 160
		TXMResultEditorInput caInput = (TXMResultEditorInput) getEditorInput();
162 161
		this.ca = (CA) caInput.getResult();
163 162

  
164
		//this.setPartName(this.ca.getName());
165

  
166 163
		// Initialize the editor parts and editor inputs
167 164
		this.initCAFactorialMapEditor();
168 165
		this.initCASingularValuesTableEditor();
169
//		this.initRowsTableEditor();
170
//		this.initColumnsTableEditor();
166
		this.initRowsTableEditor();
167
		this.initColumnsTableEditor();
171 168
		this.initCASingularValuesBarChartEditor();
172 169

  
173 170

  
......
189 186
			caFactorialMapEditorPart.setParentMultiPagesEditor(this);
190 187

  
191 188
			caFactorialMapEditorPart.createPartControl(mainEditorComposite);
192
			caFactorialMapEditorPart.refresh(false);
193 189

  
194 190
			caFactorialMapEditorPart.addPropertyListener(new IPropertyListener() {
195 191
				@Override
......
198 194
				}
199 195
			});
200 196

  
201
//			// Axis unit square ratio constraint
202
//			caFactorialMapEditorPart.getComposite().getChartComponent().setSquareOffEnabled(true);
203
//			caFactorialMapEditorPart.getComposite().getChartComponent().squareOff();
204
//			Component chartComponent = (Component) caFactorialMapEditorPart.getComposite().getChartComponent();
205
//			// Axis unit square ratio constraint on resize
206
//			chartComponent.addComponentListener(new ComponentListener() {
207
//
208
//				@Override
209
//				public void componentShown(ComponentEvent arg0) {
210
//					// TODO Auto-generated method stub
211
//				}
212
//
213
//				@Override
214
//				public void componentResized(ComponentEvent e) {
215
//					caFactorialMapEditorPart.getComposite().getChartComponent().squareOff();
216
//				}
217
//
218
//				@Override
219
//				public void componentMoved(ComponentEvent arg0) {
220
//					// TODO Auto-generated method stub
221
//				}
222
//
223
//				@Override
224
//				public void componentHidden(ComponentEvent arg0) {
225
//					// TODO Auto-generated method stub
226
//				}
227
//			});
197
			// add the other editors
198
			for (int i = 1; i < editors.size(); i++) {
199
				int editorIndex = 0;
200
				editorIndex = this.addPage(editors.get(i), inputs.get(i));
201
				setPageText(editorIndex, names.get(i));
202
			}
203
	
204
	
205
			caFactorialMapEditorPart.refresh(false);
228 206

  
207
			// Axis unit square ratio constraint
208
			caFactorialMapEditorPart.getComposite().getChartComponent().setSquareOffEnabled(true);
209
			caFactorialMapEditorPart.getComposite().getChartComponent().squareOff();
210
			Component chartComponent = (Component) caFactorialMapEditorPart.getComposite().getChartComponent();
211
			// Axis unit square ratio constraint on resize
212
			chartComponent.addComponentListener(new ComponentListener() {
229 213

  
214
				@Override
215
				public void componentShown(ComponentEvent arg0) {
216
					// TODO Auto-generated method stub
217
				}
218

  
219
				@Override
220
				public void componentResized(ComponentEvent e) {
221
					caFactorialMapEditorPart.getComposite().getChartComponent().squareOff();
222
				}
223

  
224
				@Override
225
				public void componentMoved(ComponentEvent arg0) {
226
					// TODO Auto-generated method stub
227
				}
228

  
229
				@Override
230
				public void componentHidden(ComponentEvent arg0) {
231
					// TODO Auto-generated method stub
232
				}
233
			});
234

  
235

  
236

  
237
			
230 238
		}
231 239
		catch (Exception e1) {
232 240
			org.txm.rcp.utils.Logger.printStackTrace(e1);
......
234 242
			return;
235 243
		}
236 244

  
237
		// add the other editors
238
		for (int i = 1; i < editors.size(); i++) {
239
			int editorIndex = 0;
240
			try {
241
				editorIndex = addPage(editors.get(i), inputs.get(i));
242
			} catch (PartInitException e) {
243
				org.txm.rcp.utils.Logger.printStackTrace(e);
244
				System.out.println(NLS.bind(CAUIMessages.errorWhileOpeningCAEditorColonP0, e));
245
				return;
245
		
246

  
247
		// Selection changed listener to highlight CA chart points from table lines selection
248
		ISelectionChangedListener selectionChangedListener = new ISelectionChangedListener() {
249

  
250
			@Override
251
			public void selectionChanged(SelectionChangedEvent e) {
252
				// Highlight points from table lines
253
				Table table = (Table) ((TableViewer) e.getSource()).getTable();
254
				String[] selectedLabels = new String[table.getSelectionCount()];
255
				TableItem[] selection = table.getSelection();
256

  
257
				for (int i = 0; i < selection.length; i++)	{
258
					selectedLabels[i] = selection[i].getText();
259
				}
260

  
261
				CAFactorialMapChartEditor chartEditor = (CAFactorialMapChartEditor) editors.get(0);
262
				((CAChartCreator) chartEditor.getResult().getChartCreator()).updateChartCAFactorialMapHighlightPoints(chartEditor.getChart(), (e.getSource() == getRowsInfosEditor().getViewer()), selectedLabels);
246 263
			}
247
			setPageText(editorIndex, names.get(i));
264
		};
265

  
266
		// Add selection listener to rows table to link editor with factorial map chart
267
		this.getRowsInfosEditor().getViewer().addSelectionChangedListener(selectionChangedListener);
268
		// Add selection listener to cols table to link editor with factorial map chart
269
		this.getColsInfosEditor().getViewer().addSelectionChangedListener(selectionChangedListener);
270

  
271
		// Selection listeners to change chart items selection order from table sorting
272
		SelectionListener selectionListener = new SelectionListener() {
273

  
274
			@Override
275
			public void widgetSelected(SelectionEvent e) {
276
				// Change chart items selection order
277
				CAFactorialMapChartEditor chartEditor = (CAFactorialMapChartEditor) editors.get(0); 
278
				((CAChartCreator) chartEditor.getResult().getChartCreator()).updateChartCAFactorialMapSetLabelItemsSelectionOrder(chartEditor.getChart(), getRowsInfosEditor().getOrdererLabels(), getColsInfosEditor().getOrdererLabels());
279
			}
280

  
281
			@Override
282
			public void widgetDefaultSelected(SelectionEvent e) {
283
				// TODO Auto-generated method stub
284

  
285
			}
286
		};
287
		// Add listener to column to link chart items selection order with table sorting order
288
		for(int i = 0; i < this.getRowsInfosEditor().getViewer().getTable().getColumnCount(); i++) {
289
			this.getRowsInfosEditor().getViewer().getTable().getColumn(i).addSelectionListener(selectionListener);
248 290
		}
291
		// Add listener to column to link chart items selection order with table sorting order
292
		for(int i = 0; i < this.getColsInfosEditor().getViewer().getTable().getColumnCount(); i++) {
293
			this.getColsInfosEditor().getViewer().getTable().getColumn(i).addSelectionListener(selectionListener);
294
		}
249 295

  
250 296

  
251 297

  
252
		// Selection changed listener to highlight CA chart points from table lines selection
253
//		ISelectionChangedListener selectionChangedListener = new ISelectionChangedListener() {
254
//
255
//			@Override
256
//			public void selectionChanged(SelectionChangedEvent e) {
257
//				// Highlight points from table lines
258
//				Table table = (Table) ((TableViewer) e.getSource()).getTable();
259
//				String[] selectedLabels = new String[table.getSelectionCount()];
260
//				TableItem[] selection = table.getSelection();
261
//
262
//				for (int i = 0; i < selection.length; i++)	{
263
//					selectedLabels[i] = selection[i].getText();
264
//				}
265
//
266
//				CAFactorialMapChartEditor chartEditor = (CAFactorialMapChartEditor) editors.get(0);
267
//				((CAChartCreator) chartEditor.getResult().getChartCreator()).updateChartCAFactorialMapHighlightPoints(chartEditor.getChart(), (e.getSource() == getRowsInfosEditor().getViewer()), selectedLabels);
268
//			}
269
//		};
270
//
271
//		// Add selection listener to rows table to link editor with factorial map chart
272
//		this.getRowsInfosEditor().getViewer().addSelectionChangedListener(selectionChangedListener);
273
//		// Add selection listener to cols table to link editor with factorial map chart
274
//		this.getColsInfosEditor().getViewer().addSelectionChangedListener(selectionChangedListener);
275
//
276
//		// Selection listeners to change chart items selection order from table sorting
277
//		SelectionListener selectionListener = new SelectionListener() {
278
//
279
//			@Override
280
//			public void widgetSelected(SelectionEvent e) {
281
//				// Change chart items selection order
282
//				CAFactorialMapChartEditor chartEditor = (CAFactorialMapChartEditor) editors.get(0); 
283
//				((CAChartCreator) chartEditor.getResult().getChartCreator()).updateChartCAFactorialMapSetLabelItemsSelectionOrder(chartEditor.getChart(), getRowsInfosEditor().getOrdererLabels(), getColsInfosEditor().getOrdererLabels());
284
//			}
285
//
286
//			@Override
287
//			public void widgetDefaultSelected(SelectionEvent e) {
288
//				// TODO Auto-generated method stub
289
//
290
//			}
291
//		};
292
//		// Add listener to column to link chart items selection order with table sorting order
293
//		for(int i = 0; i < this.getRowsInfosEditor().getViewer().getTable().getColumnCount(); i++) {
294
//			this.getRowsInfosEditor().getViewer().getTable().getColumn(i).addSelectionListener(selectionListener);
295
//		}
296
//		// Add listener to column to link chart items selection order with table sorting order
297
//		for(int i = 0; i < this.getColsInfosEditor().getViewer().getTable().getColumnCount(); i++) {
298
//			this.getColsInfosEditor().getViewer().getTable().getColumn(i).addSelectionListener(selectionListener);
299
//		}
300
//
301
//
302
//
303
//		// Sets the parent multi pages editor of the singular values barplot to activate it from the child editor
304
//		((ChartEditor)editors.get(4)).setParentMultiPagesEditor(this);
305
//
306
//
307
//		this.setActivePage(LAST_EDITOR_USED);
298
		// Sets the parent multi pages editor of the singular values barplot to activate it from the child editor
299
		((ChartEditor)editors.get(4)).setParentMultiPagesEditor(this);
308 300

  
301

  
302
		this.setActivePage(LAST_EDITOR_USED);
303

  
309 304
		this.setPartName(this.getEditorInput().getName());
310 305
	}
311 306

  
......
329 324
	 */
330 325
	public void initCASingularValuesBarChartEditor()	{
331 326

  
332
		// Restores or creates new Eigenvalues result
333 327
		Eigenvalues eigenvalues = (Eigenvalues) ca.getFirstChild(Eigenvalues.class);
334
		if(eigenvalues == null)	{
335
			eigenvalues = new Eigenvalues(ca);
336
		}
337
		
338
		// Editor part
339
		EigenvaluesChartEditor eigenvaluesEditor = new EigenvaluesChartEditor(new ChartEditorInput<Eigenvalues>(eigenvalues));
340
		
341
		//eigenvaluesEditor.compute(false);
342
		editors.add(eigenvaluesEditor);
343

  
344
		// Editor input
345
		inputs.add(eigenvaluesEditor.getEditorInput());
328
		EigenvaluesChartEditor editor = new EigenvaluesChartEditor(new ChartEditorInput<Eigenvalues>(eigenvalues));
329
		editors.add(editor);
330
		inputs.add(editor.getEditorInput());
346 331
	}
347 332

  
348 333
	/**
349 334
	 * Initializes CA singular values table editor.
350 335
	 */
351 336
	public void initCASingularValuesTableEditor()	{
352
		// Editor part
353
		SingularValuesEditor editor = new SingularValuesEditor(ca); 
337
		EigenvaluesTableEditor editor = new EigenvaluesTableEditor(ca); 
354 338
		editors.add(editor);
355 339
		inputs.add(editor.getEditorInput());
356 340
	}
......
359 343
	 * Initializes rows data table editor.
360 344
	 */
361 345
	public void initRowsTableEditor()	{
362
		// Editor part
363
		editors.add(new ColsRowsInfosEditor());
364

  
365
		// Editor input
366
		ITablableEditorInput table = new AbstractTablableEditorInput() {
367

  
368
			List<String> coltypes;
346
		ColsRowsInfosEditor editor = new ColsRowsInfosEditor(ca) {
347
			
369 348
			@Override
370
			public String[] getColumnTitles() {
349
			public String[] getTableTitles() {
371 350
				return ca.getRowInfosTitles();
372
				// new String[]{"Rows"," ","Quality","Mass", "Dist", "Inertia"};
373 351
			}
374

  
352
			
375 353
			@Override
376
			public String[] getColumnTypes() {
377
				coltypes = new ArrayList<String>();
378
				coltypes.add(TXMUIMessages.integer);
379
				coltypes.add(SEPARATOR);
380
				coltypes.add(COL_TYPE);
381
				coltypes.add(COL_TYPE);
382
				coltypes.add(COL_TYPE);
383
				coltypes.add(COL_TYPE);
384
				coltypes.add(COL_TYPE);
385
				for (int c = 0; c < 3; c++)// seulement les 3 premiers axes
386
				{
387
					coltypes.add(SEPARATOR);
388
					coltypes.add(COL_TYPE);
389
					coltypes.add(COL_TYPE);
390
				}
391
				coltypes.add(SEPARATOR);
392
				coltypes.add(COL_TYPE);
393
				coltypes.add(COL_TYPE);
394
				coltypes.add(COL_TYPE);
395
				coltypes.add(SEPARATOR);
396
				return coltypes.toArray(new String[] {});
397
				// new String[]{Messages.FrequencyListEditorInput_6,
398
				// Messages.SpecificitiesResultEditorInput_11,
399
				// Messages.SpecificitiesResultEditorInput_11,
400
				// Messages.SpecificitiesResultEditorInput_11};
354
			public Object getTableInput() {
355
				return ca.getRowInfos();
401 356
			}
402

  
403
			@Override
404
			public IStructuredContentProvider getContentProvider() {
405

  
406
				return new IStructuredContentProvider() {
407
					@Override
408
					public Object[] getElements(Object inputElement) {
409

  
410
						CA ca = (CA) inputElement;
411
						return ca.getRowInfos();
412
					}
413

  
414
					@Override
415
					public void dispose() {
416
						// TODO Auto-generated method stub
417
					}
418

  
419
					@Override
420
					public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
421
						// TODO Auto-generated method stub
422
					}
423
				};
424
			}
425

  
426
			@Override
427
			public Object getInput() {
428
				return ca;
429
			}
430

  
431
			@Override
432
			public LabelProvider getLabelProvider() {
433
				return new ColRowInfosLabelProvider(this.getColumnTitles());
434
			}
435 357
		};
436
		inputs.add(table);
358
		
359
		editors.add(editor);
360
		inputs.add(editor.getEditorInput());
437 361
	}
438 362

  
439 363
	/**
440 364
	 * Initializes columns data table editor.
441 365
	 */
442 366
	public void initColumnsTableEditor()	{
443
		// Editor part
444
		editors.add(new ColsRowsInfosEditor());
445 367

  
446
		// Editor input
447
		ITablableEditorInput table = new AbstractTablableEditorInput() {
448

  
449
			List<String> colnames = new ArrayList<String>();
450
			List<String> coltypes = new ArrayList<String>();
451
			boolean firstInit = true;
452

  
368
		ColsRowsInfosEditor editor = new ColsRowsInfosEditor(ca) {
369
			
453 370
			@Override
454
			public String[] getColumnTitles() {
371
			public String[] getTableTitles() {
455 372
				return ca.getColInfosTitles();
456 373
			}
457

  
374
			
458 375
			@Override
459
			public String[] getColumnTypes() {
460
				coltypes = new ArrayList<String>();
461
				coltypes.add(TXMUIMessages.integer);
462
				coltypes.add(SEPARATOR);
463
				coltypes.add(COL_TYPE);
464
				coltypes.add(COL_TYPE);
465
				coltypes.add(COL_TYPE);
466
				coltypes.add(COL_TYPE);
467
				coltypes.add(COL_TYPE);
468
				for (int c = 0; c < 3; c++) {
469
					coltypes.add(SEPARATOR);
470
					coltypes.add(COL_TYPE);
471
					coltypes.add(COL_TYPE);
472
				}
473
				coltypes.add(SEPARATOR);
474
				coltypes.add(COL_TYPE);
475
				coltypes.add(COL_TYPE);
476
				coltypes.add(COL_TYPE);
477
				coltypes.add(SEPARATOR);
478
				return coltypes.toArray(new String[] {});
479
				// new String[]{Messages.FrequencyListEditorInput_6,
480
				// COL_TYPE,
481
				// COL_TYPE,
482
				// COL_TYPE};
376
			public Object getTableInput() {
377
				return ca.getColInfos();
483 378
			}
484

  
485
			@Override
486
			public IStructuredContentProvider getContentProvider() {
487

  
488
				return new IStructuredContentProvider() {
489
					@Override
490
					public Object[] getElements(Object inputElement) {
491
						CA ca = (CA) inputElement;
492
						return ca.getColInfos();
493
					}
494

  
495
					@Override
496
					public void dispose() {
497
						// TODO Auto-generated method stub
498
					}
499

  
500
					@Override
501
					public void inputChanged(Viewer viewer, Object oldInput,
502
							Object newInput) {
503
						// TODO Auto-generated method stub
504
					}
505
				};
506
			}
507

  
508
			@Override
509
			public Object getInput() {
510
				return ca;
511
			}
512

  
513
			@Override
514
			public LabelProvider getLabelProvider() {
515
				return new ColRowInfosLabelProvider(this.getColumnTitles());
516
			}
517 379
		};
518
		inputs.add(table);
380
		
381
		editors.add(editor);
382
		inputs.add(editor.getEditorInput());
519 383
	}
520 384

  
521 385

  
tmp/org.txm.ca.rcp/src/org/txm/ca/rcp/editors/CAFactorialMapChartEditor.java (revision 1437)
1 1
package org.txm.ca.rcp.editors;
2 2

  
3
import java.awt.Component;
4
import java.awt.event.ComponentEvent;
5
import java.awt.event.ComponentListener;
6

  
7 3
import org.eclipse.swt.SWT;
8 4
import org.eclipse.swt.custom.CLabel;
9 5
import org.eclipse.swt.events.SelectionEvent;
......
21 17
import org.txm.core.preferences.TXMPreferences;
22 18
import org.txm.core.results.Parameter;
23 19
import org.txm.rcp.IImageKeys;
20
import org.txm.rcp.editors.TXMEditor;
24 21
import org.txm.rcp.editors.listeners.ComputeSelectionListener;
25 22
import org.txm.rcp.swt.GLComposite;
26 23
import org.txm.rcp.swt.widget.ThresholdsGroup;
......
256 253

  
257 254
	@Override
258 255
	public void updateEditorFromChart(boolean update) {
256
		
257
		// Updating complementary editors
258
		try {
259
			// singular values
260
			((TXMEditor)this.parentMultiPagesEditor.getEditors().get(1)).refresh(update);
261
			// cols and rows
262
			((ColsRowsInfosEditor)this.parentMultiPagesEditor.getEditors().get(2)).refresh(update);
263
			((ColsRowsInfosEditor)this.parentMultiPagesEditor.getEditors().get(3)).refresh(update);
264
			// eigenvalues
265
			((EigenvaluesChartEditor)this.parentMultiPagesEditor.getEditors().get(4)).refresh(update);
266
		}
267
		catch (Exception e) {
268
			// TODO Auto-generated catch block
269
			e.printStackTrace();
270
		}
271
		
272
		
259 273
//		if(!update)	{
260 274
//		// Axis unit square ratio constraint
261 275
//		this.getComposite().getChartComponent().setSquareOffEnabled(true);
tmp/org.txm.ca.rcp/src/org/txm/ca/rcp/editors/ColsRowsInfosEditor.java (revision 1437)
27 27
//
28 28
package org.txm.ca.rcp.editors;
29 29

  
30
import java.util.ArrayList;
31
import java.util.List;
32

  
30 33
import org.eclipse.core.runtime.IProgressMonitor;
31 34
import org.eclipse.jface.action.MenuManager;
35
import org.eclipse.jface.viewers.ArrayContentProvider;
36
import org.eclipse.jface.viewers.IStructuredContentProvider;
37
import org.eclipse.jface.viewers.LabelProvider;
32 38
import org.eclipse.jface.viewers.TableViewer;
33 39
import org.eclipse.jface.viewers.TableViewerColumn;
40
import org.eclipse.jface.viewers.Viewer;
34 41
import org.eclipse.osgi.util.NLS;
35 42
import org.eclipse.swt.SWT;
36 43
import org.eclipse.swt.events.SelectionAdapter;
37 44
import org.eclipse.swt.events.SelectionEvent;
38 45
import org.eclipse.swt.layout.FillLayout;
46
import org.eclipse.swt.layout.GridData;
39 47
import org.eclipse.swt.widgets.Composite;
40 48
import org.eclipse.swt.widgets.Menu;
41 49
import org.eclipse.swt.widgets.Table;
......
44 52
import org.eclipse.ui.IEditorInput;
45 53
import org.eclipse.ui.IEditorSite;
46 54
import org.eclipse.ui.PartInitException;
47
import org.eclipse.ui.part.EditorPart;
55
import org.txm.Toolbox;
56
import org.txm.ca.core.functions.CA;
48 57
import org.txm.ca.rcp.messages.CAUIMessages;
58
import org.txm.core.results.TXMResult;
49 59
import org.txm.rcp.StatusLine;
50 60
import org.txm.rcp.editors.ITablableEditorInput;
61
import org.txm.rcp.editors.TXMEditor;
51 62
import org.txm.rcp.editors.TableKeyListener;
63
import org.txm.rcp.editors.TableLinesViewerComparator;
52 64
import org.txm.rcp.editors.TableSorter;
65
import org.txm.rcp.editors.input.AbstractTablableEditorInput;
53 66
import org.txm.rcp.messages.TXMUIMessages;
67
import org.txm.rcp.swt.GLComposite;
54 68
// TODO: Auto-generated Javadoc
55 69
/**
56 70
 * Used to display rows and cols informations such as contribution, inertia,
57 71
 * mass, coord... @ author mdecorde
58 72
 * 
59 73
 */
60
public class ColsRowsInfosEditor extends EditorPart {
74
public abstract class ColsRowsInfosEditor extends TXMEditor {
61 75
	
62 76
	/** The ID. */
63 77
	static public String ID = "org.txm.rcp.editors.ca.ColsrowsInfosEditor"; //$NON-NLS-1$
......
65 79
	/** The viewer. */
66 80
	private TableViewer viewer;
67 81
	
68
	/** The i editor input. */
69
	private IEditorInput iEditorInput;
70
	
71
	/** The table input. */
72
	private ITablableEditorInput tableInput;
73 82

  
74
	/** The table sorter. */
75
	private TableSorter tableSorter;
76

  
77
	/* (non-Javadoc)
78
	 * @see org.eclipse.ui.part.EditorPart#doSave(org.eclipse.core.runtime.IProgressMonitor)
83
	/**
84
	 * 
85
	 * @param result
79 86
	 */
80
	@Override
81
	public void doSave(IProgressMonitor monitor) {
82
		// TODO Auto-generated method stub
87
	public ColsRowsInfosEditor(TXMResult result) {
88
		super(result);
83 89
	}
84 90

  
85
	/* (non-Javadoc)
86
	 * @see org.eclipse.ui.part.EditorPart#doSaveAs()
87
	 */
91
	
88 92
	@Override
89
	public void doSaveAs() {
90
		// TODO Auto-generated method stub
91
	}
92

  
93
	/* (non-Javadoc)
94
	 * @see org.eclipse.ui.part.EditorPart#init(org.eclipse.ui.IEditorSite, org.eclipse.ui.IEditorInput)
95
	 */
96
	@Override
97
	public void init(IEditorSite site, IEditorInput input)
98
			throws PartInitException {
99
		setSite(site);
100
		setInput(input);
101
		this.iEditorInput = input;
102
	}
103

  
104
	/* (non-Javadoc)
105
	 * @see org.eclipse.ui.part.EditorPart#isDirty()
106
	 */
107
	@Override
108
	public boolean isDirty() {
109
		// TODO Auto-generated method stub
110
		return false;
111
	}
112

  
113
	/* (non-Javadoc)
114
	 * @see org.eclipse.ui.part.EditorPart#isSaveAsAllowed()
115
	 */
116
	@Override
117
	public boolean isSaveAsAllowed() {
118
		// TODO Auto-generated method stub
119
		return false;
120
	}
121

  
122
	/* (non-Javadoc)
123
	 * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
124
	 */
125
	@Override
126
	public void createPartControl(Composite parent) {
127
		parent.setLayout(new FillLayout());
128

  
129
		if (!(iEditorInput instanceof ITablableEditorInput)) {
130
			throw new IllegalArgumentException(CAUIMessages.wrongInput);
131
		}
132
		tableInput = (ITablableEditorInput) iEditorInput;
133
		viewer = new TableViewer(parent, SWT.H_SCROLL | SWT.V_SCROLL
134
				| SWT.MULTI | SWT.FULL_SELECTION);
93
	public void _createPartControl() {
94
		
95
		CA ca = (CA) this.getResult();
96
		
97
		GLComposite resultArea = this.getResultArea();
98
		
99
		viewer = new TableViewer(resultArea, SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI | SWT.FULL_SELECTION);
100
		viewer.getTable().setLayoutData(new GridData(GridData.FILL_BOTH));
101
		
102
		
135 103
		viewer.getTable().addKeyListener(new TableKeyListener(viewer));
136 104
		Table table = viewer.getTable();
137 105
		table.setHeaderVisible(true);
138 106
		table.setLinesVisible(true);
139 107

  
140
		String[] titles = tableInput.getColumnTitles();
141
		String[] types = tableInput.getColumnTypes();
108
		String[] titles = this.getTableTitles();
109
		
110
		List<String> coltypes = new ArrayList<String>();
111
		coltypes.add(TXMUIMessages.integer);
112
		coltypes.add("");
113
		coltypes.add(CAEditor.COL_TYPE);
114
		coltypes.add(CAEditor.COL_TYPE);
115
		coltypes.add(CAEditor.COL_TYPE);
116
		coltypes.add(CAEditor.COL_TYPE);
117
		coltypes.add(CAEditor.COL_TYPE);
118
		for (int c = 0; c < 3; c++)// seulement les 3 premiers axes
119
		{
120
			coltypes.add(CAEditor.SEPARATOR);
121
			coltypes.add(CAEditor.COL_TYPE);
122
			coltypes.add(CAEditor.COL_TYPE);
123
		}
124
		coltypes.add(CAEditor.SEPARATOR);
125
		coltypes.add(CAEditor.COL_TYPE);
126
		coltypes.add(CAEditor.COL_TYPE);
127
		coltypes.add(CAEditor.COL_TYPE);
128
		coltypes.add(CAEditor.SEPARATOR);
129
		
130
		String[] types = coltypes.toArray(new String[] {});
131
		
132
		
142 133
		for (int i = 0; i < titles.length; i++) {
143 134
			final int index = i;
144 135
			final TableViewerColumn column;
145
			if (index == 0)
136
			if (index == 0) {
146 137
				column = new TableViewerColumn(viewer, SWT.LEFT);
147
			else
138
			}
139
			else {
148 140
				column = new TableViewerColumn(viewer, SWT.RIGHT);
141
			}
149 142
			column.getColumn().setText(titles[i]);
150
			if (types[i].equals("SEPARATOR")) //$NON-NLS-1$
151
				column.getColumn().setResizable(false);
152
			else
153
				column.getColumn().setResizable(true);
143
		}
154 144

  
155
			// column.getColumn().setMoveable(true);
145
		viewer.setContentProvider(ArrayContentProvider.getInstance());
146
		viewer.setLabelProvider(new ColRowInfosLabelProvider(this.getTableTitles()));
147
		
148
		// creates the viewer comparator
149
		TableLinesViewerComparator viewerComparator = new TableLinesViewerComparator(Toolbox.getCollator(this.getResult()));
150
		viewer.setComparator(viewerComparator);
151
		viewerComparator.addSelectionAdapters(viewer);
152
		
153
		this.setContentDescription(NLS.bind(CAUIMessages.infosColonP0, titles[0]));
154
		
155
		// Register the context menu
156
		TXMEditor.initContextMenu(this.viewer.getTable(), this.getSite(), this.viewer);
156 157

  
157
			column.getColumn().addSelectionListener(new SelectionAdapter() {
158
				@Override
159
				public void widgetSelected(SelectionEvent e) {
160
					StatusLine.setMessage(TXMUIMessages.sortingColumn );
161
					tableSorter.setColumn(index);
162
					int dir = viewer.getTable().getSortDirection();
163
					if (viewer.getTable().getSortColumn() == column.getColumn()) {
164
						dir = dir == SWT.UP ? SWT.DOWN : SWT.UP;
165
					} else {
166
						dir = SWT.DOWN;
167
					}
168
					viewer.getTable().setSortDirection(dir);
169
					viewer.getTable().setSortColumn(column.getColumn());
170
					viewer.refresh();
171
					StatusLine.setMessage(TXMUIMessages.sortDone);
172
				}
173
			});
174
		}
158
//		createContextMenu(viewer);
175 159

  
176
		viewer.setContentProvider(tableInput.getContentProvider());
177
		viewer.setLabelProvider(tableInput.getLabelProvider());
178
		viewer.setInput(tableInput.getInput());
179 160

  
180
		tableSorter = new TableSorter();
181
		tableSorter.setColumnTypes(tableInput.getColumnTypes());
182
		viewer.setSorter(tableSorter);
183

  
184
		this.setContentDescription(NLS.bind(CAUIMessages.infosColonP0, titles[0]));
185
		createContextMenu(viewer);
186
		viewer.refresh();
187
		for (TableColumn col : viewer.getTable().getColumns())
188
			col.pack();
161
		
189 162
	}
190 163

  
164
//	/**
165
//	 * Creates the context menu.
166
//	 *
167
//	 * @param tableViewer the table viewer
168
//	 */
169
//	private void createContextMenu(TableViewer tableViewer) {
170
//
171
//		MenuManager menuManager = new MenuManager();
172
//		Menu menu = menuManager.createContextMenu(tableViewer.getTable());
173
//
174
//		// Set the MenuManager
175
//		tableViewer.getTable().setMenu(menu);
176
//		getSite().registerContextMenu(menuManager, tableViewer);
177
//		// Make the selection available
178
//		getSite().setSelectionProvider(tableViewer);
179
//	}
180

  
191 181
	/**
182
	 * Gets the data to give to the viewer.
183
	 * @return
184
	 */
185
	public abstract Object getTableInput();
186
	
187
	/**
188
	 * Gets the titles that will be used as column labels.
189
	 * @return
190
	 */
191
	public abstract String[] getTableTitles();
192
	
193
	
194
	@Override
195
	public void updateEditorFromResult(boolean update) throws Exception {
196

  
197
		this.viewer.setInput(this.getTableInput());
198
		
199
		// Pack the columns
200
		TXMEditor.packColumns(this.viewer);
201

  
202
	}
203
	
204
	
205
	/**
192 206
	 * Gets the ordered labels according to the current table sort.
193 207
	 * @return
194 208
	 */
......
203 217
		return labels;
204 218
	}
205 219
	
206
	/**
207
	 * Creates the context menu.
208
	 *
209
	 * @param tableViewer the table viewer
210
	 */
211
	private void createContextMenu(TableViewer tableViewer) {
212 220

  
213
		MenuManager menuManager = new MenuManager();
214
		Menu menu = menuManager.createContextMenu(tableViewer.getTable());
215

  
216
		// Set the MenuManager
217
		tableViewer.getTable().setMenu(menu);
218
		getSite().registerContextMenu(menuManager, tableViewer);
219
		// Make the selection available
220
		getSite().setSelectionProvider(tableViewer);
221
	}
222

  
223 221
	/* (non-Javadoc)
224 222
	 * @see org.eclipse.ui.part.WorkbenchPart#setFocus()
225 223
	 */
......
234 232
	public TableViewer getViewer() {
235 233
		return viewer;
236 234
	}
235

  
236

  
237

  
238

  
239
	@Override
240
	public void updateResultFromEditor() {
241
		// TODO Auto-generated method stub
242
		
243
	}
244

  
245

  
246

  
237 247
}
tmp/org.txm.ca.rcp/src/org/txm/ca/rcp/editors/EigenvaluesTableEditor.java (revision 1437)
1
// Copyright © 2010-2013 ENS de Lyon.
2
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of
3
// Lyon 2, University of Franche-Comté, University of Nice
4
// Sophia Antipolis, University of Paris 3.
5
//
6
// The TXM platform is free software: you can redistribute it
7
// and/or modify it under the terms of the GNU General Public
8
// License as published by the Free Software Foundation,
9
// either version 2 of the License, or (at your option) any
10
// later version.
11
//
12
// The TXM platform is distributed in the hope that it will be
13
// useful, but WITHOUT ANY WARRANTY; without even the implied
14
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15
// PURPOSE. See the GNU General Public License for more
16
// details.
17
//
18
// You should have received a copy of the GNU General
19
// Public License along with the TXM platform. If not, see
20
// http://www.gnu.org/licenses.
21
//
22
//
23
//
24
// $LastChangedDate:$
25
// $LastChangedRevision:$
26
// $LastChangedBy:$
27
//
28
package org.txm.ca.rcp.editors;
29

  
30
import java.text.DecimalFormat;
31
import java.util.ArrayList;
32
import java.util.List;
33

  
34
import org.eclipse.jface.viewers.ArrayContentProvider;
35
import org.eclipse.jface.viewers.ITableLabelProvider;
36
import org.eclipse.jface.viewers.LabelProvider;
37
import org.eclipse.jface.viewers.TableViewer;
38
import org.eclipse.jface.viewers.TableViewerColumn;
39
import org.eclipse.swt.SWT;
40
import org.eclipse.swt.graphics.Image;
41
import org.eclipse.swt.layout.GridData;
42
import org.eclipse.swt.widgets.Event;
43
import org.eclipse.swt.widgets.Listener;
44
import org.eclipse.swt.widgets.TableItem;
45
import org.txm.Toolbox;
46
import org.txm.ca.core.functions.CA;
47
import org.txm.ca.rcp.messages.CAUIMessages;
48
import org.txm.core.results.TXMResult;
49
import org.txm.rcp.editors.TXMEditor;
50
import org.txm.rcp.editors.TableKeyListener;
51
import org.txm.rcp.editors.TableLinesViewerComparator;
52
import org.txm.rcp.swt.GLComposite;
53
// TODO: Auto-generated Javadoc
54
/**
55
 * show the singular values and compute some stats.
56
 *
57
 * @author mdecorde
58
 */
59
public class EigenvaluesTableEditor extends TXMEditor<CA> {
60

  
61

  
62

  
63
	/** The ID. */
64
	static public String ID = "org.txm.rcp.editors.TableEditor"; //$NON-NLS-1$
65

  
66
	/** The viewer. */
67
	private TableViewer viewer;
68

  
69
	/** The table input. */
70
	//private ITablableEditorInput tableInput;
71

  
72
	/** The columns. */
73
	List<TableViewerColumn> columns = new ArrayList<TableViewerColumn>();
74

  
75
	/** The table sorter. */
76
//	private TableSorter tableSorter;
77

  
78

  
79

  
80
	/**
81
	 * 
82
	 * @param result
83
	 */
84
	public EigenvaluesTableEditor(TXMResult result) {
85
		super(result);
86
	}
87

  
88

  
89
	@Override
90
	public void _createPartControl() throws Exception {
91
		
92
		//this.parent.setLayout(new FillLayout());
93

  
94
		//tableInput = (ITablableEditorInput) this.getEditorInput();
95

  
96
		GLComposite resultArea = this.getResultArea();
97
		
98
		viewer = new TableViewer(resultArea, SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI | SWT.FULL_SELECTION);
99
		
100
		viewer.getTable().setLayoutData(new GridData(GridData.FILL_BOTH));
101
		
102
		
103
		viewer.getTable().addKeyListener(new TableKeyListener(viewer));
104

  
105
		viewer.getTable().setHeaderVisible(true);
106
		viewer.getTable().setLinesVisible(true);
107

  
108
		String[] titles = new String[] {
109
				CAUIMessages.CorrespondanceAnalysisEditorInput_4,
110
				CAUIMessages.eigenvalue,
111
				"%", CAUIMessages.CorrespondanceAnalysisEditorInput_11, "", ""}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$;
112

  
113
		
114
		for (int i = 0; i < titles.length; i++) {
115
			final int index = i;
116
			final TableViewerColumn column;
117

  
118
			int alignment = SWT.RIGHT;
119
			// Align the bar plot to the left
120
			if(i == 4)	{
121
				alignment = SWT.LEFT;
122
			}
123

  
124
			column = new TableViewerColumn(viewer, alignment);
125

  
126
			column.getColumn().setText(titles[i]);
127
			column.getColumn().setWidth(100);
128
			column.getColumn().setResizable(true);
129
			column.getColumn().setMoveable(true);
130
			columns.add(column);
131

  
132
//			column.getColumn().addSelectionListener(new SelectionAdapter() {
133
//				@Override
134
//				public void widgetSelected(SelectionEvent e) {
135
//					StatusLine.setMessage(TXMUIMessages.sortingColumn);
136
//					tableSorter.setColumn(index);
137
//					int dir = viewer.getTable().getSortDirection();
138
//					if (viewer.getTable().getSortColumn() == column.getColumn()) {
139
//						dir = dir == SWT.UP ? SWT.DOWN : SWT.UP;
140
//					} else {
141
//						dir = SWT.DOWN;
142
//					}
143
//					viewer.getTable().setSortDirection(dir);
144
//					viewer.getTable().setSortColumn(column.getColumn());
145
//					viewer.refresh();
146
//					StatusLine.setMessage(TXMUIMessages.sortDone);
147
//				}
148
//			});
149
		}
150

  
151

  
152
		// To draw the bar plot column
153
		viewer.getTable().addListener(SWT.EraseItem, new Listener() {
154
		      public void handleEvent(Event event) {
155

  
156
		    	   if(event.index == 4)	{
157
		    		   int itemIndex = viewer.getTable().indexOf((TableItem)event.item);
158
		    		   double percent = Double.parseDouble(((ArrayList)viewer.getElementAt(itemIndex)).get(2).toString().replaceAll(",",".")); // comma replacement according to the locale //$NON-NLS-1$ //$NON-NLS-2$
159

  
160
		    		   int maxPercentItemIndex = 0;
161
		    		   double maxPercent = Double.parseDouble(viewer.getTable().getItem(0).getText(2).replaceAll(",",".")); //$NON-NLS-1$ //$NON-NLS-2$
162
		    		   double tmpMaxPercent;
163

  
164
		    		   // Get the max percent despite of the current row sorting
165
		    		   for(int i = 0; i < viewer.getTable().getItemCount(); i++) {
166
		    			   tmpMaxPercent =  Double.parseDouble(viewer.getTable().getItem(i).getText(2).replaceAll(",",".")); //$NON-NLS-1$ //$NON-NLS-2$
167
		    			   if(tmpMaxPercent > maxPercent)	{
168
		    				   maxPercent = tmpMaxPercent;
169
		    				   maxPercentItemIndex = i;
170
		    			   }
171
		    		   }
172

  
173
		    		   event.gc.setBackground(viewer.getTable().getDisplay().getSystemColor(SWT.COLOR_DARK_GRAY));
174
		    		   event.gc.fillRectangle(event.x, event.y, (int) (event.width * percent / Double.parseDouble(viewer.getTable().getItem(maxPercentItemIndex).getText(2).replaceAll(",","."))), event.height); //$NON-NLS-1$ //$NON-NLS-2$
175
		    	   }
176
		      }
177
		    });
178

  
179

  
180
		viewer.setContentProvider(ArrayContentProvider.getInstance());
181
		viewer.setLabelProvider(new CASingularValueLabelProvider());
182

  
183
		
184
		// creates the viewer comparator
185
		TableLinesViewerComparator viewerComparator = new TableLinesViewerComparator(Toolbox.getCollator(this.getResult()), false);
186
		viewer.setComparator(viewerComparator);
187
		viewerComparator.addSelectionAdapters(viewer);
188

  
189
		
190
//		tableSorter = new TableSorter();
191
//		
192
//		tableSorter.setColumnTypes(new String[] {
193
//				TXMUIMessages.integer,
194
//				CAEditor.COL_TYPE,
195
//				CAEditor.COL_TYPE,
196
//				CAEditor.COL_TYPE,
197
//				CAEditor.COL_TYPE,
198
//				CAEditor.SEPARATOR});
199
//		
200
//		
201
//		viewer.setSorter(tableSorter);
202

  
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff