|
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 |
// $LastChangedDate:$
|
|
23 |
// $LastChangedRevision:$
|
|
24 |
// $LastChangedBy:$
|
|
25 |
//
|
|
26 |
package org.txm.concordance.rcp.editors;
|
|
27 |
|
|
28 |
import java.io.File;
|
|
29 |
import java.util.ArrayList;
|
|
30 |
import java.util.HashMap;
|
|
31 |
import java.util.Iterator;
|
|
32 |
import java.util.List;
|
|
33 |
import java.util.Vector;
|
|
34 |
import java.util.logging.Level;
|
|
35 |
|
|
36 |
import org.eclipse.core.runtime.CoreException;
|
|
37 |
import org.eclipse.core.runtime.IConfigurationElement;
|
|
38 |
import org.eclipse.core.runtime.IProgressMonitor;
|
|
39 |
import org.eclipse.core.runtime.IStatus;
|
|
40 |
import org.eclipse.core.runtime.Platform;
|
|
41 |
import org.eclipse.core.runtime.Status;
|
|
42 |
import org.eclipse.e4.ui.workbench.modeling.EModelService;
|
|
43 |
import org.eclipse.jface.action.Action;
|
|
44 |
import org.eclipse.jface.action.IMenuListener;
|
|
45 |
import org.eclipse.jface.action.IMenuManager;
|
|
46 |
import org.eclipse.jface.action.MenuManager;
|
|
47 |
import org.eclipse.jface.action.Separator;
|
|
48 |
import org.eclipse.jface.dialogs.InputDialog;
|
|
49 |
import org.eclipse.jface.dialogs.MessageDialog;
|
|
50 |
import org.eclipse.jface.viewers.ArrayContentProvider;
|
|
51 |
import org.eclipse.jface.viewers.ComboViewer;
|
|
52 |
import org.eclipse.jface.viewers.ISelection;
|
|
53 |
import org.eclipse.jface.viewers.ISelectionChangedListener;
|
|
54 |
import org.eclipse.jface.viewers.IStructuredSelection;
|
|
55 |
import org.eclipse.jface.viewers.SelectionChangedEvent;
|
|
56 |
import org.eclipse.jface.viewers.StructuredSelection;
|
|
57 |
import org.eclipse.jface.viewers.TableViewer;
|
|
58 |
import org.eclipse.osgi.util.NLS;
|
|
59 |
import org.eclipse.swt.SWT;
|
|
60 |
import org.eclipse.swt.browser.ProgressListener;
|
|
61 |
import org.eclipse.swt.events.ControlEvent;
|
|
62 |
import org.eclipse.swt.events.ControlListener;
|
|
63 |
import org.eclipse.swt.events.KeyEvent;
|
|
64 |
import org.eclipse.swt.events.KeyListener;
|
|
65 |
import org.eclipse.swt.events.MouseAdapter;
|
|
66 |
import org.eclipse.swt.events.MouseEvent;
|
|
67 |
import org.eclipse.swt.events.MouseListener;
|
|
68 |
import org.eclipse.swt.events.SelectionEvent;
|
|
69 |
import org.eclipse.swt.events.SelectionListener;
|
|
70 |
import org.eclipse.swt.graphics.Font;
|
|
71 |
import org.eclipse.swt.graphics.FontData;
|
|
72 |
import org.eclipse.swt.graphics.GC;
|
|
73 |
import org.eclipse.swt.graphics.Image;
|
|
74 |
import org.eclipse.swt.graphics.Point;
|
|
75 |
import org.eclipse.swt.graphics.Rectangle;
|
|
76 |
import org.eclipse.swt.layout.FormAttachment;
|
|
77 |
import org.eclipse.swt.layout.FormData;
|
|
78 |
import org.eclipse.swt.layout.FormLayout;
|
|
79 |
import org.eclipse.swt.layout.GridData;
|
|
80 |
import org.eclipse.swt.layout.GridLayout;
|
|
81 |
import org.eclipse.swt.widgets.Button;
|
|
82 |
import org.eclipse.swt.widgets.Combo;
|
|
83 |
import org.eclipse.swt.widgets.Composite;
|
|
84 |
import org.eclipse.swt.widgets.Display;
|
|
85 |
import org.eclipse.swt.widgets.Event;
|
|
86 |
import org.eclipse.swt.widgets.Label;
|
|
87 |
import org.eclipse.swt.widgets.Listener;
|
|
88 |
import org.eclipse.swt.widgets.Menu;
|
|
89 |
import org.eclipse.swt.widgets.ScrollBar;
|
|
90 |
import org.eclipse.swt.widgets.TableColumn;
|
|
91 |
import org.eclipse.swt.widgets.Text;
|
|
92 |
import org.eclipse.ui.IEditorInput;
|
|
93 |
import org.eclipse.ui.IEditorSite;
|
|
94 |
import org.eclipse.ui.IWorkbenchPage;
|
|
95 |
import org.eclipse.ui.IWorkbenchPartSite;
|
|
96 |
import org.eclipse.ui.IWorkbenchWindow;
|
|
97 |
import org.eclipse.ui.PartInitException;
|
|
98 |
import org.eclipse.ui.dialogs.ListDialog;
|
|
99 |
import org.eclipse.ui.part.EditorPart;
|
|
100 |
import org.txm.Toolbox;
|
|
101 |
import org.txm.annotation.Annotation;
|
|
102 |
import org.txm.annotation.AnnotationManager;
|
|
103 |
import org.txm.annotation.repository.AnnotationType;
|
|
104 |
import org.txm.annotation.repository.KnowledgeRepository;
|
|
105 |
import org.txm.annotation.repository.KnowledgeRepositoryManager;
|
|
106 |
import org.txm.annotation.repository.LocalKnowledgeRepository;
|
|
107 |
import org.txm.annotation.repository.SQLKnowledgeRepository;
|
|
108 |
import org.txm.annotation.repository.TypedValue;
|
|
109 |
import org.txm.concordance.core.functions.Concordance;
|
|
110 |
import org.txm.concordance.core.functions.Line;
|
|
111 |
import org.txm.concordance.core.functions.comparators.CompositeComparator;
|
|
112 |
import org.txm.concordance.core.functions.comparators.LexicographicKeywordComparator;
|
|
113 |
import org.txm.concordance.core.functions.comparators.LexicographicLeftContextComparator;
|
|
114 |
import org.txm.concordance.core.functions.comparators.LexicographicRightContextComparator;
|
|
115 |
import org.txm.concordance.core.functions.comparators.LineComparator;
|
|
116 |
import org.txm.concordance.core.functions.comparators.NullComparator;
|
|
117 |
import org.txm.concordance.core.functions.comparators.PropertiesReferenceComparator;
|
|
118 |
import org.txm.concordance.core.functions.comparators.ReverseComparator;
|
|
119 |
import org.txm.concordance.core.preferences.ConcordancePreferences;
|
|
120 |
import org.txm.concordance.rcp.actions.DefineSortReferencePattern;
|
|
121 |
import org.txm.concordance.rcp.actions.DefineViewReferencePattern;
|
|
122 |
import org.txm.concordance.rcp.actions.SetContextSize;
|
|
123 |
import org.txm.concordance.rcp.actions.SetLineNumber;
|
|
124 |
import org.txm.concordance.rcp.actions.SortPropertySelection;
|
|
125 |
import org.txm.concordance.rcp.actions.ViewPropertySelection;
|
|
126 |
import org.txm.concordance.rcp.handlers.BackToTextCommand;
|
|
127 |
import org.txm.concordance.rcp.handlers.DeleteLines;
|
|
128 |
import org.txm.concordance.rcp.widgets.ComplexSortSelector;
|
|
129 |
import org.txm.cooccurrence.rcp.messages.CooccurrenceUIMessages;
|
|
130 |
import org.txm.core.messages.TXMCoreMessages;
|
|
131 |
import org.txm.core.preferences.TXMPreferences;
|
|
132 |
import org.txm.functions.ReferencePattern;
|
|
133 |
import org.txm.objects.Page;
|
|
134 |
import org.txm.rcp.IImageKeys;
|
|
135 |
import org.txm.rcp.JobsTimer;
|
|
136 |
import org.txm.rcp.Messages;
|
|
137 |
import org.txm.rcp.StatusLine;
|
|
138 |
import org.txm.rcp.TXMWindows;
|
|
139 |
import org.txm.rcp.commands.OpenBrowser;
|
|
140 |
import org.txm.rcp.commands.annotation.InitializeKnowledgeRepository;
|
|
141 |
import org.txm.rcp.commands.annotation.SaveAnnotations;
|
|
142 |
import org.txm.rcp.commands.editor.CustomizableEditor;
|
|
143 |
import org.txm.rcp.commands.krview.OpenKRView;
|
|
144 |
import org.txm.rcp.editors.TXMBrowser;
|
|
145 |
import org.txm.rcp.editors.TableKeyListener;
|
|
146 |
import org.txm.rcp.editors.input.InternalViewEditorInput;
|
|
147 |
import org.txm.rcp.editors.internal.InternalViewEditor;
|
|
148 |
import org.txm.rcp.preferences.RCPPreferences;
|
|
149 |
import org.txm.rcp.swt.dialog.ConfirmDialog;
|
|
150 |
import org.txm.rcp.swt.dialog.ViewPropertySelectionDialog;
|
|
151 |
import org.txm.rcp.swt.provider.SimpleLabelProvider;
|
|
152 |
import org.txm.rcp.swt.widget.AssistedQueryWidget;
|
|
153 |
import org.txm.rcp.swt.widget.NavigationWidget;
|
|
154 |
import org.txm.rcp.utils.JobHandler;
|
|
155 |
import org.txm.rcp.utils.SWTEditorsUtils;
|
|
156 |
import org.txm.rcp.views.QueriesView;
|
|
157 |
import org.txm.rcp.views.corpora.CorporaView;
|
|
158 |
import org.txm.rcp.views.knowledgerepositories.KRView;
|
|
159 |
import org.txm.searchengine.cqp.clientExceptions.CqiClientException;
|
|
160 |
import org.txm.searchengine.cqp.corpus.Corpus;
|
|
161 |
import org.txm.searchengine.cqp.corpus.Property;
|
|
162 |
import org.txm.searchengine.cqp.corpus.query.Match;
|
|
163 |
import org.txm.searchengine.cqp.corpus.query.Query;
|
|
164 |
import org.txm.utils.AsciiUtils;
|
|
165 |
import org.txm.utils.logger.Log;
|
|
166 |
// TODO: Auto-generated Javadoc
|
|
167 |
/**
|
|
168 |
* display the concordances parameters and results in the same editor
|
|
169 |
*
|
|
170 |
* @author mdecorde.
|
|
171 |
*/
|
|
172 |
public class ConcordanceEditor extends EditorPart implements CustomizableEditor {
|
|
173 |
|
|
174 |
/**
|
|
175 |
* the limit number of annotation when a confirm dialog box is shown
|
|
176 |
*/
|
|
177 |
private static final int NALERTAFFECTANNOTATIONS = 100;
|
|
178 |
|
|
179 |
String locale = TXMPreferences.getString(RCPPreferences.PREFERENCES_NODE, RCPPreferences.UI_LOCALE, "en");
|
|
180 |
|
|
181 |
/** The lineids. */
|
|
182 |
List<String> lineids;
|
|
183 |
|
|
184 |
/** The standard comparators. */
|
|
185 |
private List<LineComparator> standardComparators;
|
|
186 |
|
|
187 |
/** The user defined comparators. */
|
|
188 |
private List<LineComparator> userDefinedComparators;
|
|
189 |
|
|
190 |
/** The complexsorter. */
|
|
191 |
ComplexSortSelector complexsorter;
|
|
192 |
org.eclipse.swt.widgets.Text cqlSeparator;
|
|
193 |
|
|
194 |
/** The available view keyword properties. */
|
|
195 |
private List<Property> availableKeywordViewProperties;
|
|
196 |
/** The available view left properties. */
|
|
197 |
private List<Property> availableLeftViewProperties;
|
|
198 |
/** The available view right properties. */
|
|
199 |
private List<Property> availableRightViewProperties;
|
|
200 |
|
|
201 |
/** The selected left view properties. */
|
|
202 |
private List<Property> selectedLeftViewProperties;
|
|
203 |
/** The selected right view properties. */
|
|
204 |
private List<Property> selectedRightViewProperties;
|
|
205 |
/** The selected keyword view properties. */
|
|
206 |
private List<Property> selectedKeywordViewProperties;
|
|
207 |
|
|
208 |
/** The available sort properties. */
|
|
209 |
private List<Property> availableKeywordSortProperties;
|
|
210 |
|
|
211 |
/** The selected keyword sort property. */
|
|
212 |
private List<Property> selectedKeywordSortProperties;
|
|
213 |
/** The selected left sort property. */
|
|
214 |
private List<Property> selectedLeftSortProperties;
|
|
215 |
/** The selected right sort property. */
|
|
216 |
private List<Property> selectedRightSortProperties;
|
|
217 |
|
|
218 |
/** The reference pattern. */
|
|
219 |
private ReferencePattern refViewPattern;
|
|
220 |
private ReferencePattern refSortPattern;
|
|
221 |
|
|
222 |
/** The concordance. */
|
|
223 |
private Concordance concordance;
|
|
224 |
|
|
225 |
/** The annotation service */
|
|
226 |
private AnnotationManager annotManager;
|
|
227 |
|
|
228 |
//boolean annotation_expert_mode = TxmPreferences.getBoolean(AnnotationPreferencePage.MODE, false);
|
|
229 |
|
|
230 |
/** The standard comparator class name. */
|
|
231 |
private LineComparator[] standardComparatorClassName = {
|
|
232 |
new NullComparator(), new LexicographicKeywordComparator(),
|
|
233 |
new LexicographicLeftContextComparator(),
|
|
234 |
new LexicographicRightContextComparator(),
|
|
235 |
new PropertiesReferenceComparator() };
|
|
236 |
|
|
237 |
/** The corpus. */
|
|
238 |
private Corpus corpus;
|
|
239 |
|
|
240 |
/** The n line per page. */
|
|
241 |
private int nLinePerPage;
|
|
242 |
|
|
243 |
/** The top line. */
|
|
244 |
private int topLine;
|
|
245 |
|
|
246 |
/** The bottom line. */
|
|
247 |
private int bottomLine;
|
|
248 |
|
|
249 |
/** The current comparator. */
|
|
250 |
protected LineComparator currentComparator;
|
|
251 |
|
|
252 |
/** The left context size. */
|
|
253 |
private int leftContextSize;
|
|
254 |
|
|
255 |
/** The right context size. */
|
|
256 |
private int rightContextSize;
|
|
257 |
|
|
258 |
/** The mouseposition. */
|
|
259 |
private Point mouseposition;
|
|
260 |
|
|
261 |
/** The query widget. */
|
|
262 |
private AssistedQueryWidget queryWidget;
|
|
263 |
|
|
264 |
/** The line table viewer. */
|
|
265 |
private TableViewer viewer;
|
|
266 |
|
|
267 |
/** The reference column. */
|
|
268 |
private TableColumn referenceColumn;
|
|
269 |
|
|
270 |
/** The first column. */
|
|
271 |
private TableColumn firstColumn; // due to a restriction on some platforms
|
|
272 |
// (actually, MS Windows), the first
|
|
273 |
// column is always left aligned. The
|
|
274 |
// work around is to have a 0 width
|
|
275 |
// first column
|
|
276 |
/** The left context column. */
|
|
277 |
private TableColumn leftContextColumn;
|
|
278 |
/** The keyword column. */
|
|
279 |
private TableColumn keywordColumn;
|
|
280 |
/** The right context column. */
|
|
281 |
private TableColumn rightContextColumn;
|
|
282 |
|
|
283 |
/** The view properties label. */
|
|
284 |
private Label viewPropertiesLabel;
|
|
285 |
|
|
286 |
/** The set sort property action. */
|
|
287 |
private Action setSortPropertyAction;
|
|
288 |
|
|
289 |
/** The set context size action. */
|
|
290 |
private Action setContextSizeAction;
|
|
291 |
|
|
292 |
/** The set line number action. */
|
|
293 |
private Action setLineNumberAction;
|
|
294 |
|
|
295 |
/** The define view reference pattern action. */
|
|
296 |
protected Action defineViewReferencePatternAction;
|
|
297 |
|
|
298 |
/** The define sort reference pattern action. */
|
|
299 |
protected Action defineSortReferencePatternAction;
|
|
300 |
|
|
301 |
/** The set view property action. */
|
|
302 |
protected Action setViewPropertyAction;
|
|
303 |
|
|
304 |
/** The attached browser editor. */
|
|
305 |
protected TXMBrowser attachedBrowserEditor;
|
|
306 |
|
|
307 |
/** The progresslistener. */
|
|
308 |
protected ProgressListener progresslistener;
|
|
309 |
|
|
310 |
/** The textid. */
|
|
311 |
protected String textid;
|
|
312 |
|
|
313 |
/** The opened page. */
|
|
314 |
Page openedPage;
|
|
315 |
|
|
316 |
/** The query area. */
|
|
317 |
private Composite queryArea;
|
|
318 |
|
|
319 |
/** The annotation area. */
|
|
320 |
private Composite annotationArea;
|
|
321 |
|
|
322 |
/** The navigation area. */
|
|
323 |
private NavigationWidget navigationArea;
|
|
324 |
|
|
325 |
/** The is setup shown. */
|
|
326 |
private boolean isSetupShown = true;
|
|
327 |
|
|
328 |
|
|
329 |
/** The hide btn. */
|
|
330 |
private Button hideBtn;
|
|
331 |
private Button deleteLineButton;
|
|
332 |
|
|
333 |
/** The query size. */
|
|
334 |
protected Point querySize;
|
|
335 |
|
|
336 |
protected Point annotationSize;
|
|
337 |
|
|
338 |
/** The annot btn. */
|
|
339 |
private Button annotationButton;
|
|
340 |
|
|
341 |
// /** The selected typed value for new annotations **/
|
|
342 |
// private TypedValue annotSelectedTypedValue;
|
|
343 |
// private AnnotationType annotSelectedType;
|
|
344 |
|
|
345 |
private Text annotationValuesText;
|
|
346 |
private ComboViewer annotationTypesCombo;
|
|
347 |
|
|
348 |
/** The parent. */
|
|
349 |
private Composite parent;
|
|
350 |
|
|
351 |
private ArrayList<Property> availableLeftSortProperties;
|
|
352 |
|
|
353 |
private ArrayList<Property> availableRightSortProperties;
|
|
354 |
|
|
355 |
private List<TypedValue> typeValuesList;
|
|
356 |
|
|
357 |
protected Point annotSize;
|
|
358 |
|
|
359 |
private TableColumn annotationColumn;
|
|
360 |
|
|
361 |
// private Button addAnnotationButton;
|
|
362 |
// private Button deleteAnnotationButton;
|
|
363 |
private Combo addRemoveCombo;
|
|
364 |
private Combo affectCombo;
|
|
365 |
private Button affectAnnotationButton;
|
|
366 |
// private Button affectAnnotationToSelectionButton;
|
|
367 |
// private Button affectAnnotationToConcordanceButton;
|
|
368 |
// private Button affectAnnotationToPageButton;
|
|
369 |
|
|
370 |
private Label aLabel;
|
|
371 |
|
|
372 |
private Button infosAnnotTypeSelectedLink;
|
|
373 |
|
|
374 |
// private TableColumnLayout tableLayout;
|
|
375 |
|
|
376 |
|
|
377 |
/* (non-Javadoc)
|
|
378 |
* @see org.eclipse.ui.part.EditorPart#doSave(org.eclipse.core.runtime.IProgressMonitor)
|
|
379 |
*/
|
|
380 |
@Override
|
|
381 |
public void doSave(IProgressMonitor monitor) {
|
|
382 |
}
|
|
383 |
|
|
384 |
/* (non-Javadoc)
|
|
385 |
* @see org.eclipse.ui.part.EditorPart#doSaveAs()
|
|
386 |
*/
|
|
387 |
@Override
|
|
388 |
public void doSaveAs() {
|
|
389 |
}
|
|
390 |
|
|
391 |
/* (non-Javadoc)
|
|
392 |
* @see org.eclipse.ui.part.EditorPart#isDirty()
|
|
393 |
*/
|
|
394 |
@Override
|
|
395 |
public boolean isDirty() {
|
|
396 |
return false;
|
|
397 |
}
|
|
398 |
|
|
399 |
/* (non-Javadoc)
|
|
400 |
* @see org.eclipse.ui.part.EditorPart#isSaveAsAllowed()
|
|
401 |
*/
|
|
402 |
@Override
|
|
403 |
public boolean isSaveAsAllowed() {
|
|
404 |
return false;
|
|
405 |
}
|
|
406 |
|
|
407 |
/**
|
|
408 |
* Sets the standard comparators.
|
|
409 |
*/
|
|
410 |
private void setStandardComparators() {
|
|
411 |
for (int i = 0; i < standardComparatorClassName.length; i++)
|
|
412 |
standardComparators.add(standardComparatorClassName[i]);
|
|
413 |
}
|
|
414 |
|
|
415 |
/* (non-Javadoc)
|
|
416 |
* @see org.eclipse.ui.part.EditorPart#init(org.eclipse.ui.IEditorSite, org.eclipse.ui.IEditorInput)
|
|
417 |
*/
|
|
418 |
@Override
|
|
419 |
public void init(IEditorSite site, IEditorInput input)
|
|
420 |
throws PartInitException {
|
|
421 |
setSite(site);
|
|
422 |
setInput(input);
|
|
423 |
|
|
424 |
initializeEditor();
|
|
425 |
}
|
|
426 |
|
|
427 |
private void initializeEditor() {
|
|
428 |
this.corpus = ((ConcordanceEditorInput) getEditorInput()).getCorpus();
|
|
429 |
this.annotManager = corpus.getAnnotationManager();
|
|
430 |
|
|
431 |
this.standardComparators = new ArrayList<LineComparator>();
|
|
432 |
this.userDefinedComparators = new ArrayList<LineComparator>();
|
|
433 |
new ArrayList<LineComparator>();
|
|
434 |
setStandardComparators();
|
|
435 |
this.nLinePerPage = TXMPreferences.getInt(ConcordancePreferences.PREFERENCES_NODE, ConcordancePreferences.N_LINE_PER_PAGE);
|
|
436 |
try {
|
|
437 |
this.availableKeywordViewProperties = new ArrayList<Property>(
|
|
438 |
corpus.getOrderedProperties());
|
|
439 |
this.availableLeftViewProperties = new ArrayList<Property>(corpus
|
|
440 |
.getOrderedProperties());
|
|
441 |
this.availableRightViewProperties = new ArrayList<Property>(corpus
|
|
442 |
.getOrderedProperties());
|
|
443 |
this.availableLeftSortProperties = new ArrayList<Property>(corpus
|
|
444 |
.getOrderedProperties());
|
|
445 |
this.availableKeywordSortProperties = new ArrayList<Property>(corpus
|
|
446 |
.getOrderedProperties());
|
|
447 |
this.availableRightSortProperties = new ArrayList<Property>(corpus
|
|
448 |
.getOrderedProperties());
|
|
449 |
} catch (CqiClientException e) {
|
|
450 |
//System.err.println(Messages.CorporaView_3+" : "+Log.toString(e)); //$NON-NLS-1$
|
|
451 |
try {
|
|
452 |
System.out.println(Messages.ConcordancesEditor_0+Toolbox.getCqiClient().getLastCQPError());
|
|
453 |
Log.severe(Messages.ConcordancesEditor_0+Toolbox.getCqiClient().getLastCQPError());
|
|
454 |
} catch (Exception e1) {
|
|
455 |
org.txm.rcp.utils.Logger.printStackTrace(e1);
|
|
456 |
Log.severe("Error while computing concordance: "+e.getLocalizedMessage());
|
|
457 |
}
|
|
458 |
|
|
459 |
return;
|
|
460 |
}
|
|
461 |
|
|
462 |
this.concordance = ((ConcordanceEditorInput) getEditorInput()).getConcordance();
|
|
463 |
|
|
464 |
if (this.concordance == null) {
|
|
465 |
leftContextSize = TXMPreferences.getInt(ConcordancePreferences.PREFERENCES_NODE, ConcordancePreferences.LEFT_CONTEXT_SIZE);
|
|
466 |
rightContextSize = TXMPreferences.getInt(ConcordancePreferences.PREFERENCES_NODE, ConcordancePreferences.RIGHT_CONTEXT_SIZE);
|
|
467 |
|
|
468 |
selectedLeftViewProperties = new ArrayList<Property>();
|
|
469 |
selectedRightViewProperties = new ArrayList<Property>();
|
|
470 |
selectedKeywordViewProperties = new ArrayList<Property>();
|
|
471 |
|
|
472 |
//set default view property
|
|
473 |
Property defaultViewProperty = availableKeywordViewProperties.get(0);
|
|
474 |
if(!defaultViewProperty.getName().equals("word")) //$NON-NLS-1$
|
|
475 |
for(int i = 0 ; i < availableKeywordViewProperties.size() ; i++ )
|
|
476 |
if (availableKeywordViewProperties.get(i).getName().equals("word")) //$NON-NLS-1$
|
|
477 |
{
|
|
478 |
defaultViewProperty = availableKeywordViewProperties.get(i);
|
|
479 |
break;
|
|
480 |
}
|
|
481 |
|
|
482 |
availableKeywordViewProperties.remove(defaultViewProperty);
|
|
483 |
availableLeftViewProperties.remove(defaultViewProperty);
|
|
484 |
availableRightViewProperties.remove(defaultViewProperty);
|
|
485 |
selectedLeftViewProperties.add(defaultViewProperty);
|
|
486 |
selectedRightViewProperties.add(defaultViewProperty);
|
|
487 |
selectedKeywordViewProperties.add(defaultViewProperty);
|
|
488 |
|
|
489 |
//set default sort property
|
|
490 |
selectedLeftSortProperties = new ArrayList<Property>();
|
|
491 |
selectedRightSortProperties = new ArrayList<Property>();
|
|
492 |
selectedKeywordSortProperties = new ArrayList<Property>();
|
|
493 |
|
|
494 |
Property defaultSortProperty = availableKeywordSortProperties.get(0);
|
|
495 |
if(!defaultSortProperty.getName().equals("word")) //$NON-NLS-1$
|
|
496 |
for(int i = 0 ; i < availableKeywordSortProperties.size() ; i++ )
|
|
497 |
if (availableKeywordSortProperties.get(i).getName().equals("word")) //$NON-NLS-1$
|
|
498 |
{
|
|
499 |
defaultSortProperty = availableKeywordSortProperties.get(i);
|
|
500 |
break;
|
|
501 |
}
|
|
502 |
|
|
503 |
availableKeywordSortProperties.remove(defaultSortProperty);
|
|
504 |
availableLeftSortProperties.remove(defaultSortProperty);
|
|
505 |
availableRightSortProperties.remove(defaultSortProperty);
|
|
506 |
selectedLeftSortProperties.add(defaultSortProperty);
|
|
507 |
selectedRightSortProperties.add(defaultSortProperty);
|
|
508 |
selectedKeywordSortProperties.add(defaultSortProperty);
|
|
509 |
|
|
510 |
this.refViewPattern = new ReferencePattern();
|
|
511 |
this.refSortPattern = new ReferencePattern();
|
|
512 |
try { // set the default reference is there is one
|
|
513 |
if (corpus.getProperty("ref") != null) //$NON-NLS-1$
|
|
514 |
{
|
|
515 |
refViewPattern.addProperty(corpus.getProperty("ref")); //$NON-NLS-1$
|
|
516 |
refSortPattern.addProperty(corpus.getProperty("ref")); //$NON-NLS-1$
|
|
517 |
} else {
|
|
518 |
if (corpus.getStructuralUnit("text") != null) //$NON-NLS-1$
|
|
519 |
if (corpus.getStructuralUnit("text").getProperty("id") != null) //$NON-NLS-1$ //$NON-NLS-2$
|
|
520 |
{
|
|
521 |
refViewPattern.addProperty(corpus.getStructuralUnit("text").getProperty("id")); //$NON-NLS-1$ //$NON-NLS-2$
|
|
522 |
refSortPattern.addProperty(corpus.getStructuralUnit("text").getProperty("id")); //$NON-NLS-1$ //$NON-NLS-2$
|
|
523 |
}
|
|
524 |
}
|
|
525 |
} catch (CqiClientException e) {
|
|
526 |
System.out.println(NLS.bind(Messages.ConcordancesEditor_43, corpus.getName(), e));
|
|
527 |
}
|
|
528 |
} else {
|
|
529 |
leftContextSize = concordance.getLeftContextSize();
|
|
530 |
rightContextSize = concordance.getRightContextSize();
|
|
531 |
|
|
532 |
selectedLeftViewProperties = concordance.getLeftViewProperties();
|
|
533 |
selectedRightViewProperties = concordance.getRightViewProperties();
|
|
534 |
selectedKeywordViewProperties = concordance.getKeywordViewProperties();
|
|
535 |
availableKeywordViewProperties.remove(selectedKeywordViewProperties);
|
|
536 |
availableLeftViewProperties.remove(selectedLeftViewProperties);
|
|
537 |
availableRightViewProperties.remove(selectedRightViewProperties);
|
|
538 |
|
|
539 |
selectedLeftSortProperties = concordance.getLeftAnalysisProperties();
|
|
540 |
selectedRightSortProperties = concordance.getRightAnalysisProperties();
|
|
541 |
selectedKeywordSortProperties = concordance.getKeywordAnalysisProperties();
|
|
542 |
availableKeywordSortProperties.remove(selectedKeywordSortProperties);
|
|
543 |
availableLeftSortProperties.remove(selectedLeftSortProperties);
|
|
544 |
availableRightSortProperties.remove(selectedRightSortProperties);
|
|
545 |
|
|
546 |
this.refViewPattern = concordance.getRefViewPattern();
|
|
547 |
this.refSortPattern = concordance.getRefAnalysePattern();
|
|
548 |
}
|
|
549 |
|
|
550 |
|
|
551 |
|
|
552 |
if (concordance != null)
|
|
553 |
setPartName(concordance.getName());
|
|
554 |
else
|
|
555 |
setPartName(corpus.getName());
|
|
556 |
}
|
|
557 |
|
|
558 |
/* (non-Javadoc)
|
|
559 |
* @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
|
|
560 |
*/
|
|
561 |
@Override
|
|
562 |
public void createPartControl(Composite parent) {
|
|
563 |
this.parent = parent;
|
|
564 |
// GridLayout layout = new GridLayout(1, false);
|
|
565 |
// layout.horizontalSpacing = 0;
|
|
566 |
// layout.verticalSpacing = 0;
|
|
567 |
// parent.setLayout(layout);
|
|
568 |
|
|
569 |
parent.setLayout(new FormLayout());
|
|
570 |
|
|
571 |
Composite controlArea = new Composite(parent, SWT.NONE); // the form
|
|
572 |
FormData formdata1 = new FormData();
|
|
573 |
formdata1.top = new FormAttachment(0);
|
|
574 |
//formdata1.bottom = new FormAttachment(100);
|
|
575 |
formdata1.left = new FormAttachment(0);
|
|
576 |
formdata1.right = new FormAttachment(100);
|
|
577 |
controlArea.setLayoutData(formdata1);
|
|
578 |
|
|
579 |
|
|
580 |
Composite displayArea = new Composite(parent, SWT.NONE); // the lines
|
|
581 |
FormData formdata2 = new FormData();
|
|
582 |
formdata2.top = new FormAttachment(controlArea);
|
|
583 |
formdata2.bottom = new FormAttachment(100);
|
|
584 |
formdata2.left = new FormAttachment(0);
|
|
585 |
formdata2.right = new FormAttachment(100);
|
|
586 |
displayArea.setLayoutData(formdata2);
|
|
587 |
|
|
588 |
composeControlArea(controlArea);
|
|
589 |
composeDisplayArea(displayArea);
|
|
590 |
|
|
591 |
//if (concordance != null)
|
|
592 |
// fillDisplayArea(0, nLinePerPage);
|
|
593 |
}
|
|
594 |
|
|
595 |
/**
|
|
596 |
* Compose display area.
|
|
597 |
*
|
|
598 |
* @param displayArea the display area
|
|
599 |
*/
|
|
600 |
private void composeDisplayArea(final Composite displayArea) {
|
|
601 |
// tableLayout = new TableColumnLayout();
|
|
602 |
displayArea.setLayout(new GridLayout(1, true));
|
|
603 |
|
|
604 |
viewer = new TableViewer(displayArea, SWT.MULTI | SWT.FULL_SELECTION | SWT.BORDER);
|
|
605 |
viewer.getTable().addKeyListener(new TableKeyListener(viewer));
|
|
606 |
viewer.setLabelProvider(new LineLabelProvider(this));
|
|
607 |
viewer.setContentProvider(new ConcordancesProvider());
|
|
608 |
viewer.getTable().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
|
|
609 |
|
|
610 |
if (corpus != null && corpus.getFont() != null && corpus.getFont().length() > 0) {
|
|
611 |
Font old = viewer.getTable().getFont();
|
|
612 |
FontData fD = old.getFontData()[0];
|
|
613 |
Font font = new Font(Display.getCurrent(), corpus.getFont(), fD.getHeight(), fD.getStyle());
|
|
614 |
viewer.getTable().setFont(font);
|
|
615 |
}
|
|
616 |
|
|
617 |
viewer.getTable().addListener(SWT.Resize, new Listener() {
|
|
618 |
@Override
|
|
619 |
public void handleEvent(Event event) {
|
|
620 |
ScrollBar bar = viewer.getTable().getHorizontalBar();
|
|
621 |
float l=leftContextColumn.getWidth();
|
|
622 |
float k=keywordColumn.getWidth();
|
|
623 |
float r=rightContextColumn.getWidth();
|
|
624 |
float t=viewer.getTable().getClientArea().width;//the width of the visible part of the table; l+k+r>=t
|
|
625 |
float x=l+k/2-t/2; //the abcisse the visible rectangle must have for the keyword column to be centered
|
|
626 |
float M=bar.getMaximum();
|
|
627 |
float T=bar.getThumb();
|
|
628 |
bar.setSelection(Math.round(x*(M-T)/(l+k+r-t)));//this is how x translate in terms of bar selection
|
|
629 |
}
|
|
630 |
});
|
|
631 |
|
|
632 |
//TODO: to enable line deletion, Concordance code must updated
|
|
633 |
viewer.getTable().addKeyListener(new KeyListener() {
|
|
634 |
|
|
635 |
@Override
|
|
636 |
public void keyReleased(KeyEvent e) { }
|
|
637 |
|
|
638 |
@Override
|
|
639 |
public void keyPressed(KeyEvent e) {
|
|
640 |
if (e.keyCode != SWT.DEL ) { // CTRL + C
|
|
641 |
return;
|
|
642 |
}
|
|
643 |
|
|
644 |
DeleteLines.deleteConcordanceLines(ConcordanceEditor.this);
|
|
645 |
}
|
|
646 |
});
|
|
647 |
|
|
648 |
|
|
649 |
firstColumn = new TableColumn(viewer.getTable(), SWT.LEFT);
|
|
650 |
firstColumn.setWidth(0);
|
|
651 |
|
|
652 |
referenceColumn = new TableColumn(viewer.getTable(), SWT.V_SCROLL | SWT.H_SCROLL);
|
|
653 |
refreshReferenceColumnTitle();
|
|
654 |
referenceColumn.setToolTipText(Messages.ConcordancesEditor_1);
|
|
655 |
referenceColumn.setAlignment(SWT.LEFT);
|
|
656 |
referenceColumn.addSelectionListener(new SelectionListener() {
|
|
657 |
@Override
|
|
658 |
public void widgetSelected(SelectionEvent e) {
|
|
659 |
StatusLine.setMessage(Messages.ConcordancesEditor_37);
|
|
660 |
LineComparator comparator = new PropertiesReferenceComparator();
|
|
661 |
if (viewer.getTable().getSortColumn() != referenceColumn) {
|
|
662 |
viewer.getTable().setSortColumn(null);
|
|
663 |
viewer.getTable().setSortColumn(referenceColumn);
|
|
664 |
viewer.getTable().setSortDirection(SWT.UP);
|
|
665 |
} else if (viewer.getTable().getSortDirection() == SWT.UP) {
|
|
666 |
viewer.getTable().setSortDirection(SWT.DOWN);
|
|
667 |
comparator = new ReverseComparator(comparator);
|
|
668 |
} else {
|
|
669 |
viewer.getTable().setSortDirection(SWT.UP);
|
|
670 |
}
|
|
671 |
comparator.initialize(corpus);
|
|
672 |
currentComparator = comparator;
|
|
673 |
complexsorter.setKey(4);//set ref key
|
|
674 |
sort();
|
|
675 |
StatusLine.setMessage(""); //$NON-NLS-1$
|
|
676 |
}
|
|
677 |
|
|
678 |
@Override
|
|
679 |
public void widgetDefaultSelected(SelectionEvent e) {
|
|
680 |
}
|
|
681 |
});
|
|
682 |
|
|
683 |
leftContextColumn = new TableColumn(viewer.getTable(), SWT.RIGHT);
|
|
684 |
leftContextColumn.setText(Messages.ConcordancesEditor_2);
|
|
685 |
leftContextColumn.setToolTipText(Messages.ConcordancesEditor_2);
|
|
686 |
leftContextColumn.setAlignment(SWT.RIGHT);
|
|
687 |
leftContextColumn.addSelectionListener(new SelectionListener() {
|
|
688 |
@Override
|
|
689 |
public void widgetSelected(SelectionEvent e) {
|
|
690 |
StatusLine.setMessage(Messages.ConcordancesEditor_41);
|
|
691 |
LineComparator comparator = new LexicographicLeftContextComparator();
|
|
692 |
if (viewer.getTable().getSortColumn() != leftContextColumn) {
|
|
693 |
viewer.getTable().setSortColumn(leftContextColumn);
|
|
694 |
viewer.getTable().setSortDirection(SWT.UP);
|
|
695 |
} else if (viewer.getTable().getSortDirection() == SWT.UP) {
|
|
696 |
viewer.getTable().setSortDirection(SWT.DOWN);
|
|
697 |
comparator = new ReverseComparator(comparator);
|
|
698 |
} else
|
|
699 |
viewer.getTable().setSortDirection(SWT.UP);
|
|
700 |
comparator.initialize(corpus);
|
|
701 |
currentComparator = comparator;
|
|
702 |
complexsorter.setKey(2);//set ref key
|
|
703 |
sort();
|
|
704 |
StatusLine.setMessage(""); //$NON-NLS-1$
|
|
705 |
}
|
|
706 |
|
|
707 |
@Override
|
|
708 |
public void widgetDefaultSelected(SelectionEvent e) {
|
|
709 |
}
|
|
710 |
});
|
|
711 |
|
|
712 |
keywordColumn = new TableColumn(viewer.getTable(), SWT.CENTER);
|
|
713 |
keywordColumn.setText(Messages.ConcordancesEditor_3);
|
|
714 |
keywordColumn.setToolTipText(Messages.ConcordancesEditor_3);
|
|
715 |
keywordColumn.setAlignment(SWT.CENTER);
|
|
716 |
keywordColumn.addSelectionListener(new SelectionListener() {
|
|
717 |
@Override
|
|
718 |
public void widgetSelected(SelectionEvent e) {
|
|
719 |
StatusLine.setMessage(Messages.ConcordancesEditor_45);
|
|
720 |
LineComparator comparator = new LexicographicKeywordComparator();
|
|
721 |
if (viewer.getTable().getSortColumn() != keywordColumn) {
|
|
722 |
viewer.getTable().setSortColumn(keywordColumn);
|
|
723 |
viewer.getTable().setSortDirection(SWT.UP);
|
|
724 |
} else if (viewer.getTable().getSortDirection() == SWT.UP) {
|
|
725 |
viewer.getTable().setSortDirection(SWT.DOWN);
|
|
726 |
comparator = new ReverseComparator(comparator);
|
|
727 |
} else
|
|
728 |
viewer.getTable().setSortDirection(SWT.UP);
|
|
729 |
comparator.initialize(corpus);
|
|
730 |
currentComparator = comparator;
|
|
731 |
complexsorter.setKey(1);//set ref key
|
|
732 |
sort();
|
|
733 |
StatusLine.setMessage(""); //$NON-NLS-1$
|
|
734 |
}
|
|
735 |
|
|
736 |
@Override
|
|
737 |
public void widgetDefaultSelected(SelectionEvent e) {
|
|
738 |
}
|
|
739 |
});
|
|
740 |
|
|
741 |
annotationColumn = new TableColumn(viewer.getTable(), SWT.CENTER);
|
|
742 |
annotationColumn.setText(Messages.ConcordancesEditor_15);
|
|
743 |
annotationColumn.setToolTipText(Messages.ConcordancesEditor_17);
|
|
744 |
annotationColumn.setAlignment(SWT.CENTER);
|
|
745 |
|
|
746 |
rightContextColumn = new TableColumn(viewer.getTable(), SWT.LEFT);
|
|
747 |
rightContextColumn.setText(Messages.ConcordancesEditor_4);
|
|
748 |
rightContextColumn.setToolTipText(Messages.ConcordancesEditor_4);
|
|
749 |
rightContextColumn.setAlignment(SWT.LEFT);
|
|
750 |
rightContextColumn.addSelectionListener(new SelectionListener() {
|
|
751 |
@Override
|
|
752 |
public void widgetSelected(SelectionEvent e) {
|
|
753 |
StatusLine.setMessage(Messages.ConcordancesEditor_48);
|
|
754 |
LineComparator comparator = new LexicographicRightContextComparator();
|
|
755 |
|
|
756 |
if (viewer.getTable().getSortColumn() != rightContextColumn) {
|
|
757 |
viewer.getTable().setSortColumn(rightContextColumn);
|
|
758 |
} else if (viewer.getTable().getSortDirection() == SWT.UP) {
|
|
759 |
viewer.getTable().setSortDirection(SWT.DOWN);
|
|
760 |
comparator = new ReverseComparator(comparator);
|
|
761 |
} else {
|
|
762 |
viewer.getTable().setSortDirection(SWT.UP);
|
|
763 |
}
|
|
764 |
comparator.initialize(corpus);
|
|
765 |
currentComparator = comparator;
|
|
766 |
complexsorter.setKey(3); //set ref key
|
|
767 |
sort();
|
|
768 |
StatusLine.setMessage(""); //$NON-NLS-1$
|
|
769 |
}
|
|
770 |
|
|
771 |
@Override
|
|
772 |
public void widgetDefaultSelected(SelectionEvent e) {
|
|
773 |
}
|
|
774 |
});
|
|
775 |
|
|
776 |
resetColumnWidths(); // set column widths
|
|
777 |
|
|
778 |
viewer.getTable().setLinesVisible(true);
|
|
779 |
viewer.getTable().setHeaderVisible(true);
|
|
780 |
|
|
781 |
createContextMenu();
|
|
782 |
|
|
783 |
// And now, a sweet piece of code :)
|
|
784 |
// When the window is resized, the scrollbar is adjusted so that the
|
|
785 |
// keywords remain centered
|
|
786 |
viewer.getTable().addListener(SWT.Resize, new Listener() {
|
|
787 |
@Override
|
|
788 |
public void handleEvent(Event event) {
|
|
789 |
ScrollBar bar = viewer.getTable().getHorizontalBar();
|
|
790 |
//float l = leftContextColumn.getWidth();
|
|
791 |
//float k = keywordColumn.getWidth();
|
|
792 |
rightContextColumn.getWidth();
|
|
793 |
//float t = lineTableViewer.getTable().getClientArea().width;
|
|
794 |
bar.getMaximum();
|
|
795 |
bar.getThumb();
|
|
796 |
}
|
|
797 |
});
|
|
798 |
|
|
799 |
// back to text mouse listener
|
|
800 |
viewer.getTable().addMouseListener(new MouseListener() {
|
|
801 |
@Override
|
|
802 |
public void mouseDoubleClick(MouseEvent e) {
|
|
803 |
StatusLine.setMessage(Messages.ConcordancesEditor_50);
|
|
804 |
backToText();
|
|
805 |
StatusLine.setMessage(""); //$NON-NLS-1$
|
|
806 |
}
|
|
807 |
|
|
808 |
@Override
|
|
809 |
public void mouseDown(MouseEvent e) { }
|
|
810 |
@Override
|
|
811 |
public void mouseUp(MouseEvent e) { }
|
|
812 |
});
|
|
813 |
|
|
814 |
// On Windows, the selection is gray if the table does not have focus.
|
|
815 |
// To make both tables appear in focus, draw the selection background
|
|
816 |
// here.
|
|
817 |
// This part only works on version 3.2 or later.
|
|
818 |
Listener eraseListener = new Listener() {
|
|
819 |
@Override
|
|
820 |
public void handleEvent(Event event) {
|
|
821 |
event.detail &= ~SWT.HOT;
|
|
822 |
if ((event.detail & SWT.SELECTED) != 0) {
|
|
823 |
GC gc = event.gc;
|
|
824 |
Rectangle rect = event.getBounds();
|
|
825 |
gc.setForeground(displayArea.getDisplay().getSystemColor(
|
|
826 |
SWT.COLOR_LIST_SELECTION_TEXT));
|
|
827 |
gc.setBackground(displayArea.getDisplay().getSystemColor(
|
|
828 |
SWT.COLOR_LIST_SELECTION));
|
|
829 |
gc.fillRectangle(rect);
|
|
830 |
event.detail &= ~SWT.SELECTED;
|
|
831 |
}
|
|
832 |
}
|
|
833 |
};
|
|
834 |
|
|
835 |
// Listeners to avoid 0 width clumns
|
|
836 |
referenceColumn.addControlListener(new ControlListener() {
|
|
837 |
@Override
|
|
838 |
public void controlMoved(ControlEvent e) { }
|
|
839 |
@Override
|
|
840 |
public void controlResized(ControlEvent e) {
|
|
841 |
if (referenceColumn.getWidth() < 5) referenceColumn.setWidth(5);
|
|
842 |
|
|
843 |
}
|
|
844 |
});
|
|
845 |
leftContextColumn.addControlListener(new ControlListener() {
|
|
846 |
@Override
|
|
847 |
public void controlMoved(ControlEvent e) { }
|
|
848 |
@Override
|
|
849 |
public void controlResized(ControlEvent e) {
|
|
850 |
if (leftContextColumn.getWidth() < 5) leftContextColumn.setWidth(5);
|
|
851 |
|
|
852 |
}
|
|
853 |
});
|
|
854 |
keywordColumn.addControlListener(new ControlListener() {
|
|
855 |
@Override
|
|
856 |
public void controlMoved(ControlEvent e) { }
|
|
857 |
@Override
|
|
858 |
public void controlResized(ControlEvent e) {
|
|
859 |
if (keywordColumn.getWidth() < 5) keywordColumn.setWidth(5);
|
|
860 |
|
|
861 |
}
|
|
862 |
});
|
|
863 |
annotationColumn.addControlListener(new ControlListener() {
|
|
864 |
@Override
|
|
865 |
public void controlMoved(ControlEvent e) { }
|
|
866 |
@Override
|
|
867 |
public void controlResized(ControlEvent e) {
|
|
868 |
if (annotationArea != null && annotationColumn.getWidth() < 5) annotationColumn.setWidth(5);
|
|
869 |
|
|
870 |
}
|
|
871 |
});
|
|
872 |
rightContextColumn.addControlListener(new ControlListener() {
|
|
873 |
@Override
|
|
874 |
public void controlMoved(ControlEvent e) { }
|
|
875 |
@Override
|
|
876 |
public void controlResized(ControlEvent e) {
|
|
877 |
if (rightContextColumn.getWidth() < 5) rightContextColumn.setWidth(5);
|
|
878 |
|
|
879 |
}
|
|
880 |
});
|
|
881 |
|
|
882 |
viewer.getTable().addListener(SWT.EraseItem, eraseListener);
|
|
883 |
|
|
884 |
// tableLayout.setColumnData(firstColumn, new ColumnWeightData(0, false));
|
|
885 |
// tableLayout.setColumnData(referenceColumn, new ColumnWeightData(1, true));
|
|
886 |
// tableLayout.setColumnData(keywordColumn, new ColumnWeightData(1, true));
|
|
887 |
// tableLayout.setColumnData(leftContextColumn, new ColumnWeightData(1, true));
|
|
888 |
// tableLayout.setColumnData(annotationColumn, new ColumnWeightData(0, true));
|
|
889 |
// tableLayout.setColumnData(rightContextColumn, new ColumnWeightData(1, true));
|
|
890 |
}
|
|
891 |
|
|
892 |
/**
|
|
893 |
* Sort.
|
|
894 |
*/
|
|
895 |
public void sort() {
|
|
896 |
if (concordance != null && currentComparator != null) {
|
|
897 |
|
|
898 |
//System.out.println("concordance sort props: "+concordance.getLeftCAnalysisProperty()+", "+concordance.getKeywordAnalysisProperty()+", "+concordance.getRightCAnalysisProperty());
|
|
899 |
concordance.setLeftAnalysisProperties(selectedLeftSortProperties);
|
|
900 |
concordance.setKeywordAnalysisProperties(selectedKeywordSortProperties);
|
|
901 |
concordance.setRightAnalysisProperties(selectedRightSortProperties);
|
|
902 |
|
|
903 |
try {
|
|
904 |
Log.info(NLS.bind(CooccurrenceUIMessages.CooccurrencesEditor_0, currentComparator.getName()));
|
|
905 |
if (currentComparator instanceof CompositeComparator)
|
|
906 |
Log.info(((CompositeComparator) currentComparator).getComparators().toString());
|
|
907 |
JobHandler jobhandler = new JobHandler("Sorting...") { //$NON-NLS-1$
|
|
908 |
@Override
|
|
909 |
protected IStatus run(IProgressMonitor monitor) {
|
|
910 |
this.runInit(monitor);
|
|
911 |
JobsTimer.start();
|
|
912 |
try {
|
|
913 |
monitor.beginTask(Messages.ConcordancesEditor_6, concordance.getNLines());
|
|
914 |
concordance.setCurrentMonitor(this);
|
|
915 |
concordance.sort(currentComparator);
|
|
916 |
concordance.setCurrentMonitor(null);
|
|
917 |
syncExec(new Runnable() {
|
|
918 |
@Override
|
|
919 |
public void run() {
|
|
920 |
StatusLine.setMessage(Messages.SORT_DONE);
|
|
921 |
fillDisplayArea(topLine, topLine + nLinePerPage - 1);
|
|
922 |
}
|
|
923 |
});
|
|
924 |
|
|
925 |
} catch (ThreadDeath td) {
|
|
926 |
return Status.CANCEL_STATUS;
|
|
927 |
} catch (Exception e) {
|
|
928 |
System.err.println(NLS.bind(Messages.ERROR_WHILE_LOADING_CONCORDANCE_LINE, e));
|
|
929 |
org.txm.rcp.utils.Logger.printStackTrace(e);
|
|
930 |
} finally {
|
|
931 |
monitor.done();
|
|
932 |
JobsTimer.stopAndPrint();
|
|
933 |
}
|
|
934 |
return Status.OK_STATUS;
|
|
935 |
}
|
|
936 |
};
|
|
937 |
|
|
938 |
jobhandler.startJob();
|
|
939 |
} catch (Exception e) {
|
|
940 |
System.err.println(NLS.bind(Messages.ERROR_WHILE_LOADING_CONCORDANCE_LINE, e));
|
|
941 |
org.txm.rcp.utils.Logger.printStackTrace(e);
|
|
942 |
}
|
|
943 |
}
|
|
944 |
}
|
|
945 |
|
|
946 |
/**
|
|
947 |
* Lazy loads the concordance lines range and fills the display area.
|
|
948 |
*
|
|
949 |
* @param from the from
|
|
950 |
* @param to the to
|
|
951 |
*/
|
|
952 |
public void fillDisplayArea(int from, int to) {
|
|
953 |
if (viewer == null)
|
|
954 |
return;
|
|
955 |
|
|
956 |
viewer.getControl().setRedraw(false);
|
|
957 |
|
|
958 |
from = Math.max(from, 0);
|
|
959 |
to = Math.min(to, concordance.getNLines() - 1);
|
|
960 |
List<Line> lines = null;
|
|
961 |
if (concordance.getNLines() > 0) {
|
|
962 |
try {
|
|
963 |
lines = concordance.getLines(from, to);
|
|
964 |
} catch (Exception e) {
|
|
965 |
System.err.println(Messages.ERROR_WHILE_LOADING_CONCORDANCE_LINE+ e);
|
|
966 |
org.txm.rcp.utils.Logger.printStackTrace(e);
|
|
967 |
}
|
|
968 |
} else
|
|
969 |
lines = new ArrayList<Line>();
|
|
970 |
|
|
971 |
viewer.setInput(lines);
|
|
972 |
referenceColumn.pack();
|
|
973 |
leftContextColumn.pack();
|
|
974 |
keywordColumn.pack();
|