Revision 209

tmp/org.txm.index.rcp/.classpath (revision 209)
1
<?xml version="1.0" encoding="UTF-8"?>
2
<classpath>
3
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
4
	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
5
	<classpathentry kind="src" path="src"/>
6
	<classpathentry kind="output" path="bin"/>
7
</classpath>
0 8

  
tmp/org.txm.index.rcp/META-INF/MANIFEST.MF (revision 209)
1
Manifest-Version: 1.0
2
Bundle-ManifestVersion: 2
3
Bundle-Name: Index RCP
4
Bundle-SymbolicName: org.txm.index.rcp;singleton:=true
5
Bundle-Version: 1.0.0.qualifier
6
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
7
Require-Bundle: org.eclipse.ui;bundle-version="3.106.1",
8
 org.eclipse.core.runtime;bundle-version="3.10.0",
9
 org.txm.rcp
0 10

  
tmp/org.txm.index.rcp/.project (revision 209)
1
<?xml version="1.0" encoding="UTF-8"?>
2
<projectDescription>
3
	<name>org.txm.index.rcp</name>
4
	<comment></comment>
5
	<projects>
6
	</projects>
7
	<buildSpec>
8
		<buildCommand>
9
			<name>org.eclipse.jdt.core.javabuilder</name>
10
			<arguments>
11
			</arguments>
12
		</buildCommand>
13
		<buildCommand>
14
			<name>org.eclipse.pde.ManifestBuilder</name>
15
			<arguments>
16
			</arguments>
17
		</buildCommand>
18
		<buildCommand>
19
			<name>org.eclipse.pde.SchemaBuilder</name>
20
			<arguments>
21
			</arguments>
22
		</buildCommand>
23
	</buildSpec>
24
	<natures>
25
		<nature>org.eclipse.pde.PluginNature</nature>
26
		<nature>org.eclipse.jdt.core.javanature</nature>
27
	</natures>
28
</projectDescription>
0 29

  
tmp/org.txm.index.rcp/src/org/txm/index/rcp/handlers/ComputeIndex.java (revision 209)
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.index.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.jface.viewers.IStructuredSelection;
34
import org.eclipse.ui.IWorkbenchPage;
35
import org.eclipse.ui.handlers.HandlerUtil;
36
import org.txm.Toolbox;
37
import org.txm.index.rcp.editors.IndexEditor;
38
import org.txm.index.rcp.editors.IndexEditorInput;
39
import org.txm.rcpapplication.Messages;
40
import org.txm.rcpapplication.StatusLine;
41
import org.txm.rcpapplication.TXMWindows;
42
import org.txm.searchengine.cqp.corpus.Corpus;
43
import org.txm.searchengine.cqp.corpus.Partition;
44
/**
45
 * Open the Index Editor.
46
 * @author mdecorde
47
 */
48
public class ComputeIndex extends AbstractHandler {
49

  
50
	/** The selection. */
51
	private IStructuredSelection selection;
52
	
53
	/* (non-Javadoc)
54
	 * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
55
	 */
56
	@Override
57
	public Object execute(ExecutionEvent event) throws ExecutionException {
58
		if (!Toolbox.isSearchEngineInitialized()) return false;
59
		
60
		selection = (IStructuredSelection) HandlerUtil.getCurrentSelection(event);
61

  
62
		Object s = selection.getFirstElement();
63
		if (s instanceof Corpus) {
64
			final Corpus corpus = (Corpus) s;
65
			openEditor(corpus);
66
		} else if (s instanceof Partition) {
67
			final Partition partition = (Partition) s;
68
			openEditor(partition);
69
		}
70

  
71
		return null;
72
	}
73
	
74
	/**
75
	 * Create an index from the specified corpus and opens an index editor.
76
	 * @param corpus
77
	 * @return
78
	 */
79
	public static boolean openEditor(Corpus corpus) {
80
		if (!Toolbox.isSearchEngineInitialized()) return false;
81
		
82
		IWorkbenchPage page = TXMWindows.getActiveWindow().getActivePage();
83
		IndexEditorInput editorInput = new IndexEditorInput(corpus);
84
		try {
85
			StatusLine.setMessage(Messages.ComputeIndex_0);
86
			IndexEditor editor = (IndexEditor) page.openEditor(editorInput, "IndexEditor"); //$NON-NLS-1$
87
			//editor.initializeFields();
88
			return true;
89
		} catch (Exception e) {
90
			org.txm.rcpapplication.utils.Logger.printStackTrace(e);
91
		}
92
		return false;
93
	}
94
	
95
	/**
96
	 * Create an index from the specified partition and opens an index editor.
97
	 * @param partition
98
	 * @return
99
	 */
100
	public static boolean openEditor(Partition partition) {
101
		if (!Toolbox.isSearchEngineInitialized()) return false;
102
		IWorkbenchPage page = TXMWindows.getActiveWindow().getActivePage();
103
		IndexEditorInput editorInput = new IndexEditorInput(partition);
104
		try {
105
			StatusLine.setMessage(Messages.ComputeIndex_0);
106
			IndexEditor editor = (IndexEditor) page.openEditor(editorInput, "IndexEditor"); //$NON-NLS-1$
107
			editor.initializeFields();
108
			return true;
109
		} catch (Exception e) {
110
			org.txm.rcpapplication.utils.Logger.printStackTrace(e);
111
		}
112
		return false;
113
	}
114
}
0 115

  
tmp/org.txm.index.rcp/src/org/txm/index/rcp/adapters/IndexAdapterFactory.java (revision 209)
1
// Copyright © 2010-2013 ENS de Lyon.
2
package org.txm.index.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.index.core.functions.Index;
9
import org.txm.rcp.adapters.BaseAdapterFactory;
10
import org.txm.stat.data.LexicalTable;
11

  
12

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

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

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

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

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

  
65

  
66
}
0 67

  
tmp/org.txm.index.rcp/src/org/txm/index/rcp/editors/LineContentProvider.java (revision 209)
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.index.rcp.editors;
29

  
30
import java.util.List;
31

  
32
import org.eclipse.jface.viewers.IStructuredContentProvider;
33
import org.eclipse.jface.viewers.Viewer;
34
import org.txm.index.core.functions.Line;
35

  
36
// TODO: Auto-generated Javadoc
37
/**
38
 * The IStructuredContentProvider used by the reference and line tables.
39
 *
40
 * @author jmague
41
 */
42
public class LineContentProvider implements IStructuredContentProvider {
43

  
44
	/*
45
	 * (non-Javadoc)
46
	 * 
47
	 * @see
48
	 * org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java
49
	 * .lang.Object)
50
	 */
51
	@Override
52
	public Object[] getElements(Object inputElement) {
53
		@SuppressWarnings("unchecked")
54
		List<Line> lines = (List<Line>) inputElement;
55
		return lines.toArray();
56
	}
57

  
58
	/*
59
	 * (non-Javadoc)
60
	 * 
61
	 * @see org.eclipse.jface.viewers.IContentProvider#dispose()
62
	 */
63
	@Override
64
	public void dispose() {
65
		// TODO Auto-generated method stub
66

  
67
	}
68

  
69
	/*
70
	 * (non-Javadoc)
71
	 * 
72
	 * @see
73
	 * org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface
74
	 * .viewers.Viewer, java.lang.Object, java.lang.Object)
75
	 */
76
	@Override
77
	public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
78
		// TODO Auto-generated method stub
79
	}
80

  
81
}
0 82

  
tmp/org.txm.index.rcp/src/org/txm/index/rcp/editors/IndexEditor.java (revision 209)
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.index.rcp.editors;
29

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

  
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.action.MenuManager;
37
import org.eclipse.jface.viewers.IStructuredSelection;
38
import org.eclipse.jface.viewers.TableViewer;
39
import org.eclipse.osgi.util.NLS;
40
import org.eclipse.swt.SWT;
41
import org.eclipse.swt.custom.ScrolledComposite;
42
import org.eclipse.swt.events.ControlAdapter;
43
import org.eclipse.swt.events.ControlEvent;
44
import org.eclipse.swt.events.KeyEvent;
45
import org.eclipse.swt.events.KeyListener;
46
import org.eclipse.swt.events.MouseAdapter;
47
import org.eclipse.swt.events.MouseEvent;
48
import org.eclipse.swt.events.SelectionEvent;
49
import org.eclipse.swt.events.SelectionListener;
50
import org.eclipse.swt.graphics.Font;
51
import org.eclipse.swt.graphics.FontData;
52
import org.eclipse.swt.graphics.Image;
53
import org.eclipse.swt.graphics.Point;
54
import org.eclipse.swt.graphics.Rectangle;
55
import org.eclipse.swt.layout.FormAttachment;
56
import org.eclipse.swt.layout.FormData;
57
import org.eclipse.swt.layout.FormLayout;
58
import org.eclipse.swt.layout.GridData;
59
import org.eclipse.swt.layout.GridLayout;
60
import org.eclipse.swt.widgets.Button;
61
import org.eclipse.swt.widgets.Composite;
62
import org.eclipse.swt.widgets.Display;
63
import org.eclipse.swt.widgets.Event;
64
import org.eclipse.swt.widgets.Label;
65
import org.eclipse.swt.widgets.Listener;
66
import org.eclipse.swt.widgets.Menu;
67
import org.eclipse.swt.widgets.Spinner;
68
import org.eclipse.swt.widgets.TableColumn;
69
import org.eclipse.ui.IEditorInput;
70
import org.eclipse.ui.IEditorSite;
71
import org.eclipse.ui.PartInitException;
72
import org.eclipse.ui.part.EditorPart;
73
import org.txm.Toolbox;
74
import org.txm.index.core.functions.Index;
75
import org.txm.index.core.functions.Line;
76
import org.txm.index.core.functions.LineComparator.SortMode;
77
import org.txm.rcpapplication.JobsTimer;
78
import org.txm.rcpapplication.Messages;
79
import org.txm.rcpapplication.StatusLine;
80
import org.txm.rcpapplication.TxmPreferences;
81
import org.txm.rcpapplication.commands.editor.CustomizableEditor;
82
import org.txm.rcpapplication.commands.link.IndexToConcordance;
83
import org.txm.rcpapplication.commands.link.IndexToProgression;
84
import org.txm.rcpapplication.editors.TableKeyListener;
85
import org.txm.rcpapplication.preferences.UserPreferencePage;
86
import org.txm.rcpapplication.swt.widget.AssistedQueryWidget;
87
import org.txm.rcpapplication.swt.widget.NavigationWidget;
88
import org.txm.rcpapplication.swt.widget.PropertiesSelector;
89
import org.txm.rcpapplication.utils.JobHandler;
90
import org.txm.rcpapplication.views.CorporaView;
91
import org.txm.rcpapplication.views.QueriesView;
92
import org.txm.rcpapplication.views.RVariablesView;
93
import org.txm.searchengine.cqp.clientExceptions.CqiClientException;
94
import org.txm.searchengine.cqp.corpus.Corpus;
95
import org.txm.searchengine.cqp.corpus.Partition;
96
import org.txm.searchengine.cqp.corpus.Property;
97
import org.txm.searchengine.cqp.corpus.StructuralUnitProperty;
98
import org.txm.searchengine.cqp.corpus.query.Query;
99
import org.txm.utils.logger.Log;
100
// TODO: Auto-generated Javadoc
101
/**
102
 * display the index parameters and result.
103
 *
104
 * @author mdecorde
105
 */
106
public class IndexEditor extends EditorPart implements CustomizableEditor{
107

  
108
	/** The corpus. */
109
	protected Corpus corpus;
110

  
111
	/** The partition. */
112
	protected Partition partition;
113

  
114
	/** The index. */
115
	protected Index index;
116
	protected boolean saveIndex = true;
117

  
118
	// params
119
	/** The query label. */
120
	protected Label queryLabel;
121

  
122
	/** The query widget. */
123
	protected AssistedQueryWidget queryWidget;
124

  
125
	/** The go. */
126
	protected Button go;
127

  
128
	/** The props area. */
129
	protected PropertiesSelector propsArea;
130
	// seuils
131
	/** The Fmin spinner. */
132
	protected Spinner FminSpinner;
133

  
134
	/** The Fmax spinner. */
135
	protected Spinner FmaxSpinner;
136

  
137
	/** The Tmax spinner. */
138
	protected Spinner TmaxSpinner;
139

  
140
	/** The N ligne p page spinner. */
141
	protected Spinner NLignePPageSpinner;
142
	// infos
143
	/** The navigation area. */
144
	protected NavigationWidget navigationArea;
145

  
146
	/** The l fmin info. */
147
	protected Label lFminInfo;
148

  
149
	/** The l fmax info. */
150
	protected Label lFmaxInfo;
151

  
152
	/** The l v info. */
153
	protected Label lVInfo;
154

  
155
	/** The l t info. */
156
	protected Label lTInfo;
157
	// result
158
	/** The line table viewer. */
159
	protected TableViewer viewer;
160

  
161
	/** The n column. */
162
	protected TableColumn nColumn;
163

  
164
	/** The unit column. */
165
	protected TableColumn unitColumn;
166

  
167
	/** The freq column. */
168
	protected TableColumn freqColumn;
169

  
170
	/** The separator column. */
171
	protected TableColumn separatorColumn;
172

  
173
	/** The top line. */
174
	protected int topLine;
175

  
176
	/** The bottom line. */
177
	protected int bottomLine;
178

  
179
	/** The nblinesperpage. */
180
	protected int nblinesperpage;
181

  
182
	/** The nblinesmax. */
183
	protected int nblinesmax;
184

  
185
	/** The prop separator. */
186
	protected String propSeparator = "_"; //$NON-NLS-1$
187

  
188
	/** The scroll composite. */
189
	private ScrolledComposite scrollComposite;
190

  
191
	/** The head composite. */
192
	private Composite headComposite;
193
	private Button hideBtn;
194
	private boolean isSetupShown;
195
	private Point querySize;
196
	private Point oldSize;
197
	/** The title. */
198
	String title;
199

  
200
	/** The source. */
201
	private Object source;
202

  
203
	/**
204
	 * Instantiates a new index editor.
205
	 */
206
	public IndexEditor() {
207
		super();
208
	}
209

  
210
	/**
211
	 * Do save.
212
	 *
213
	 * @param arg0 the arg0
214
	 * @see org.eclipse.ui.part.EditorPart#doSave(org.eclipse.core.runtime.IProgressMonitor)
215
	 */
216
	@Override
217
	public void doSave(IProgressMonitor arg0) {
218
		// TODO Auto-generated method stub
219
	}
220

  
221
	/**
222
	 * Do save as.
223
	 *
224
	 * @see org.eclipse.lyon gournd zeroui.part.EditorPart#doSaveAs()
225
	 */
226
	@Override
227
	public void doSaveAs() {
228
		// TODO Auto-generated method stub
229
	}
230

  
231
	/**
232
	 * Inits the.
233
	 *
234
	 * @param site the site
235
	 * @param input the input
236
	 * @throws PartInitException the part init exception
237
	 * @see org.eclipse.ui.part.EditorPart#init(org.eclipse.ui.IEditorSite,
238
	 * org.eclipse.ui.IEditorInput)
239
	 */
240
	@Override
241
	public void init(IEditorSite site, IEditorInput input)
242
			throws PartInitException {
243
		setSite(site);
244
		setInput(input);
245

  
246
		this.corpus = ((IndexEditorInput) input).getCorpus();
247
		this.partition = ((IndexEditorInput) input).getPartition();
248
		this.index = ((IndexEditorInput) input).getIndex();
249
	}
250

  
251
	/**
252
	 * Checks if is dirty.
253
	 *
254
	 * @return true, if is dirty
255
	 * @see org.eclipse.ui.part.EditorPart#isDirty()
256
	 */
257
	@Override
258
	public boolean isDirty() {
259
		return false;
260
	}
261

  
262
	/**
263
	 * Checks if is save as allowed.
264
	 *
265
	 * @return true, if is save as allowed
266
	 * @see org.eclipse.ui.part.EditorPart#isSaveAsAllowed()
267
	 */
268
	@Override
269
	public boolean isSaveAsAllowed() {
270
		return false;
271
	}
272

  
273
	/**
274
	 * Compute index.
275
	 */
276
	public void compute() {
277
		StatusLine.setMessage(Messages.IndexEditor_33);
278
		final Query query; // if the query is empty then we put "[]" instead
279
		if (queryWidget.isDisposed()) { // lexicon editor
280
			query = new Query("[]"); //$NON-NLS-1$
281
		} else if (!queryWidget.getQueryString().equals("\"\"")) { //$NON-NLS-1$
282
			query = new Query(queryWidget.getQueryString());
283
		} else {
284
			System.err.println(Messages.IndexEditor_0);
285
			return;
286
		}
287

  
288
		final int Fmin = Integer.parseInt(FminSpinner.getText());
289
		final int Fmax = Integer.parseInt(FmaxSpinner.getText());
290
		final int Tmax = Integer.parseInt(this.TmaxSpinner.getText());
291
		final List<Property> properties = propsArea.getProperties();
292
		//System.out.println("PROPERTIES: "+properties);
293
		try {
294
			title = NLS.bind(Messages.IndexEditor_2, new Object[]{
295
					query.getQueryString(), properties, corpus.getName()});
296
			if (partition != null)
297
				title = NLS.bind(Messages.IndexEditor_20, new Object[]{
298
						query.getQueryString(), properties, corpus.getName()});
299

  
300
			JobHandler jobhandler = new JobHandler(title, go.getParent()) {
301
				@Override
302
				protected IStatus run(IProgressMonitor monitor) {
303
					this.runInit(monitor);
304
					try {
305
						JobsTimer.start();
306
						Index oldIndex = index;
307

  
308
						System.out.println(title);
309
						Log.info("Start computing Index...");
310
						if (partition != null) {
311
							if (simpleQuery(query, properties)) {
312
								index = new Index(partition, query, properties);
313
							} else {
314
								index = new Index(partition, query, properties);
315
							}
316
						} else {
317
							if (simpleQuery(query, properties)) {
318
								index = new Index(corpus, properties.get(0));
319
							} else {
320
								index = new Index(corpus, query, properties);
321
							}
322
						}
323

  
324
						if (monitor.isCanceled())
325
							return Status.CANCEL_STATUS;
326

  
327
						if (index == null) {
328
							StatusLine.setMessage(Messages.IndexEditor_1);
329
							return Status.CANCEL_STATUS;
330
						}
331
						Log.info("Filtering Fmin="+Fmin+" and Fmax="+Fmax);
332
						index.setCurrentMonitor(this);
333
						index.filterLines(Fmin, Fmax);
334
						Log.info("Sorting...");
335
						index.sortLines(SortMode.FREQUNIT, true);
336
						Log.info("Cutting Tmax="+Tmax);
337
						index.cut(Tmax);
338
						Log.info("Index done.");
339

  
340
						if (monitor.isCanceled())
341
							return Status.CANCEL_STATUS;
342

  
343
						this.acquireSemaphore();
344
						
345
						if (oldIndex != null)
346
							if (oldIndex.equals(index))
347
								if (index.isComputedWithPartition())
348
									partition.removeResult(oldIndex);
349
								else
350
									corpus.removeResult(oldIndex);
351
						if (index.getV() > 0 && saveIndex)
352
							if (index.isComputedWithPartition())
353
								partition.storeResult(index);
354
							else
355
								corpus.storeResult(index);
356
						this.releaseSemaphore();
357

  
358
						final String message;
359
						if (index.getV() == 1)
360
							message= (Messages.ConcordancesEditor_52);
361
						else if (index.getV() > 0)
362
							message= (Messages.bind(Messages.CreatePartition_55, index.getV(), index.getT()));
363
						else
364
							message= (Messages.IndexEditor_31);
365

  
366
						if (monitor.isCanceled())
367
							return Status.CANCEL_STATUS;
368

  
369
						monitor.worked(95);
370
						// refresh ui
371
						syncExec(new Runnable() {
372
							@Override
373
							public void run() {
374

  
375
								System.out.println(message);
376
								StatusLine.setMessage(message);
377

  
378
								CorporaView.refresh();
379
								CorporaView.expand(index.getParent());
380
								QueriesView.refresh();
381
								RVariablesView.refresh();
382
								if (partition != null)
383
									setPartName(partition.getName()+": "+index.getName()); //$NON-NLS-1$
384
								else
385
									setPartName(corpus.getName()+": "+index.getName()); //$NON-NLS-1$
386

  
387
								if (!queryWidget.isDisposed()) queryWidget.memorize();
388
								nblinesperpage = NLignePPageSpinner.getSelection();
389
								nblinesmax = TmaxSpinner.getSelection();
390
								fillDisplayArea(0, NLignePPageSpinner.getSelection());
391

  
392
								viewer.getTable().setFocus();
393
							}
394
						});
395

  
396
					} catch (ThreadDeath td) {
397
						return Status.CANCEL_STATUS;
398
					} catch (Exception e) {
399
						System.out.println(e.getLocalizedMessage());
400
						try {
401
							System.out.println(Messages.LastCQPError+Toolbox.getCqiClient().getLastCQPError());
402
						} catch (Exception e1) {
403
							System.out.println(Messages.IndexEditor_10+e1);
404
							org.txm.rcpapplication.utils.Logger.printStackTrace(e1);
405
						}
406
						Log.severe("Error while computing Index with "+query+" query: "+e.getLocalizedMessage());
407
					} finally {
408
						monitor.done();
409
						JobsTimer.stopAndPrint();
410
					}
411
					return Status.OK_STATUS;
412
				}
413
			};
414
			jobhandler.startJob();
415

  
416
		} catch (Exception e1) {
417
			org.txm.rcpapplication.utils.Logger.printStackTrace(e1);
418
		}
419
	}
420

  
421

  
422

  
423
	/**
424
	 * Simple query.
425
	 *
426
	 * @param query the query
427
	 * @param props the props
428
	 * @return true, if successful
429
	 */
430
	private boolean simpleQuery(Query query, List<Property> props) {
431
		for(Property p : props) {
432
			if(p instanceof StructuralUnitProperty) return false;
433
		}
434
		String trimed = query.getQueryString().trim();
435
		Property p = props.get(0);
436
		if (props.size() > 1)
437
			return false;
438
		else if (trimed.equals("[]")) //$NON-NLS-1$
439
			return true;
440
		else if (trimed.equals("[" + p.getName() + "=\".*\"]")) //$NON-NLS-1$ //$NON-NLS-2$
441
		{
442
			return true;
443
		} 
444
		return false;
445
	}
446

  
447
	/**
448
	 * Creates the part control.
449
	 *
450
	 * @param parent the parent
451
	 * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
452
	 */
453
	@Override
454
	public void createPartControl(final Composite parent) {
455
		FormLayout parentLayout = new FormLayout();
456
		parent.setLayout(parentLayout);
457

  
458
		//create scrollable area
459
		scrollComposite = new ScrolledComposite(parent, SWT.H_SCROLL | SWT.NONE);
460
		FormData headLayoutData = new FormData();
461
		headLayoutData.top = new FormAttachment(0, 0);
462
		headLayoutData.left = new FormAttachment(0);
463
		headLayoutData.right = new FormAttachment(100);
464
		scrollComposite.setLayoutData(headLayoutData);
465
		scrollComposite.setLayout(new FormLayout());
466

  
467
		headComposite = new Composite(scrollComposite, SWT.NONE);
468
		headLayoutData = new FormData();
469
		headLayoutData.top = new FormAttachment(0);
470
		headLayoutData.bottom = new FormAttachment(100);
471
		headLayoutData.left = new FormAttachment(0);
472
		headLayoutData.right = new FormAttachment(100);
473
		headComposite.setLayoutData(headLayoutData);
474
		headComposite.setLayout(new FormLayout());
475

  
476
		scrollComposite.setContent(headComposite);
477
		scrollComposite.setExpandVertical(true);
478
		scrollComposite.setExpandHorizontal(true);
479
		scrollComposite.addControlListener(new ControlAdapter() {
480
			@Override
481
			public void controlResized(ControlEvent e) {
482
				Rectangle r = scrollComposite.getClientArea();
483
				scrollComposite.setMinSize(headComposite.computeSize(
484
						SWT.DEFAULT, SWT.DEFAULT));
485
			}
486
		});
487

  
488
		final Composite paramArea = new Composite(headComposite, SWT.NONE);
489
		FormData paramLayoutData = new FormData();
490
		paramLayoutData.top = new FormAttachment(0);
491
		paramLayoutData.left = new FormAttachment(0);
492
		paramLayoutData.right = new FormAttachment(100);
493
		paramArea.setLayoutData(paramLayoutData);
494

  
495
		// info&navigation panel
496
		final Composite infosArea = new Composite(headComposite, SWT.NONE);
497
		FormData infosLayoutData = new FormData();
498
		infosLayoutData.top = new FormAttachment(paramArea, 0);
499
		infosLayoutData.left = new FormAttachment(0);
500
		infosLayoutData.right = new FormAttachment(100);
501
		infosArea.setLayoutData(infosLayoutData);
502

  
503
		Composite resultArea = new Composite(parent, SWT.NONE);
504
		FormData resultLayoutData = new FormData();
505
		resultLayoutData.top = new FormAttachment(scrollComposite, 0);
506
		resultLayoutData.left = new FormAttachment(0);
507
		resultLayoutData.right = new FormAttachment(100);
508
		resultLayoutData.bottom = new FormAttachment(100);
509
		resultArea.setLayoutData(resultLayoutData);
510

  
511
		// compose paramArea
512
		FormLayout paramLayout = new FormLayout();
513
		paramArea.setLayout(paramLayout);
514

  
515
		// on créé une Query, ici le pivot de la concordance est "[]"
516
		// Query Area: query itself + view properties
517
		Composite queryArea = new Composite(paramArea, SWT.NONE);
518

  
519
		FormData queryLayoutData = new FormData();
520
		queryLayoutData.top = new FormAttachment(0);
521
		queryLayoutData.left = new FormAttachment(0);
522
		queryLayoutData.right = new FormAttachment(100);
523
		queryArea.setLayoutData(queryLayoutData);
524

  
525
		queryArea.setLayout(new GridLayout(4, false));
526

  
527
		// | Query: [ (v)] [Search] |
528
		// Query:
529
		queryLabel = new Label(queryArea, SWT.NONE);
530
		queryLabel.setText(Messages.IndexEditor_3);
531
		queryLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false,
532
				true));
533

  
534
		// [ (v)]
535
		queryWidget = new AssistedQueryWidget(queryArea, SWT.DROP_DOWN,
536
				this.corpus);
537
		GridData layoutData = new GridData(GridData.VERTICAL_ALIGN_CENTER);
538
		layoutData.horizontalAlignment = GridData.FILL;
539
		layoutData.grabExcessHorizontalSpace = true;
540
		queryWidget.setLayoutData(layoutData);
541

  
542
		KeyListener listener = new KeyListener() {
543
			@Override
544
			public void keyPressed(KeyEvent e) {
545
				if (e.keyCode == SWT.CR || e.keyCode == SWT.KEYPAD_CR) {
546
					compute();
547
				}
548
			}
549
			@Override
550
			public void keyReleased(KeyEvent e) {
551
			}
552
		};
553
		queryWidget.addKeyListener(listener);
554

  
555
		// select focus properties
556
		propsArea = new PropertiesSelector(queryArea, SWT.NONE);
557
		propsArea.setLayoutData(new GridData(GridData.FILL, GridData.FILL,
558
				false, false));
559
		propsArea.setLayout(new GridLayout(3, false));
560
		propsArea.addValueChangeListener(new Listener() {
561
			@Override
562
			public void handleEvent(Event event) {
563
				if (!initializing && TxmPreferences.getBoolean(UserPreferencePage.AUTO_UPDATE_EDITOR))
564
					compute();
565
			}
566
		});
567

  
568
		//propsArea
569
		go = new Button(queryArea, SWT.BOLD);
570
		go.setText(Messages.IndexEditor_4);
571

  
572
		Font f = go.getFont();
573
		FontData defaultFont = f.getFontData()[0];
574
		defaultFont.setStyle(SWT.BOLD);
575
		Font newf = new Font(go.getDisplay(), defaultFont);
576
		go.setFont(newf);
577

  
578
		layoutData = new GridData(GridData.VERTICAL_ALIGN_CENTER);
579
		layoutData.horizontalAlignment = GridData.FILL;
580
		layoutData.grabExcessHorizontalSpace = false;
581
		go.setLayoutData(layoutData);
582

  
583
		SelectionListener listener2 = new SelectionListener() {
584
			@Override
585
			public void widgetSelected(SelectionEvent e) {
586
				compute();
587
			}
588
			@Override
589
			public void widgetDefaultSelected(SelectionEvent e) { }
590
		};
591
		go.addSelectionListener(listener2);
592

  
593
		// | Properties: word_pos [Edit] |
594
		/*
595
		 * propsArea = new PropertiesSelector(paramArea, SWT.NONE);
596
		 * propsArea.setLayout(new GridLayout(3, false));
597
		 * //propsArea.setCorpus(this.corpus);
598
		 * 
599
		 * FormData propsLayoutData = new FormData(); propsLayoutData.top = new
600
		 * FormAttachment (queryArea, 0); propsLayoutData.left = new
601
		 * FormAttachment (0); propsLayoutData.right = new FormAttachment (100);
602
		 * propsArea.setLayoutData(propsLayoutData);
603
		 */
604
		// Filters
605
		Composite filtercontrols = new Composite(paramArea, SWT.NONE);
606
		FormData filtersLayoutData = new FormData();
607
		filtersLayoutData.top = new FormAttachment(queryArea, 0);
608
		filtersLayoutData.bottom = new FormAttachment(100);
609
		filtersLayoutData.left = new FormAttachment(0);
610
		filtersLayoutData.right = new FormAttachment(100);
611
		filtercontrols.setLayoutData(filtersLayoutData);
612

  
613
		GridLayout gridLayout = new GridLayout();
614
		gridLayout.numColumns = 9;
615
		gridLayout.makeColumnsEqualWidth = false;
616
		filtercontrols.setLayout(gridLayout);
617

  
618
		Label tmp = new Label(filtercontrols, SWT.NONE);
619
		tmp.setText(Messages.IndexEditor_9);
620
		tmp.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
621

  
622
		Label lFmin = new Label(filtercontrols, SWT.NONE);
623
		lFmin.setText(Messages.IndexEditor_5);
624
		lFmin.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
625

  
626
		FminSpinner = new Spinner(filtercontrols, SWT.BORDER);
627
		FminSpinner.setMinimum(0);
628
		FminSpinner.setMaximum(9999999);
629
		FminSpinner.setIncrement(1);
630
		FminSpinner.setPageIncrement(100);
631
		FminSpinner.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_END));
632
		FminSpinner.addKeyListener(listener);
633

  
634
		Label lFmax = new Label(filtercontrols, SWT.NONE);
635
		lFmax.setText(Messages.IndexEditor_6);
636
		lFmax.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
637

  
638
		FmaxSpinner = new Spinner(filtercontrols, SWT.BORDER);
639
		FmaxSpinner.setMinimum(0);
640
		FmaxSpinner.setMaximum(9999999);
641
		FmaxSpinner.setIncrement(1);
642
		FmaxSpinner.setPageIncrement(100);
643
		FmaxSpinner.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_END));
644
		FmaxSpinner.addKeyListener(listener);
645

  
646
		Label lVmax = new Label(filtercontrols, SWT.NONE);
647
		lVmax.setText(Messages.IndexEditor_7);
648
		lVmax.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
649

  
650
		TmaxSpinner = new Spinner(filtercontrols, SWT.BORDER);
651
		TmaxSpinner.setMinimum(0);
652
		TmaxSpinner.setMaximum(9999999);
653
		TmaxSpinner.setSelection(9999999);
654
		TmaxSpinner.setIncrement(1);
655
		TmaxSpinner.setPageIncrement(100);
656
		TmaxSpinner.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_END));
657
		TmaxSpinner.addKeyListener(listener);
658

  
659
		Label lNLigneppage = new Label(filtercontrols, SWT.NONE);
660
		lNLigneppage.setText(Messages.IndexEditor_8);
661
		lNLigneppage.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
662

  
663
		NLignePPageSpinner = new Spinner(filtercontrols, SWT.BORDER);
664
		NLignePPageSpinner.setMinimum(0);
665
		NLignePPageSpinner.setMaximum(99999);
666
		NLignePPageSpinner.setSelection(100);
667
		NLignePPageSpinner.setIncrement(1);
668
		NLignePPageSpinner.setPageIncrement(100);
669
		NLignePPageSpinner.setLayoutData(new GridData(
670
				GridData.VERTICAL_ALIGN_END));
671
		NLignePPageSpinner.addSelectionListener(new SelectionListener() {
672
			@Override
673
			public void widgetSelected(SelectionEvent e) {
674
			}
675

  
676
			@Override
677
			public void widgetDefaultSelected(SelectionEvent e) {
678
				fillDisplayArea(0, NLignePPageSpinner.getSelection());
679
				viewer.getTable().select(0);
680
				viewer.getTable().showSelection();
681
			}
682
		});
683

  
684
		// compose infosArea
685
		infosArea.setLayout(new GridLayout(6, false));
686

  
687
		navigationArea = new NavigationWidget(infosArea, SWT.NONE);
688
		navigationArea.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true,
689
				false));
690

  
691
		navigationArea.addFirstListener(new SelectionListener() {
692
			@Override
693
			public void widgetDefaultSelected(SelectionEvent e) {
694
			}
695

  
696
			@Override
697
			public void widgetSelected(SelectionEvent e) {
698
				fillDisplayArea(0, NLignePPageSpinner.getSelection());
699
				viewer.getTable().select(0);
700
				viewer.getTable().showSelection();
701
			}
702
		});
703
		navigationArea.addLastListener(new SelectionListener() {
704
			@Override
705
			public void widgetDefaultSelected(SelectionEvent e) {
706
			}
707

  
708
			@Override
709
			public void widgetSelected(SelectionEvent e) {
710
				int i = (index.getV()/NLignePPageSpinner.getSelection());
711
				int top = top = i*NLignePPageSpinner.getSelection();
712

  
713
				int bottom = top + NLignePPageSpinner.getSelection();
714
				fillDisplayArea(top, bottom);
715
				viewer.getTable().select(0);
716
				viewer.getTable().showSelection();
717
			}
718
		});
719
		navigationArea.addNextListener(new SelectionListener() {
720
			@Override
721
			public void widgetDefaultSelected(SelectionEvent e) {
722
			}
723

  
724
			@Override
725
			public void widgetSelected(SelectionEvent e) {
726
				int top = topLine + NLignePPageSpinner.getSelection();
727
				int bottom = top + NLignePPageSpinner.getSelection();
728
				fillDisplayArea(top,bottom);
729
				viewer.getTable().select(0);
730
				viewer.getTable().showSelection();
731
			}
732
		});
733
		navigationArea.addPreviousListener(new SelectionListener() {
734
			@Override
735
			public void widgetDefaultSelected(SelectionEvent e) {
736
			}
737

  
738
			@Override
739
			public void widgetSelected(SelectionEvent e) {
740
				int top = topLine - NLignePPageSpinner.getSelection();
741
				if (top < 0)
742
					top = 0;
743
				int bottom = top + NLignePPageSpinner.getSelection();
744
				fillDisplayArea(top, bottom);
745
				viewer.getTable().select(0);
746
				viewer.getTable().showSelection();
747
			}
748
		});
749

  
750
		// Labels
751
		lTInfo = new Label(infosArea, SWT.NONE);
752
		lTInfo.setText(""); //$NON-NLS-1$
753
		lTInfo.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
754

  
755
		lVInfo = new Label(infosArea, SWT.NONE);
756
		lVInfo.setText(""); //$NON-NLS-1$
757
		lVInfo.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
758

  
759
		lFminInfo = new Label(infosArea, SWT.NONE);
760
		lFminInfo.setText(""); //$NON-NLS-1$
761
		lFminInfo.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
762

  
763
		lFmaxInfo = new Label(infosArea, SWT.NONE);
764
		lFmaxInfo.setText(""); //$NON-NLS-1$
765
		lFmaxInfo.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
766

  
767
		//hide button
768
		isSetupShown = true;
769
		/*hideBtn = new Button(infosArea, SWT.PUSH);
770
		hideBtn.setText("Hide");
771
		hideBtn.addSelectionListener(new SelectionListener() {
772
			@Override
773
			public void widgetSelected(SelectionEvent e) {
774
				if (isSetupShown)// must hide
775
				{
776
					hideBtn.setText("Show");
777
					querySize = paramArea.getSize(); // save paramArea size
778
//					oldSize = scrollComposite.getSize(); // get head size
779
//					scrollComposite.setSize(oldSize.x, oldSize.y - querySize.y); // cut it
780
//					FormData data1 = (FormData) scrollComposite.getLayoutData();
781
//					data1.height = oldSize.y - querySize.y;
782

  
783
					paramArea.setSize(querySize.x, 0); // set paramArea size to 0
784
					FormData data = (FormData) paramArea.getLayoutData();
785
					data.height = 0;
786

  
787
					headComposite.layout(true); // refresh layout
788
					scrollComposite.layout(true); // refresh layout
789
					parent.pack();
790
					parent.layout(true);
791
					isSetupShown = false;
792
				}
793
				else // restore the size
794
				{
795
					hideBtn.setText("Hide");
796
    				Point size = scrollComposite.getSize(); // get head size
797
//					scrollComposite.setSize(size.x, oldSize.y); // restore original size
798
//					FormData data1 = (FormData) scrollComposite.getLayoutData();
799
//					data1.height = oldSize.y;
800

  
801
					paramArea.setSize(size.x, querySize.y); // restore original size
802
					FormData data = (FormData) paramArea.getLayoutData();
803
					data.height = querySize.y;
804

  
805
					headComposite.layout(true); // refresh layout
806
					scrollComposite.layout(true); // refresh
807
					parent.layout(true);
808
					isSetupShown = true;
809
				}
810
			}
811

  
812
			@Override
813
			public void widgetDefaultSelected(SelectionEvent e) {	}
814
		});
815
		 */
816
		// results
817
		FormLayout resultLayout = new FormLayout();
818
		resultArea.setLayout(resultLayout);
819

  
820
		viewer = new TableViewer(resultArea, SWT.MULTI
821
				| SWT.FULL_SELECTION | SWT.BORDER);
822
		viewer.getTable().setLinesVisible(true);
823
		viewer.getTable().setHeaderVisible(true);
824
		viewer.getTable().addKeyListener(new TableKeyListener(viewer));
825

  
826
		if (corpus != null && corpus.getFont() != null && corpus.getFont().length() > 0) {
827
			Font old = viewer.getTable().getFont();
828
			FontData fD = old.getFontData()[0];
829
			//Font f = new Font(old.getDevice(), corpus.getFont(), fD.getHeight(), fD.getStyle());
830
			Font font = new Font(Display.getCurrent(), corpus.getFont(), fD.getHeight(), fD.getStyle()); 
831
			viewer.getTable().setFont(font);
832
		}
833

  
834
		FormData tableLayoutData = new FormData();
835
		tableLayoutData.top = new FormAttachment(0);
836
		tableLayoutData.bottom = new FormAttachment(100);
837
		tableLayoutData.left = new FormAttachment(0);
838
		tableLayoutData.right = new FormAttachment(100);
839
		viewer.getTable().setLayoutData(tableLayoutData);
840

  
841
		viewer.setLabelProvider(new LineLabelProvider());
842
		viewer.setContentProvider(new LineContentProvider());
843
		viewer.setInput(new ArrayList<Property>());
844

  
845
		viewer.getTable().addMouseListener(new MouseAdapter() {
846
			@Override
847
			public void mouseDoubleClick(MouseEvent e) {
848
				Point mouseposition = new Point(e.x
849
						+ viewer.getTable().getHorizontalBar()
850
						.getSelection(), e.y);
851
				int col = getPointedColumn(mouseposition);
852
				if (col == 1) {
853
					IndexToConcordance.link(IndexEditor.this,
854
							(IStructuredSelection) viewer
855
							.getSelection());
856
				} else if (col == 2) {
857
					IndexToProgression.link(IndexEditor.this,
858
							(IStructuredSelection) viewer
859
							.getSelection());
860
				}
861
			}
862
		});
863

  
864

  
865
		nColumn = new TableColumn(viewer.getTable(), SWT.LEFT);
866
		nColumn.setText(" "); //$NON-NLS-1$
867
		nColumn.pack();
868

  
869
		unitColumn = new TableColumn(viewer.getTable(), SWT.LEFT);
870
		unitColumn.setText(Messages.ReferencerEditor_9);
871
		unitColumn.setToolTipText(Messages.ReferencerEditor_9);
872
		unitColumn.setWidth(200);
873
		unitColumn.addSelectionListener(new SelectionListener() {
874
			@Override
875
			public void widgetSelected(SelectionEvent e) {
876
				StatusLine.setMessage(Messages.IndexEditor_36);
877
				if (viewer.getTable().getSortColumn() != unitColumn) {
878
					viewer.getTable().setSortColumn(unitColumn);
879
					viewer.getTable().setSortDirection(SWT.UP);
880
					index.sortLines(SortMode.UNIT, false);
881
				} else {
882
					if (viewer.getTable().getSortDirection() == SWT.UP) {
883
						viewer.getTable().setSortDirection(SWT.DOWN);
884
						index.sortLines(SortMode.UNITFREQ, true);
885
					} else {
886
						viewer.getTable().setSortDirection(SWT.UP);
887
						index.sortLines(SortMode.UNITFREQ, false);
888
					}
889
				}
890

  
891
				StatusLine.setMessage(Messages.IndexEditor_37);
892
				fillDisplayArea(topLine, bottomLine);
893
			}
894

  
895
			@Override
896
			public void widgetDefaultSelected(SelectionEvent e) {
897
			}
898
		});
899

  
900
		freqColumn = new TableColumn(viewer.getTable(), SWT.RIGHT);
901
		try {
902
			if(partition != null)
903
				freqColumn.setText(Messages.FrequencyListEditorInput_4+" T="+partition.getTotalSize()); //$NON-NLS-1$
904
			else
905
				freqColumn.setText(Messages.FrequencyListEditorInput_4);
906
		} catch (CqiClientException e2) {
907
			// TODO Auto-generated catch block
908
			org.txm.rcpapplication.utils.Logger.printStackTrace(e2);
909
		}
910
		freqColumn.setToolTipText(Messages.FrequencyListEditorInput_4);
911
		freqColumn.setWidth(100);
912
		freqColumn.addSelectionListener(new SelectionListener() {
913
			@Override
914
			public void widgetSelected(SelectionEvent e) {
915
				if (viewer.getTable().getSortColumn() != freqColumn) {
916
					viewer.getTable().setSortColumn(freqColumn);
917
					viewer.getTable().setSortDirection(SWT.UP);
918
					index.sortLines(SortMode.FREQUNIT, false);
919
				} else {
920
					if (viewer.getTable().getSortDirection() == SWT.UP) {
921
						viewer.getTable().setSortDirection(SWT.DOWN);
922
						index.sortLines(SortMode.FREQUNIT, true);
923
					} else {
924
						viewer.getTable().setSortDirection(SWT.UP);
925
						index.sortLines(SortMode.FREQUNIT, false);
926
					}
927
				}
928
				StatusLine.setMessage(Messages.IndexEditor_37);
929
				fillDisplayArea(topLine, bottomLine);
930
			}
931

  
932
			@Override
933
			public void widgetDefaultSelected(SelectionEvent e) {
934
			}
935
		});
936

  
937
		// rmv/creates parts columns if needed
938
		if (this.partition != null) {
939
			List<String> partnames = this.partition.getPartNames();
940
			if (partnames.size() > 1)
941
				if (viewer.getTable().getColumnCount() < partnames
942
						.size() + 3) {
943
					for (int i = 0; i < partnames.size(); i++) {
944
						final TableColumn partColumn = new TableColumn(
945
								viewer.getTable(), SWT.RIGHT);
946
						try {
947
							partColumn.setText(partnames.get(i)+" t="+partition.getParts().get(i).getSize()); //$NON-NLS-1$
948
						} catch (CqiClientException e1) {
949
							// TODO Auto-generated catch block
950
							org.txm.rcpapplication.utils.Logger.printStackTrace(e1);
951
						}
952
						partColumn.setToolTipText(partnames.get(i));
953
						partColumn.setWidth(100);
954
						//						partColumn.addSelectionListener(new SelectionListener() {
955
						//									@Override
956
						//									public void widgetSelected(SelectionEvent e) {
957
						//										if (viewer.getTable()
958
						//												.getSortColumn() != partColumn) {
959
						//											viewer.getTable()
960
						//													.setSortColumn(partColumn);
961
						//											viewer.getTable()
962
						//													.setSortDirection(SWT.UP);
963
						//											index.sortLines(
964
						//													SortMode.FREQUNIT, false);
965
						//										} else {
966
						//											if (viewer.getTable()
967
						//													.getSortDirection() == SWT.UP) {
968
						//												viewer.getTable()
969
						//														.setSortDirection(
970
						//																SWT.DOWN);
971
						//												index
972
						//														.sortLines(
973
						//																SortMode.FREQUNIT,
974
						//																true);
975
						//											} else {
976
						//												viewer.getTable()
977
						//														.setSortDirection(
978
						//																SWT.UP);
979
						//												index.sortLines(
980
						//														SortMode.FREQUNIT,
981
						//														false);
982
						//											}
983
						//										}
984
						//										fillDisplayArea(topLine, bottomLine);
985
						//									}
986
						//
987
						//									@Override
988
						//									public void widgetDefaultSelected(
989
						//											SelectionEvent e) {
990
						//									}
991
						//								});
992
					}
993
				}
994
		}
995
		separatorColumn = new TableColumn(viewer.getTable(), SWT.LEFT);
996
		separatorColumn.setText(""); //$NON-NLS-1$
997
		separatorColumn.pack();
998

  
999
		initializeFields();
1000
		createContextMenu(viewer);
1001
		viewer.getTable().pack();
1002
		parent.layout(true);
1003
		//System.out.println("Part control done.");
1004
	}
1005

  
1006
	/**
1007
	 * Gets the pointed column.
1008
	 *
1009
	 * @param mouseposition the mouseposition
1010
	 * @return the pointed column
1011
	 */
1012
	public int getPointedColumn(Point mouseposition) {
1013
		int x = mouseposition.x; // + lineTableViewer.getTable().get;
1014
		int sumWidthColumn = this.nColumn.getWidth();
1015
		if (x < sumWidthColumn)
1016
			return 0;
1017

  
1018
		sumWidthColumn += this.unitColumn.getWidth();
1019
		if (x < sumWidthColumn)
1020
			return 1;
1021

  
1022
		sumWidthColumn += this.freqColumn.getWidth();
1023
		if (x < sumWidthColumn)
1024
			return 2;
1025

  
1026
		return 2;
1027
	}
1028

  
1029
	/**
1030
	 * Creates the context menu.
1031
	 *
1032
	 * @param tableViewer the table viewer
1033
	 */
1034
	private void createContextMenu(TableViewer tableViewer) {
1035
		MenuManager menuManager = new MenuManager();
1036
		Menu menu = menuManager.createContextMenu(tableViewer.getTable());
1037
		tableViewer.getTable().setMenu(menu);
1038
		getSite().registerContextMenu(menuManager, tableViewer);
1039
		getSite().setSelectionProvider(tableViewer);
1040
	}
1041

  
1042
	boolean initializing = false; // prevent properties widget listener to activate when adding new properties (and refresh the result)
1043
	/**
1044
	 * Initialize fields.
1045
	 */
1046
	public void initializeFields() {
1047
		initializing = true;
1048
		if (this.index != null) {
1049
			// query
1050
			this.queryWidget.memorize(index.getQuery().getQueryString());
1051
			// props
1052
			ArrayList<Property> availables = new ArrayList<Property>();
1053
			try {
1054
				for (Property p : index.getCorpus().getOrderedProperties())
1055
					if (!index.getProperties().contains(p))
1056
						availables.add(p);
1057
			} catch (CqiClientException e) {
1058
				org.txm.rcpapplication.utils.Logger.printStackTrace(e);
1059
				initializing = false;
1060
			}
1061
			ArrayList<Property> props = new ArrayList<Property>();
1062
			props.addAll(index.getProperties());
1063
			this.propsArea.setProperties(availables, props);
1064
			// min, max
1065
			this.FminSpinner.setSelection(index.getFilterFmin());
1066
			this.FmaxSpinner.setSelection(index.getFilterFmax());
1067

  
1068
			if (index.getPartition() != null)
1069
				setPartName(index.getPartition().getName()+": "+index.getName()); //$NON-NLS-1$
1070
			else
1071
				setPartName(index.getCorpus().getName()+": "+index.getName()); //$NON-NLS-1$
1072
			queryWidget.setFocus();
1073

  
1074
			index.filterLines(index.getFilterFmin(), index
1075
					.getFilterFmax());
1076
			index.sortLines(SortMode.FREQUNIT, true);
1077

  
1078
			fillDisplayArea(0, NLignePPageSpinner.getSelection());
1079
		} else if (this.corpus != null) {
1080
			// no query
1081
			queryWidget.setText(""); //$NON-NLS-1$
1082
			// props
1083
			this.propsArea.setCorpus(corpus);
1084
			// min, max
1085
			this.FminSpinner.setSelection(1);
1086
			this.FmaxSpinner.setSelection(9999999);
1087

  
1088
			if (partition != null)
1089
				setPartName(Messages.ObjectExplorer_9 + partition.getName());
1090
			else
1091
				setPartName(Messages.ObjectExplorer_9 + corpus.getName());
1092
			queryWidget.setFocus();
1093
		} else {
1094
			System.err.println(Messages.IndexEditor_22);
1095
		}
1096
		initializing = false;
1097
	}
1098

  
1099
	/**
1100
	 * Fill display area.
1101
	 *
1102
	 * @param from the from
1103
	 * @param to the to
1104
	 */
1105
	public void fillDisplayArea(int from, int to) {
1106
		// System.out.println("call fill from "+from+" to "+to);
1107
		from = Math.max(from, 0);
1108
		to = Math.min(to, index.getV());
1109
		List<Line> lines = null;
1110
		if (index.getV() > 0) {
1111
			lines = index.getLines(from, to);
1112
		} else
1113
			lines = new ArrayList<Line>();
1114

  
1115
		navigationArea.setInfoLineText(""+(from + 1), //$NON-NLS-1$
1116
				"-" + (to) + " / " + index.getV()); //$NON-NLS-1$ //$NON-NLS-2$
1117
		navigationArea.setPreviousEnabled(from > 0);
1118
		navigationArea.setFirstEnabled(from > 0);
1119
		navigationArea.setNextEnabled(to < index.getV());
1120
		navigationArea.setLastEnabled(to < index.getV());
1121

  
1122
		lFminInfo.setText(Messages.IndexEditor_25 + index.getFmin());
1123
		lFmaxInfo.setText(Messages.IndexEditor_26 + index.getFmax());
1124
		lTInfo.setText(Messages.IndexEditor_27 + index.getT());
1125
		lVInfo.setText(Messages.IndexEditor_28 + index.getV());
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff