Revision 75

tmp/org.txm.specificities.rcp/src/org/txm/specificities/rcp/handlers/ComputeSpecifities.java (revision 75)
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.specificities.rcp.handlers;
29

  
30
import org.eclipse.core.commands.AbstractHandler;
31
import org.eclipse.core.commands.ExecutionEvent;
32
import org.eclipse.core.commands.ExecutionException;
33
import org.eclipse.core.runtime.IProgressMonitor;
34
import org.eclipse.core.runtime.IStatus;
35
import org.eclipse.core.runtime.Status;
36
import org.eclipse.jface.viewers.IStructuredSelection;
37
import org.eclipse.jface.window.Window;
38
import org.eclipse.osgi.util.NLS;
39
import org.eclipse.ui.IEditorInput;
40
import org.eclipse.ui.IWorkbenchPage;
41
import org.eclipse.ui.IWorkbenchWindow;
42
import org.eclipse.ui.PartInitException;
43
import org.eclipse.ui.handlers.HandlerUtil;
44
import org.txm.Toolbox;
45
import org.txm.core.preferences.TXMPreferences;
46
import org.txm.rcpapplication.JobsTimer;
47
import org.txm.rcpapplication.Messages;
48
import org.txm.rcpapplication.StatusLine;
49
import org.txm.rcpapplication.TxmPreferences;
50
import org.txm.rcpapplication.preferences.LexicalTablePreferencePage;
51
import org.txm.rcpapplication.utils.JobHandler;
52
import org.txm.rcpapplication.views.CorporaView;
53
import org.txm.rcpapplication.views.QueriesView;
54
import org.txm.rcpapplication.views.RVariablesView;
55
import org.txm.searchengine.cqp.clientExceptions.CqiClientException;
56
import org.txm.searchengine.cqp.corpus.Corpus;
57
import org.txm.searchengine.cqp.corpus.Partition;
58
import org.txm.searchengine.cqp.corpus.Property;
59
import org.txm.searchengine.cqp.corpus.Subcorpus;
60
import org.txm.specificities.core.functions.Specificites;
61
import org.txm.specificities.core.functions.SpecificitesResult;
62
import org.txm.specificities.core.preferences.SpecificitiesPreferences;
63
import org.txm.specificities.rcp.dialogs.ComputeSpecificitiesDialog;
64
import org.txm.specificities.rcp.dialogs.ComputeSpecificitiesForSubcorpusDialog;
65
import org.txm.specificities.rcp.editors.SpecificitiesResultEditorInput;
66
import org.txm.specificities.rcp.editors.SpecificitiesTableEditor;
67
import org.txm.stat.StatException;
68
import org.txm.stat.data.LexicalTable;
69
import org.txm.utils.logger.Log;
70

  
71
// TODO: Auto-generated Javadoc
72
/**
73
 * if the selection is a Partition : open the dialog for partition if the
74
 * selection is a sub-corpus : open the diaog for sub-corpus then open the
75
 * result in the Specificities Editor
76
 * 
77
 * @author mdecorde
78
 */
79
public class ComputeSpecifities extends AbstractHandler {
80
	
81
	
82
	// FIXME: should be put in an Activator? or better in an extension point loaded by the corpora view?
83
	// adds a double click listener to the Corpus View
84
	static	{
85
		CorporaView.addDoubleClickListener(SpecificitesResult.class, "ComputeSpecifities"); //$NON-NLS-1$
86
	}
87
	
88
	
89
	
90

  
91
	/** The window. */
92
	private IWorkbenchWindow window;
93

  
94
	/** The selection. */
95
	private IStructuredSelection selection;
96

  
97
	/** The specificities result. */
98
	private SpecificitesResult specificitiesResult;
99

  
100
	/*
101
	 * (non-Javadoc)
102
	 * 
103
	 * @see
104
	 * org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands
105
	 * .ExecutionEvent)
106
	 */
107
	@Override
108
	public Object execute(ExecutionEvent event) throws ExecutionException {
109

  
110
		if(!Toolbox.isStatEngineInitialized()) {
111
			System.out.println(Messages.ComputeSpecifities_0);
112
			return null;
113
		}
114

  
115
		window = HandlerUtil.getActiveWorkbenchWindow(event);
116
		selection = (IStructuredSelection) HandlerUtil.getCurrentSelection(event);
117
		if(selection == null) {
118
			Log.info(Messages.ComputeSpecifities_1);
119
			return null;
120
		}
121
		Object s = selection.getFirstElement();
122
		final int maxScore = TXMPreferences.getInt(SpecificitiesPreferences.PREFERENCES_NODE, SpecificitiesPreferences.MAX_SCORE);
123
		if(s instanceof Partition) {
124
			final Partition partition = (Partition) selection.getFirstElement();
125
			final int Fmin = TxmPreferences.getInt(LexicalTablePreferencePage.FMIN, 1);
126

  
127
			final ComputeSpecificitiesDialog d = new ComputeSpecificitiesDialog(window.getShell(), partition, false);
128
			int code = d.open();
129
			if(code == Window.OK) {
130
				final Property property = d.getAnalysisProperty();
131

  
132
				// final CorporaView corporaView = (CorporaView)
133
				// PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(CorporaView.ID);
134
				JobHandler jobhandler = new JobHandler(Messages.ComputeSpecificities_0) {
135
					@Override
136
					protected IStatus run(IProgressMonitor monitor) {
137
						this.runInit(monitor);
138
						try {
139
							JobsTimer.start();
140
							String str = NLS.bind(Messages.ComputeSpecificities_2, new Object[] { partition.getName(), property });
141
							monitor.beginTask(str, 100);
142
							try {
143
								System.out.println(str);
144
								this.acquireSemaphore();
145
								specificitiesResult = Specificites.specificites(partition, property, d.getPartFocus(), Fmin, maxScore);
146
								this.releaseSemaphore();
147

  
148
								System.out.println(NLS.bind(Messages.DONE, specificitiesResult.getName()));
149
							}
150
							catch(StatException e) {
151
								System.out.println(Messages.ComputeSpecifities_4 + e);
152
								org.txm.rcpapplication.utils.Logger.printStackTrace(e);
153
								return Status.CANCEL_STATUS;
154
							}
155
							monitor.worked(45);
156

  
157
							specificitiesResult.getLexicalTable().storeResult(specificitiesResult);
158
							// partition.storeResult(specificitiesResult);
159
							monitor.worked(5);
160

  
161
							monitor.subTask(Messages.ComputeSpecifities_10);
162
							syncExec(new Runnable() {
163
								@Override
164
								public void run() {
165
									IWorkbenchPage page = window.getActivePage();
166
									SpecificitiesResultEditorInput editorInput = new SpecificitiesResultEditorInput(specificitiesResult, partition);
167
									try {
168
										StatusLine.setMessage(Messages.ComputeSpecifities_10);
169
										page.openEditor(editorInput, SpecificitiesTableEditor.ID); //$NON-NLS-1$
170
									}
171
									catch(PartInitException e) {
172
										System.err.println(NLS.bind(Messages.Error_computing_specificities, e));
173
										org.txm.rcpapplication.utils.Logger.printStackTrace(e);
174
									}
175
								}
176
							});
177

  
178
							monitor.worked(50);
179
							if(monitor.isCanceled())
180
								return Status.CANCEL_STATUS;
181

  
182
							monitor.subTask(Messages.ComputeSpecifities_2);
183
							syncExec(new Runnable() {
184
								@Override
185
								public void run() {
186
									CorporaView.refresh();
187
									CorporaView.expand(specificitiesResult.getParent());
188
									QueriesView.refresh();
189
									RVariablesView.refresh();
190
								}
191
							});
192

  
193
							monitor.worked(100);
194
						}
195
						catch(ThreadDeath td) {
196
							return Status.CANCEL_STATUS;
197
						}
198
						catch(CqiClientException e) {
199
							org.txm.rcpapplication.utils.Logger.printStackTrace(e);
200
						}
201
						finally {
202
							monitor.done();
203
							JobsTimer.stopAndPrint();
204
						}
205
						return Status.OK_STATUS;
206
					}
207
				};
208
				jobhandler.startJob();
209
			}
210
		}
211
		else if(s instanceof Subcorpus) {
212
			final Subcorpus subcorpus = (Subcorpus) s;
213
			ComputeSpecificitiesForSubcorpusDialog d = new ComputeSpecificitiesForSubcorpusDialog(window.getShell(), subcorpus);
214
			int code = d.open();
215
			if(code == Window.OK) {
216
				final Property property = d.getProperty();
217
				try {
218
					JobHandler jobhandler = new JobHandler(Messages.ComputeSpecificities_0) {
219
						@Override
220
						protected IStatus run(IProgressMonitor monitor) {
221
							this.runInit(monitor);
222

  
223
							try {
224
								Corpus parentCorpus = subcorpus.getMotherSubcorpus();
225
								if(parentCorpus == null)
226
									parentCorpus = subcorpus.getMainCorpus();
227

  
228
								System.out.println(NLS.bind(Messages.ComputeSpecifities_3, new Object[] { subcorpus.getName(), parentCorpus.getName(), property }));
229
								specificitiesResult = Specificites.specificites(parentCorpus, subcorpus, property, maxScore);
230
								System.out.println(NLS.bind(Messages.DONE, specificitiesResult.getName()));
231
								subcorpus.storeResult(specificitiesResult);
232
							}
233
							catch(Exception e) {
234
								System.err.println(NLS.bind(Messages.Error_computing_specificities, e));
235
								System.err.println(e);
236
								org.txm.rcpapplication.utils.Logger.printStackTrace(e);
237
							}
238

  
239
							monitor.subTask(Messages.ComputeSpecifities_2);
240
							syncExec(new Runnable() {
241
								@Override
242
								public void run() {
243
									IWorkbenchPage page = window.getActivePage();
244
									SpecificitiesResultEditorInput editorInput = new SpecificitiesResultEditorInput(specificitiesResult, subcorpus);
245

  
246
									try {
247
										page.openEditor(editorInput, SpecificitiesTableEditor.ID);
248
									}
249
									catch(PartInitException e) {
250
										e.printStackTrace();
251
									}
252

  
253
									CorporaView.refresh();
254
									CorporaView.expand(specificitiesResult.getParent());
255
									QueriesView.refresh();
256
									RVariablesView.refresh();
257
								}
258
							});
259

  
260
							return Status.OK_STATUS;
261
						}
262
					};
263
					jobhandler.startJob();
264
				}
265
				catch(Exception e) {
266
					System.err.println(NLS.bind(Messages.Error_computing_specificities, e));
267
				}
268
			}
269
		}
270
		else if(s instanceof LexicalTable) {
271
			final LexicalTable table = (LexicalTable) s;
272
			JobHandler jobhandler = new JobHandler(Messages.ComputeSpecificities_0) {
273
				@Override
274
				protected IStatus run(IProgressMonitor monitor) {
275
					this.runInit(monitor);
276
					try {
277
						JobsTimer.start();
278
						monitor.beginTask(NLS.bind(Messages.ComputeSpecifities_11, table.getPartition().getName()), 100);
279
						try {
280
							System.out.println(Messages.ComputeSpecificities_0 + ": " + table.getPartition().getName()); //$NON-NLS-1$
281
							this.acquireSemaphore();
282
							specificitiesResult = Specificites.specificites(table, maxScore);
283
							this.releaseSemaphore();
284
							System.out.println(NLS.bind(Messages.DONE, specificitiesResult.getName()));
285
						}
286
						catch(StatException e) {
287
							System.err.println(NLS.bind(Messages.Error_computing_specificities, e));
288
							org.txm.rcpapplication.utils.Logger.printStackTrace(e);
289
							return Status.CANCEL_STATUS;
290
						}
291
						monitor.worked(45);
292
						if(monitor.isCanceled())
293
							return Status.CANCEL_STATUS;
294

  
295
						this.acquireSemaphore();
296
						table.storeResult(specificitiesResult);
297
						this.releaseSemaphore();
298
						monitor.worked(5);
299

  
300
						monitor.subTask(Messages.ComputeSpecifities_10);
301
						syncExec(new Runnable() {
302
							@Override
303
							public void run() {
304
								IWorkbenchPage page = window.getActivePage();
305
								SpecificitiesResultEditorInput editorInput = null;
306
								if(table.getPartition() == null) {
307
									editorInput = new SpecificitiesResultEditorInput(specificitiesResult, table.getCorpus());
308
								}
309
								else {
310
									editorInput = new SpecificitiesResultEditorInput(specificitiesResult, table.getPartition());
311
								}
312
								try {
313
									StatusLine.setMessage(Messages.ComputeSpecifities_10);
314
									page.openEditor(editorInput, SpecificitiesTableEditor.ID); //$NON-NLS-1$
315

  
316
								}
317
								catch(PartInitException e) {
318
									org.txm.rcpapplication.utils.Logger.printStackTrace(e);
319
								}
320
							}
321
						});
322

  
323
						monitor.worked(50);
324
						if(monitor.isCanceled()) {
325
							return Status.CANCEL_STATUS;
326
						}
327

  
328
						monitor.subTask(Messages.ComputeSpecifities_2);
329
						syncExec(new Runnable() {
330
							@Override
331
							public void run() {
332
								CorporaView.refresh();
333
								CorporaView.expand(specificitiesResult.getParent());
334
								QueriesView.refresh();
335
								RVariablesView.refresh();
336
							}
337
						});
338

  
339
						monitor.worked(100);
340
					}
341
					catch(ThreadDeath td) {
342
						return Status.CANCEL_STATUS;
343
					}
344
					catch(CqiClientException e) {
345
						org.txm.rcpapplication.utils.Logger.printStackTrace(e);
346
					}
347
					finally {
348
						monitor.done();
349
						JobsTimer.stopAndPrint();
350
					}
351
					return Status.OK_STATUS;
352
				}
353
			};
354
			jobhandler.startJob();
355
		}
356
		// reopens an existing result
357
		else if(s instanceof SpecificitesResult) {
358
			SpecificitesResult specifRes = (SpecificitesResult) s;
359
			Partition partition = null;
360
			IEditorInput editorInput = null;
361

  
362
			if(specifRes.getLexicalTable() != null) {
363
				if(specifRes.getLexicalTable().getPartition() != null) {
364
					partition = specifRes.getLexicalTable().getPartition();
365
					editorInput = new SpecificitiesResultEditorInput(specifRes, partition);
366
				}
367
				else {
368
					editorInput = new SpecificitiesResultEditorInput(specifRes, specifRes.getLexicalTable().getCorpus());
369
				}
370
			}
371
			else {
372
				editorInput = new SpecificitiesResultEditorInput(specifRes, specifRes.getCorpus());
373
			}
374

  
375
			IWorkbenchPage page = window.getActivePage();
376
			try {
377
				page.openEditor(editorInput, SpecificitiesTableEditor.ID); //$NON-NLS-1$
378
			}
379
			catch(PartInitException e) {
380
				System.err.println(Messages.CorporaView_5 + e);
381
			}
382
		}
383

  
384
		return null;
385
	}
386
}
0 387

  
tmp/org.txm.specificities.rcp/src/org/txm/specificities/rcp/handlers/ComputeSpecifictiesBarChart.java (revision 75)
1
package org.txm.specificities.rcp.handlers;
2

  
3
import org.eclipse.core.commands.AbstractHandler;
4
import org.eclipse.core.commands.ExecutionEvent;
5
import org.eclipse.core.commands.ExecutionException;
6
import org.eclipse.swt.widgets.Table;
7
import org.eclipse.ui.IEditorPart;
8
import org.eclipse.ui.IWorkbenchPage;
9
import org.eclipse.ui.IWorkbenchWindow;
10
import org.eclipse.ui.handlers.HandlerUtil;
11
import org.txm.chartsengine.rcp.SWTChartsComponentsProvider;
12
import org.txm.chartsengine.rcp.editors.ChartEditorPart;
13
import org.txm.specificities.core.functions.SpecificitesResult;
14
import org.txm.specificities.core.preferences.SpecificitiesPreferences;
15
import org.txm.specificities.rcp.editors.SpecificitiesTableEditor;
16
import org.txm.specificities.rcp.editors.SpecificitiesTableLines;
17

  
18
public class ComputeSpecifictiesBarChart extends AbstractHandler {
19

  
20

  
21
	/**
22
	 * Get the active editor and show a bar chart if the editor is a SpecificitiesTableEditor
23
	 */
24
	@Override
25
	public Object execute(ExecutionEvent event) throws ExecutionException {
26
		try {
27
			IWorkbenchWindow iww = HandlerUtil.getActiveWorkbenchWindow(event);
28
			IWorkbenchPage iwp = iww.getActivePage();
29
			IEditorPart ieditor = iwp.getActiveEditor();
30
			if (!(ieditor instanceof SpecificitiesTableEditor)) {
31
				System.out.println("Editor is not SpecificitiesTableEditor: " + ieditor.getClass());
32
				return null;
33
			}
34

  
35
			SpecificitiesTableEditor editor = (SpecificitiesTableEditor)ieditor;
36
			SpecificitesResult specificitiesResult = editor.getSpecificitiesResult();
37
			Table specificitesTable = editor.getSpecificitesTable();
38
			SpecificitiesTableLines tableLines = editor.getTableLines();
39
			double[][] specIndex = specificitiesResult.getSpecificitesIndex();
40

  
41
			int[] indices = specificitesTable.getSelectionIndices();
42
			if (indices.length == 0) return null; // no line selected
43

  
44
			final String[] selectedTypeNames = new String[indices.length];
45
			for (int i = 0; i < selectedTypeNames.length; i++) {
46
				selectedTypeNames[i] = (String) ((Object[]) tableLines.getLines()[indices[i]])[0];
47
			}
48

  
49
			int nbrPart = specIndex[0].length;
50
			final double[][] selectedSpecificteIndices = new double[indices.length][nbrPart];
51
			for (int i = 0; i < selectedSpecificteIndices.length; i++) {
52
				selectedSpecificteIndices[i] = (double[]) ((Object[]) tableLines.getLines()[indices[i]])[3];
53
			}
54

  
55
			String[] partNames = specificitiesResult.getPartShortNames();
56

  
57
			show(specificitiesResult, partNames, selectedTypeNames, selectedSpecificteIndices);
58
		} catch (Exception e) {
59
			System.out.println("Error while computing specificities bar chart: "+e.getLocalizedMessage());
60
			org.txm.rcpapplication.utils.Logger.printStackTrace(e);
61
		}
62
		return null;
63
	}
64

  
65
	/**
66
	 * Opens the bar chart of the selected partNames, typeNames and specif indexes 
67
	 * 
68
	 * @param specificitiesResult
69
	 * @param partNames
70
	 * @param typeNames
71
	 * @param specificteIndices
72
	 */
73
	public void show(SpecificitesResult specificitiesResult, String[] partNames, String[] typeNames, double[][] specificteIndices) {
74
		try {
75

  
76
			// Set the data to focus on
77
			specificitiesResult.setSelectedPartNames(partNames);
78
			specificitiesResult.setSelectedTypeNames(typeNames);
79
			specificitiesResult.setSelectedSpecificitiesIndex(specificteIndices);
80

  
81
			// Create and open the chart editor
82
			ChartEditorPart editor = SWTChartsComponentsProvider.getCurrent().openEditor(specificitiesResult.getName(), specificitiesResult, SpecificitiesPreferences.PREFERENCES_NODE);
83

  
84
		}
85
		catch (Exception e) {
86
			System.out.println("Error while computing specificities bar chart: "+e.getLocalizedMessage());
87
			org.txm.rcpapplication.utils.Logger.printStackTrace(e);
88
		}
89
	}
90

  
91
}
0 92

  
tmp/org.txm.specificities.rcp/src/org/txm/specificities/rcp/preferences/SpecificitiesPreferencePage.java (revision 75)
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.specificities.rcp.preferences;
29

  
30
import org.eclipse.jface.preference.BooleanFieldEditor;
31
import org.eclipse.jface.preference.IntegerFieldEditor;
32
import org.eclipse.jface.preference.StringFieldEditor;
33
import org.eclipse.swt.SWT;
34
import org.eclipse.swt.layout.GridData;
35
import org.eclipse.swt.widgets.Composite;
36
import org.eclipse.ui.IWorkbench;
37
import org.txm.chartsengine.rcp.SWTChartsComponentsProvider;
38
import org.txm.rcp.preferences.TXMPreferencePage;
39
import org.txm.rcp.preferences.TXMPreferenceStore;
40
import org.txm.rcpapplication.jface.DoubleFieldEditor;
41
import org.txm.specificities.core.preferences.SpecificitiesPreferences;
42
import org.txm.specificities.rcp.adapters.SpecificitiesAdapterFactory;
43
import org.txm.specificities.rcp.messages.RCPSpecificitiesMessages;
44
/**
45
 * Specificities preferences page.
46
 * @author mdecorde
47
 * @author sjacquot
48
 *
49
 */
