Revision 2557

tmp/org.txm.lexicaltable.rcp/src/org/txm/lexicaltable/rcp/editors/___LexicalTableLinesViewerComparator.java (revision 2557)
1
/**
2
 * 
3
 */
4
package org.txm.lexicaltable.rcp.editors;
5

  
6
import java.text.Collator;
7

  
8
import org.eclipse.jface.viewers.Viewer;
9
import org.txm.rcp.editors.TableLinesViewerComparator;
10

  
11
/**
12
 * Viewer comparator for the lines sorting.
13
 * 
14
 * @author sjacquot
15
 *
16
 */
17
// FIXME: viewer comparator tests
18
public class ___LexicalTableLinesViewerComparator extends TableLinesViewerComparator {
19

  
20
	
21
	/**
22
	 * 
23
	 * @param collator
24
	 */
25
	public ___LexicalTableLinesViewerComparator(Collator collator) {
26
		super(collator);
27
	}
28
	
29
	
30
	@Override
31
	public int compare(Viewer viewer, Object e1, Object e2) {
32

  
33
		int result = 0;
34
		System.err.println("LexicalTableLinesViewerComparator.compare(): index = " + this.lastColumnIndex + ", e1 = " + e1 + ", e2 = " + e2);
35
		switch (this.lastColumnIndex) {
36
		// unit
37
		case 1:
38
			result = this.collator.compare(e1, e2);
39
			break;
40
		// total frequencies and columns frequencies	
41
		case 2:
42
		default:
43
			result = ((Integer) e1).compareTo(((Integer) e2));
44
			break;
45
		}
46

  
47
		// reverse if needed
48
		if (this.direction == DESCENDING) {
49
			result = -result;
50
		}
51
		return result;
52
	}
53

  
54
}
tmp/org.txm.lexicaltable.rcp/src/org/txm/lexicaltable/rcp/editors/___TableEditor.java (revision 2557)
46 46
import org.txm.rcp.editors.TableKeyListener;
47 47
import org.txm.rcp.editors.TableSorter;
48 48
import org.txm.rcp.messages.TXMUIMessages;
49

  
49 50
// TODO: Auto-generated Javadoc
50 51
/**
51 52
 * Generic editor of tableable objects.
......
53 54
 * @author sloiseau
54 55
 */
55 56
public class ___TableEditor extends EditorPart {
56

  
57
	
57 58
	/** The ID. */
58 59
	static public String ID = "org.txm.rcp.editors.TableEditor"; //$NON-NLS-1$
59 60
	
......
62 63
	
63 64
	/** The i editor input. */
64 65
	private IEditorInput iEditorInput;
65

  
66
	
66 67
	/** The table sorter. */
67 68
	private TableSorter tableSorter;
68

  
69
	
69 70
	/**
70 71
	 * Linking with the OutlineView.
71 72
	 *
72 73
	 * @param monitor the monitor
73 74
	 */
74 75
	// private OverviewOutlinePage overviewOutlinePage;
75

  
76
	
76 77
	@Override
77 78
	public void doSave(IProgressMonitor monitor) {
78 79
		// TODO Auto-generated method stub
79

  
80
		
80 81
	}
81

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

  
90
		
89 91
	}
90

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

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

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

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

  
132
		
127 133
		viewer = new TableViewer(parent, SWT.H_SCROLL | SWT.V_SCROLL
128 134
				| SWT.MULTI | SWT.FULL_SELECTION | SWT.VIRTUAL);
129 135
		viewer.getTable().addKeyListener(new TableKeyListener(viewer));
130 136
		Table table = viewer.getTable();
131 137
		table.setHeaderVisible(true);
132 138
		table.setLinesVisible(true);
133

  
139
		
134 140
		if (!(iEditorInput instanceof ITablableEditorInput)) {
135 141
			throw new IllegalArgumentException(TXMUIMessages.canNotCreateATableWithTheProvidedInformationColonP0);
136 142
		}
137

  
143
		
138 144
		ITablableEditorInput tableInput = (ITablableEditorInput) iEditorInput;
139

  
145
		
140 146
		String[] titles = tableInput.getColumnTitles();
141

  
147
		
142 148
		for (int i = 0; i < titles.length; i++) {
143 149
			final int index = i;
144 150
			final TableViewerColumn column = new TableViewerColumn(viewer,
145 151
					SWT.NONE);
146

  
152
			
147 153
			column.getColumn().setText(titles[i]);
148 154
			column.getColumn().setWidth(100);
149 155
			column.getColumn().setResizable(true);
150 156
			column.getColumn().setMoveable(true);
151

  
157
			
152 158
			column.getColumn().addSelectionListener(new SelectionAdapter() {
159
				
153 160
				@Override
154 161
				public void widgetSelected(SelectionEvent e) {
155 162
					tableSorter.setColumn(index);
156 163
					int dir = viewer.getTable().getSortDirection();
157 164
					if (viewer.getTable().getSortColumn() == column.getColumn()) {
158 165
						dir = dir == SWT.UP ? SWT.DOWN : SWT.UP;
159
					} else {
166
					}
167
					else {
160 168
						dir = SWT.DOWN;
161 169
					}
162 170
					viewer.getTable().setSortDirection(dir);
......
165 173
				}
166 174
			});
167 175
		}
168

  
176
		
169 177
		viewer.setContentProvider(tableInput.getContentProvider());
170 178
		viewer.setLabelProvider(tableInput.getLabelProvider());
171 179
		viewer.setInput(tableInput.getInput());
172

  
180
		
173 181
		tableSorter = new TableSorter();
174 182
		tableSorter.setColumnTypes(tableInput.getColumnTypes());
175 183
		if (this.iEditorInput instanceof ___LexicalTableEditorInput) {
......
177 185
			tableSorter.setLocale(ed.getResult().getPartition().getParent().getLocale());
178 186
		}
179 187
		viewer.setSorter(tableSorter);
180

  
188
		
181 189
		createContextMenu(viewer);
182 190
	}
183

  
191
	
184 192
	/**
185 193
	 * Creates the context menu.
186 194
	 *
187 195
	 * @param tableViewer the table viewer
188 196
	 */
189 197
	private void createContextMenu(TableViewer tableViewer) {
190

  
198
		
191 199
		MenuManager menuManager = new MenuManager();
192 200
		Menu menu = menuManager.createContextMenu(tableViewer.getTable());
193

  
201
		
194 202
		// Set the MenuManager
195 203
		tableViewer.getTable().setMenu(menu);
196 204
		getSite().registerContextMenu(menuManager, tableViewer);
197 205
		// Make the selection available
198 206
		getSite().setSelectionProvider(tableViewer);
199 207
	}
200

  
208
	
201 209
	/**
202 210
	 * Gets the table sorter.
203 211
	 *
......
206 214
	public TableSorter getTableSorter() {
207 215
		return tableSorter;
208 216
	}
209

  
217
	
210 218
	/**
211 219
	 * Gets the table viewer.
212 220
	 *
......
215 223
	public TableViewer getTableViewer() {
216 224
		return viewer;
217 225
	}
218

  
219
	/* (non-Javadoc)
226
	
227
	/*
228
	 * (non-Javadoc)
220 229
	 * @see org.eclipse.ui.part.WorkbenchPart#setFocus()
221 230
	 */
222 231
	@Override
223 232
	public void setFocus() {
224 233
		viewer.getControl().setFocus();
225 234
	}
226
}
235
}
tmp/org.txm.lexicaltable.rcp/src/org/txm/lexicaltable/rcp/editors/___LexicalTableEditorInput.java (revision 2557)
46 46
import org.txm.rcp.messages.TXMUIMessages;
47 47
import org.txm.searchengine.cqp.corpus.Property;
48 48
import org.txm.statsengine.core.StatException;
49

  
49 50
// TODO: Auto-generated Javadoc
50 51
/**
51 52
 * The Class LexicalTableEditorInput.
......
53 54
 * @author sloiseau
54 55
 */
55 56
public class ___LexicalTableEditorInput extends TXMResultEditorInput {
56

  
57
	
57 58
	/** The editors. */
58 59
	private List<EditorPart> editors;
59 60
	
60 61
	/** The inputs. */
61 62
	private List<IEditorInput> inputs;
62

  
63
	
63 64
	/**
64 65
	 * Instantiates a new lexical table editor input.
65 66
	 *
......
72 73
		
73 74
		editors = new ArrayList<EditorPart>();
74 75
		editors.add(new ___TableEditor());
75

  
76
		
76 77
		inputs = new ArrayList<IEditorInput>();
77

  
78
		
78 79
		class LexicalTableLabelProvider extends LabelProvider implements
79 80
				ITableLabelProvider {
80

  
81
			
81 82
			@Override
82 83
			public Image getColumnImage(Object element, int columnIndex) {
83 84
				return null;
84 85
			}
85

  
86
			
86 87
			@Override
87 88
			public String getColumnText(Object element, int columnIndex) {
88 89
				int[] val = (int[]) element;
89 90
				return String.valueOf(val[columnIndex]);
90 91
			}
91

  
92
			
92 93
		}
93

  
94
		
94 95
		ITablableEditorInput asTable = new AbstractTablableEditorInput() {
95

  
96
			
96 97
			@Override
97 98
			public String[] getColumnTitles() {
98 99
				return new String[] { TXMUIMessages.form,
99 100
						TXMCoreMessages.common_frequency };
100 101
			}
101

  
102
			
102 103
			@Override
103 104
			public String[] getColumnTypes() {
104 105
				return new String[] { TXMUIMessages.string,
105 106
						TXMUIMessages.integer };
106 107
			}
107

  
108
			
108 109
			@Override
109 110
			public IStructuredContentProvider getContentProvider() {
110 111
				return new IStructuredContentProvider() {
112
					
111 113
					@Override
112 114
					public Object[] getElements(Object inputElement) {
113 115
						LexicalTable res = (LexicalTable) inputElement;
......
117 119
								int[] v = null;
118 120
								try {
119 121
									v = res.getRow(i).asIntArray();
120
								} catch (StatException e) {
122
								}
123
								catch (StatException e) {
121 124
									System.err.println(NLS.bind(TXMCoreMessages.errorColonP0, e));
122 125
								}
123 126
								row.add(v);
124 127
							}
125
						} catch (Exception e) {
128
						}
129
						catch (Exception e) {
126 130
							// TODO Auto-generated catch block
127 131
							e.printStackTrace();
128 132
						}
129 133
						return row.toArray();
130 134
					}
131

  
135
					
132 136
					@Override
133 137
					public void dispose() {
134 138
						// TODO Auto-generated method stub
135 139
					}
136

  
140
					
137 141
					@Override
138 142
					public void inputChanged(Viewer viewer, Object oldInput,
139 143
							Object newInput) {
140 144
						// TODO Auto-generated method stub
141 145
					}
142

  
146
					
143 147
				};
144 148
			}
145

  
149
			
146 150
			@Override
147 151
			public Object getInput() {
148 152
				return table;
149 153
			}
150

  
154
			
151 155
			@Override
152 156
			public LabelProvider getLabelProvider() {
153 157
				return new LexicalTableLabelProvider();
154 158
			}
155

  
159
			
156 160
		};
157 161
		inputs.add(asTable);
158

  
162
		
159 163
	}
160

  
161

  
164
	
165
	
162 166
	@Override
163 167
	public LexicalTable getResult() {
164 168
		return (LexicalTable) this.result;
165 169
	}
166

  
170
	
167 171
	/**
168 172
	 * Gets the property.
169 173
	 *
......
172 176
	public Property getProperty() {
173 177
		return this.getResult().getProperty();
174 178
	}
175

  
176
}
179
	
180
}

Also available in: Unified diff