Révision 517

tmp/org.txm.annotation.rcp/META-INF/MANIFEST.MF (revision 517)
12 12
 org.txm.rcp;bundle-version="0.8.0";visibility:=reexport,
13 13
 org.txm.concordance.core;bundle-version="1.0.0",
14 14
 org.txm.concordance.rcp;bundle-version="1.0.0"
15
Export-Package: org.txm.annoation.rcp.concordance,
16
 org.txm.annotation.rcp.commands,
15
Export-Package: org.txm.annotation.rcp.commands,
17 16
 org.txm.annotation.rcp.commands.krview,
17
 org.txm.annotation.rcp.concordance,
18 18
 org.txm.annotation.rcp.editors.imports.sections,
19 19
 org.txm.annotation.rcp.preferences,
20 20
 org.txm.annotation.rcp.views.knowledgerepositories,
tmp/org.txm.annotation.rcp/src/org/txm/annotation/rcp/concordance/ConcordanceAnnotations.java (revision 517)
1
package org.txm.annotation.rcp.concordance;
2

  
3
import java.io.IOException;
4
import java.util.ArrayList;
5
import java.util.Arrays;
6
import java.util.Collections;
7
import java.util.HashMap;
8
import java.util.List;
9

  
10
import org.txm.annotation.core.Annotation;
11
import org.txm.annotation.core.AnnotationManager;
12
import org.txm.annotation.core.KRAnnotationEngine;
13
import org.txm.annotation.core.repository.AnnotationType;
14
import org.txm.annotation.core.repository.TypedValue;
15
import org.txm.concordance.core.functions.Concordance;
16
import org.txm.concordance.core.functions.Line;
17
import org.txm.concordance.core.messages.ConcordanceMessages;
18
import org.txm.searchengine.cqp.clientExceptions.CqiClientException;
19
import org.txm.searchengine.cqp.corpus.query.Match;
20
import org.txm.searchengine.cqp.serverException.CqiServerError;
21
import org.txm.utils.logger.Log;
22

  
23
public class ConcordanceAnnotations {
24
	
25
	Concordance concordance;
26
	
27
	private AnnotationType viewAnnotation;
28
	
29
	public ConcordanceAnnotations(Concordance concordance) {
30
		
31
	}
32
	
33
	private boolean overlapAnnotation;
34

  
35
	private ArrayList<AnnotationLine> lines;
36

  
37
	private List<Line> concordanceLines;
38
	public void setAnnotationOverlap(boolean overlap) {
39
		overlapAnnotation = overlap;
40
	}
41
	public boolean getAnnotationOverlap() {
42
		return overlapAnnotation;
43
	}
44
	
45
	public List<AnnotationLine> getLines(int from, int to) throws CqiClientException, IOException, CqiServerError {
46

  
47
		concordanceLines = concordance.getLines(from, to);
48
		ArrayList<Match> matches = new ArrayList<Match>();
49
		for (Line line : concordanceLines) matches.add(line.getMatch());
50
		
51
		List<Annotation> ann = getAnnotationForMatches(matches, overlapAnnotation);
52
		
53
		lines = new ArrayList<AnnotationLine>();
54
		
55
		for (Annotation a : ann) {
56
			AnnotationLine aline = new AnnotationLine(a, getAnnotationTypedValue(a));
57
			lines.add(aline);
58
		}
59
		
60
		return lines; // TODO find a way to add 
61
	}
62
	
63
	private String findAnnotationForLine(Match match, List<Annotation> annots, boolean overlap) {
64
		String annotationValue = "";
65
		if (annots!=null) {
66
			if (!annots.isEmpty()) {
67
				for (Annotation annot : annots) {
68
					if (overlap) {
69
						if ((annot.getStart()<=match.getStart() && annot.getEnd()>=match.getEnd()) || (annot.getStart()>match.getStart() && annot.getEnd()<match.getEnd())
70
								) {
71
							annotationValue = annot.getValue(); 
72
							// use the first Annotation found, the one stored in the temporary HSQL database
73
							//should be modified to display a list of annotation values corresponding to the match positions (or wrapped if overlap is admitted)
74
						}
75
					} else {
76
						if (annot.getStart()==match.getStart() && annot.getEnd()==match.getEnd()) {
77
							annotationValue = annot.getValue(); 
78
							// use the first Annotation found, the one stored in the temporary HSQL database
79
						}
80
					}
81
				}
82
			}
83
		}
84
		return annotationValue;
85
	}
86
	
87
	public TypedValue getAnnotationTypedValue(Annotation annotation) { 
88

  
89
		TypedValue annotationValue = null;
90
		if (annotation!=null) {
91
			annotationValue = viewAnnotation.getTypedValue(annotation.getValue());
92
			if (annotationValue == null) { // the annotation is not stored in the KR type -> the annotation is surely built with the CQPAnnotationManager
93
				//System.out.println("WARNING: no annotation value found for value id="+annotation.getValue()+" - will be created.");
94
				annotationValue = new TypedValue(annotation.getValue(), annotation.getValue(), annotation.getType());
95
			}
96
		}
97
		
98
		return annotationValue;
99
	}
100

  
101
	public AnnotationType getViewAnnotation(AnnotationType type) {
102
		return viewAnnotation;
103
	}
104

  
105

  
106
	private List<Annotation> prepareAnnotationsList(List<Match> matches, List<Annotation> annotations, boolean overlap){
107
		List<Annotation> annotsList = new ArrayList<Annotation>();
108

  
109
		int iMatch = 0;
110
		int iAnnotation = 0;
111
		int nMatch = matches.size();
112
		int nAnnotations = annotations.size();
113

  
114
		while (iMatch < nMatch && iAnnotation < nAnnotations) {
115
			if (overlap) {
116
				if (matches.get(iMatch).getEnd() < annotations.get(iAnnotation).getStart()) {
117
					iMatch++;
118
					annotsList.add(null); // nothing for this match
119
				} else if (annotations.get(iAnnotation).getEnd() < matches.get(iMatch).getStart()) {
120
					iAnnotation++;
121
				} else {
122
					annotsList.add(annotations.get(iAnnotation));
123
					iMatch++;
124
				}
125
			} else {
126
				if (matches.get(iMatch).getEnd() < annotations.get(iAnnotation).getStart()) {
127
					iMatch++;
128
					annotsList.add(null); // nothing for this match
129
				} else if (annotations.get(iAnnotation).getEnd() < matches.get(iMatch).getStart()) {
130
					iAnnotation++;
131
				} else if (annotations.get(iAnnotation).getStart() == matches.get(iMatch).getStart() && 
132
						annotations.get(iAnnotation).getEnd() == matches.get(iMatch).getEnd()) {
133
					annotsList.add(annotations.get(iAnnotation));
134
					iMatch++;
135
					iAnnotation++;
136
				} else {
137
					iAnnotation++;
138
				}
139
			}
140
		}
141

  
142
		while (annotsList.size() < matches.size() ) annotsList.add(null); // fill matches that were not process due to no more annotations
143

  
144
		return annotsList;
145
	}
146

  
147
	private HashMap<Match, Annotation> prepareAnnotationsMap(List<Match> matches, List<Annotation> annots, boolean overlap){
148
		HashMap<Match, Annotation> annotsList = new HashMap<Match, Annotation>();
149
		for (Match m : matches) {
150
			boolean hasAnnotations = false;
151
			if (annots!=null) {
152
				if (!annots.isEmpty()) {
153
					for (Annotation annot : annots) {
154
						if (overlap){
155
							if ((annot.getStart() <= m.getStart() && m.getStart() <= annot.getEnd() && m.getEnd() >= annot.getEnd()) || 
156
									(annot.getStart() <= m.getEnd() && m.getEnd() <= annot.getEnd() && m.getStart() <= annot.getStart()) 
157
									|| !(annot.getEnd() < m.getStart() || annot.getStart() > m.getEnd())){
158
								annotsList.put(m, annot);
159
								hasAnnotations = true;
160
							}
161
						} else {
162
							if (annot.getStart()==m.getStart() && annot.getEnd()==m.getEnd()) {
163
								annotsList.put(m, annot); 
164
								hasAnnotations = true;
165
							}
166
						}
167
					}
168
				}
169
			}
170
			if (!hasAnnotations) {
171
				annotsList.put(m, null);
172
			}
173
		}
174
		return annotsList;
175
	}
176

  
177
	public List<Annotation> getAnnotationForMatches(List<Match> subsetMatch, boolean overlapAnnotation) {
178
		
179
		AnnotationManager am = KRAnnotationEngine.getAnnotationManager(concordance.getCorpus());
180
		
181
		//List<Annotation> allAnnotations = null;
182
		List<Annotation> annotationsPerMatch = null;;
183
		if (viewAnnotation != null && am != null) {
184
			try {
185
				annotationsPerMatch = am.getAnnotationsForMatches(viewAnnotation, subsetMatch, overlapAnnotation);
186
				//System.out.println("annotationsPerMatch: "+annotationsPerMatch);
187
			} catch (Exception e) {
188
				System.out.println("Error while reading annotation "+viewAnnotation+" and with "+subsetMatch.size()+" matches");
189
				Log.printStackTrace(e);
190
			}
191
		}
192
		return annotationsPerMatch;
193
	}
194
	
195

  
196
	public void setViewAnnotation(AnnotationType type) {
197
		viewAnnotation = type;
198
		concordance.resetLines();
199
	}
200
	
201
	/**
202
	 * 
203
	 * @param i the relative position of the AnnotationLine in the lines list
204
	 * 
205
	 * @return the AnnotationLine pointed by 'i'. May return null if i is wrong.
206
	 */
207
	public AnnotationLine getAnnotationLine(Line line) {
208
		int i = concordanceLines.indexOf(line);
209
		if (i < 0) return null;
210
		return getAnnotationLine(i);
211
	}
212
	
213
	/**
214
	 * 
215
	 * @param i the relative position of the AnnotationLine in the lines list
216
	 * 
217
	 * @return the AnnotationLine pointed by 'i'. May return null if i is wrong.
218
	 */
219
	public AnnotationLine getAnnotationLine(int i) {
220
		if (lines.size() < i) return null;
221
		if (i < 0) return null;
222
		
223
		return lines.get(i);
224
	}
225
}
0 226

  
tmp/org.txm.annotation.rcp/src/org/txm/annotation/rcp/concordance/AnnotationLine.java (revision 517)
1
package org.txm.annotation.rcp.concordance;
2

  
3
import org.txm.annotation.core.Annotation;
4
import org.txm.annotation.core.repository.TypedValue;
5

  
6
public class AnnotationLine {
7

  
8
	private TypedValue annotationValue;
9

  
10
	private Annotation annotation;
11
	
12
	public AnnotationLine(Annotation annotation, TypedValue annotationValue) {
13
		this.annotation = annotation;
14
		this.annotationValue = annotationValue; 
15
	}
16
	
17

  
18
	public Annotation getAnnotation() {
19
		return annotation;
20
	}
21
	
22

  
23
	public TypedValue getAnnotationValue() {
24
		return annotationValue;
25
	}
26
}
0 27

  
tmp/org.txm.annotation.rcp/src/org/txm/annotation/rcp/concordance/AnnotationLineDecorator.java (revision 517)
1
package org.txm.annotation.rcp.concordance;
2

  
3
import org.txm.annotation.core.Annotation;
4
import org.txm.concordance.core.functions.LineDecorator;
5

  
6
public class AnnotationLineDecorator extends LineDecorator {
7
	ConcordanceAnnotations annotations;
8
	
9
	public AnnotationLineDecorator(ConcordanceAnnotations annotations) {
10
		this.annotations = annotations;
11
	}
12
	
13
	/**
14
	 * Add "<" or ">" depending of the current position of the match and the annotation start end positions
15
	 */
16
	@Override
17
	public String decorate(int i, int currentPos, String str) {
18
		Annotation annotation = annotations.getAnnotationLine(i).getAnnotation();
19
		
20
		if (annotation != null) {
21
			if (currentPos == annotation.getStart()) {
22
				return "< "+str;
23
			} else if (currentPos == annotation.getEnd()) {
24
				return str+" >";
25
			}
26
		}
27
		return str;
28
	}
29
}
0 30

  
tmp/org.txm.annotation.rcp/src/org/txm/annotation/rcp/concordance/ConcordanceAnnotationExtension.java (revision 517)
1
package org.txm.annotation.rcp.concordance;
2

  
3
import java.io.File;
4
import java.util.ArrayList;
5
import java.util.HashMap;
6
import java.util.List;
7
import java.util.Vector;
8
import java.util.logging.Level;
9

  
10
import org.eclipse.core.runtime.IProgressMonitor;
11
import org.eclipse.core.runtime.IStatus;
12
import org.eclipse.core.runtime.Status;
13
import org.eclipse.jface.dialogs.InputDialog;
14
import org.eclipse.jface.dialogs.MessageDialog;
15
import org.eclipse.jface.viewers.ArrayContentProvider;
16
import org.eclipse.jface.viewers.ColumnLabelProvider;
17
import org.eclipse.jface.viewers.ComboViewer;
18
import org.eclipse.jface.viewers.ISelection;
19
import org.eclipse.jface.viewers.ISelectionChangedListener;
20
import org.eclipse.jface.viewers.IStructuredSelection;
21
import org.eclipse.jface.viewers.SelectionChangedEvent;
22
import org.eclipse.jface.viewers.TableViewer;
23
import org.eclipse.jface.viewers.TableViewerColumn;
24
import org.eclipse.jface.viewers.ViewerCell;
25
import org.eclipse.swt.SWT;
26
import org.eclipse.swt.events.ControlEvent;
27
import org.eclipse.swt.events.ControlListener;
28
import org.eclipse.swt.events.KeyEvent;
29
import org.eclipse.swt.events.KeyListener;
30
import org.eclipse.swt.events.SelectionEvent;
31
import org.eclipse.swt.events.SelectionListener;
32
import org.eclipse.swt.graphics.Point;
33
import org.eclipse.swt.layout.GridData;
34
import org.eclipse.swt.layout.GridLayout;
35
import org.eclipse.swt.widgets.Button;
36
import org.eclipse.swt.widgets.Combo;
37
import org.eclipse.swt.widgets.Composite;
38
import org.eclipse.swt.widgets.Display;
39
import org.eclipse.swt.widgets.Label;
40
import org.eclipse.swt.widgets.TableColumn;
41
import org.eclipse.swt.widgets.Text;
42
import org.eclipse.ui.IWorkbenchWindow;
43
import org.eclipse.ui.PartInitException;
44
import org.eclipse.ui.dialogs.ListDialog;
45
import org.txm.concordance.core.functions.Concordance;
46
import org.txm.concordance.core.functions.Line;
47
import org.txm.concordance.rcp.editors.ConcordanceEditor;
48
import org.txm.concordance.rcp.editors.ConcordanceEditor.ConcordanceColumnSizeControlListener;
49
import org.txm.concordance.rcp.editors.ConcordanceEditorExtension;
50
import org.txm.concordance.rcp.messages.Messages;
51
import org.txm.core.preferences.TXMPreferences;
52
import org.txm.rcp.IImageKeys;
53
import org.txm.rcp.RCPMessages;
54
import org.txm.rcp.commands.OpenBrowser;
55
import org.txm.rcp.preferences.RCPPreferences;
56
import org.txm.rcp.swt.dialog.ConfirmDialog;
57
import org.txm.rcp.swt.provider.SimpleLabelProvider;
58
import org.txm.rcp.utils.JobHandler;
59
import org.txm.rcp.views.corpora.CorporaView;
60
import org.txm.searchengine.cqp.clientExceptions.CqiClientException;
61
import org.txm.searchengine.cqp.corpus.Corpus;
62
import org.txm.searchengine.cqp.corpus.query.Match;
63
import org.txm.utils.AsciiUtils;
64
import org.txm.utils.logger.Log;
65
import org.txm.annotation.core.Annotation;
66
import org.txm.annotation.core.AnnotationManager;
67
import org.txm.annotation.core.KRAnnotationEngine;
68
import org.txm.annotation.core.preferences.AnnotationPreferences;
69
import org.txm.annotation.core.repository.AnnotationType;
70
import org.txm.annotation.core.repository.KnowledgeRepository;
71
import org.txm.annotation.core.repository.KnowledgeRepositoryManager;
72
import org.txm.annotation.core.repository.LocalKnowledgeRepository;
73
import org.txm.annotation.core.repository.SQLKnowledgeRepository;
74
import org.txm.annotation.core.repository.TypedValue;
75
import org.txm.annotation.rcp.commands.InitializeKnowledgeRepository;
76
import org.txm.annotation.rcp.commands.SaveAnnotations;
77
import org.txm.annotation.rcp.commands.krview.OpenKRView;
78
import org.txm.annotation.rcp.views.knowledgerepositories.KRView;
79

  
80
public class ConcordanceAnnotationExtension extends ConcordanceEditorExtension {
81

  
82
	/**
83
	 * the limit number of annotation when a confirm dialog box is shown
84
	 */
85
	protected static final int NALERTAFFECTANNOTATIONS = 100;
86

  
87
	/** The annotation service */
88
	protected AnnotationManager  annotManager;
89
	
90
	//boolean annotation_expert_mode = TxmPreferences.getBoolean(AnnotationPreferencePage.MODE, false);
91

  
92
	/** The annotation area. */
93
	protected Composite annotationArea;
94
	
95
	protected Point annotationSize;
96

  
97
	/** The annot btn. */
98
	protected Button annotationButton;
99
	private Button addAnnotationTypeLink;
100

  
101
	protected Text annotationValuesText;
102
	protected ComboViewer annotationTypesCombo;
103
	
104
	protected List<TypedValue> typeValuesList;
105

  
106
	protected Point annotSize;
107

  
108
	protected TableColumn annotationColumn;
109

  
110
	protected Combo addRemoveCombo;
111
	protected Combo affectCombo;
112
	protected Button affectAnnotationButton;
113

  
114
	protected Button infosAnnotTypeSelectedLink;
115
	
116
	protected HashMap<AnnotationType, ArrayList<TypedValue>> history = new HashMap<AnnotationType, ArrayList<TypedValue>>();
117

  
118
	protected KnowledgeRepository currentKnowledgeRepository = null;
119
	protected Vector<AnnotationType> typesList = new Vector<AnnotationType>(); 
120

  
121
	protected Button addTypedValueLink;
122

  
123
	protected Label withLabel;
124

  
125
	protected AnnotationType tagAnnotationType; // the tag annotation type if annotation mode is simple
126

  
127
	protected Label equalLabel;
128
	protected Boolean advanced_annotation_mode = false;
129
	
130
	protected TypedValue value_to_add;
131

  
132
	protected Concordance concordance;
133

  
134
	private Corpus corpus;
135

  
136
	private ConcordanceAnnotations annotations;
137
	
138
	public ConcordanceAnnotationExtension() {
139
		
140
	}
141

  
142
	@Override
143
	public String getName() {
144
		return "Annotation";
145
	}
146

  
147
	@Override
148
	public boolean installWidgets() throws Exception {
149
		
150
		final Composite controlArea = editor.getNavigationArea();
151
		final Composite navigationArea = editor.getNavigationArea();
152
		TableViewer viewer = editor.getLineTableViewer();
153
		
154
		// CONTROLS
155
		if (KRAnnotationEngine.getKnowledgeRepositoryNames(corpus).size() > 0) { // shown only if corpus has a registered KR
156

  
157
			annotationButton = new Button(navigationArea, SWT.PUSH);
158
			annotationButton.setToolTipText(Messages.ConcordancesEditor_75);
159
			annotationButton.setImage(IImageKeys.getImage(IImageKeys.PENCIL));
160
			annotationButton.addSelectionListener(new SelectionListener() {
161
				@Override
162
				public void widgetSelected(SelectionEvent e) {
163
					if (annotationArea != null) {
164
						AnnotationManager am = KRAnnotationEngine.getAnnotationManager(corpus);
165
						if (am != null && am.hasChanges()) {
166
							// && MessageDialog.openConfirm(e.display.getActiveShell(), "Confirm annotation save", "Saving annotation will close this editor. Are you sure you want to save annotations right now ?")
167
							JobHandler saveJob = SaveAnnotations.save(corpus.getMainCorpus());
168
							if (saveJob.getResult() == Status.CANCEL_STATUS) {
169
								// update editor corpus
170
								System.out.println("Fail to save annotations of the corpus."); //$NON-NLS-1$
171
							}
172
						}
173

  
174
					} else {
175
						if (annotationArea == null) composeAnnotationArea(controlArea);
176
						if (annotationArea == null) return;
177

  
178
						annotationColumn.pack();
179
						annotationButton.setToolTipText(Messages.ConcordancesEditor_76);
180
						annotationButton.setImage(IImageKeys.getImage(IImageKeys.PENCIL_SAVE));
181

  
182
						annotSize = annotationArea.getSize();
183
						Point size = controlArea.getSize();
184
						controlArea.setSize(size.x, size.y + annotSize.y);
185
						GridData data = (GridData) annotationArea.getLayoutData();
186
						data.heightHint = annotSize.y;
187
						data.minimumHeight = annotSize.y;
188
						annotationArea.setSize(annotSize);
189
						controlArea.layout(true);
190
						controlArea.getParent().layout();
191

  
192
						if (concordance != null) {
193
							AnnotationType type = getSelectedAnnotationType();
194
							if (type != null) {
195
								annotations.setViewAnnotation(type);
196
								annotations.setAnnotationOverlap(true);
197
								editor.fillDisplayArea(editor.getTopLine(), editor.getBottomLine()+1);
198
							}
199
						}
200

  
201
						CorporaView.refreshObject(corpus);
202
					}
203
				}
204

  
205
				@Override
206
				public void widgetDefaultSelected(SelectionEvent e) {	}
207
			});
208
		}
209
		
210
		// RESULT
211
		
212
		int position = 3;
213
		TableViewerColumn annotationColumnViewer = new TableViewerColumn(viewer, SWT.CENTER, position);
214
		annotationColumn = annotationColumnViewer.getColumn();
215
		annotationColumn.setText(Messages.ConcordancesEditor_15);
216
		annotationColumn.setToolTipText(Messages.ConcordancesEditor_17);
217
		annotationColumn.setAlignment(SWT.CENTER);
218
		
219
		annotationColumn.addControlListener(new ConcordanceColumnSizeControlListener(annotationColumn));
220
		annotationColumnViewer.setLabelProvider(new ColumnLabelProvider() {
221
			@Override
222
			public String getText(Object element) {
223
				Line line = (Line)element;
224
				AnnotationLine annotationLine = annotations.getAnnotationLine(line);
225
				if (annotationLine.getAnnotation()!=null) {
226
					String value = annotationLine.getAnnotationValue().getStandardName();
227
					Annotation a = annotationLine.getAnnotation();
228
					if (value == null) value = a.getValue();
229
									
230
					if (a.getStart() < line.matchGetStart() - line.getLeftContextSize()) {
231
						value = "… "+value;
232
					}
233
					
234
					if (a.getEnd() > line.matchGetEnd() + line.getRightContextSize()) {
235
						value = value+" …";
236
					} 
237
					return value;
238
				} else {
239
					return "";
240
				}
241
			}
242
		});
243
		
244
		
245
		return true;
246
	}
247
	
248
	public boolean initialiseInput(ConcordanceEditor editor) throws Exception {
249
		this.editor = editor;
250
		concordance = editor.getConcordance();
251
		annotations = new ConcordanceAnnotations(concordance);
252
		corpus = concordance.getCorpus();
253
		
254
		Corpus corpus = editor.getCorpus();
255
		
256
		this.annotManager = KRAnnotationEngine.getAnnotationManager(corpus);
257
		
258
		return true;
259
		
260
	}
261
	
262
	private void composeAnnotationArea(final Composite parent){ 
263
		advanced_annotation_mode = "advanced".equals(TXMPreferences.getString(AnnotationPreferences.ANNOTATION_MODE, RCPPreferences.PREFERENCES_NODE));
264

  
265
		List<KnowledgeRepository> krs = InitializeKnowledgeRepository.get(corpus.getMainCorpus());
266
		typesList.clear();
267
		Log.warning("Corpus KRs: "+krs); //$NON-NLS-1$
268

  
269
		for (KnowledgeRepository kr : krs) {
270
			if (kr == null) continue;
271

  
272
			currentKnowledgeRepository = kr;
273
			Log.warning(" KR: "+kr); //$NON-NLS-1$
274
			List<AnnotationType> krtypes = kr.getAllAnnotationTypes();
275
			Log.warning("Advanced annotation mode ? "+advanced_annotation_mode);
276
			if (!advanced_annotation_mode) { // creates the "span" annotation type
277
				boolean createTagAnnotationType = true;
278
				for (AnnotationType type : krtypes) {
279
					if (type.getName().equals("span")) { //$NON-NLS-1$
280
						createTagAnnotationType = false;
281
					}
282
				}
283
				if (createTagAnnotationType) {
284
					tagAnnotationType = kr.addType("span", "span");//corresponds to an "undef" type //$NON-NLS-1$ //$NON-NLS-2$
285
					typesList.add(tagAnnotationType);
286
				} else {
287
					tagAnnotationType = kr.getType("span"); //$NON-NLS-1$
288
				}
289
			} else {
290
				typesList.addAll(krtypes);
291
			}
292
			Log.warning("Available annotation types: "+typesList);
293
			break;
294
		}
295

  
296
		if (currentKnowledgeRepository == null) {
297
			System.out.println("Error: no suitable KnowledgeRepository found");
298
			return;
299
		}
300

  
301
		annotationArea = new Composite(parent, SWT.NONE);
302
		annotationArea.setLayoutData(new GridData(SWT.FILL, SWT.LEFT, false, false));
303

  
304
		GridLayout annotLayout = new GridLayout(12, false);
305
		annotLayout.verticalSpacing = 0;
306
		annotLayout.marginWidth = 0;
307
		annotLayout.marginHeight = 0;
308
		annotationArea.setLayout(annotLayout);
309

  
310
		//init values history
311
		for (AnnotationType type : typesList) {
312
			history.put(type, new ArrayList<TypedValue>());
313
		}
314

  
315
		addRemoveCombo = new Combo(annotationArea, SWT.READ_ONLY);
316
		String affectLabel = currentKnowledgeRepository.getString(editor.getLocale(), "ConcordancesEditor_22");
317
		if (affectLabel == null) affectLabel= Messages.ConcordancesEditor_22;
318
		String removeLabel = currentKnowledgeRepository.getString(editor.getLocale(), "ConcordancesEditor_24");
319
		if (removeLabel == null) removeLabel= Messages.ConcordancesEditor_24;
320
		String items[] = {affectLabel, removeLabel};
321
		addRemoveCombo.setItems(items);
322
		addRemoveCombo.select(0);
323
		addRemoveCombo.addSelectionListener(new SelectionListener() {
324
			@Override
325
			public void widgetSelected(SelectionEvent e) {
326
				if (addRemoveCombo.getSelectionIndex() == 0) { // add
327
					annotationValuesText.setEnabled(true);
328
					String withLabelText = currentKnowledgeRepository.getString(editor.getLocale(), "ConcordancesEditor_83");
329
					if (withLabelText == null) withLabelText= Messages.ConcordancesEditor_83;
330
					withLabel.setText(withLabelText);
331
					if (equalLabel != null) equalLabel.setText("=");
332
				} else { // remove
333
					annotationValuesText.setEnabled(false);
334
					withLabel.setText(""); //$NON-NLS-1$
335
					if (equalLabel != null) equalLabel.setText("");
336
				}
337
				withLabel.redraw();
338
				annotationArea.layout();
339
				updateAnnotationWidgetStates();
340
			}
341
			@Override
342
			public void widgetDefaultSelected(SelectionEvent e) { }
343
		});
344
		GridData gdata = new GridData(SWT.CENTER, SWT.CENTER, false, true);
345
		gdata.widthHint = 90;
346
		addRemoveCombo.setLayoutData(gdata);
347

  
348
		withLabel = new Label(annotationArea, SWT.NONE);
349
		String withLabelText = currentKnowledgeRepository.getString(editor.getLocale(), "ConcordancesEditor_83");
350
		if (withLabelText == null) withLabelText= Messages.ConcordancesEditor_83;
351
		withLabel.setText(withLabelText);
352
		withLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
353

  
354
		if (advanced_annotation_mode) {
355
			equalLabel = new Label(annotationArea, SWT.NONE);
356
			equalLabel.setText("="); //$NON-NLS-1$
357
			equalLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
358
		}
359

  
360
		//Display combo with list of Annotation Type 
361
		if (advanced_annotation_mode) {
362
			annotationTypesCombo = new ComboViewer(annotationArea, SWT.READ_ONLY);
363
			annotationTypesCombo.setContentProvider(new ArrayContentProvider());
364
			annotationTypesCombo.setLabelProvider(new SimpleLabelProvider() {
365
				@Override
366
				public String getColumnText(Object element, int columnIndex) {
367
					return ((AnnotationType)element).getName(); //$NON-NLS-1$
368
				}
369
				@Override
370
				public String getText(Object element) {
371
					return ((AnnotationType)element).getName(); //$NON-NLS-1$
372
				}
373
			});
374
			gdata = new GridData(SWT.CENTER, SWT.CENTER, false, true);
375
			gdata.widthHint = 200;
376

  
377
			annotationTypesCombo.getCombo().setLayoutData(gdata);
378
			annotationTypesCombo.setInput(typesList);
379
			if (advanced_annotation_mode.equals(RCPMessages.AnnotationPreferences_2)) {
380
				annotationTypesCombo.getCombo().select(0);
381
			}
382

  
383
			annotationTypesCombo.addSelectionChangedListener(new ISelectionChangedListener() {
384
				@Override
385
				public void selectionChanged(SelectionChangedEvent event) {
386
					AnnotationType type = getSelectedAnnotationType();
387
					if (type == null) return;
388
					if (type.getSize() != AnnotationType.ValuesSize.LARGE) {
389
						try {
390
							KnowledgeRepository kr = KnowledgeRepositoryManager.getKnowledgeRepository(type.getKnowledgeRepository());
391
							typeValuesList = kr.getValues(type);
392
						} catch (Exception e) {
393
							// TODO Auto-generated catch block
394
							e.printStackTrace();
395
						}
396
					} else { // set history values
397
						typeValuesList = history.get(type);
398
					}
399

  
400
					annotationColumn.setText(type.getName());
401
					if (concordance != null) {
402
						annotations.setViewAnnotation(type);
403
						annotations.setAnnotationOverlap(true);
404
						editor.fillDisplayArea(editor.getTopLine(), editor.getBottomLine()+1);
405
					}
406

  
407
					updateAnnotationWidgetStates();
408
				}
409
			});
410
		}
411

  
412
		if (advanced_annotation_mode) {
413
			if (currentKnowledgeRepository instanceof SQLKnowledgeRepository) {
414
				infosAnnotTypeSelectedLink = new Button(annotationArea, SWT.PUSH);
415
				infosAnnotTypeSelectedLink.setImage(IImageKeys.getImage(IImageKeys.ACTION_INFO));
416
				infosAnnotTypeSelectedLink.setEnabled(true);
417
				infosAnnotTypeSelectedLink.setLayoutData(new GridData(SWT.FILL,	SWT.CENTER, false, true));
418
				infosAnnotTypeSelectedLink.addSelectionListener(new SelectionListener() {
419
					@Override
420
					public void widgetSelected(SelectionEvent e) {
421
						AnnotationType type = getSelectedAnnotationType();
422
						if (type == null) return;
423

  
424
						String typedValueURL = type.getURL(); // may be null/empty
425
						if (typedValueURL != null && typedValueURL.length() > 0) {
426
							KnowledgeRepository kr = KnowledgeRepositoryManager.getKnowledgeRepository(type.getKnowledgeRepository());
427
							kr.getTypeURL(type);
428
						}
429
						if (typedValueURL != null && typedValueURL.length() > 0) {
430
							OpenBrowser.openfile(typedValueURL, new File(typedValueURL).getName());
431
						} else {
432
							IWorkbenchWindow window = editor.getSite().getWorkbenchWindow();
433
							try {
434
								OpenKRView.openView(window, type);
435
							} catch (PartInitException e1) {
436
								e1.printStackTrace();
437
							}
438
						}
439
					}
440

  
441
					@Override
442
					public void widgetDefaultSelected(SelectionEvent e) { }
443
				});
444
			}
445

  
446
			if (currentKnowledgeRepository instanceof LocalKnowledgeRepository) {
447
				addAnnotationTypeLink = new Button(annotationArea, SWT.PUSH);
448
				addAnnotationTypeLink.setToolTipText(Messages.ConcordancesEditor_115);
449
				addAnnotationTypeLink.setImage(IImageKeys.getImage(IImageKeys.ACTION_ADD));
450
				addAnnotationTypeLink.setEnabled(true);
451
				addAnnotationTypeLink.setLayoutData(new GridData(SWT.FILL,	SWT.CENTER, false, true));
452
				addAnnotationTypeLink.addSelectionListener(new SelectionListener() {
453
					@Override
454
					public void widgetSelected(SelectionEvent e) {
455
						if (currentKnowledgeRepository == null) return;
456
						if (!(currentKnowledgeRepository instanceof LocalKnowledgeRepository)) return;
457

  
458
						LocalKnowledgeRepository kr = (LocalKnowledgeRepository)currentKnowledgeRepository;
459

  
460
						InputDialog dialog = new InputDialog(e.widget.getDisplay().getActiveShell(), Messages.ConcordancesEditor_82, Messages.ConcordancesEditor_81, "", null); //$NON-NLS-3$
461
						if (dialog.open() == InputDialog.OK) {
462
							String name = dialog.getValue();
463
							if (name.trim().length() == 0) return;
464
							String baseid = AsciiUtils.buildId(name);
465
							String id = AsciiUtils.buildId(name);
466
							int c = 1;
467
							while (kr.getType(id) != null) {
468
								id = baseid+"_"+(c++); //$NON-NLS-1$
469
							}
470
							AnnotationType type = kr.addType(name, id, ""); //$NON-NLS-1$
471
							typesList.add(type);
472
							history.put(type, new ArrayList<TypedValue>());
473

  
474
							if (annotationTypesCombo != null) annotationTypesCombo.refresh();
475
							if (typesList.size() == 1) {
476
								if (annotationTypesCombo != null) annotationTypesCombo.getCombo().select(0);
477
								if (concordance != null) {
478
									annotations.setViewAnnotation(type);
479
									annotations.setAnnotationOverlap(true);
480
									editor.fillDisplayArea(editor.getTopLine(), editor.getBottomLine()+1);
481
								}
482
								annotationArea.layout(true);
483
							}else {
484
								if (typesList.size() > 1){
485
									if (annotationTypesCombo != null) annotationTypesCombo.getCombo().select(typesList.size()-1);
486

  
487
								}
488

  
489
							}
490
							KRView.refresh();
491
							updateAnnotationWidgetStates();
492
						} else {
493
							System.out.println("Creation aborted."); //$NON-NLS-1$
494
						}
495
					}
496

  
497
					@Override
498
					public void widgetDefaultSelected(SelectionEvent e) { }
499
				});
500
			}
501
		}
502
		if (advanced_annotation_mode) {
503
			Label valueLabel = new Label(annotationArea, SWT.NONE);
504
			String valueLabelText = currentKnowledgeRepository.getString(editor.getLocale(), "ConcordancesEditor_80");
505
			if (valueLabelText == null) valueLabelText= Messages.ConcordancesEditor_80;
506
			valueLabel.setText(valueLabelText);
507
			valueLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
508
		}
509

  
510
		annotationValuesText = new Text(annotationArea, SWT.BORDER);
511
		annotationValuesText.setToolTipText(Messages.ConcordancesEditor_32);
512
		GridData gdata2 = new GridData(SWT.FILL, SWT.CENTER, false, true);
513
		gdata2.widthHint = 200;
514
		annotationValuesText.setLayoutData(gdata2);
515
		annotationValuesText.addKeyListener(new KeyListener() {
516
			@Override
517
			public void keyReleased(KeyEvent e) {
518
				if (e.keyCode == SWT.CR || e.keyCode == SWT.KEYPAD_CR) {
519
					affectAnnotationToSelection(editor.getLineTableViewer().getSelection());
520
				}
521
			}
522

  
523
			@Override
524
			public void keyPressed(KeyEvent e) { }
525
		});
526

  
527
		if (currentKnowledgeRepository instanceof LocalKnowledgeRepository) {
528
			addTypedValueLink = new Button(annotationArea, SWT.PUSH);
529
			addTypedValueLink.setText("..."); //$NON-NLS-1$
530
			if (advanced_annotation_mode.equals(RCPMessages.AnnotationPreferences_2)) {
531
				addTypedValueLink.setToolTipText(Messages.ConcordancesEditor_79);
532
			}else {
533
				addTypedValueLink.setToolTipText(Messages.ConcordancesEditor_77);
534
			}
535
			addTypedValueLink.setEnabled(true);
536
			addTypedValueLink.setLayoutData(new GridData(SWT.FILL,	SWT.CENTER, false, true));
537
			addTypedValueLink.addSelectionListener(new SelectionListener() {
538
				@Override
539
				public void widgetSelected(SelectionEvent e) {
540
					if (currentKnowledgeRepository == null) return;
541
					if (!(currentKnowledgeRepository instanceof LocalKnowledgeRepository)) return;
542

  
543
					AnnotationType type = getSelectedAnnotationType();
544
					if (type == null) return;
545

  
546
					LocalKnowledgeRepository kr = (LocalKnowledgeRepository)currentKnowledgeRepository;
547

  
548
					ListDialog dialog = new ListDialog(e.widget.getDisplay().getActiveShell());
549
					if (advanced_annotation_mode.equals(RCPMessages.AnnotationPreferences_2)) {
550
						String title = currentKnowledgeRepository.getString(editor.getLocale(), "ConcordancesEditor_100");
551
						if (title == null) title = Messages.ConcordancesEditor_100;
552
						dialog.setTitle(Messages.bind(title, type.getName()));//+"valeurs de "+type.getName());
553
					}else {
554
						dialog.setTitle(Messages.ConcordancesEditor_99);//+"valeurs de "+type.getName());
555
					}
556
					dialog.setContentProvider(new ArrayContentProvider());
557
					dialog.setLabelProvider(new SimpleLabelProvider() {
558
						public String getColumnText(Object element, int columnIndex) {
559
							if (element instanceof TypedValue)
560
								return ((TypedValue)element).getId();
561
							return element.toString();
562
						}
563
					});
564
					List<TypedValue> values;
565
					try {
566
						values = kr.getValues(type);
567
					} catch (Exception e1) {
568
						e1.printStackTrace();
569
						return;
570
					}
571
					dialog.setInput(values);
572
					if (dialog.open() == InputDialog.OK) {
573
						TypedValue value = (TypedValue) dialog.getResult()[0];
574
						String name = value.getId();
575
						if (name.trim().length() == 0) return;
576

  
577
						annotationValuesText.setText(name);
578
					} else {
579

  
580
					}
581
				}
582

  
583
				@Override
584
				public void widgetDefaultSelected(SelectionEvent e) { }
585
			});
586
		}
587

  
588
		affectCombo = new Combo(annotationArea, SWT.READ_ONLY);
589
		affectCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, true));
590
		String items2[] = {Messages.ConcordancesEditor_35, Messages.ConcordancesEditor_42, Messages.ConcordancesEditor_49};
591
		affectCombo.setItems(items2);
592
		affectCombo.select(0);
593
		gdata = new GridData(SWT.CENTER, SWT.CENTER, false, true);
594
		gdata.widthHint = 140;
595
		affectCombo.setLayoutData(gdata);
596

  
597
		affectAnnotationButton = new Button(annotationArea, SWT.PUSH);
598
		affectAnnotationButton.setText(Messages.ConcordancesEditor_85);
599
		affectAnnotationButton.setToolTipText(Messages.ConcordancesEditor_116);
600
		affectAnnotationButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, true));
601
		affectAnnotationButton.addSelectionListener(new SelectionListener() {
602
			@Override
603
			public void widgetSelected(SelectionEvent e) {
604
				int isel = affectCombo.getSelectionIndex();
605
				if (isel == 0) { // selected line
606
					affectAnnotationToSelection(editor.getLineTableViewer().getSelection());
607
				} else if (isel == 1) { // page
608
					try {
609
						List<Match> matches = concordance.getMatches().subList(editor.getTopLine(), editor.getBottomLine()+1);
610
						affectMatchesToSelection(matches);
611
					} catch (CqiClientException e1) {
612
						Log.severe(Messages.ConcordancesEditor_53+e1);
613
						Log.printStackTrace(e1);
614
						return;
615
					}
616
				} else { // all
617
					try {
618
						List<Match> matches = concordance.getMatches();
619
						affectMatchesToSelection(matches);
620
					} catch (CqiClientException e1) {
621
						Log.severe(Messages.ConcordancesEditor_53+e1);
622
						Log.printStackTrace(e1);
623
						return;
624
					}
625
				}
626
			}
627

  
628
			@Override
629
			public void widgetDefaultSelected(SelectionEvent e) { }
630
		});
631
		Button cancelAnnotateButton = new Button(annotationArea, SWT.PUSH);
632
		cancelAnnotateButton.setText(Messages.ConcordancesEditor_101);
633
		cancelAnnotateButton.addSelectionListener(new SelectionListener() {
634
			@Override
635
			public void widgetSelected(SelectionEvent e) {
636
				//@TODO Closing the annotation tool bar 
637
				//System.out.println("must hide");
638
				annotationSize = annotationArea.getSize();
639
				annotationArea.dispose();
640
				annotationArea = null;
641
				parent.layout(true);
642
				parent.layout();
643
				annotationButton.setToolTipText(Messages.ConcordancesEditor_75);
644
				annotationButton.setImage(IImageKeys.getImage(IImageKeys.PENCIL));
645
				annotationColumn.setWidth(0);
646
				annotationColumn.setResizable(false);
647
			}
648

  
649
			@Override
650
			public void widgetDefaultSelected(SelectionEvent e) { }
651
		});
652

  
653

  
654
		updateAnnotationWidgetStates();
655
		
656
		
657

  
658
		parent.layout();
659
	}
660

  
661
	protected void affectAnnotationToSelection(ISelection selection) {
662

  
663
		final IStructuredSelection lineSelection = (IStructuredSelection) selection;
664
		List<Line> lines = lineSelection.toList();
665
		ArrayList<Match> matches = new ArrayList<Match>();
666
		for (Line l : lines) matches.add(l.getMatch());
667

  
668
		affectMatchesToSelection(matches);
669
	}
670

  
671
	protected AnnotationType getSelectedAnnotationType() {
672
		if (annotationTypesCombo != null) {
673
			IStructuredSelection isel = (IStructuredSelection)annotationTypesCombo.getSelection();
674
			if (isel.isEmpty()) return null;
675
			return (AnnotationType) isel.getFirstElement();
676
		} else { // simple mode
677
			return tagAnnotationType;
678
		}
679
	}
680

  
681
	protected void affectMatchesToSelection(final List<Match> matches) {
682
		final AnnotationType type = getSelectedAnnotationType();
683
		final String svalue = annotationValuesText.getText();
684
		final boolean doAffect = addRemoveCombo.getSelectionIndex() == 0; // add is default
685

  
686
		JobHandler job = new JobHandler(Messages.ConcordancesEditor_36, true) {
687
			@Override
688
			protected IStatus run(IProgressMonitor monitor) {
689
				this.runInit(monitor);
690
				try {
691
					if (doAffect) {
692
						affectAnnotationValues(matches, type, svalue, this);
693
					} else {
694
						deleteAnnotationValues(matches, type, this);
695
					}
696
				} catch(Exception e) {
697
					Log.severe(Messages.ConcordancesEditor_40+e);
698
					Log.printStackTrace(e);
699
					return Status.CANCEL_STATUS;
700
				} catch(ThreadDeath td) {
701
					System.out.println("Annotation canceled by user.");
702
					return Status.CANCEL_STATUS;
703
				}
704

  
705
				return Status.OK_STATUS;
706
			}
707
		};
708
		job.startJob(true);
709
	}
710

  
711
	public void updateAnnotationWidgetStates() {
712
		if (annotationArea == null) return; // :)
713

  
714
		if (addRemoveCombo.getSelectionIndex() == 0) { // add is default
715

  
716
			if (getSelectedAnnotationType() != null) {
717
				annotationValuesText.setEnabled(true);
718

  
719
				affectAnnotationButton.setEnabled(true);
720
				affectCombo.setEnabled(true);
721
			} else {
722
				annotationValuesText.setEnabled(false);
723

  
724
				affectAnnotationButton.setEnabled(false);
725
				affectCombo.setEnabled(false);
726
			}
727
		} else {
728
			annotationValuesText.setEnabled(false);
729

  
730
			if (getSelectedAnnotationType() != null) {
731
				affectAnnotationButton.setEnabled(true);
732
				affectCombo.setEnabled(true);
733
			} else {
734
				affectAnnotationButton.setEnabled(false);
735
				affectCombo.setEnabled(false);
736
			}
737
		}
738

  
739
		if (advanced_annotation_mode.equals(RCPMessages.AnnotationPreferences_2)) {
740
			if (infosAnnotTypeSelectedLink != null) infosAnnotTypeSelectedLink.setEnabled(getSelectedAnnotationType() != null);
741
		}
742
		if (addTypedValueLink != null) addTypedValueLink.setEnabled(getSelectedAnnotationType() != null);
743

  
744
		if (concordance == null) {
745
			affectAnnotationButton.setEnabled(false);
746
			affectCombo.setEnabled(false);
747
		}
748
	}
749

  
750
	protected void deleteAnnotationValues(List<Match> matches, AnnotationType type, JobHandler job) {
751
		if (concordance == null) return;
752
		if (matches.size() == 0) {
753
			System.out.println("No lines selected. Aborting."); //$NON-NLS-1$
754
			return;
755
		}
756
		if (type == null) return;
757

  
758
		if (concordance != null) {
759
			try {
760
				if (annotManager != null && annotManager.deleteAnnotations(type, matches, job)) {
761
					if (Log.getLevel().intValue() < Level.WARNING.intValue()) annotManager.checkData();
762
					concordance.reloadLines(editor.getTopLine(), editor.getBottomLine()+1);
763
				} else {
764
					return;
765
				}
766
			} catch (Exception e1) {
767
				System.out.println(Messages.ConcordancesEditor_54+e1);
768
				Log.printStackTrace(e1);
769
				return;
770
			}
771

  
772
			job.syncExec(new Runnable() {
773
				@Override
774
				public void run() {
775
					editor.fillDisplayArea(editor.getTopLine(), editor.getBottomLine()+1);
776
					CorporaView.refreshObject(corpus);
777
				}
778
			});
779
		}
780
	}
781
	
782
	protected void affectAnnotationValues(final List<Match> matches,  final AnnotationType type, final String svalue, JobHandler job) {
783
		value_to_add = null; // reset
784
		if (concordance == null) {
785
			System.out.println("No concordance done. Aborting."); //$NON-NLS-1$
786
			return;
787
		}
788
		if (matches.size() == 0) {
789
			System.out.println("No line selected. Aborting."); //$NON-NLS-1$
790
			return;
791
		}
792
		if (type == null) return; // no type, no annotation
793

  
794
		job.syncExec(new Runnable() {
795
			@Override
796
			public void run() {
797
				if (matches.size() > NALERTAFFECTANNOTATIONS) {
798
					ConfirmDialog dialog = new ConfirmDialog(Display.getCurrent().getActiveShell(), 
799
							"confirm_annotate",  //$NON-NLS-1$
800
							Messages.ConcordancesEditor_86, 
801
							Messages.ConcordancesEditor_87+matches.size()+Messages.ConcordancesEditor_108);
802

  
803
					if (dialog.open() == ConfirmDialog.CANCEL) {
804
						System.out.println("Annotation aborted by user."); //$NON-NLS-1$
805
						matches.clear();
806
					}
807
				}
808
			}
809
		});
810

  
811
		// get value from combo text value
812
		Log.warning(Messages.ConcordancesEditor_57+svalue);
813
		final KnowledgeRepository kr = KnowledgeRepositoryManager.getKnowledgeRepository(type.getKnowledgeRepository());
814
		value_to_add = kr.getValue(type, svalue);
815

  
816

  
817
		if (value_to_add == null && kr instanceof LocalKnowledgeRepository) { // create or not the annotation is simple mode
818
			job.syncExec(new Runnable() {
819
				@Override
820
				public void run() {
821
					String title = kr.getString(editor.getLocale(), "ConcordancesEditor_110");
822
					String content = kr.getString(editor.getLocale(), "ConcordancesEditor_112");
823
					if (title == null ) title = Messages.ConcordancesEditor_110;
824
					if (content == null ) content = Messages.ConcordancesEditor_112;
825
					ConfirmDialog dialog = new ConfirmDialog(Display.getCurrent().getActiveShell(), 
826
							"create_value", //$NON-NLS-1$
827
							Messages.bind(title, svalue, type.getName()),  
828
							Messages.bind(content, svalue, type.getName()));
829
					if (dialog.open() == ConfirmDialog.CANCEL) {
830
						System.out.println("Annotation aborted by user."); //$NON-NLS-1$
831
						return;
832
					} else {
833
						value_to_add = kr.addValue(svalue, svalue, type.getId());
834
						KRView.refresh();
835
					}
836
				}
837
			});
838
		}
839

  
840
		if (value_to_add == null && kr instanceof LocalKnowledgeRepository) return; // canceled
841

  
842
		if (value_to_add == null) {	
843
			job.syncExec(new Runnable() {
844
				@Override
845
				public void run() {
846
					String mess = Messages.bind(Messages.ConcordancesEditor_58, svalue);
847
					System.out.println(mess);
848
					MessageDialog.openError(Display.getCurrent().getActiveShell(), "Annotation canceled", mess); //$NON-NLS-1$
849
				}
850
			});
851
			return;
852
		}
853

  
854
		Log.info(Messages.ConcordancesEditor_59+value_to_add+Messages.ConcordancesEditor_60+matches);
855

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

  
860
			// did we had problems ?
861
			if (existingAnnots!=null && existingAnnots.size() > 0) {
862
				String message = Messages.ConcordancesEditor_61+value_to_add.getStandardName()+
863
						Messages.ConcordancesEditor_62;
864
				for (Match m : existingAnnots.keySet()) {
865
					message += Messages.ConcordancesEditor_63+m+Messages.ConcordancesEditor_64;
866

  
867
					for (Annotation existingAnnot : existingAnnots.get(m)) {
868
						if (existingAnnot.getStart() < m.getStart()){
869
							message += Messages.ConcordancesEditor_65+existingAnnot.getType()+Messages.ConcordancesEditor_66+existingAnnot.getStart()+Messages.ConcordancesEditor_67+existingAnnot.getEnd()+Messages.ConcordancesEditor_68;
870
						} else {
871
							message += Messages.ConcordancesEditor_69+existingAnnot.getType()+Messages.ConcordancesEditor_70+existingAnnot.getStart()+Messages.ConcordancesEditor_71+existingAnnot.getEnd()+Messages.ConcordancesEditor_72;
872
						}
873
					}
874
				}
875
				final String final_message = message;
876
				job.syncExec(new Runnable() {
877
					@Override
878
					public void run() {
879
						MessageDialog.openInformation(editor.getSite().getShell(), Messages.ConcordancesEditor_73, final_message);
880
					}
881
				});
882
			}
883
			//				if (history != null && !history.get(type).contains(value_to_add))
884
			//					history.get(type).add(value_to_add);
885

  
886
			if (Log.getLevel().intValue() < Level.WARNING.intValue() && annotManager != null) annotManager.checkData();
887
			concordance.reloadLines(editor.getTopLine(), editor.getBottomLine()+1);
888
		} catch (Exception e1) {
889
			System.out.println(Messages.ConcordancesEditor_74+e1);
890
			Log.printStackTrace(e1);
891
			return;
892
		}
893

  
894
		job.syncExec(new Runnable() {
895
			@Override
896
			public void run() {
897
				editor.fillDisplayArea(editor.getTopLine(), editor.getBottomLine()+1);
898
				CorporaView.refreshObject(corpus);
899
			}
900
		});
901

  
902
	}
903

  
904
	@Override
905
	public boolean notifyStartOfCompute() throws Exception {
906
		if (annotationArea != null) {
907
			AnnotationType type = getSelectedAnnotationType();
908
			if (type != null) {
909
				annotations.setViewAnnotation(type);
910
				annotations.setAnnotationOverlap(true);
911
			}
912
		}
913
		return true;
914
	}
915

  
916
	@Override
917
	public boolean notifyEndOfCompute() throws Exception {
918
		updateAnnotationWidgetStates();
919
		
920
		// update annotation column width
921
		if (annotationArea != null) {
922
			annotationColumn.pack();
923

  
924
			annotationColumn.setResizable(true);
925
		} else { 
926
			annotationColumn.setWidth(0);
927
		}
928
		
929
		return true;
930
	}
931
	
932

  
933
	public boolean isAnnotationEnable() {
934
		return annotationArea != null;
935
	}
936
}
0 937

  
tmp/org.txm.annotation.rcp/plugin.xml (revision 517)
7 7
            categoryId="org.txm.rcp.category.txm"
8 8
            defaultHandler="org.txm.rcp.commands.workspace.RecodeCorpus"
9 9
            id="org.txm.rcp.commands.workspace.RecodeCorpus"
10
            name="%command.name.100">
10
            name="Recode Corpus">
11 11
      </command>
12 12
            <command
13 13
            categoryId="org.txm.rcp.category.txm"
14 14
            defaultHandler="org.txm.annotation.rcp.commands.SaveAnnotations"
15 15
            id="org.txm.rcp.commands.annotation.SaveAnnotations"
16
            name="%command.name.97">
16
            name="Save annotations">
17 17
      </command>
18 18
            <command
19 19
            defaultHandler="org.txm.annotation.rcp.commands.krview.OpenKRView"
20 20
            id="org.txm.rcp.commands.krview.OpenKRView"
21
            name="%command.name.99">
21
            name="Open KR View">
22 22
      </command>
23 23
      <command
24 24
            defaultHandler="org.txm.annotation.rcp.commands.krview.Copy"
25 25
            id="org.txm.rcp.commands.krview.Copy"
26
            name="%command.name.101">
26
            name="Copy">
27 27
      </command>
28 28
      <command
29 29
            defaultHandler="org.txm.annotation.rcp.commands.krview.Reload"
30 30
            id="org.txm.rcp.commands.krview.Reload"
31
            name="%command.name.102">
31
            name="Reload">
32 32
      </command>
33 33
      <command
34 34
            defaultHandler="org.txm.annotation.rcp.commands.krview.Informations"
35 35
            id="org.txm.rcp.commands.krview.Informations"
36
            name="%command.name.103">
36
            name="Informations">
37 37
      </command>
38 38
      <command
39 39
            defaultHandler="org.txm.annotation.rcp.commands.krview.Delete"
40 40
            id="org.txm.rcp.commands.krview.Delete"
41
            name="%command.name.104">
41
            name="Delete">
42 42
      </command>
43 43
      <command
44 44
            defaultHandler="org.txm.annotation.rcp.commands.krview.Add"
45 45
            id="org.txm.rcp.commands.krview.Add"
46
            name="%command.name.105">
46
            name="Add">
47 47
      </command>
48 48
      <command
49 49
            defaultHandler="org.txm.annotation.rcp.commands.ExportStandoff"
50 50
            id="org.txm.rcp.commands.annotation.ExportStandoff"
51
            name="%command.name.107">
51
            name="Export annotations">
52 52
      </command>
53 53
   </extension>
54 54
  <extension
......
57 57
           category="org.txm.rcp.preferences.UserPreferencePage"
58 58
           class="org.txm.annotation.rcp.preferences.AnnotationPreferencePage"
59 59
           id="org.txm.rcp.preferences.AnnotationPreferencePage"
60
           name="%page.name.23">
60
           name="Annotation">
61 61
     </page>
62 62
  </extension>
63
     <extension
64
         point="org.eclipse.ui.views">
65
      <view
66
            category="org.txm.rcp"
67
            class="org.txm.annotation.rcp.views.knowledgerepositories.KRView"
68
            id="org.txm.rcp.views.knowledgerepositories.KRView"
69
            name="KR"
70
            restorable="true">
71
      </view>
72
   </extension>
63 73
  <extension
64 74
         point="org.eclipse.ui.bindings">
65 75
      <key
......
100 110
           locationURI="menu:menu.display.views">
101 111
           <command
102 112
                     commandId="org.txm.rcp.commands.krview.OpenKRView"
103
                     label="%command.label.150"
113
                     label="KR"
104 114
                     style="push">
105 115
               </command>
106 116
     </menuContribution>
......
108 118
            locationURI="popup:org.txm.rcp.views.knowledgerepositories.KRView">
109 119
         <command
110 120
               commandId="org.txm.rcp.commands.krview.Copy"
111
               label="%command.label.188"
112 121
               style="push"
113 122
               tooltip="%command.tooltip.89">
114 123
         </command>
115 124
         <command
116 125
               commandId="org.txm.rcp.commands.krview.Reload"
117
               label="%command.label.189"
118 126
               style="push"
119 127
               tooltip="%command.tooltip.90">
120 128
            <visibleWhen
......
126 134
         </command>
127 135
         <command
128 136
               commandId="org.txm.rcp.commands.krview.Informations"
129
               label="%command.label.190"
130 137
               style="push"
131 138
               tooltip="%command.tooltip.93">
132 139
         </command>
133 140
         <command
134 141
               commandId="org.txm.rcp.commands.krview.Add"
135
               label="%command.label.191"
136 142
               style="push"
137 143
               tooltip="%command.tooltip.94">
138 144
            <visibleWhen
......
149 155
         </command>
150 156
         <command
151 157
               commandId="org.txm.rcp.commands.krview.Delete"
152
               label="%command.label.192"
153 158
               style="push"
154 159
               tooltip="%command.tooltip.95">
155 160
            <visibleWhen
......
171 176
           <command
172 177
                     commandId="org.txm.rcp.commands.annotation.ExportStandoff"
173 178
                     id="menu.file.export.exporttei"
174
                     label="%command.label.193"
179
                     label="Export annotations"
175 180
                     style="push">
176 181
                  <visibleWhen
177 182
                        checkEnabled="false">
......
309 314
            </definition>
310 315
  </extension>
311 316
  <extension
312
        point="org.txm.concordance.rcp.concordanceeditor.button">
313
     <button
314
           class="org.txm.annoation.rcp.concordance.AnnotationButton"
317
        point="org.txm.concordance.rcp.editors.ConcordanceEditorExtension">
318
     <concextension
319
           class="org.txm.annotation.rcp.concordance.ConcordanceAnnotationExtension"
315 320
           name="Annotation">
316
     </button>
321
     </concextension>
317 322
  </extension>
318 323
</plugin>
tmp/org.txm.concordance.core/META-INF/MANIFEST.MF (revision 517)
4 4
Bundle-SymbolicName: org.txm.concordance.core;singleton:=true
5 5
Bundle-Version: 1.0.0.qualifier
6 6
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
7
Require-Bundle: org.txm.annotation.core;bundle-version="1.0.0";visibility:=reexport,
8
 org.txm.utils;bundle-version="1.0.0";visibility:=reexport,
7
Require-Bundle: org.txm.utils;bundle-version="1.0.0";visibility:=reexport,
9 8
 org.txm.searchengine.cqp.core;bundle-version="1.1.0";visibility:=reexport,
10 9
 org.eclipse.osgi;bundle-version="3.10.2",
11 10
 org.eclipse.core.runtime;bundle-version="3.10.0",
tmp/org.txm.concordance.core/src/org/txm/concordance/core/functions/Concordance.java (revision 517)
43 43
import java.util.Map;
44 44

  
45 45
import org.eclipse.core.runtime.IProgressMonitor;
46
import org.txm.annotation.core.Annotation;
47
import org.txm.annotation.core.AnnotationManager;
48
import org.txm.annotation.core.KRAnnotationEngine;
49
import org.txm.annotation.core.repository.AnnotationType;
50
import org.txm.annotation.core.repository.TypedValue;
51 46
import org.txm.concordance.core.functions.comparators.LineComparator;
52 47
import org.txm.concordance.core.messages.ConcordanceMessages;
53 48
import org.txm.concordance.core.preferences.ConcordancePreferences;
......
91 86
	/** The n lines. */
92 87
	private int nLines;
93 88

  
94
	private boolean overlapAnnotation;
95

  
96 89
	String pCQLLimit;
97 90
	/** The keyword analysis property. */
98 91
	private List<Property> pKeywordAnalysisProperties;
......
123 116
	/** The symbol. */
124 117
	private String symbol;
125 118

  
126
	private AnnotationType viewAnnotation;
127

  
128 119
	/** The writer. */
129 120
	private Writer writer;
130 121

  
......
284 275
		return true;
285 276
	}
286 277

  
287
	private String findAnnotationForLine(Match match, List<Annotation> annots, boolean overlap) {
288
		String annotationValue = "";
289
		if (annots!=null) {
290
			if (!annots.isEmpty()) {
291
				for (Annotation annot : annots) {
292
					if (overlap) {
293
						if ((annot.getStart()<=match.getStart() && annot.getEnd()>=match.getEnd()) || (annot.getStart()>match.getStart() && annot.getEnd()<match.getEnd())
294
								) {
295
							annotationValue = annot.getValue(); 
296
							// use the first Annotation found, the one stored in the temporary HSQL database
297
							//should be modified to display a list of annotation values corresponding to the match positions (or wrapped if overlap is admitted)
298
						}
299
					} else {
300
						if (annot.getStart()==match.getStart() && annot.getEnd()==match.getEnd()) {
301
							annotationValue = annot.getValue(); 
302
							// use the first Annotation found, the one stored in the temporary HSQL database
303
						}
304
					}
305
				}
306
			}
307
		}
... Ce différentiel a été tronqué car il excède la taille maximale pouvant être affichée.

Formats disponibles : Unified diff