50
public class SpecificitiesPreferencePage extends TXMPreferencePage	{
51
	
52
	
53
	
54

  
55
	/**
56
	 * Instantiates a new specificities preference page.
57
	 */
58
	public SpecificitiesPreferencePage() {
59
		super();
60
	}
61

  
62
	/* (non-Javadoc)
63
	 * @see org.eclipse.jface.preference.FieldEditorPreferencePage#createFieldEditors()
64
	 */
65
	@Override
66
	protected void createFieldEditors() {
67
				
68
		
69
		this.addField(new StringFieldEditor(SpecificitiesPreferences.FORMAT, RCPSpecificitiesMessages.SpecificitiesPreferencePage_3, this.getFieldEditorParent()));
70

  
71
		
72
		IntegerFieldEditor maxScoreField = new IntegerFieldEditor(SpecificitiesPreferences.MAX_SCORE, RCPSpecificitiesMessages.SpecificitiesPreferencePage_8, this.getFieldEditorParent()); 
73
		maxScoreField.setTextLimit(4);
74
		maxScoreField.setValidRange(10, 1000);
75
		this.addField(maxScoreField);
76
		
77
		
78
		// Charts rendering
79
		Composite chartsTab = SWTChartsComponentsProvider.createChartsRenderingPreferencesTabFolderComposite(this.getFieldEditorParent());
80
		
81
		this.addField(new DoubleFieldEditor(SpecificitiesPreferences.CHART_BANALITY, RCPSpecificitiesMessages.SpecificitiesPreferencePage_7, chartsTab));
82
		
83
		// Create a group for columns management of mixed boolean fields and field/text input fields
84
		Composite booleansGroup = new Composite(chartsTab, SWT.NONE);
85
		GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, false);
86
		gridData.horizontalSpan = 2;
87
		booleansGroup.setLayoutData(gridData);
88
		
89
		this.addField(new BooleanFieldEditor(SpecificitiesPreferences.CHART_TRANSPOSE, RCPSpecificitiesMessages.SpecificitiesPreferencePage_4, booleansGroup));
90
		this.addField(new BooleanFieldEditor(SpecificitiesPreferences.CHART_DRAW_LINES, RCPSpecificitiesMessages.SpecificitiesPreferencePage_5, booleansGroup));
91
		this.addField(new BooleanFieldEditor(SpecificitiesPreferences.CHART_DRAW_BARS, RCPSpecificitiesMessages.SpecificitiesPreferencePage_6, booleansGroup));
92
		
93
		// other shared preferences
94
		SWTChartsComponentsProvider.createChartsRenderingPreferencesFields(this, chartsTab);
95
		
96
	}
97

  
98
	
99
	public static TXMPreferenceStore getNewPreferenceStore()	{
100
		return new TXMPreferenceStore(SpecificitiesPreferences.PREFERENCES_NODE);
101
	}
102
	
103
	@Override
104
	public void init(IWorkbench workbench) {
105
		this.setPreferenceStore(getNewPreferenceStore());
106
		this.setTitle(RCPSpecificitiesMessages.SpecificitiesPreferencePage_2);
107
		this.setImageDescriptor(SpecificitiesAdapterFactory.ICON);
108
	}
109

  
110

  
111

  
112
}
0 113

  
tmp/org.txm.specificities.rcp/src/org/txm/specificities/rcp/dialogs/ComputeSpecificitiesForSubcorpusDialog.java (revision 75)
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.specificities.rcp.dialogs;
29

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

  
33
import org.eclipse.jface.dialogs.Dialog;
34
import org.eclipse.jface.dialogs.MessageDialog;
35
import org.eclipse.swt.SWT;
36
import org.eclipse.swt.layout.GridData;
37
import org.eclipse.swt.layout.GridLayout;
38
import org.eclipse.swt.widgets.Combo;
39
import org.eclipse.swt.widgets.Composite;
40
import org.eclipse.swt.widgets.Control;
41
import org.eclipse.swt.widgets.Label;
42
import org.eclipse.swt.widgets.Shell;
43
import org.txm.rcpapplication.Messages;
44
import org.txm.searchengine.cqp.clientExceptions.CqiClientException;
45
import org.txm.searchengine.cqp.corpus.Property;
46
import org.txm.searchengine.cqp.corpus.Subcorpus;
47
// TODO: Auto-generated Javadoc
48
/**
49
 * 
50
 * TODO : this dialog box should be factorized between function (getProperty,
51
 * getPropertyWithModality, etc.)
52
 * 
53
 * @author sloiseau
54
 * 
55
 */
56
public class ComputeSpecificitiesForSubcorpusDialog extends Dialog {
57

  
58
	/** The property. */
59
	private Property property;
60
	
61
	/** The properties. */
62
	private List<Property> properties;
63
	
64
	/** The ana prop combo. */
65
	private Combo anaPropCombo;
66

  
67
	/**
68
	 * Instantiates a new compute specificities for subcorpus dialog.
69
	 *
70
	 * @param parentShell the parent shell
71
	 * @param subcorpus the subcorpus
72
	 */
73
	public ComputeSpecificitiesForSubcorpusDialog(Shell parentShell,
74
			Subcorpus subcorpus) {
75
		super(parentShell);
76
		try {
77
			this.properties = new ArrayList<Property>(subcorpus.getOrderedProperties());
78
		} catch (CqiClientException e) {
79
			// TODO Auto-generated catch block
80
			org.txm.rcpapplication.utils.Logger.printStackTrace(e);
81
		}
82
	}
83

  
84
	/* (non-Javadoc)
85
	 * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
86
	 */
87
	@Override
88
	protected void configureShell(Shell newShell) {
89
		super.configureShell(newShell);
90
		newShell.setText(Messages.Compute_Specificities);
91
	}
92

  
93
	/**
94
	 * Gets the property.
95
	 *
96
	 * @return the property
97
	 */
98
	public Property getProperty() {
99
		return property;
100
	}
101

  
102
	/* (non-Javadoc)
103
	 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
104
	 */
105
	@Override
106
	protected Control createDialogArea(Composite parent) {
107
		Composite composite = new Composite(parent, SWT.NONE);
108
		GridLayout layout = new GridLayout(2, false);
109
		composite.setLayout(layout);
110

  
111
		Label anaPropLabel = new Label(composite, SWT.NONE);
112
		anaPropLabel.setText(Messages.CreatePartitionDialog_4);
113
		anaPropLabel.setLayoutData(new GridData(GridData.END, GridData.CENTER,
114
				false, false));
115

  
116
		anaPropCombo = new Combo(composite, SWT.READ_ONLY);
117
		anaPropCombo.setLayoutData(new GridData(GridData.FILL, GridData.FILL,
118
				true, false));
119
		int iword= 0;
120
		int i = 0;
121
		for (Property p : properties) {
122
			anaPropCombo.add(p.getName());
123
			if (p.getName().equals("word")) //$NON-NLS-1$
124
				iword=i;
125
			i++;
126
		}
127
		anaPropCombo.select(iword);
128
		return composite;
129
	}
130

  
131
	/* (non-Javadoc)
132
	 * @see org.eclipse.jface.dialogs.Dialog#okPressed()
133
	 */
134
	@Override
135
	protected void okPressed() {
136
		int propIndex = anaPropCombo.getSelectionIndex();
137
		if (propIndex == -1) {
138
			MessageDialog.openError(getShell(),
139
					Messages.Invalid_analysis_property,
140
					Messages.Structure_field_not_empty);
141
			return;
142
		}
143

  
144
		property = properties.get(propIndex);
145
		super.okPressed();
146
	}
147

  
148
}
0 149

  
tmp/org.txm.specificities.rcp/src/org/txm/specificities/rcp/dialogs/ComputeSpecificitiesDialog.java (revision 75)
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.specificities.rcp.dialogs;
29

  
30
import java.util.ArrayList;
31
import java.util.List;
32
import java.util.regex.Pattern;
33
import java.util.regex.PatternSyntaxException;
34

  
35
import org.eclipse.jface.dialogs.Dialog;
36
import org.eclipse.jface.dialogs.MessageDialog;
37
import org.eclipse.osgi.util.NLS;
38
import org.eclipse.swt.SWT;
39
import org.eclipse.swt.layout.GridData;
40
import org.eclipse.swt.layout.GridLayout;
41
import org.eclipse.swt.widgets.Button;
42
import org.eclipse.swt.widgets.Combo;
43
import org.eclipse.swt.widgets.Composite;
44
import org.eclipse.swt.widgets.Control;
45
import org.eclipse.swt.widgets.Event;
46
import org.eclipse.swt.widgets.Label;
47
import org.eclipse.swt.widgets.Listener;
48
import org.eclipse.swt.widgets.Shell;
49
import org.eclipse.swt.widgets.Text;
50
import org.txm.rcpapplication.Messages;
51
import org.txm.rcpapplication.StatusLine;
52
import org.txm.searchengine.cqp.clientExceptions.CqiClientException;
53
import org.txm.searchengine.cqp.corpus.Part;
54
import org.txm.searchengine.cqp.corpus.Partition;
55
import org.txm.searchengine.cqp.corpus.Property;
56
// TODO: Auto-generated Javadoc
57
/**
58
 * User can choose a lexical property the values to keep and the parts to keep.
59
 *
60
 * @author jpmague, Sylvain Loiseau
61
 */
62
public class ComputeSpecificitiesDialog extends Dialog {
63

  
64
	/** The properties. */
65
	private List<Property> properties;
66
	
67
	/** The ana prop combo. */
68
	private Combo anaPropCombo;
69
	
70
	/** The property. */
71
	private Property property;
72

  
73
	/** The type focus. */
74
	private List<Text> typeFocus = new ArrayList<Text>();
75
	
76
	/** The part focus. */
77
	private List<Combo> partFocus = new ArrayList<Combo>();
78
	
79
	/** The type focus string. */
80
	private List<String> typeFocusString;
81
	
82
	/** The part focus string. */
83
	private ArrayList<Part> partFocusString;
84

  
85
	/** The partition. */
86
	private Partition partition;
87

  
88
	/** The show part focus selection. */
89
	boolean showPartFocusSelection = false;
90

  
91
	/**
92
	 * Instantiates a new compute specificities dialog.
93
	 *
94
	 * @param parentShell the parent shell
95
	 * @param partition the partition
96
	 * @param showPartFocusSelection the show part focus selection
97
	 */
98
	public ComputeSpecificitiesDialog(Shell parentShell, Partition partition,
99
			boolean showPartFocusSelection) {
100
		super(parentShell);
101
		this.partition = partition;
102
		this.showPartFocusSelection = showPartFocusSelection;
103
		try {
104
			this.properties = new ArrayList<Property>(partition
105
					.getCorpus().getOrderedProperties());
106
		} catch (CqiClientException e) {
107
			System.err.println(NLS.bind(
108
					Messages.ComputeSpecificitiesDialog_0, e));
109
		}
110
		this.setShellStyle(this.getShellStyle() | SWT.RESIZE);
111
	}
112

  
113
	/* (non-Javadoc)
114
	 * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
115
	 */
116
	@Override
117
	protected void configureShell(Shell newShell) {
118
		super.configureShell(newShell);
119
		newShell.setText(Messages.Compute_Specificities);
120
	}
121

  
122
	/* (non-Javadoc)
123
	 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
124
	 */
125
	@Override
126
	protected Control createDialogArea(Composite parent) {
127
		Composite composite = new Composite(parent, SWT.NONE);
128
		// TODO : we just put a composite into another composite. Everything
129
		// should be directly put into parent
130
		GridLayout layout = new GridLayout(2, false);
131
		composite.setLayout(layout);
132

  
133
		Label anaPropLabel = new Label(composite, SWT.NONE);
134
		anaPropLabel.setText(Messages.CreatePartitionDialog_4);
135
		anaPropLabel.setLayoutData(new GridData(GridData.END, GridData.CENTER,
136
				false, false));
137

  
138
		anaPropCombo = new Combo(composite, SWT.READ_ONLY);
139
		anaPropCombo.setLayoutData(new GridData(GridData.FILL, GridData.FILL,
140
				true, false));
141
		int iword= 0;
142
		int i = 0;
143
		for (Property p : properties) {
144
			anaPropCombo.add(p.getName());
145
			if (p.getName().equals("word")) //$NON-NLS-1$
146
				iword=i;
147
			i++;
148
		}
149
		anaPropCombo.select(iword);
150

  
151
		// set the focus
152
//		Label advancedFocusLabel = new Label(composite, SWT.NONE);
153
//		advancedFocusLabel.setText(Messages.ComputeSpecificitiesDialog_3);
154
//		advancedFocusLabel.setLayoutData(new GridData(GridData.END,
155
//				GridData.CENTER, false, false));
156
//
157
//		Composite focusComposite = new Composite(composite, SWT.NONE);
158
//		// TODO : we just put a composite into another composite. Everything
159
//		// should be directly put into parent
160
//		focusComposite.setLayout(new GridLayout(1, false));
161
//
162
//		createTypeFocusField(focusComposite);
163

  
164
		// Set the part focus
165
		if (showPartFocusSelection) {
166

  
167
			Label advancedPartLabel = new Label(composite, SWT.NONE);
168
			advancedPartLabel.setText(Messages.ComputeSpecificitiesDialog_4);
169
			advancedPartLabel.setLayoutData(new GridData(GridData.END,
170
					GridData.CENTER, false, false));
171

  
172
			Composite partFocusComposite = new Composite(composite, SWT.NONE);
173
			// TODO : we just put a composite into another composite. Everything
174
			// should be directly put into parent
175
			partFocusComposite.setLayout(new GridLayout(1, false));
176

  
177
			createPartFocusField(partFocusComposite);
178
		}
179

  
180
		return composite;
181
	}
182

  
183
	/**
184
	 * Creates the type focus field.
185
	 *
186
	 * @param composite the composite
187
	 */
188
	private void createTypeFocusField(final Composite composite) {
189
		Text focusTextBox = new Text(composite, SWT.BORDER);
190
		focusTextBox.setLayoutData(new GridData(GridData.FILL, GridData.FILL,
191
				true, false));
192
		GridData gridData = new GridData(GridData.FILL, GridData.FILL, true,
193
				false);
194
		gridData.widthHint = convertHeightInCharsToPixels(20);
195
		focusTextBox.setLayoutData(gridData);
196

  
197
		final Button plusButton = new Button(composite, SWT.NONE);
198
		plusButton.setText("+"); //$NON-NLS-1$
199
		plusButton.addListener(SWT.Selection, new Listener() {
200
			@Override
201
			public void handleEvent(Event event) {
202
				createTypeFocusField(composite);
203
				getShell().pack();
204
			}
205
		});
206

  
207
		// final Button minusButton = new Button(composite, SWT.NONE);
208
		// minusButton.setText("-");
209
		// minusButton.addListener(SWT.Selection, new Listener() {
210
		// public void handleEvent(Event event) {
211
		// }
212
		// });
213

  
214
		// queryText.addKeyListener(new KeyListener() {
215
		// public void keyPressed(KeyEvent e) {
216
		// // If there is no query in any text field, disabled the "Ok" button.
217
		// if (noquery()) {
218
		// CreatePartitionDialog.this.getButton(IDialogConstants.OK_ID).setEnabled(false);
219
		// } else {
220
		// CreatePartitionDialog.this.getButton(IDialogConstants.OK_ID).setEnabled(true);
221
		// }
222
		//
223
		// // // If there is no text in this particular text field, disabled the
224
		// "+" button.
225
		// // if (queryText.getText().length() == 0) {
226
		// // plusButton.setEnabled(false);
227
		// // } else {
228
		// // plusButton.setEnabled(true);
229
		// // }
230
		// }
231
		//
232
		// public void keyReleased(KeyEvent e) {
233
		// }
234
		// }
235
		// );
236

  
237
		typeFocus.add(focusTextBox);
238
	}
239

  
240
	/**
241
	 * Creates the part focus field.
242
	 *
243
	 * @param composite the composite
244
	 */
245
	private void createPartFocusField(final Composite composite) {
246

  
247
		final Combo partFocusBox;
248
		partFocusBox = new Combo(composite, SWT.BORDER);
249
		partFocusBox.setLayoutData(new GridData(GridData.FILL, GridData.FILL,
250
				true, false));
251
		GridData gridData = new GridData(GridData.FILL, GridData.FILL, true,
252
				false);
253
		gridData.widthHint = convertHeightInCharsToPixels(20);
254
		partFocusBox.setLayoutData(gridData);
255
		for (String name : partition.getPartShortNames()) {
256
			partFocusBox.add(name);
257
		}
258

  
259
		final Button plusButton = new Button(composite, SWT.NONE);
260
		plusButton.setText("+"); //$NON-NLS-1$
261
		plusButton.addListener(SWT.Selection, new Listener() {
262
			@Override
263
			public void handleEvent(Event event) {
264
				createPartFocusField(composite);
265
				getShell().pack();
266
			}
267
		});
268

  
269
		// final Button minusButton = new Button(composite, SWT.NONE);
270
		// minusButton.setText("-");
271
		// minusButton.addListener(SWT.Selection, new Listener() {
272
		// public void handleEvent(Event event) {
273
		// }
274
		// });
275

  
276
		// queryText.addKeyListener(new KeyListener() {
277
		// public void keyPressed(KeyEvent e) {
278
		// // If there is no query in any text field, disabled the "Ok" button.
279
		// if (noquery()) {
280
		// CreatePartitionDialog.this.getButton(IDialogConstants.OK_ID).setEnabled(false);
281
		// } else {
282
		// CreatePartitionDialog.this.getButton(IDialogConstants.OK_ID).setEnabled(true);
283
		// }
284
		//
285
		// // // If there is no text in this particular text field, disabled the
286
		// "+" button.
287
		// // if (queryText.getText().length() == 0) {
288
		// // plusButton.setEnabled(false);
289
		// // } else {
290
		// // plusButton.setEnabled(true);
291
		// // }
292
		// }
293
		//
294
		// public void keyReleased(KeyEvent e) {
295
		// }
296
		// }
297
		// );
298

  
299
		partFocus.add(partFocusBox);
300
	}
301

  
302
	/* (non-Javadoc)
303
	 * @see org.eclipse.jface.dialogs.Dialog#okPressed()
304
	 */
305
	@Override
306
	protected void okPressed() {
307
		int propIndex = anaPropCombo.getSelectionIndex();
308
		if (propIndex == -1) {
309
			MessageDialog.openError(getShell(),
310
					Messages.Invalid_analysis_property,
311
					Messages.Structure_field_not_empty);
312
			return;
313
		}
314
		property = properties.get(propIndex);
315

  
316
		typeFocusString = new ArrayList<String>();
317
		if (typeFocus != null)
318
		for (Text foc : typeFocus) {
319
			String regex = foc.getText().trim();
320
			if (regex.length() != 0) {
321
				try
322
				{
323
					Pattern p = Pattern.compile(regex);
324
					if (p != null)
325
						typeFocusString.add(regex);
326
				}
327
				catch(PatternSyntaxException e)
328
				{
329
					String str = NLS.bind(Messages.ComputeSpecificitiesDialog_1, e.getMessage());
330
					System.out.println(str);
331
					StatusLine.error(str);
332
					return;
333
				}
334
			}
335
		}
336

  
337
		partFocusString = new ArrayList<Part>();
338
		if (partFocus != null)
339
		for (Combo com : partFocus) {
340
			if (com.getText().length() != 0) {
341
				partFocusString.add(partition.getParts().get(
342
						com.getSelectionIndex()));
343
			}
344
		}
345

  
346
		super.okPressed();
347
	}
348

  
349
	/**
350
	 * Gets the analysis property.
351
	 *
352
	 * @return the analysis property
353
	 */
354
	public Property getAnalysisProperty() {
355
		return property;
356
	}
357

  
358
	/**
359
	 * Gets the type focus.
360
	 *
361
	 * @return the type focus
362
	 */
363
	public List<String> getTypeFocus() {
364
		return typeFocusString;
365
	}
366

  
367
	/**
368
	 * Gets the part focus.
369
	 *
370
	 * @return the part focus
371
	 */
372
	public List<Part> getPartFocus() {
373
		if (!showPartFocusSelection) {
374
			//throw new IllegalStateException(Messages.ComputeSpecificitiesDialog_9);
375
		}
376
		// System.out.println("get partfocus (string ,normalement) "+partFocusString);
377
		return partFocusString;
378
	}
379

  
380
}
0 381

  
tmp/org.txm.specificities.rcp/src/org/txm/specificities/rcp/adapters/SpecificitiesAdapterFactory.java (revision 75)
1
// Copyright © 2010-2013 ENS de Lyon.
2
package org.txm.specificities.rcp.adapters;
3

  
4
import org.eclipse.jface.resource.ImageDescriptor;
5
import org.eclipse.ui.model.IWorkbenchAdapter;
6
import org.eclipse.ui.plugin.AbstractUIPlugin;
7
import org.osgi.framework.FrameworkUtil;
8
import org.txm.rcp.adapters.BaseAdapterFactory;
9
import org.txm.specificities.core.functions.SpecificitesResult;
10

  
11

  
12
/**
13
 * A factory for creating Adapter objects.
14
 *  
15
 * @author mdecorde
16
 * @author sjacquot
17
 */
18
public class SpecificitiesAdapterFactory extends BaseAdapterFactory {
19

  
20
	
21
	public static final ImageDescriptor ICON =
22
			AbstractUIPlugin.imageDescriptorFromPlugin(FrameworkUtil.getBundle(SpecificitiesAdapterFactory.class).getSymbolicName(),
23
					"platform:/plugin/"+ FrameworkUtil.getBundle(SpecificitiesAdapterFactory.class).getSymbolicName() + "/icons/functions/specificities.png"); //$NON-NLS-1$
24
	
25
	/**
26
	 * Gets the adapter.
27
	 *
28
	 * @param adaptableObject the adaptable object
29
	 * @param adapterType the adapter type
30
	 * @return the adapter
31
	 * @see org.eclipse.core.runtime.IAdapterFactory#getAdapter(java.lang.Object, java.lang.Class)
32
	 */
33
	@Override
34
	public Object getAdapter(Object adaptableObject, Class adapterType) {
35
		
36
		if(adapterType == IWorkbenchAdapter.class)	{
37
			if(adaptableObject instanceof SpecificitesResult)	{
38
				return new IWorkbenchAdapter() {
39
					@Override
40
					public Object[] getChildren(Object o) {
41
						return new Object[0];
42
					}
43

  
44
					@Override
45
					public ImageDescriptor getImageDescriptor(Object object) {
46
						return ICON;
47
					}
48

  
49
					@Override
50
					public String getLabel(Object o) {
51
						return ((SpecificitesResult) o).getName();
52
					}
53

  
54
					@Override
55
					public Object getParent(Object o) {
56
						return ((SpecificitesResult) o).getParent();
57
					}
58
				};
59
			}
60
		}
61
		return null;
62
	}
63

  
64

  
65
}
0 66

  
tmp/org.txm.specificities.rcp/src/org/txm/specificities/rcp/messages/RCPSpecificitiesMessages.java (revision 75)
1
package org.txm.specificities.rcp.messages;
2

  
3
import org.eclipse.osgi.util.NLS;
4

  
5
public class RCPSpecificitiesMessages extends NLS {
6
	
7

  
8
	//private static final String BUNDLE_NAME = "org.txm.rcp.wordcloud.messages.messages"; //$NON-NLS-1$
9
	// FIXME: use the same properties file than the bundle	
10
	private static final String BUNDLE_NAME = "l10n.bundle"; //$NON-NLS-1$
11
	
12
	
13
	
14
	public static String SpecificitiesPreferencePage_0;
15
	public static String SpecificitiesPreferencePage_1;
16
	public static String SpecificitiesPreferencePage_2;
17
	public static String SpecificitiesPreferencePage_3;
18
	public static String SpecificitiesPreferencePage_4;
19
	public static String SpecificitiesPreferencePage_5;
20
	public static String SpecificitiesPreferencePage_6;
21
	public static String SpecificitiesPreferencePage_7;
22

  
23
	public static String SpecificitiesPreferencePage_8;
24
	public static String SpecificitiesResultEditorInput_0;
25
	public static String SpecificitiesResultEditorInput_1;
26
	public static String SpecificitiesResultEditorInput_11;
27
	public static String SpecificitiesResultEditorInput_2;
28
	public static String SpecificitiesResultEditorInput_5;
29
	public static String SpecificitiesResultEditorInput_6;
30
	public static String SpecificitiesResultEditorInput_7;
31
	public static String SpecificitiesTableEditor_0;
32
	public static String SpecificitiesTableEditor_1;
33
	public static String SpecificitiesTableEditor_11;
34
	public static String SpecificitiesTableEditor_16;
35
	public static String SpecificitiesTableEditor_17;
36
	public static String SpecificitiesTableEditor_5;
37
	public static String SpecificitiesTableEditor_8;
38
	
39
	
40
	static {
41
		// initialize resource bundle
42
		NLS.initializeMessages(BUNDLE_NAME, RCPSpecificitiesMessages.class);
43
	}
44

  
45
	private RCPSpecificitiesMessages() {
46
	}
47
}
0 48

  
tmp/org.txm.specificities.rcp/src/org/txm/specificities/rcp/editors/ReverseComparator.java (revision 75)
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.specificities.rcp.editors;
29

  
30
import java.util.Comparator;
31

  
32
// TODO: Auto-generated Javadoc
33
/**
34
 * reverse a comparator results @ author mdecorde.
35
 */
36
public class ReverseComparator implements Comparator {
37

  
38
	/** The inverse comparator. */
39
	private Comparator inverseComparator;
40

  
41
	/**
42
	 * Instantiates a new reverse comparator.
43
	 *
44
	 * @param comparator the comparator
45
	 */
46
	public ReverseComparator(Comparator comparator) {
47
		inverseComparator = comparator;
48
	}
49

  
50
	/* (non-Javadoc)
51
	 * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
52
	 */
53
	@Override
54
	public int compare(Object o1, Object o2) {
55
		return -1 * inverseComparator.compare(o1, o2);
56
	}
57

  
58
}
0 59

  
tmp/org.txm.specificities.rcp/src/org/txm/specificities/rcp/editors/SpecificitiesTableLabelProvider.java (revision 75)
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.specificities.rcp.editors;
29

  
30
import org.eclipse.jface.viewers.ILabelProviderListener;
31
import org.eclipse.jface.viewers.ITableLabelProvider;
32
import org.eclipse.jface.viewers.LabelProvider;
33
import org.eclipse.swt.graphics.Image;
34
import org.txm.core.preferences.TXMPreferences;
35
import org.txm.specificities.core.preferences.SpecificitiesPreferences;
36

  
37
// TODO: Auto-generated Javadoc
38
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
39
// create the specificites table (as many columns as parts)
40
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
41

  
42
/**
43
 * The Class SpecificitesTableLabelProvider.
44
 */
45
class SpecificitiesTableLabelProvider extends LabelProvider implements ITableLabelProvider {
46

  
47
	/** The partindexes. */
48
	//int[] partindexes;
49

  
50
	private boolean showPValues;
51
	private String format;
52

  
53
	/**
54
	 * Instantiates a new specificites table label provider.
55
	 *
56
	 * @param partindexes the partindexes
57
	 */
58
	public SpecificitiesTableLabelProvider() {
59
		//this.partindexes = partindexes;
60
		//showPValues = "true".equals(Toolbox.getParam(SpecificitiesPreferencePage.SPECIF_PVALUES)); //$NON-NLS-1$
61
		this.format = TXMPreferences.getString(SpecificitiesPreferences.PREFERENCES_NODE, SpecificitiesPreferences.FORMAT);
62
		if (format == null || format.trim().length() == 0) format = "%,.1f"; //$NON-NLS-1$
63
	}
64

  
65
	/* (non-Javadoc)
66
	 * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnImage(java.lang.Object, int)
67
	 */
68
	@Override
69
	public Image getColumnImage(Object element, int columnIndex) {
70
		return null;
71
	}
72

  
73
	/* (non-Javadoc)
74
	 * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang.Object, int)
75
	 */
76
	@Override
77
	public String getColumnText(Object element, int columnIndex) {
78

  
79
		Object[] line = (Object[]) element;
80
		//line content : {unit, freq, freqs[], scores[]}
81

  
82
		if (columnIndex < 2) {
83
			Object cell = line[columnIndex];
84
			return cell.toString();
85
		} else if (columnIndex == 2) { // separator column
86
			return ""; //$NON-NLS-1$
87
		} else {
88
			columnIndex = columnIndex - 3 ;//this.partindexes[columnIndex - 3];
89
			if (columnIndex%2 == 0) { // FREQ COLUMN
90
				columnIndex = columnIndex/2; // because there is 2 col per part
91
				int[] freqs = (int[])line[2];// get the freqs
92
				return String.valueOf(freqs[columnIndex]);
93
			} else { // SCORE COLUMN
94
				columnIndex = columnIndex/2; // because there is 2 cols per part
95
				Object specif = line[3]; // get the scores
96
				double[] specifs = (double[]) specif ;
97

  
98
				double s = specifs[columnIndex];
99
				//if (-2 < s && s < 2) return "";
100
				return String.format(format, s);
101
//				if (showPValues) {
102
//					return String.valueOf();
103
//				} else {
104
//					return String.valueOf((int) specifs[columnIndex]);
105
//				}
106
			}
107
		}
108
	}
109

  
110
	/* (non-Javadoc)
111
	 * @see org.eclipse.jface.viewers.BaseLabelProvider#addListener(org.eclipse.jface.viewers.ILabelProviderListener)
112
	 */
113
	@Override
114
	public void addListener(ILabelProviderListener listener) {
115

  
116
	}
117

  
118
	/* (non-Javadoc)
119
	 * @see org.eclipse.jface.viewers.BaseLabelProvider#dispose()
120
	 */
121
	@Override
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff