Revision 517

tmp/org.txm.concordance.rcp/src/org/txm/concordance/rcp/widgets/ComplexSortSelector.java (revision 517)
228 228
		fourthKey.select(0);
229 229
		editor.getUserDefinedComparators().add(defaultComparator);
230 230
		editor.setCurrentComparator(defaultComparator);
231
		editor.sort();
231
//		editor.sort(); // do it later 
232 232
	}
233 233
}
tmp/org.txm.concordance.rcp/src/org/txm/concordance/rcp/editors/ConcordanceEditorButton.java (revision 517)
1
package org.txm.concordance.rcp.editors;
2

  
3
import org.eclipse.swt.SWT;
4
import org.eclipse.swt.widgets.Button;
5

  
6
/**
7
 * Extension point class to add a column to the concordance result.
8
 * 
9
 * You need to :
10
 * - define the ColumnLabelProvider methods
11
 * - set a Comparator called by the ColumnSorter
12
 * 
13
 * @author mdecorde
14
 *
15
 */
16
public abstract class ConcordanceEditorButton extends Button {
17
	
18
	protected ConcordanceEditor editor;
19
	
20
	public ConcordanceEditorButton(ConcordanceEditor editor) {
21
		super(editor.getExtensionButtonComposite(), SWT.PUSH);
22
		this.editor = editor;
23
	}
24

  
25
	/**
26
	 * 
27
	 * @return the column name displayed in the concordance table widget
28
	 */
29
	public abstract String getName();
30
	
31
	public abstract boolean install();
32
}
tmp/org.txm.concordance.rcp/src/org/txm/concordance/rcp/editors/ConcordanceEditorExtension.java (revision 517)
1
package org.txm.concordance.rcp.editors;
2

  
3

  
4

  
5
/**
6
 * Extension point class to add a stuff to the concordance editor.
7
 * 
8
 * All widgets creation are done after the editor widgets creation
9
 * 
10
 * @author mdecorde
11
 *
12
 */
13
public abstract class ConcordanceEditorExtension {
14
	
15
	public static final String EXTENSION_ID = ConcordanceEditorExtension.class.getName();
16
	protected ConcordanceEditor editor;
17
	
18
	public ConcordanceEditorExtension() {
19
		
20
	}
21

  
22
	/**
23
	 * 
24
	 * @return the column name displayed in the concordance table widget
25
	 */
26
	public abstract String getName();
27
	
28
	/**
29
	 * implement this command to add widgets to the concordance interface using the 2 available area : editor.getQueryArea() and editor.getDisplayArea()
30
	 * @return
31
	 */
32
	public abstract boolean installWidgets() throws Exception;
33
	
34
	/**
35
	 * implement this command to do something when the EditorPart.init(IEditorSite site, IEditorInput input) is called
36
	 * @return
37
	 */
38
	public abstract boolean initialiseInput(ConcordanceEditor editor) throws Exception;
39
	
40
	/**
41
	 * implement this command to do set something before computing the result
42
	 * @return
43
	 */
44
	public abstract boolean notifyStartOfCompute() throws Exception;
45
	
46
	/**
47
	 * implement this command to do set something after computing the result
48
	 * @return
49
	 */
50
	public abstract boolean notifyEndOfCompute() throws Exception;
51
}
0 52

  
tmp/org.txm.concordance.rcp/src/org/txm/concordance/rcp/editors/LineLabelProvider.java (revision 517)
30 30
import org.eclipse.jface.viewers.ILabelProviderListener;
31 31
import org.eclipse.jface.viewers.ITableLabelProvider;
32 32
import org.eclipse.swt.graphics.Image;
33
import org.txm.annotation.core.Annotation;
34
import org.txm.concordance.core.functions.Line;
35
import org.txm.rcp.RCPMessages;
36 33

  
37 34
// TODO: Auto-generated Javadoc
38 35
/**
......
40 37
 * 
41 38
 * @author mdecorde.
42 39
 */
43
public class LineLabelProvider implements ITableLabelProvider {
40
public abstract class LineLabelProvider implements ITableLabelProvider {
44 41

  
45 42
	private ConcordanceEditor editor;
46 43

  
......
60 57
	 * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang.Object, int)
61 58
	 */
62 59
	@Override
63
	public String getColumnText(Object element, int columnIndex) {
64
		Line line = (Line) element;
60
	public abstract String getColumnText(Object element, int columnIndex);
65 61

  
66
		switch (columnIndex) {
67
		case 0:
68
		case 6:
69
			return ""; //this is the fake column used to work around the fact that MS windows refuses to right align the 1st column  //$NON-NLS-1$
70
//		case 1: // moved to the left table
71
//			return line.getViewRef().toString();
72
		case 1:
73
			return line.leftContextToString();
74
		case 2:
75
			return line.keywordToString();
76
		case 3:
77
			if (line.getAnnotation()!=null) {
78
				String value = line.getAnnotationValue().getStandardName();
79
				Annotation a = line.getAnnotation();
80
				if (value == null) value = a.getValue();
81
								
82
				if (a.getStart() < line.matchGetStart() - line.getLeftContextSize()) {
83
					value = "… "+value;
84
				}
85
				
86
				if (a.getEnd() > line.matchGetEnd() + line.getRightContextSize()) {
87
					value = value+" …";
88
				} 
89
				return value;
90
			} else {
91
				return "";
92
			}
93
		case 4:
94
			return line.rightContextToString();
95
		default:
96
			throw new RuntimeException(RCPMessages.LineLabelProvider_1);
97
		}
98

  
99
	}
100

  
101 62
	/* (non-Javadoc)
102 63
	 * @see org.eclipse.jface.viewers.IBaseLabelProvider#addListener(org.eclipse.jface.viewers.ILabelProviderListener)
103 64
	 */
tmp/org.txm.concordance.rcp/src/org/txm/concordance/rcp/editors/ConcordanceEditor.java (revision 517)
25 25
//
26 26
package org.txm.concordance.rcp.editors;
27 27

  
28
import java.io.File;
29 28
import java.util.ArrayList;
30
import java.util.HashMap;
29
import java.util.Arrays;
30
import java.util.HashSet;
31 31
import java.util.Iterator;
32 32
import java.util.List;
33
import java.util.Vector;
34
import java.util.logging.Level;
35 33

  
36 34
import org.eclipse.core.runtime.CoreException;
37 35
import org.eclipse.core.runtime.IConfigurationElement;
38 36
import org.eclipse.core.runtime.IProgressMonitor;
37
import org.eclipse.core.runtime.ISafeRunnable;
39 38
import org.eclipse.core.runtime.IStatus;
40 39
import org.eclipse.core.runtime.Platform;
40
import org.eclipse.core.runtime.SafeRunner;
41 41
import org.eclipse.core.runtime.Status;
42 42
import org.eclipse.e4.ui.workbench.modeling.EModelService;
43 43
import org.eclipse.jface.action.Action;
......
45 45
import org.eclipse.jface.action.IMenuManager;
46 46
import org.eclipse.jface.action.MenuManager;
47 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;
48
import org.eclipse.jface.viewers.ColumnLabelProvider;
56 49
import org.eclipse.jface.viewers.StructuredSelection;
57 50
import org.eclipse.jface.viewers.TableViewer;
51
import org.eclipse.jface.viewers.TableViewerColumn;
58 52
import org.eclipse.osgi.util.NLS;
59 53
import org.eclipse.swt.SWT;
60 54
import org.eclipse.swt.browser.ProgressListener;
......
79 73
import org.eclipse.swt.layout.GridData;
80 74
import org.eclipse.swt.layout.GridLayout;
81 75
import org.eclipse.swt.widgets.Button;
82
import org.eclipse.swt.widgets.Combo;
83 76
import org.eclipse.swt.widgets.Composite;
84 77
import org.eclipse.swt.widgets.Display;
85 78
import org.eclipse.swt.widgets.Event;
......
90 83
import org.eclipse.swt.widgets.ScrollBar;
91 84
import org.eclipse.swt.widgets.Table;
92 85
import org.eclipse.swt.widgets.TableColumn;
93
import org.eclipse.swt.widgets.Text;
86
import org.eclipse.swt.widgets.TableItem;
94 87
import org.eclipse.ui.IEditorInput;
95 88
import org.eclipse.ui.IEditorSite;
96 89
import org.eclipse.ui.IWorkbenchPage;
97 90
import org.eclipse.ui.IWorkbenchPartSite;
98
import org.eclipse.ui.IWorkbenchWindow;
99 91
import org.eclipse.ui.PartInitException;
100
import org.eclipse.ui.dialogs.ListDialog;
101
import org.txm.annotation.core.Annotation;
102
import org.txm.annotation.core.AnnotationManager;
103
import org.txm.annotation.core.KRAnnotationEngine;
104
import org.txm.annotation.core.preferences.AnnotationPreferences;
105
import org.txm.annotation.core.repository.AnnotationType;
106
import org.txm.annotation.core.repository.KnowledgeRepository;
107
import org.txm.annotation.core.repository.KnowledgeRepositoryManager;
108
import org.txm.annotation.core.repository.LocalKnowledgeRepository;
109
import org.txm.annotation.core.repository.SQLKnowledgeRepository;
110
import org.txm.annotation.core.repository.TypedValue;
111
import org.txm.annotation.rcp.commands.InitializeKnowledgeRepository;
112
import org.txm.annotation.rcp.commands.SaveAnnotations;
113
import org.txm.annotation.rcp.commands.krview.OpenKRView;
114
import org.txm.annotation.rcp.views.knowledgerepositories.KRView;
115 92
import org.txm.concordance.core.functions.Concordance;
116 93
import org.txm.concordance.core.functions.Line;
117 94
import org.txm.concordance.core.functions.comparators.CompositeComparator;
......
145 122
import org.txm.rcp.RCPMessages;
146 123
import org.txm.rcp.StatusLine;
147 124
import org.txm.rcp.TXMWindows;
148
import org.txm.rcp.commands.OpenBrowser;
149 125
import org.txm.rcp.editors.TXMBrowser;
150 126
import org.txm.rcp.editors.TXMEditorPart;
151 127
import org.txm.rcp.editors.TXMResultEditorInput;
152 128
import org.txm.rcp.editors.TableKeyListener;
153 129
import org.txm.rcp.preferences.RCPPreferences;
154
import org.txm.rcp.swt.dialog.ConfirmDialog;
155 130
import org.txm.rcp.swt.dialog.ViewPropertySelectionDialog;
156
import org.txm.rcp.swt.provider.SimpleLabelProvider;
157 131
import org.txm.rcp.swt.widget.AssistedQueryWidget;
158 132
import org.txm.rcp.swt.widget.NavigationWidget;
159 133
import org.txm.rcp.utils.JobHandler;
......
166 140
import org.txm.searchengine.cqp.corpus.Corpus;
167 141
import org.txm.searchengine.cqp.corpus.Property;
168 142
import org.txm.searchengine.cqp.corpus.StructuralUnitProperty;
169
import org.txm.searchengine.cqp.corpus.query.Match;
170 143
import org.txm.searchengine.cqp.corpus.query.Query;
171
import org.txm.utils.AsciiUtils;
172 144
import org.txm.utils.logger.Log;
173 145

  
174 146
/**
......
180 152

  
181 153
	public static final String ID = ConcordanceEditor.class.getName();
182 154

  
183
	/**
184
	 * the limit number of annotation when a confirm dialog box is shown
185
	 */
186
	private static final int NALERTAFFECTANNOTATIONS = 100;
187

  
188 155
	String locale = TXMPreferences.getString(RCPPreferences.UI_LOCALE, RCPPreferences.PREFERENCES_NODE);
189 156

  
190 157
	/** The lineids. */
......
230 197
	/** The concordance. */
231 198
	private Concordance concordance;
232 199

  
233
	/** The annotation service */
234
	private AnnotationManager  annotManager;
235 200

  
236
	//boolean annotation_expert_mode = TxmPreferences.getBoolean(AnnotationPreferencePage.MODE, false);
237

  
238 201
	/** The standard comparator class name. */
239 202
	private LineComparator[] standardComparatorClassName = {
240 203
			new NullComparator(), new LexicographicKeywordComparator(),
......
324 287
	/** The query area. */
325 288
	private Composite queryArea;
326 289

  
327
	/** The annotation area. */
328
	private Composite annotationArea;
329

  
330 290
	/** The navigation area. */
331
	private NavigationWidget navigationArea;
291
	private NavigationWidget navigationWidget;
332 292

  
333 293
	/** The is setup shown. */
334 294
	private boolean isSetupShown = true;
335 295

  
336

  
337
	/** The hide btn. */
296
	/** The hide btn: hides the form
297
	 * TODO: remove the button when the TXMEditorToolbar is fully functionnal. */
338 298
	private Button hideBtn;
339 299
	private Button deleteLineButton;
340 300

  
341 301
	/** The query size. */
342 302
	protected Point querySize;
343 303

  
344
	protected Point annotationSize;
345

  
346
	/** The annot btn. */
347
	private Button annotationButton;
348

  
349
	private Text annotationValuesText;
350
	private ComboViewer annotationTypesCombo;
351

  
352 304
	/** The parent. */
353 305
	private Composite parent;
354 306

  
......
356 308

  
357 309
	private ArrayList<Property> availableRightSortProperties;
358 310

  
359
	private List<TypedValue> typeValuesList;
360

  
361
	protected Point annotSize;
362

  
363
	private TableColumn annotationColumn;
364

  
365
	private Combo addRemoveCombo;
366
	private Combo affectCombo;
367
	private Button affectAnnotationButton;
368

  
369
	private Button infosAnnotTypeSelectedLink;
370

  
371 311
	private Sash sash;
312
	
313
	HashSet<ConcordanceEditorExtension> extensions = new HashSet<ConcordanceEditorExtension>();
372 314

  
373 315
	/* (non-Javadoc)
374 316
	 * @see org.eclipse.ui.part.EditorPart#doSave(org.eclipse.core.runtime.IProgressMonitor)
......
414 356
			throws PartInitException {
415 357
		setSite(site);
416 358
		setInput(input);
417

  
359
		
418 360
		initializeEditor();
361
		
362
		// fetch extensions
363
		IConfigurationElement[] config = Platform.getExtensionRegistry()
364
				.getConfigurationElementsFor(ConcordanceEditorExtension.EXTENSION_ID);
365
		Log.warning("Installing ConcordanceEditorExtension...");
366
		Log.warning(Arrays.toString(config));
367
		
368
		for (IConfigurationElement e : config) {
369
			try {
370
				Log.warning(" "+e.getName()+" from "+e.getContributor().getName());
371
				final Object o = e.createExecutableExtension("class"); //$NON-NLS-1$
372
				if (o instanceof ConcordanceEditorExtension) {
373
					ISafeRunnable runnable = new ISafeRunnable() {
374

  
375
						@Override
376
						public void handleException(Throwable exception) {
377
							System.out.println("Error while installing: "+o+": "+ exception.getLocalizedMessage());
378
						}
379

  
380
						@Override
381
						public void run() throws Exception {
382
							ConcordanceEditorExtension ext = ((ConcordanceEditorExtension) o);
383
							if (ext.initialiseInput(ConcordanceEditor.this)) {
384
								extensions.add(ext);
385
							}
386
						}
387
					};
388
					SafeRunner.run(runnable);
389
				}
390
			} catch (Exception ex) {
391
				System.out.println("Exception while installing "+e.getName()+": "+ex.getLocalizedMessage());
392
			}
393
		}
419 394
	}
420 395

  
421 396
	private void initializeEditor() throws PartInitException {
......
427 402
		}
428 403
		this.concordance = (Concordance)result;
429 404
		this.corpus = concordance.getCorpus();
430
		this.annotManager = KRAnnotationEngine.getAnnotationManager(corpus);
431 405

  
432 406
		this.standardComparators = new ArrayList<LineComparator>();
433 407
		this.userDefinedComparators = new ArrayList<LineComparator>();
......
484 458
		try {
485 459
			composeControlArea(controlArea);
486 460
			composeDisplayArea(getDisplayArea());
461
			composeExtraAreas(controlArea, getDisplayArea());
462
			// finally set the sorter to fill the tables
463
			if (complexsorter != null) {
464
				complexsorter.setComparators(this);
465
			}
466
			
467
			fillDisplayArea(topLine, bottomLine); // init columns and show first results if any
468
			resetColumnWidths();
469
			
487 470
		} catch(Exception e) {
488 471
			System.out.println("Error while building interface: "+e.getLocalizedMessage());
489 472
			Log.printStackTrace(e);
490 473
		}
491 474
	}
492 475

  
476
	private void composeExtraAreas(Composite controlArea, Composite displayArea) {
477
		
478
		for (final ConcordanceEditorExtension ext : extensions) {
479
			ISafeRunnable runnable = new ISafeRunnable() {
480
				@Override
481
				public void handleException(Throwable exception) {
482
					System.out.println("Error while installing: "+ext+": "+ exception.getLocalizedMessage());
483
				}
484

  
485
				@Override
486
				public void run() throws Exception {
487
					if (!ext.installWidgets()) {
488
						extensions.remove(ext);
489
					}
490
				}
491
			};
492
			SafeRunner.run(runnable);
493
		}
494
	}
495

  
493 496
	/**
494 497
	 * Compose display area.
495 498
	 *
......
504 507
		viewer2.setLabelProvider(new LineLabelProvider(this) {
505 508
			@Override
506 509
			public String getColumnText(Object element, int columnIndex) {
507
				if (columnIndex == 1) {
508 510
					Line line = (Line) element;
509 511
					return line.getViewRef().toString();
510
				} else {
511
					return "";
512
				}
513 512
			}
514 513
		});
515 514
		viewer2.setContentProvider(new ConcordancesProvider());
516 515
		viewer2.getTable().setLinesVisible(true);
517 516
		viewer2.getTable().setHeaderVisible(true);
518 517

  
519
		firstColumn = new TableColumn(viewer2.getTable(), SWT.LEFT);
520
		firstColumn.setWidth(0);
518
//		firstColumn = new TableColumn(viewer2.getTable(), SWT.LEFT);
519
//		firstColumn.setWidth(10);
521 520

  
522 521
		referenceColumn = new TableColumn(viewer2.getTable(), SWT.LEFT);
523 522
		refreshReferenceColumnTitle();
......
549 548
			}
550 549
		});
551 550
		referenceColumn.setWidth(100);
552
		
553
		firstColumn = new TableColumn(viewer2.getTable(), SWT.LEFT);
554
		firstColumn.setWidth(0);
555
		
551
				
556 552
		sash = new Sash(displayArea, SWT.VERTICAL);
557 553
		sash.addSelectionListener(new SelectionAdapter() {
558 554
		      public void widgetSelected(SelectionEvent event) {
......
562 558
		    });
563 559
		viewer = new TableViewer(displayArea, SWT.MULTI | SWT.FULL_SELECTION | SWT.BORDER | SWT.VIRTUAL);
564 560
		viewer.getTable().addKeyListener(new TableKeyListener(viewer));
565
		viewer.setLabelProvider(new LineLabelProvider(this));
561
		//viewer.setLabelProvider(new LineLabelProvider(this));
566 562
		viewer.setContentProvider(new ConcordancesProvider());
567 563
		viewer.getTable().setLinesVisible(true);
568 564
		viewer.getTable().setHeaderVisible(true);
......
575 571
			viewer2.getTable().setFont(font);
576 572
		}
577 573

  
574
		// try to center on keyword column
578 575
		viewer.getTable().addListener(SWT.Resize, new Listener() {
579 576
			@Override
580 577
			public void handleEvent(Event event) {
......
603 600
		viewer.getTable().addKeyListener(kldelete);
604 601
		viewer2.getTable().addKeyListener(kldelete);
605 602

  
606
		firstColumn = new TableColumn(viewer.getTable(), SWT.LEFT);
607
		firstColumn.setWidth(0);
603
//		firstColumn = new TableColumn(viewer.getTable(), SWT.LEFT);
604
//		firstColumn.setWidth(0);
605
//		firstColumn.setResizable(false);
608 606

  
609
		leftContextColumn = new TableColumn(viewer.getTable(), SWT.RIGHT);
607
		TableViewerColumn leftColumnViewer = new TableViewerColumn(viewer, SWT.RIGHT);
608
		leftContextColumn = leftColumnViewer.getColumn();
610 609
		leftContextColumn.setText(Messages.ConcordancesEditor_2);
611 610
		leftContextColumn.setToolTipText(Messages.ConcordancesEditor_2);
612 611
		leftContextColumn.setAlignment(SWT.RIGHT);
612
		leftColumnViewer.setLabelProvider(new ColumnLabelProvider() {
613
			@Override
614
			public String getText(Object element) {
615
				Line line = (Line) element;
616
				return line.leftContextToString();
617
			}
618
		});
613 619
		leftContextColumn.addSelectionListener(new SelectionListener() {
614 620
			@Override
615 621
			public void widgetSelected(SelectionEvent e) {
......
635 641
			}
636 642
		});
637 643

  
638
		keywordColumn = new TableColumn(viewer.getTable(), SWT.CENTER);
644
		TableViewerColumn keywordColumnViewer = new TableViewerColumn(viewer, SWT.CENTER);
645
		keywordColumn = keywordColumnViewer.getColumn();
639 646
		keywordColumn.setText(Messages.ConcordancesEditor_3);
640 647
		keywordColumn.setToolTipText(Messages.ConcordancesEditor_3);
641 648
		keywordColumn.setAlignment(SWT.CENTER);
649
		keywordColumnViewer.setLabelProvider(new ColumnLabelProvider() {
650
			@Override
651
			public String getText(Object element) {
652
				Line line = (Line) element;
653
				return line.keywordToString();
654
			}
655
		});
642 656
		keywordColumn.addSelectionListener(new SelectionListener() {
643 657
			@Override
644 658
			public void widgetSelected(SelectionEvent e) {
......
664 678
			}
665 679
		});
666 680

  
667
		annotationColumn = new TableColumn(viewer.getTable(), SWT.CENTER);
668
		annotationColumn.setText(Messages.ConcordancesEditor_15);
669
		annotationColumn.setToolTipText(Messages.ConcordancesEditor_17);
670
		annotationColumn.setAlignment(SWT.CENTER);
671

  
672
		rightContextColumn = new TableColumn(viewer.getTable(), SWT.LEFT);
681
		
682
		TableViewerColumn rightContextColumnViewer = new TableViewerColumn(viewer, SWT.LEFT);
683
		rightContextColumn = rightContextColumnViewer.getColumn();
673 684
		rightContextColumn.setText(Messages.ConcordancesEditor_4);
674 685
		rightContextColumn.setToolTipText(Messages.ConcordancesEditor_4);
675 686
		rightContextColumn.setAlignment(SWT.LEFT);
687
		rightContextColumnViewer.setLabelProvider(new ColumnLabelProvider() {
688
			@Override
689
			public String getText(Object element) {
690
				Line line = (Line) element;
691
				return line.rightContextToString();
692
			}
693
		});
676 694
		rightContextColumn.addSelectionListener(new SelectionListener() {
677 695
			@Override
678 696
			public void widgetSelected(SelectionEvent e) {
......
699 717
			}
700 718
		});
701 719

  
702
		resetColumnWidths(); // set column widths
720
//		firstColumn = new TableColumn(viewer.getTable(), SWT.LEFT);
721
//		firstColumn.setWidth(0);
722
//		firstColumn.setResizable(false);
723
		
724
		leftContextColumn.setWidth(200);
725
		keywordColumn.setWidth(100);
726
		rightContextColumn.setWidth(200);
727
		
728
		//resetColumnWidths(); // set column widths
703 729

  
704 730
		createContextMenu();
705 731

  
706
		// And now, a sweet piece of code :)
707
		// When the window is resized, the scrollbar is adjusted so that the
708
		// keywords remain centered
709
		viewer.getTable().addListener(SWT.Resize, new Listener() {
710
			@Override
711
			public void handleEvent(Event event) {
712
				ScrollBar bar = viewer.getTable().getHorizontalBar();
713
				//float l = leftContextColumn.getWidth();
714
				//float k = keywordColumn.getWidth();
715
				rightContextColumn.getWidth();
716
				//float t = lineTableViewer.getTable().getClientArea().width;
717
				bar.getMaximum();
718
				bar.getThumb();
719
			}
720
		});
732
//		// And now, a sweet piece of code :)
733
//		// When the window is resized, the scrollbar is adjusted so that the
734
//		// keywords remain centered
735
//		viewer.getTable().addListener(SWT.Resize, new Listener() {
736
//			@Override
737
//			public void handleEvent(Event event) {
738
//				ScrollBar bar = viewer.getTable().getHorizontalBar();
739
//				//float l = leftContextColumn.getWidth();
740
//				//float k = keywordColumn.getWidth();
741
//				rightContextColumn.getWidth();
742
//				//float t = lineTableViewer.getTable().getClientArea().width;
743
//				bar.getMaximum();
744
//				bar.getThumb();
745
//			}
746
//		});
721 747

  
722 748
		// back to text mouse listener
723
		viewer.getTable().addMouseListener(new MouseListener() {
749
		MouseListener ms = new MouseListener() {
724 750
			@Override
725 751
			public void mouseDoubleClick(MouseEvent e) {
726 752
				StatusLine.setMessage(Messages.ConcordancesEditor_50);
......
732 758
			public void mouseDown(MouseEvent e) { }
733 759
			@Override
734 760
			public void mouseUp(MouseEvent e) {	}
735
		});
736

  
761
		};
762
		viewer.getTable().addMouseListener(ms);
763
		viewer2.getTable().addMouseListener(ms);
764
		
737 765
		// On Windows, the selection is gray if the table does not have focus.
738 766
		// To make both tables appear in focus, draw the selection background
739 767
		// here.
......
756 784
		};
757 785

  
758 786
		// Listeners to avoid 0 width columns
759
		referenceColumn.addControlListener(new ControlListener() {
760
			@Override
761
			public void controlMoved(ControlEvent e) { }
762
			@Override
763
			public void controlResized(ControlEvent e) {
764
				if (referenceColumn.getWidth() < 5) referenceColumn.setWidth(5);
787
		referenceColumn.addControlListener(new ConcordanceColumnSizeControlListener(referenceColumn));
788
		leftContextColumn.addControlListener(new ConcordanceColumnSizeControlListener(leftContextColumn));
789
		keywordColumn.addControlListener(new ConcordanceColumnSizeControlListener(keywordColumn));
790
		rightContextColumn.addControlListener(new ConcordanceColumnSizeControlListener(rightContextColumn));
765 791

  
766
			}
767
		});
768
		leftContextColumn.addControlListener(new ControlListener() {
769
			@Override
770
			public void controlMoved(ControlEvent e) { }
771
			@Override
772
			public void controlResized(ControlEvent e) {
773
				if (leftContextColumn.getWidth() < 5) leftContextColumn.setWidth(5);
774

  
775
			}
776
		});
777
		keywordColumn.addControlListener(new ControlListener() {
778
			@Override
779
			public void controlMoved(ControlEvent e) { }
780
			@Override
781
			public void controlResized(ControlEvent e) {
782
				if (keywordColumn.getWidth() < 5) keywordColumn.setWidth(5);
783

  
784
			}
785
		});
786
		annotationColumn.addControlListener(new ControlListener() {
787
			@Override
788
			public void controlMoved(ControlEvent e) { }
789
			@Override
790
			public void controlResized(ControlEvent e) {
791
				if (annotationArea != null && annotationColumn.getWidth() < 5) annotationColumn.setWidth(5);
792

  
793
			}
794
		});
795
		rightContextColumn.addControlListener(new ControlListener() {
796
			@Override
797
			public void controlMoved(ControlEvent e) { }
798
			@Override
799
			public void controlResized(ControlEvent e) {
800
				if (rightContextColumn.getWidth() < 5) rightContextColumn.setWidth(5);
801

  
802
			}
803
		});
804

  
805 792
		viewer.getTable().addListener(SWT.EraseItem, eraseListener);
806 793
		
807 794
		leftTable = viewer2.getTable();
......
944 931

  
945 932
		viewer.setInput(lines);
946 933
		viewer2.setInput(lines);
947
//		referenceColumn.pack();
948
		leftContextColumn.pack();
949
		keywordColumn.pack();
950
		rightContextColumn.pack();
951
		viewer.getTable().pack(true);
952
		viewer.getTable().getParent().layout();
953
//		viewer2.getTable().pack(true);
954
		viewer2.getTable().getParent().layout();
955 934

  
956 935
		topLine = from;
957 936
		bottomLine = to;
958 937

  
959
		navigationArea.setInfoLineText(""+(from + 1), //$NON-NLS-1$
938
		navigationWidget.setInfoLineText(""+(from + 1), //$NON-NLS-1$
960 939
				" - "+(to + 1) + " / " + concordance.getNLines()); //$NON-NLS-1$ //$NON-NLS-2$
961 940

  
962
		navigationArea.setPreviousEnabled(topLine > 0);
963
		navigationArea.setFirstEnabled(topLine > 0);
964
		navigationArea.setNextEnabled(bottomLine < concordance.getNLines() - 1);
965
		navigationArea.setLastEnabled(bottomLine < concordance.getNLines() - 1);
966
		navigationArea.layout();
967
		navigationArea.getParent().layout();
941
		navigationWidget.setPreviousEnabled(topLine > 0);
942
		navigationWidget.setFirstEnabled(topLine > 0);
943
		navigationWidget.setNextEnabled(bottomLine < concordance.getNLines() - 1);
944
		navigationWidget.setLastEnabled(bottomLine < concordance.getNLines() - 1);
945
		navigationWidget.layout();
946
		navigationWidget.getParent().layout();
968 947

  
969 948
		refreshReferenceColumnTitle();
970 949

  
......
972 951
		viewer2.getControl().setRedraw(true);
973 952
	}
974 953

  
975
	HashMap<AnnotationType, ArrayList<TypedValue>> history = new HashMap<AnnotationType, ArrayList<TypedValue>>();
976 954

  
977
	private Button addAnnotationTypeLink;
978

  
979
	private KnowledgeRepository currentKnowledgeRepository = null;
980
	Vector<AnnotationType> typesList = new Vector<AnnotationType>(); 
981

  
982
	private Button addTypedValueLink;
983

  
984
	private Label withLabel;
985

  
986
	private AnnotationType tagAnnotationType; // the tag annotation type if annotation mode is simple
987

  
988
	private Label equalLabel;
989
	Boolean advanced_annotation_mode = false;
990

  
991 955
	private Table leftTable;
992 956

  
993 957
	private Table rightTable;
......
996 960

  
997 961
	private ScrollBar vBarRight;
998 962

  
999
	private void composeAnnotationArea(final Composite parent){ 
1000
		advanced_annotation_mode = "advanced".equals(TXMPreferences.getString(AnnotationPreferences.ANNOTATION_MODE, RCPPreferences.PREFERENCES_NODE));
963
	private Label queryLabel;
1001 964

  
1002
		List<KnowledgeRepository> krs = InitializeKnowledgeRepository.get(corpus.getMainCorpus());
1003
		typesList.clear();
1004
		Log.warning("Corpus KRs: "+krs); //$NON-NLS-1$
965
	private Composite navigationArea;
1005 966

  
1006
		for (KnowledgeRepository kr : krs) {
1007
			if (kr == null) continue;
1008

  
1009
			currentKnowledgeRepository = kr;
1010
			Log.warning(" KR: "+kr); //$NON-NLS-1$
1011
			List<AnnotationType> krtypes = kr.getAllAnnotationTypes();
1012
			Log.warning("Advanced annotation mode ? "+advanced_annotation_mode);
1013
			if (!advanced_annotation_mode) { // creates the "span" annotation type
1014
				boolean createTagAnnotationType = true;
1015
				for (AnnotationType type : krtypes) {
1016
					if (type.getName().equals("span")) { //$NON-NLS-1$
1017
						createTagAnnotationType = false;
1018
					}
1019
				}
1020
				if (createTagAnnotationType) {
1021
					tagAnnotationType = kr.addType("span", "span");//corresponds to an "undef" type //$NON-NLS-1$ //$NON-NLS-2$
1022
					typesList.add(tagAnnotationType);
1023
				} else {
1024
					tagAnnotationType = kr.getType("span"); //$NON-NLS-1$
1025
				}
1026
			} else {
1027
				typesList.addAll(krtypes);
1028
			}
1029
			Log.warning("Available annotation types: "+typesList);
1030
			break;
1031
		}
1032

  
1033
		if (currentKnowledgeRepository == null) {
1034
			System.out.println("Error: no suitable KnowledgeRepository found");
1035
			return;
1036
		}
1037

  
1038
		annotationArea = new Composite(parent, SWT.NONE);
1039
		annotationArea.setLayoutData(new GridData(SWT.FILL, SWT.LEFT, false, false));
1040

  
1041
		GridLayout annotLayout = new GridLayout(12, false);
1042
		annotLayout.verticalSpacing = 0;
1043
		annotLayout.marginWidth = 0;
1044
		annotLayout.marginHeight = 0;
1045
		annotationArea.setLayout(annotLayout);
1046

  
1047
		//init values history
1048
		for (AnnotationType type : typesList) {
1049
			history.put(type, new ArrayList<TypedValue>());
1050
		}
1051

  
1052
		addRemoveCombo = new Combo(annotationArea, SWT.READ_ONLY);
1053
		String affectLabel = currentKnowledgeRepository.getString(locale, "ConcordancesEditor_22");
1054
		if (affectLabel == null) affectLabel= Messages.ConcordancesEditor_22;
1055
		String removeLabel = currentKnowledgeRepository.getString(locale, "ConcordancesEditor_24");
1056
		if (removeLabel == null) removeLabel= Messages.ConcordancesEditor_24;
1057
		String items[] = {affectLabel, removeLabel};
1058
		addRemoveCombo.setItems(items);
1059
		addRemoveCombo.select(0);
1060
		addRemoveCombo.addSelectionListener(new SelectionListener() {
1061
			@Override
1062
			public void widgetSelected(SelectionEvent e) {
1063
				if (addRemoveCombo.getSelectionIndex() == 0) { // add
1064
					annotationValuesText.setEnabled(true);
1065
					String withLabelText = currentKnowledgeRepository.getString(locale, "ConcordancesEditor_83");
1066
					if (withLabelText == null) withLabelText= Messages.ConcordancesEditor_83;
1067
					withLabel.setText(withLabelText);
1068
					if (equalLabel != null) equalLabel.setText("=");
1069
				} else { // remove
1070
					annotationValuesText.setEnabled(false);
1071
					withLabel.setText(""); //$NON-NLS-1$
1072
					if (equalLabel != null) equalLabel.setText("");
1073
				}
1074
				withLabel.redraw();
1075
				annotationArea.layout();
1076
				updateAnnotationWidgetStates();
1077
			}
1078
			@Override
1079
			public void widgetDefaultSelected(SelectionEvent e) { }
1080
		});
1081
		GridData gdata = new GridData(SWT.CENTER, SWT.CENTER, false, true);
1082
		gdata.widthHint = 90;
1083
		addRemoveCombo.setLayoutData(gdata);
1084

  
1085
		withLabel = new Label(annotationArea, SWT.NONE);
1086
		String withLabelText = currentKnowledgeRepository.getString(locale, "ConcordancesEditor_83");
1087
		if (withLabelText == null) withLabelText= Messages.ConcordancesEditor_83;
1088
		withLabel.setText(withLabelText);
1089
		withLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
1090

  
1091
		if (advanced_annotation_mode) {
1092
			equalLabel = new Label(annotationArea, SWT.NONE);
1093
			equalLabel.setText("="); //$NON-NLS-1$
1094
			equalLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
1095
		}
1096

  
1097
		//Display combo with list of Annotation Type 
1098
		if (advanced_annotation_mode) {
1099
			annotationTypesCombo = new ComboViewer(annotationArea, SWT.READ_ONLY);
1100
			annotationTypesCombo.setContentProvider(new ArrayContentProvider());
1101
			annotationTypesCombo.setLabelProvider(new SimpleLabelProvider() {
1102
				@Override
1103
				public String getColumnText(Object element, int columnIndex) {
1104
					return ((AnnotationType)element).getName(); //$NON-NLS-1$
1105
				}
1106
				@Override
1107
				public String getText(Object element) {
1108
					return ((AnnotationType)element).getName(); //$NON-NLS-1$
1109
				}
1110
			});
1111
			gdata = new GridData(SWT.CENTER, SWT.CENTER, false, true);
1112
			gdata.widthHint = 200;
1113

  
1114
			annotationTypesCombo.getCombo().setLayoutData(gdata);
1115
			annotationTypesCombo.setInput(typesList);
1116
			if (advanced_annotation_mode.equals(RCPMessages.AnnotationPreferences_2)) {
1117
				annotationTypesCombo.getCombo().select(0);
1118
			}
1119

  
1120
			annotationTypesCombo.addSelectionChangedListener(new ISelectionChangedListener() {
1121
				@Override
1122
				public void selectionChanged(SelectionChangedEvent event) {
1123
					AnnotationType type = getSelectedAnnotationType();
1124
					if (type == null) return;
1125
					if (type.getSize() != AnnotationType.ValuesSize.LARGE) {
1126
						try {
1127
							KnowledgeRepository kr = KnowledgeRepositoryManager.getKnowledgeRepository(type.getKnowledgeRepository());
1128
							typeValuesList = kr.getValues(type);
1129
						} catch (Exception e) {
1130
							// TODO Auto-generated catch block
1131
							e.printStackTrace();
1132
						}
1133
					} else { // set history values
1134
						typeValuesList = history.get(type);
1135
					}
1136

  
1137
					annotationColumn.setText(type.getName());
1138
					if (concordance != null) {
1139
						concordance.setViewAnnotation(type);
1140
						concordance.setAnnotationOverlap(true);
1141
						fillDisplayArea(topLine, bottomLine);
1142
					}
1143

  
1144
					updateAnnotationWidgetStates();
1145
				}
1146
			});
1147
		}
1148

  
1149
		if (advanced_annotation_mode) {
1150
			if (currentKnowledgeRepository instanceof SQLKnowledgeRepository) {
1151
				infosAnnotTypeSelectedLink = new Button(annotationArea, SWT.PUSH);
1152
				infosAnnotTypeSelectedLink.setImage(IImageKeys.getImage(IImageKeys.ACTION_INFO));
1153
				infosAnnotTypeSelectedLink.setEnabled(true);
1154
				infosAnnotTypeSelectedLink.setLayoutData(new GridData(SWT.FILL,	SWT.CENTER, false, true));
1155
				infosAnnotTypeSelectedLink.addSelectionListener(new SelectionListener() {
1156
					@Override
1157
					public void widgetSelected(SelectionEvent e) {
1158
						AnnotationType type = getSelectedAnnotationType();
1159
						if (type == null) return;
1160

  
1161
						String typedValueURL = type.getURL(); // may be null/empty
1162
						if (typedValueURL != null && typedValueURL.length() > 0) {
1163
							KnowledgeRepository kr = KnowledgeRepositoryManager.getKnowledgeRepository(type.getKnowledgeRepository());
1164
							kr.getTypeURL(type);
1165
						}
1166
						if (typedValueURL != null && typedValueURL.length() > 0) {
1167
							OpenBrowser.openfile(typedValueURL, new File(typedValueURL).getName());
1168
						} else {
1169
							IWorkbenchWindow window = getSite().getWorkbenchWindow();
1170
							try {
1171
								OpenKRView.openView(window, type);
1172
							} catch (PartInitException e1) {
1173
								e1.printStackTrace();
1174
							}
1175
						}
1176
					}
1177

  
1178
					@Override
1179
					public void widgetDefaultSelected(SelectionEvent e) { }
1180
				});
1181
			}
1182

  
1183
			if (currentKnowledgeRepository instanceof LocalKnowledgeRepository) {
1184
				addAnnotationTypeLink = new Button(annotationArea, SWT.PUSH);
1185
				addAnnotationTypeLink.setToolTipText(Messages.ConcordancesEditor_115);
1186
				addAnnotationTypeLink.setImage(IImageKeys.getImage(IImageKeys.ACTION_ADD));
1187
				addAnnotationTypeLink.setEnabled(true);
1188
				addAnnotationTypeLink.setLayoutData(new GridData(SWT.FILL,	SWT.CENTER, false, true));
1189
				addAnnotationTypeLink.addSelectionListener(new SelectionListener() {
1190
					@Override
1191
					public void widgetSelected(SelectionEvent e) {
1192
						if (currentKnowledgeRepository == null) return;
1193
						if (!(currentKnowledgeRepository instanceof LocalKnowledgeRepository)) return;
1194

  
1195
						LocalKnowledgeRepository kr = (LocalKnowledgeRepository)currentKnowledgeRepository;
1196

  
1197
						InputDialog dialog = new InputDialog(e.widget.getDisplay().getActiveShell(), Messages.ConcordancesEditor_82, Messages.ConcordancesEditor_81, "", null); //$NON-NLS-3$
1198
						if (dialog.open() == InputDialog.OK) {
1199
							String name = dialog.getValue();
1200
							if (name.trim().length() == 0) return;
1201
							String baseid = AsciiUtils.buildId(name);
1202
							String id = AsciiUtils.buildId(name);
1203
							int c = 1;
1204
							while (kr.getType(id) != null) {
1205
								id = baseid+"_"+(c++); //$NON-NLS-1$
1206
							}
1207
							AnnotationType type = kr.addType(name, id, ""); //$NON-NLS-1$
1208
							typesList.add(type);
1209
							history.put(type, new ArrayList<TypedValue>());
1210

  
1211
							if (annotationTypesCombo != null) annotationTypesCombo.refresh();
1212
							if (typesList.size() == 1) {
1213
								if (annotationTypesCombo != null) annotationTypesCombo.getCombo().select(0);
1214
								if (concordance != null) {
1215
									concordance.setViewAnnotation(type);
1216
									concordance.setAnnotationOverlap(true);
1217
									fillDisplayArea(topLine, bottomLine);
1218
								}
1219
								annotationArea.layout(true);
1220
							}else {
1221
								if (typesList.size() > 1){
1222
									if (annotationTypesCombo != null) annotationTypesCombo.getCombo().select(typesList.size()-1);
1223

  
1224
								}
1225

  
1226
							}
1227
							KRView.refresh();
1228
							updateAnnotationWidgetStates();
1229
						} else {
1230
							System.out.println("Creation aborted."); //$NON-NLS-1$
1231
						}
1232
					}
1233

  
1234
					@Override
1235
					public void widgetDefaultSelected(SelectionEvent e) { }
1236
				});
1237
			}
1238
		}
1239
		if (advanced_annotation_mode) {
1240
			Label valueLabel = new Label(annotationArea, SWT.NONE);
1241
			String valueLabelText = currentKnowledgeRepository.getString(locale, "ConcordancesEditor_80");
1242
			if (valueLabelText == null) valueLabelText= Messages.ConcordancesEditor_80;
1243
			valueLabel.setText(valueLabelText);
1244
			valueLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
1245
		}
1246

  
1247
		annotationValuesText = new Text(annotationArea, SWT.BORDER);
1248
		annotationValuesText.setToolTipText(Messages.ConcordancesEditor_32);
1249
		GridData gdata2 = new GridData(SWT.FILL, SWT.CENTER, false, true);
1250
		gdata2.widthHint = 200;
1251
		annotationValuesText.setLayoutData(gdata2);
1252
		annotationValuesText.addKeyListener(new KeyListener() {
1253
			@Override
1254
			public void keyReleased(KeyEvent e) {
1255
				if (e.keyCode == SWT.CR || e.keyCode == SWT.KEYPAD_CR) {
1256
					affectAnnotationToSelection(viewer.getSelection());
1257
				}
1258
			}
1259

  
1260
			@Override
1261
			public void keyPressed(KeyEvent e) { }
1262
		});
1263

  
1264
		if (currentKnowledgeRepository instanceof LocalKnowledgeRepository) {
1265
			addTypedValueLink = new Button(annotationArea, SWT.PUSH);
1266
			addTypedValueLink.setText("..."); //$NON-NLS-1$
1267
			if (advanced_annotation_mode.equals(RCPMessages.AnnotationPreferences_2)) {
1268
				addTypedValueLink.setToolTipText(Messages.ConcordancesEditor_79);
1269
			}else {
1270
				addTypedValueLink.setToolTipText(Messages.ConcordancesEditor_77);
1271
			}
1272
			addTypedValueLink.setEnabled(true);
1273
			addTypedValueLink.setLayoutData(new GridData(SWT.FILL,	SWT.CENTER, false, true));
1274
			addTypedValueLink.addSelectionListener(new SelectionListener() {
1275
				@Override
1276
				public void widgetSelected(SelectionEvent e) {
1277
					if (currentKnowledgeRepository == null) return;
1278
					if (!(currentKnowledgeRepository instanceof LocalKnowledgeRepository)) return;
1279

  
1280
					AnnotationType type = getSelectedAnnotationType();
1281
					if (type == null) return;
1282

  
1283
					LocalKnowledgeRepository kr = (LocalKnowledgeRepository)currentKnowledgeRepository;
1284

  
1285
					ListDialog dialog = new ListDialog(e.widget.getDisplay().getActiveShell());
1286
					if (advanced_annotation_mode.equals(RCPMessages.AnnotationPreferences_2)) {
1287
						String title = currentKnowledgeRepository.getString(locale, "ConcordancesEditor_100");
1288
						if (title == null) title = Messages.ConcordancesEditor_100;
1289
						dialog.setTitle(Messages.bind(title, type.getName()));//+"valeurs de "+type.getName());
1290
					}else {
1291
						dialog.setTitle(Messages.ConcordancesEditor_99);//+"valeurs de "+type.getName());
1292
					}
1293
					dialog.setContentProvider(new ArrayContentProvider());
1294
					dialog.setLabelProvider(new SimpleLabelProvider() {
1295
						public String getColumnText(Object element, int columnIndex) {
1296
							if (element instanceof TypedValue)
1297
								return ((TypedValue)element).getId();
1298
							return element.toString();
1299
						}
1300
					});
1301
					List<TypedValue> values;
1302
					try {
1303
						values = kr.getValues(type);
1304
					} catch (Exception e1) {
1305
						e1.printStackTrace();
1306
						return;
1307
					}
1308
					dialog.setInput(values);
1309
					if (dialog.open() == InputDialog.OK) {
1310
						TypedValue value = (TypedValue) dialog.getResult()[0];
1311
						String name = value.getId();
1312
						if (name.trim().length() == 0) return;
1313

  
1314
						annotationValuesText.setText(name);
1315
					} else {
1316

  
1317
					}
1318
				}
1319

  
1320
				@Override
1321
				public void widgetDefaultSelected(SelectionEvent e) { }
1322
			});
1323
		}
1324

  
1325
		affectCombo = new Combo(annotationArea, SWT.READ_ONLY);
1326
		affectCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, true));
1327
		String items2[] = {Messages.ConcordancesEditor_35, Messages.ConcordancesEditor_42, Messages.ConcordancesEditor_49};
1328
		affectCombo.setItems(items2);
1329
		affectCombo.select(0);
1330
		gdata = new GridData(SWT.CENTER, SWT.CENTER, false, true);
1331
		gdata.widthHint = 140;
1332
		affectCombo.setLayoutData(gdata);
1333

  
1334
		affectAnnotationButton = new Button(annotationArea, SWT.PUSH);
1335
		affectAnnotationButton.setText(Messages.ConcordancesEditor_85);
1336
		affectAnnotationButton.setToolTipText(Messages.ConcordancesEditor_116);
1337
		affectAnnotationButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, true));
1338
		affectAnnotationButton.addSelectionListener(new SelectionListener() {
1339
			@Override
1340
			public void widgetSelected(SelectionEvent e) {
1341
				int isel = affectCombo.getSelectionIndex();
1342
				if (isel == 0) { // selected line
1343
					affectAnnotationToSelection(viewer.getSelection());
1344
				} else if (isel == 1) { // page
1345
					try {
1346
						List<Match> matches = concordance.getMatches().subList(topLine, bottomLine+1);
1347
						affectMatchesToSelection(matches);
1348
					} catch (CqiClientException e1) {
1349
						Log.severe(Messages.ConcordancesEditor_53+e1);
1350
						Log.printStackTrace(e1);
1351
						return;
1352
					}
1353
				} else { // all
1354
					try {
1355
						List<Match> matches = concordance.getMatches();
1356
						affectMatchesToSelection(matches);
1357
					} catch (CqiClientException e1) {
1358
						Log.severe(Messages.ConcordancesEditor_53+e1);
1359
						Log.printStackTrace(e1);
1360
						return;
1361
					}
1362
				}
1363
			}
1364

  
1365
			@Override
1366
			public void widgetDefaultSelected(SelectionEvent e) { }
1367
		});
1368
		Button cancelAnnotateButton = new Button(annotationArea, SWT.PUSH);
1369
		cancelAnnotateButton.setText(Messages.ConcordancesEditor_101);
1370
		cancelAnnotateButton.addSelectionListener(new SelectionListener() {
1371
			@Override
1372
			public void widgetSelected(SelectionEvent e) {
1373
				//@TODO Closing the annotation tool bar 
1374
				//System.out.println("must hide");
1375
				annotationSize = annotationArea.getSize();
1376
				annotationArea.dispose();
1377
				annotationArea = null;
1378
				parent.layout(true);
1379
				parent.layout();
1380
				annotationButton.setToolTipText(Messages.ConcordancesEditor_75);
1381
				annotationButton.setImage(IImageKeys.getImage(IImageKeys.PENCIL));
1382
				annotationColumn.setWidth(0);
1383
				annotationColumn.setResizable(false);
1384
			}
1385

  
1386
			@Override
1387
			public void widgetDefaultSelected(SelectionEvent e) { }
1388
		});
1389

  
1390

  
1391
		updateAnnotationWidgetStates();
1392
		
1393
		
1394

  
1395
		parent.layout();
967
	/**
968
	 * Get the Composite that contains the query and sort forms
969
	 * 
970
	 * GridLayout with 4 columns
971
	 * 
972
	 * @return
973
	 */
974
	public Composite getQueryArea() {
975
		return queryArea;
1396 976
	}
1397

  
1398
	protected void affectAnnotationToSelection(ISelection selection) {
1399

  
1400
		final IStructuredSelection lineSelection = (IStructuredSelection) selection;
1401
		List<Line> lines = lineSelection.toList();
1402
		ArrayList<Match> matches = new ArrayList<Match>();
1403
		for (Line l : lines) matches.add(l.getMatch());
1404

  
1405
		affectMatchesToSelection(matches);
977
	
978
	/**
979
	 * Get the Composite that contains the navigation buttons
980
	 * 
981
	 * GridLayout with 7 columns
982
	 * 
983
	 * @return
984
	 */
985
	public Composite getNavigationArea() {
986
		return queryArea;
1406 987
	}
1407

  
1408
	protected AnnotationType getSelectedAnnotationType() {
1409
		if (annotationTypesCombo != null) {
1410
			IStructuredSelection isel = (IStructuredSelection)annotationTypesCombo.getSelection();
1411
			if (isel.isEmpty()) return null;
1412
			return (AnnotationType) isel.getFirstElement();
1413
		} else { // simple mode
1414
			return tagAnnotationType;
1415
		}
1416
	}
1417

  
1418
	protected void affectMatchesToSelection(final List<Match> matches) {
1419
		final AnnotationType type = getSelectedAnnotationType();
1420
		final String svalue = annotationValuesText.getText();
1421
		final boolean doAffect = addRemoveCombo.getSelectionIndex() == 0; // add is default
1422

  
1423
		JobHandler job = new JobHandler(Messages.ConcordancesEditor_36, true) {
1424
			@Override
1425
			protected IStatus run(IProgressMonitor monitor) {
1426
				this.runInit(monitor);
1427
				try {
1428
					if (doAffect) {
1429
						affectAnnotationValues(matches, type, svalue, this);
1430
					} else {
1431
						deleteAnnotationValues(matches, type, this);
1432
					}
1433
				} catch(Exception e) {
1434
					Log.severe(Messages.ConcordancesEditor_40+e);
1435
					Log.printStackTrace(e);
1436
					return Status.CANCEL_STATUS;
1437
				} catch(ThreadDeath td) {
1438
					System.out.println("Annotation canceled by user.");
1439
					return Status.CANCEL_STATUS;
1440
				}
1441

  
1442
				return Status.OK_STATUS;
1443
			}
1444
		};
1445
		job.startJob(true);
1446
	}
1447

  
1448
	public void updateAnnotationWidgetStates() {
1449
		if (annotationArea == null) return; // :)
1450

  
1451
		if (addRemoveCombo.getSelectionIndex() == 0) { // add is default
1452

  
1453
			if (getSelectedAnnotationType() != null) {
1454
				annotationValuesText.setEnabled(true);
1455

  
1456
				affectAnnotationButton.setEnabled(true);
1457
				affectCombo.setEnabled(true);
1458
			} else {
1459
				annotationValuesText.setEnabled(false);
1460

  
1461
				affectAnnotationButton.setEnabled(false);
1462
				affectCombo.setEnabled(false);
1463
			}
1464
		} else {
1465
			annotationValuesText.setEnabled(false);
1466

  
1467
			if (getSelectedAnnotationType() != null) {
1468
				affectAnnotationButton.setEnabled(true);
1469
				affectCombo.setEnabled(true);
1470
			} else {
1471
				affectAnnotationButton.setEnabled(false);
1472
				affectCombo.setEnabled(false);
1473
			}
1474
		}
1475

  
1476
		if (advanced_annotation_mode.equals(RCPMessages.AnnotationPreferences_2)) {
1477
			if (infosAnnotTypeSelectedLink != null) infosAnnotTypeSelectedLink.setEnabled(getSelectedAnnotationType() != null);
1478
		}
1479
		if (addTypedValueLink != null) addTypedValueLink.setEnabled(getSelectedAnnotationType() != null);
1480

  
1481
		if (concordance == null) {
1482
			affectAnnotationButton.setEnabled(false);
1483
			affectCombo.setEnabled(false);
1484
		}
1485
	}
1486

  
1487
	protected void deleteAnnotationValues(List<Match> matches, AnnotationType type, JobHandler job) {
1488
		if (concordance == null) return;
1489
		if (matches.size() == 0) {
1490
			System.out.println("No lines selected. Aborting."); //$NON-NLS-1$
1491
			return;
1492
		}
1493
		if (type == null) return;
1494

  
1495
		if (concordance != null) {
1496
			try {
1497
				if (annotManager != null && annotManager.deleteAnnotations(type, matches, job)) {
1498
					if (Log.getLevel().intValue() < Level.WARNING.intValue()) annotManager.checkData();
1499
					concordance.reloadLines(topLine, bottomLine);
1500
				} else {
1501
					return;
1502
				}
1503
			} catch (Exception e1) {
1504
				System.out.println(Messages.ConcordancesEditor_54+e1);
1505
				Log.printStackTrace(e1);
1506
				return;
1507
			}
1508

  
1509
			job.syncExec(new Runnable() {
1510
				@Override
1511
				public void run() {
1512
					fillDisplayArea(topLine, bottomLine+1);
1513
					CorporaView.refreshObject(corpus);
1514
				}
1515
			});
1516
		}
1517
	}
1518

  
1519
	TypedValue value_to_add;
1520
	protected void affectAnnotationValues(final List<Match> matches,  final AnnotationType type, final String svalue, JobHandler job) {
1521
		value_to_add = null; // reset
1522
		if (concordance == null) {
1523
			System.out.println("No concordance done. Aborting."); //$NON-NLS-1$
1524
			return;
1525
		}
1526
		if (matches.size() == 0) {
1527
			System.out.println("No line selected. Aborting."); //$NON-NLS-1$
1528
			return;
1529
		}
1530
		if (type == null) return; // no type, no annotation
1531

  
1532
		job.syncExec(new Runnable() {
1533
			@Override
1534
			public void run() {
1535
				if (matches.size() > NALERTAFFECTANNOTATIONS) {
1536
					ConfirmDialog dialog = new ConfirmDialog(Display.getCurrent().getActiveShell(), 
1537
							"confirm_annotate",  //$NON-NLS-1$
1538
							Messages.ConcordancesEditor_86, 
1539
							Messages.ConcordancesEditor_87+matches.size()+Messages.ConcordancesEditor_108);
1540

  
1541
					if (dialog.open() == ConfirmDialog.CANCEL) {
1542
						System.out.println("Annotation aborted by user."); //$NON-NLS-1$
1543
						matches.clear();
1544
					}
1545
				}
1546
			}
1547
		});
1548

  
1549
		// get value from combo text value
1550
		Log.warning(Messages.ConcordancesEditor_57+svalue);
1551
		final KnowledgeRepository kr = KnowledgeRepositoryManager.getKnowledgeRepository(type.getKnowledgeRepository());
1552
		value_to_add = kr.getValue(type, svalue);
1553

  
1554

  
1555
		if (value_to_add == null && kr instanceof LocalKnowledgeRepository) { // create or not the annotation is simple mode
1556
			job.syncExec(new Runnable() {
1557
				@Override
1558
				public void run() {
1559
					String title = kr.getString(locale, "ConcordancesEditor_110");
1560
					String content = kr.getString(locale, "ConcordancesEditor_112");
1561
					if (title == null ) title = Messages.ConcordancesEditor_110;
1562
					if (content == null ) content = Messages.ConcordancesEditor_112;
1563
					ConfirmDialog dialog = new ConfirmDialog(Display.getCurrent().getActiveShell(), 
1564
							"create_value", //$NON-NLS-1$
1565
							Messages.bind(title, svalue, type.getName()),  
1566
							Messages.bind(content, svalue, type.getName()));
1567
					if (dialog.open() == ConfirmDialog.CANCEL) {
1568
						System.out.println("Annotation aborted by user."); //$NON-NLS-1$
1569
						return;
1570
					} else {
1571
						value_to_add = kr.addValue(svalue, svalue, type.getId());
1572
						KRView.refresh();
1573
					}
1574
				}
1575
			});
1576
		}
1577

  
1578
		if (value_to_add == null && kr instanceof LocalKnowledgeRepository) return; // canceled
1579

  
1580
		if (value_to_add == null) {	
1581
			job.syncExec(new Runnable() {
1582
				@Override
1583
				public void run() {
1584
					String mess = Messages.bind(Messages.ConcordancesEditor_58, svalue);
1585
					System.out.println(mess);
1586
					MessageDialog.openError(Display.getCurrent().getActiveShell(), "Annotation canceled", mess); //$NON-NLS-1$
1587
				}
1588
			});
1589
			return;
1590
		}
1591

  
1592
		Log.info(Messages.ConcordancesEditor_59+value_to_add+Messages.ConcordancesEditor_60+matches);
1593

  
1594
		// finally we can 'try' to create the annotations \o/
1595
		try {
1596
			HashMap<Match, List<Annotation>> existingAnnots = annotManager.createAnnotations(type, value_to_add, matches, job);
1597

  
1598
			// did we had problems ?
1599
			if (existingAnnots!=null && existingAnnots.size() > 0) {
1600
				String message = Messages.ConcordancesEditor_61+value_to_add.getStandardName()+
1601
						Messages.ConcordancesEditor_62;
1602
				for (Match m : existingAnnots.keySet()) {
1603
					message += Messages.ConcordancesEditor_63+m+Messages.ConcordancesEditor_64;
1604

  
1605
					for (Annotation existingAnnot : existingAnnots.get(m)) {
1606
						if (existingAnnot.getStart() < m.getStart()){
1607
							message += Messages.ConcordancesEditor_65+existingAnnot.getType()+Messages.ConcordancesEditor_66+existingAnnot.getStart()+Messages.ConcordancesEditor_67+existingAnnot.getEnd()+Messages.ConcordancesEditor_68;
1608
						} else {
1609
							message += Messages.ConcordancesEditor_69+existingAnnot.getType()+Messages.ConcordancesEditor_70+existingAnnot.getStart()+Messages.ConcordancesEditor_71+existingAnnot.getEnd()+Messages.ConcordancesEditor_72;
1610
						}
1611
					}
1612
				}
1613
				final String final_message = message;
1614
				job.syncExec(new Runnable() {
1615
					@Override
1616
					public void run() {
1617
						MessageDialog.openInformation(getSite().getShell(), Messages.ConcordancesEditor_73, final_message);
1618
					}
1619
				});
1620
			}
1621
			//				if (history != null && !history.get(type).contains(value_to_add))
1622
			//					history.get(type).add(value_to_add);
1623

  
1624
			if (Log.getLevel().intValue() < Level.WARNING.intValue() && annotManager != null) annotManager.checkData();
1625
			concordance.reloadLines(topLine, bottomLine+1);
1626
		} catch (Exception e1) {
1627
			System.out.println(Messages.ConcordancesEditor_74+e1);
1628
			Log.printStackTrace(e1);
1629
			return;
1630
		}
1631

  
1632
		job.syncExec(new Runnable() {
1633
			@Override
1634
			public void run() {
1635
				fillDisplayArea(topLine, bottomLine+1);
1636
				CorporaView.refreshObject(corpus);
1637
			}
1638
		});
1639

  
1640
	}
1641

  
988
	
1642 989
	/**
1643 990
	 * Compose control area.
1644 991
	 *
......
1660 1007
		//composeAnnotationArea(controlArea);
1661 1008
		//////////////////////////////////
1662 1009

  
1663
		Composite navigationPanel = new Composite(controlArea, SWT.NONE);
1664
		navigationPanel.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, true));
1010
		navigationArea = new Composite(controlArea, SWT.NONE);
1011
		navigationArea.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, true));
1665 1012
		GridLayout navigationLayout = new GridLayout(7, false); 
1666 1013
		navigationLayout.verticalSpacing = 0;
1667 1014
		navigationLayout.marginWidth = 0;
1668 1015
		navigationLayout.marginHeight = 0;
1669
		navigationPanel.setLayout(navigationLayout);
1016
		navigationArea.setLayout(navigationLayout);
1670 1017
		///////////////////////////
1671 1018
		// | Query: [ (v)] [Search] |
1672 1019

  
1673 1020
		// Query:
1674
		Label queryLabel = new Label(queryArea, SWT.NONE);
1021
		queryLabel = new Label(queryArea, SWT.NONE);
1675 1022
		queryLabel.setText(RCPMessages.CreateSubcorpusDialog_10);
1676 1023
		queryLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false,
1677 1024
				false));
......
1765 1112
				true, 4, 1));
1766 1113

  
1767 1114
		// Delete line button
1768
		deleteLineButton = new Button(navigationPanel, SWT.PUSH);
1115
		deleteLineButton = new Button(navigationArea, SWT.PUSH);
1769 1116
		deleteLineButton.setLayoutData(new GridData(GridData.FILL, GridData.FILL, false,
1770 1117
				false));
1771 1118
		deleteLineButton.setToolTipText(Messages.ConcordancesEditor_88);
......
1781 1128
		});
1782 1129

  
1783 1130

  
1784
		if (KRAnnotationEngine.getKnowledgeRepositoryNames(corpus).size() > 0) { // shown only if corpus has a registered KR
1785

  
1786
			annotationButton = new Button(navigationPanel, SWT.PUSH);
1787
			annotationButton.setToolTipText(Messages.ConcordancesEditor_75);
1788
			annotationButton.setImage(IImageKeys.getImage(IImageKeys.PENCIL));
1789
			annotationButton.addSelectionListener(new SelectionListener() {
1790
				@Override
1791
				public void widgetSelected(SelectionEvent e) {
1792
					if (annotationArea != null) {
1793
						AnnotationManager am = KRAnnotationEngine.getAnnotationManager(corpus);
1794
						if (am != null && am.hasChanges()) {
1795
							// && MessageDialog.openConfirm(e.display.getActiveShell(), "Confirm annotation save", "Saving annotation will close this editor. Are you sure you want to save annotations right now ?")
1796
							JobHandler saveJob = SaveAnnotations.save(corpus.getMainCorpus());
1797
							if (saveJob.getResult() == Status.CANCEL_STATUS) {
1798
								// update editor corpus
1799
								System.out.println("Fail to save annotations of the corpus."); //$NON-NLS-1$
1800
							}
1801
						}
1802

  
1803
					} else {
1804
						if (annotationArea == null) composeAnnotationArea(controlArea);
1805
						if (annotationArea == null) return;
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff