Révision 4027

TXM/trunk/bundles/org.txm.annotation.kr.core/src/org/txm/annotation/kr/core/AnnotationManager.java (revision 4027)
194 194
	 * 
195 195
	 * CQP Annotations must be shadowed by temporary annotations of the same type and positions
196 196
	 */
197
	public List<Annotation> getAnnotationsForMatches(AnnotationType type, List<Match> matches, boolean overlap) {
197
	public List<Annotation> getAnnotationsForMatches(AnnotationType type, List<Match> subsetMatches, boolean overlap) {
198
		
198 199
		List<Annotation> temporaryAnnotations = null;
199 200
		List<Annotation> resultAnnotations = new ArrayList<>();
200 201
		try {
201
			temporaryAnnotations = tempManager.getAnnotations(type, matches, null, false, overlap);
202
			temporaryAnnotations = tempManager.getAnnotationsForMatches(matches, temporaryAnnotations, overlap);
202
			temporaryAnnotations = tempManager.getAnnotations(type, subsetMatches, null, false, overlap);
203
			temporaryAnnotations = tempManager.getAnnotationsForMatches(subsetMatches, temporaryAnnotations, overlap);
203 204
			
204
			List<? extends Annotation> cqpAnnotations = cqpManager.getAnnotationsForMatches(matches, type, overlap);
205
			List<? extends Annotation> cqpAnnotations = cqpManager.getAnnotationsForMatches(subsetMatches, type, overlap);
205 206
			
206 207
			// System.out.println("Temporary annotations: "+temporaryAnnotations);
207 208
			// System.out.println("CQP annotations: "+cqpAnnotations);
208
			if (cqpAnnotations.size() != matches.size() || temporaryAnnotations.size() != matches.size()) {
209
			if (cqpAnnotations.size() != subsetMatches.size() || temporaryAnnotations.size() != subsetMatches.size()) {
209 210
				Log.info("ERROR in getAnnotationsForMatches methods! "); //$NON-NLS-1$
210
				return new ArrayList<>(matches.size());
211
				return new ArrayList<>(subsetMatches.size());
211 212
			}
212 213
			// merge the 2 results
213
			for (int i = 0; i < matches.size(); i++) {
214
			for (int i = 0; i < subsetMatches.size(); i++) {
214 215
				if (cqpAnnotations.get(i) == null && temporaryAnnotations.get(i) == null) {
215 216
					resultAnnotations.add(null);
216 217
				}
......
227 228
		}
228 229
		catch (Exception e) {
229 230
			e.printStackTrace();
230
			return new ArrayList<>(matches.size());
231
			return new ArrayList<>(subsetMatches.size());
231 232
		}
232 233
		return resultAnnotations;
233 234
	}
......
385 386
		return temporaryAnnotations;
386 387
	}
387 388
	
388
	public List<Annotation> getAnnotations(AnnotationType type, int i, int j) {
389
		return getAnnotations(type, i, j, false);
389
	public List<Annotation> getAnnotations(AnnotationType type, boolean overlap) {
390
		List<Annotation> temporaryAnnotations = null;
391
		List<Annotation> cqpAnnotations = null;
392
		try {
393
			temporaryAnnotations = tempManager.getAnnotations(type, true);
394
			cqpAnnotations = cqpManager.getAnnotations(type, overlap);
395
			
396
			int i = 0;
397
			for (Annotation a : cqpAnnotations) {
398
				while (temporaryAnnotations.get(i).getStart() < a.getStart()) {
399
					i++;
400
				}
401
				temporaryAnnotations.add(i, a);
402
			}
403
		}
404
		catch (Exception e) {
405
			
406
		}
407
		return temporaryAnnotations;
390 408
	}
391 409
	
410
	public List<Annotation> getAnnotations(AnnotationType type, int start, int end) {
411
		return getAnnotations(type, start, end, false);
412
	}
413
	
392 414
	public void closeAll() {
393 415
		Log.fine("Closing annotation manager of " + corpus); //$NON-NLS-1$
394 416
		tempManager.close();
TXM/trunk/bundles/org.txm.annotation.kr.core/src/org/txm/annotation/kr/core/CQPAnnotationManager.java (revision 4027)
4 4
import java.util.ArrayList;
5 5
import java.util.HashMap;
6 6
import java.util.List;
7
import java.util.regex.Pattern;
7 8

  
8 9
import org.osgi.service.prefs.BackingStoreException;
9 10
import org.txm.annotation.kr.core.repository.AnnotationEffect;
......
72 73
	 * @throws IOException
73 74
	 */
74 75
	public List<Annotation> getAnnotations(AnnotationType type, Match match, String value, boolean overlap) throws CqiClientException, IOException, CqiServerError {
76
		if (type == null || type.getEffect().equals(AnnotationEffect.SEGMENT)) {
77
			return getSegmentAnnotations(type, match, value, overlap);
78
		} else {
79
			return getTokenAnnotations(type, match, value, overlap);
80
		}
81
	}
82
	
83
	/**
84
	 * 
85
	 * @param matches Ordered matches, not null
86
	 * @param type not null
87
	 * @param overlap use true to detect overlapping annotations
88
	 * @return ONE Annotation per Match for a given type
89
	 * 
90
	 * @throws CqiServerError
91
	 * @throws IOException
92
	 * @throws CqiClientException
93
	 */
94
	public List<Annotation> getTokenAnnotations(AnnotationType type, Match subsetMatch, String value, boolean overlap) throws IOException, CqiServerError, CqiClientException {
95
		
96
		Property prop = corpus.getProperty(type.getId().toLowerCase());
97
		if (prop == null) return nullAnnotationList(0); // no property, no annotation :)
98
		
99
		AbstractCqiClient cqi = CQPSearchEngine.getCqiClient();
100
		
101
		int start = corpus.getFirstPosition();
102
		int n = corpus.getSize();
103
		
104
		if (subsetMatch != null) { // use a subset instead of all the corpus
105
			start = subsetMatch.getStart();
106
			n = subsetMatch.size();
107
		}
108
		
109
		int i = 0;
110
		int positions[] = new int[n];
111
		for (i = 0 ; i < n ; i++) {
112
			positions[i] = start + i;
113
		}
114
		
115
		String[] strs = cqi.cpos2Str(prop.getQualifiedName(), positions);
116
		
117
		Pattern pattern = null;
118
		if (value != null) pattern = Pattern.compile(value);
119
		
120
		ArrayList<Annotation> annotations = new ArrayList<Annotation>();
121
		i = 0;
122
		for (String str : strs) {
123
			int p = positions[i++];
124
			if (value == null || pattern.matcher(str).matches()) {
125
				annotations.add(new CQPAnnotation(type.getId(), str, p, p));
126
			}
127
		}
128
		// Log.info("TOKEN ANNOTATION CQP VALUES: "+annotations);
129
		return annotations;
130
	}
131
	
132
	/**
133
	 * Return all annotations for ONE match
134
	 * can be use to find out overlap
135
	 * 
136
	 * @param match can be null
137
	 * @param value can be null
138
	 * @param overlap
139
	 * @return
140
	 * @throws CqiClientException
141
	 * @throws CqiServerError
142
	 * @throws IOException
143
	 */
144
	public List<Annotation> getSegmentAnnotations(AnnotationType type, Match match, String value, boolean overlap) throws CqiClientException, IOException, CqiServerError {
75 145
		HashMap<StructuralUnitProperty, AnnotationType> supList = new HashMap<StructuralUnitProperty, AnnotationType>();
76 146
		
77 147
		// TODO add a corpus parameters for structures that code annotations
TXM/trunk/bundles/org.txm.edition.rcp/src/org/txm/edition/rcp/editors/EditionPanel.java (revision 4027)
1 1
package org.txm.edition.rcp.editors;
2 2

  
3 3
import java.io.File;
4
import java.io.IOException;
4 5
import java.net.URL;
5 6
import java.util.ArrayList;
6 7
import java.util.Arrays;
......
50 51
import org.txm.rcp.editors.TXMBrowserEditor;
51 52
import org.txm.rcp.editors.menu.PagePropertiesMenu;
52 53
import org.txm.rcp.utils.IOClipboard;
54
import org.txm.searchengine.cqp.clientExceptions.CqiClientException;
55
import org.txm.searchengine.cqp.serverException.CqiServerError;
53 56
import org.txm.utils.io.IOUtils;
54 57
import org.txm.utils.logger.Log;
55 58

  
......
1154 1157
	/**
1155 1158
	 * Next text.
1156 1159
	 */
1157
	public void nextText() {
1160
	public Text getNextText() {
1158 1161
		
1159 1162
		// Text current = this.currentPage.getEdition().getText();
1160 1163
		Project project = currentText.getProject();
1161 1164
		String id;
1162
		try {
1163
			String[] ids = this.synopticEditionEditor.getCorpus().getCorpusTextIdsList();
1164
			String currentId = currentText.getName();
1165
			int idx = 0;
1166
			for (int i = 0; i < ids.length; i++) {
1167
				if (currentId.equals(ids[i])) {
1168
					idx = i;
1169
					break;
1165
		
1166
			String[] ids;
1167
			try {
1168
				ids = this.synopticEditionEditor.getCorpus().getCorpusTextIdsList();
1169
				
1170
				String currentId = currentText.getName();
1171
				int idx = 0;
1172
				for (int i = 0; i < ids.length; i++) {
1173
					if (currentId.equals(ids[i])) {
1174
						idx = i;
1175
						break;
1176
					}
1170 1177
				}
1178
				if (idx < ids.length - 1) idx++;
1179
				id = ids[idx];
1180
			} catch (Exception e) {
1181
				// TODO Auto-generated catch block
1182
				e.printStackTrace();
1183
				return currentText;
1171 1184
			}
1172
			if (idx < ids.length - 1) idx++;
1173
			id = ids[idx];
1174
		}
1175
		catch (Exception e) {
1176
			e.printStackTrace();
1177
			return;
1178
		}
1179
		Text nextText = project.getText(id);
1185
			
1180 1186
		
1187
		return project.getText(id);
1188
	}
1189
	
1190
	/**
1191
	 * Next text.
1192
	 */
1193
	public void nextText() {
1194
		
1195
		Text nextText = getNextText();
1196
		
1181 1197
		if (nextText != null) {
1182 1198
			String editionName = currentEdition.getName();
1183 1199
			Edition tmp = nextText.getEdition(editionName);
TXM/trunk/bundles/org.txm.edition.rcp/src/org/txm/edition/rcp/editors/RGBA.java (revision 4027)
1 1
package org.txm.edition.rcp.editors;
2 2

  
3 3
import java.awt.Color;
4
import java.util.HashMap;
4 5

  
5 6
public class RGBA {
6 7
	public int r=0, g=0, b=0;
......
17 18
	public RGBA(String rgbOrrgba) {
18 19
		if (rgbOrrgba.startsWith("#")) { //$NON-NLS-1$
19 20
			
20
			Color c = HexToColor(rgbOrrgba);
21
			Color c = hexToColor(rgbOrrgba);
21 22
			
22 23
			this.r = c.getRed();
23 24
			this.g = c.getGreen();
......
40 41
		this.a = a;
41 42
	}
42 43
	
44
	static HashMap<String, String> nameToHex;
45
	static {
46
		nameToHex = new HashMap<String, String>();
47
		String[] ss = {"AliceBlue","#F0F8FF","AntiqueWhite","#FAEBD7","Aqua","#00FFFF","Aquamarine","#7FFFD4","Azure","#F0FFFF","Beige","#F5F5DC","Bisque","#FFE4C4","Black","#000000","BlanchedAlmond","#FFEBCD","Blue","#0000FF","BlueViolet","#8A2BE2","Brown","#A52A2A","BurlyWood","#DEB887","CadetBlue","#5F9EA0","Chartreuse","#7FFF00","Chocolate","#D2691E","Coral","#FF7F50","CornflowerBlue","#6495ED","Cornsilk","#FFF8DC","Crimson","#DC143C","Cyan","#00FFFF","DarkBlue","#00008B","DarkCyan","#008B8B","DarkGoldenRod","#B8860B","DarkGray","#A9A9A9","DarkGrey","#A9A9A9","DarkGreen","#006400","DarkKhaki","#BDB76B","DarkMagenta","#8B008B","DarkOliveGreen","#556B2F","DarkOrange","#FF8C00","DarkOrchid","#9932CC","DarkRed","#8B0000","DarkSalmon","#E9967A","DarkSeaGreen","#8FBC8F","DarkSlateBlue","#483D8B","DarkSlateGray","#2F4F4F","DarkSlateGrey","#2F4F4F","DarkTurquoise","#00CED1","DarkViolet","#9400D3","DeepPink","#FF1493","DeepSkyBlue","#00BFFF","DimGray","#696969","DimGrey","#696969","DodgerBlue","#1E90FF","FireBrick","#B22222","FloralWhite","#FFFAF0","ForestGreen","#228B22","Fuchsia","#FF00FF","Gainsboro","#DCDCDC","GhostWhite","#F8F8FF","Gold","#FFD700","GoldenRod","#DAA520","Gray","#808080","Grey","#808080","Green","#008000","GreenYellow","#ADFF2F","HoneyDew","#F0FFF0","HotPink","#FF69B4","IndianRed","#CD5C5C","Indigo","#4B0082","Ivory","#FFFFF0","Khaki","#F0E68C","Lavender","#E6E6FA","LavenderBlush","#FFF0F5","LawnGreen","#7CFC00","LemonChiffon","#FFFACD","LightBlue","#ADD8E6","LightCoral","#F08080","LightCyan","#E0FFFF","LightGoldenRodYellow","#FAFAD2","LightGray","#D3D3D3","LightGrey","#D3D3D3","LightGreen","#90EE90","LightPink","#FFB6C1","LightSalmon","#FFA07A","LightSeaGreen","#20B2AA","LightSkyBlue","#87CEFA","LightSlateGray","#778899","LightSlateGrey","#778899","LightSteelBlue","#B0C4DE","LightYellow","#FFFFE0","Lime","#00FF00","LimeGreen","#32CD32","Linen","#FAF0E6","Magenta","#FF00FF","Maroon","#800000","MediumAquaMarine","#66CDAA","MediumBlue","#0000CD","MediumOrchid","#BA55D3","MediumPurple","#9370DB","MediumSeaGreen","#3CB371","MediumSlateBlue","#7B68EE","MediumSpringGreen","#00FA9A","MediumTurquoise","#48D1CC","MediumVioletRed","#C71585","MidnightBlue","#191970","MintCream","#F5FFFA","MistyRose","#FFE4E1","Moccasin","#FFE4B5","NavajoWhite","#FFDEAD","Navy","#000080","OldLace","#FDF5E6","Olive","#808000","OliveDrab","#6B8E23","Orange","#FFA500","OrangeRed","#FF4500","Orchid","#DA70D6","PaleGoldenRod","#EEE8AA","PaleGreen","#98FB98","PaleTurquoise","#AFEEEE","PaleVioletRed","#DB7093","PapayaWhip","#FFEFD5","PeachPuff","#FFDAB9","Peru","#CD853F","Pink","#FFC0CB","Plum","#DDA0DD","PowderBlue","#B0E0E6","Purple","#800080","RebeccaPurple","#663399","Red","#FF0000","RosyBrown","#BC8F8F","RoyalBlue","#4169E1","SaddleBrown","#8B4513","Salmon","#FA8072","SandyBrown","#F4A460","SeaGreen","#2E8B57","SeaShell","#FFF5EE","Sienna","#A0522D","Silver","#C0C0C0","SkyBlue","#87CEEB","SlateBlue","#6A5ACD","SlateGray","#708090","SlateGrey","#708090","Snow","#FFFAFA","SpringGreen","#00FF7F","SteelBlue","#4682B4","Tan","#D2B48C","Teal","#008080","Thistle","#D8BFD8","Tomato","#FF6347","Turquoise","#40E0D0","Violet","#EE82EE","Wheat","#F5DEB3","White","#FFFFFF","WhiteSmoke","#F5F5F5","Yellow","#FFFF00","Color Mixer","Color Picker","YellowGreen","#9ACD32"};
48
		for (int i = 0 ; i < ss.length ; i = i+2) {
49
			nameToHex.put(ss[i].toLowerCase(), ss[i+1]);
50
		}
51
	}
52
	
43 53
	/**
54
	 * Convert a CSS color name to its HEX code
55
	 * @return Hex color code
56
	 */
57
	public static String nameToHex(String name) {
58
		
59
		String hex = nameToHex.get(name.toLowerCase());
60
		if (hex != null) {
61
			return hex+"FF";
62
		}
63
		return "#FF FF FF FF";
64
	}
65
	
66
	/**
67
	 * Convert a CSS color name to a java.awt.Color
68
	 * 
69
	 * @return Color
70
	 */
71
	public static Color nameToColor(String name) {
72
		
73
		String hex = nameToHex.get(name);
74
		if (hex != null) {
75
			return hexToColor(nameToHex.get(name)+"FF");
76
		}
77
		return new Color(255,255,255);
78
	}
79
	
80
	/**
44 81
	 * Converts a hex string to a color. If it can't be converted null is returned.
45 82
	 * @param hex (i.e. #CCCCCCFF or CCCCCC)
46 83
	 * @return Color
47 84
	 */
48
	public static Color HexToColor(String hex) 
49
	{
85
	public static Color hexToColor(String hex) {
86
		
50 87
	    hex = hex.replace("#", ""); //$NON-NLS-1$ //$NON-NLS-2$
88
	    hex = hex.replace(" ", ""); //$NON-NLS-1$ //$NON-NLS-2$
51 89
	    switch (hex.length()) {
52 90
	        case 6:
53 91
	            return new Color(
TXM/trunk/bundles/org.txm.analec.rcp/src/org/txm/annotation/urs/toolbar/UnitToolbar.java (revision 4027)
292 292
	@Override
293 293
	public void clearHighlight() {
294 294
		if (previousSelectedUnitIDS != null) {
295
			if (editor.isDisposed()) {
295
			if (!editor.isDisposed()) {
296 296
				editor.removeHighlightWordsById(selected_unit_color, previousSelectedUnitIDS);
297 297
				editor.removeFontWeightWordsById(previousSelectedUnitIDS);
298 298
			}
TXM/trunk/bundles/org.txm.annotation.kr.rcp/src/org/txm/annotation/kr/rcp/concordance/WordAnnotationToolbar.java (revision 4027)
215 215
		final KnowledgeRepository kr = KnowledgeRepositoryManager.getKnowledgeRepository(type.getKnowledgeRepository());
216 216
		value_to_add = kr.getValue(type, svalue);
217 217
		
218
		
219 218
		if (value_to_add == null && kr instanceof LocalKnowledgeRepository) { // create or not the annotation is simple mode
220 219
			value_to_add = kr.addValue(svalue, svalue, type.getId());
221 220
		}
TXM/trunk/bundles/org.txm.annotation.kr.rcp/src/org/txm/annotation/kr/rcp/edition/WordAnnotationToolbar.java (revision 4027)
1 1
package org.txm.annotation.kr.rcp.edition;
2 2

  
3 3
import java.util.ArrayList;
4
import java.util.Arrays;
4 5
import java.util.HashMap;
6
import java.util.HashSet;
5 7
import java.util.List;
6 8
import java.util.Vector;
7 9
import java.util.logging.Level;
10
import java.util.regex.Pattern;
8 11

  
9 12
import org.eclipse.core.runtime.IProgressMonitor;
10 13
import org.eclipse.core.runtime.IStatus;
......
46 49
import org.txm.annotation.kr.core.repository.TypedValue;
47 50
import org.txm.annotation.kr.rcp.commands.InitializeKnowledgeRepository;
48 51
import org.txm.annotation.kr.rcp.commands.SaveAnnotations;
49
import org.txm.annotation.kr.rcp.concordance.ConcordanceAnnotations;
50 52
import org.txm.annotation.kr.rcp.messages.Messages;
51 53
import org.txm.annotation.kr.rcp.views.knowledgerepositories.KRView;
52 54
import org.txm.annotation.rcp.editor.AnnotationArea;
53 55
import org.txm.annotation.rcp.editor.AnnotationExtension;
54
import org.txm.concordance.core.functions.Concordance;
55 56
import org.txm.concordance.rcp.messages.ConcordanceUIMessages;
56 57
import org.txm.core.messages.TXMCoreMessages;
57 58
import org.txm.core.results.TXMResult;
59
import org.txm.edition.rcp.editors.RGBA;
58 60
import org.txm.edition.rcp.editors.SynopticEditionEditor;
59 61
import org.txm.objects.Match;
60 62
import org.txm.objects.Match2P;
......
65 67
import org.txm.rcp.swt.dialog.ConfirmDialog;
66 68
import org.txm.rcp.swt.provider.SimpleLabelProvider;
67 69
import org.txm.rcp.utils.JobHandler;
70
import org.txm.searchengine.cqp.AbstractCqiClient;
68 71
import org.txm.searchengine.cqp.CQPSearchEngine;
72
import org.txm.searchengine.cqp.clientExceptions.CqiClientException;
69 73
import org.txm.searchengine.cqp.corpus.CQPCorpus;
70 74
import org.txm.searchengine.cqp.corpus.WordProperty;
71 75
import org.txm.utils.AsciiUtils;
72 76
import org.txm.utils.logger.Log;
73 77

  
74 78
public class WordAnnotationToolbar extends AnnotationArea {
75
	
79

  
76 80
	/**
77 81
	 * the limit number of annotation when a confirm dialog box is shown
78 82
	 */
79 83
	protected static final int NALERTAFFECTANNOTATIONS = 100;
80
	
84

  
81 85
	public static final String EMPTYTEXT = ""; //$NON-NLS-1$
82
	
86

  
83 87
	/** The annotation service */
84 88
	protected AnnotationManager annotManager;
85
	
89

  
86 90
	protected SynopticEditionEditor editor;
87
	
91

  
88 92
	/**
89 93
	 * The concordance annotations to show in the concordance column table
90 94
	 */
91 95
	private EditionAnnotations annotations = null;
92
	
96

  
93 97
	/**
94 98
	 * All available annotation types
95 99
	 */
96 100
	protected List<TypedValue> typeValuesList;
97
	
101

  
98 102
	protected ComboViewer annotationTypesCombo;
99
	
103

  
100 104
	protected Label equalLabel;
101
	
105

  
102 106
	protected Text annotationValuesText;
103
	
107

  
104 108
	protected Button affectAnnotationButton;
105
	
109

  
106 110
	protected Button deleteAnnotationButton;
107
	
111

  
108 112
	protected KnowledgeRepository currentKnowledgeRepository = null;
109
	
113

  
110 114
	protected Vector<AnnotationType> typesList = new Vector<>();
111
	
115

  
112 116
	protected AnnotationType tagAnnotationType; // the tag annotation type if annotation mode is simple
113
	
117

  
114 118
	protected TypedValue value_to_add;
115
	
119

  
116 120
	//protected Concordance concordance;
117
	
121

  
118 122
	private CQPCorpus corpus;
119
	
123

  
120 124
	private TableViewerColumn annotationColumnViewer;
121
	
125

  
122 126
	private Font annotationColummnFont;
123
	
127

  
124 128
	private Font defaultColummnFont;
125
	
129

  
126 130
	private Button addAnnotationTypeLink;
127
	
131

  
128 132
	private Button addTypedValueLink;
129
	
133

  
134
	protected Label colorsLabel;
135

  
136
	protected Text colorsValuesText;
137

  
130 138
	@Override
131 139
	public String getName() {
132 140
		return Messages.motsPropritsInfDfaut;
133 141
	}
134
	
142

  
135 143
	@Override
136 144
	public boolean allowMultipleAnnotations() {
137 145
		return true;
138 146
	}
139
	
147

  
140 148
	public WordAnnotationToolbar() {}
141
	
149

  
142 150
	protected AnnotationType getSelectedAnnotationType() {
143 151
		return annotations.getViewAnnotation();
144 152
	}
145
	
153

  
146 154
	public void updateAnnotationWidgetStates() {
147 155
		if (annotationArea == null) return; // :)
148
		
156

  
149 157
		if (getSelectedAnnotationType() != null) {
150 158
			annotationValuesText.setEnabled(true);
151 159
			affectAnnotationButton.setEnabled(true);
......
157 165
			deleteAnnotationButton.setEnabled(false);
158 166
		}
159 167
	}
160
	
168

  
161 169
	protected void affectAnnotationToSelection(String[] word_selection) {
162
		
170

  
171
		if (word_selection == null) return;
172

  
163 173
		ArrayList<Match> matches = new ArrayList<>();
164 174

  
175
		if (word_selection[1] == null) word_selection[1] = word_selection[0];
176

  
165 177
		try {
178
			
166 179
			int[] indexes = CQPSearchEngine.getCqiClient().str2Id(corpus.getProperty("id").getQualifiedName(), word_selection);
167 180
			int[] allPositions = CQPSearchEngine.getCqiClient().idList2Cpos(corpus.getProperty("id").getQualifiedName(), indexes);
168
			for (int p : allPositions) {
181
			for (int p = allPositions[0] ; p <= allPositions[1] ; p++) {
169 182
				matches.add(new Match2P(p));
170 183
			}
171 184
			affectAnnotationsToMatches(matches);
......
174 187
			e.printStackTrace();
175 188
		}
176 189
	}
177
	
190

  
178 191
	protected void affectAnnotationValues(final List<? extends Match> matches, final AnnotationType type, final String svalue, JobHandler job) {
179 192
		value_to_add = null; // reset
180 193
		if (matches == null || matches.size() == 0) {
......
182 195
			return;
183 196
		}
184 197
		if (type == null) return; // no type, no annotation
185
		
198

  
186 199
		job.syncExec(new Runnable() {
187
			
200

  
188 201
			@Override
189 202
			public void run() {
190 203
				if (matches.size() > NALERTAFFECTANNOTATIONS) {
......
192 205
							"confirm_annotate",  //$NON-NLS-1$
193 206
							Messages.confirmAnnotationAffectation,
194 207
							NLS.bind(Messages.youAreAboutToAnnotateP0ElementsContinue, matches.size()));
195
					
208

  
196 209
					if (dialog.open() == ConfirmDialog.CANCEL) {
197 210
						Log.info("Annotation aborted by user.");
198 211
						matches.clear();
......
200 213
				}
201 214
			}
202 215
		});
203
		
216

  
204 217
		// get value from combo text value
205 218
		Log.fine(NLS.bind(Messages.lookingForTypedValueWithIdEqualsP0, svalue));
206 219
		final KnowledgeRepository kr = KnowledgeRepositoryManager.getKnowledgeRepository(type.getKnowledgeRepository());
207 220
		value_to_add = kr.getValue(type, svalue);
208
		
209
		
221

  
222

  
210 223
		if (value_to_add == null && kr instanceof LocalKnowledgeRepository) { // create or not the annotation is simple mode
211 224
			value_to_add = kr.addValue(svalue, svalue, type.getId());
212 225
		}
213
		
226

  
214 227
		if (value_to_add == null) {
215 228
			job.syncExec(new Runnable() {
216
				
229

  
217 230
				@Override
218 231
				public void run() {
219 232
					String mess = Messages.bind(Messages.noValueFoundWithTheP0Id, svalue);
......
223 236
			});
224 237
			return;
225 238
		}
226
		
239

  
227 240
		Log.info(TXMCoreMessages.bind(Messages.AffectP0ToP1SelectionEqualsP2, value_to_add.getId(), value_to_add.getTypeID(), matches.size()));
228
		
241

  
229 242
		// finally we can 'try' to create the annotations \o/
230 243
		try {
231 244
			HashMap<Match, List<Annotation>> existingAnnots = annotManager.createAnnotations(type, value_to_add, matches, job);
232
			
245

  
233 246
			// did we had problems ?
234 247
			if (existingAnnots != null && existingAnnots.size() > 0) {
235 248
				String message = NLS.bind(Messages.couldNotAnnotateTheValueP0OnCertainSequences, value_to_add.getStandardName());
236 249
				for (Match m : existingAnnots.keySet()) {
237 250
					message += NLS.bind(Messages.theSequenceP0IsOverlappingWith, m);
238
					
251

  
239 252
					for (Annotation existingAnnot : existingAnnots.get(m)) {
240 253
						if (existingAnnot.getStart() < m.getStart()) {
241 254
							message += TXMCoreMessages.bind(Messages.theEndOfAStructureP0AtP1P2, existingAnnot.getType(), existingAnnot.getStart(), existingAnnot.getEnd());
......
247 260
				}
248 261
				final String final_message = message;
249 262
				job.syncExec(new Runnable() {
250
					
263

  
251 264
					@Override
252 265
					public void run() {
253 266
						MessageDialog.openInformation(editor.getSite().getShell(), Messages.aboutAnnotations, final_message);
......
256 269
			}
257 270
			// if (history != null && !history.get(type).contains(value_to_add))
258 271
			// history.get(type).add(value_to_add);
259
			
272

  
260 273
			if (Log.getLevel().intValue() < Level.INFO.intValue() && annotManager != null) {
261 274
				annotManager.checkData();
262 275
			}
......
267 280
			Log.printStackTrace(e1);
268 281
			return;
269 282
		}
270
		
283

  
271 284
		job.syncExec(new Runnable() {
272
			
285

  
273 286
			@Override
274 287
			public void run() {
275 288
				try {
......
282 295
			}
283 296
		});
284 297
	}
285
	
298

  
299
	private HashMap<RGBA, HashSet<String>> previousSelectedTypeUnitIDS;
300

  
301
	public void clearHighlight() {
302

  
303
		if (previousSelectedTypeUnitIDS != null) {
304
			if (!editor.isDisposed()) {
305
				for (RGBA color : previousSelectedTypeUnitIDS.keySet()) {
306
					editor.removeHighlightWordsById(color, previousSelectedTypeUnitIDS.get(color));
307
				}
308
			}
309
			previousSelectedTypeUnitIDS = null; // release memory
310
		} else {
311
			previousSelectedTypeUnitIDS = new HashMap<RGBA, HashSet<String>>();
312
		}
313
	}
314

  
286 315
	protected void deleteAnnotationValues(String[] word_selection) {
287
		
316

  
317
		if (word_selection == null) return;
318

  
288 319
		ArrayList<Match> matches = new ArrayList<>();
289 320
		try {
290 321
			int[] indexes = CQPSearchEngine.getCqiClient().str2Id(corpus.getProperty("id").getQualifiedName(), word_selection);
......
297 328
		catch (Exception e) {
298 329
			e.printStackTrace();
299 330
		}
300
		
331

  
301 332
	}
302
	
333

  
303 334
	protected void deleteAnnotationValues(final List<Match> matches) {
304 335
		final AnnotationType type = getSelectedAnnotationType();
305
		
336

  
306 337
		JobHandler job = new JobHandler(Messages.annotatingConcordanceSelection, true) {
307
			
338

  
308 339
			@Override
309 340
			protected IStatus run(IProgressMonitor monitor) {
310 341
				this.runInit(monitor);
311 342
				try {
312 343
					deleteAnnotationValues(matches, type, this);
344
					
345
					this.syncExec(new Runnable() {
346
						
347
						@Override
348
						public void run() {
349
							updateHighlights(null);
350
							editor.updateWordStyles();
351
						}
352
					});
353
					
313 354
				}
314 355
				catch (Exception e) {
315 356
					Log.severe(NLS.bind(Messages.errorWhileAnnotatingConcordanceSelectionColonP0, e));
......
320 361
					Log.info(Messages.annotationCanceledByUser);
321 362
					return Status.CANCEL_STATUS;
322 363
				}
323
				
364

  
324 365
				return Status.OK_STATUS;
325 366
			}
326 367
		};
327 368
		job.startJob(true);
328 369
	}
329
	
370

  
330 371
	protected void deleteAnnotationValues(List<Match> matches, AnnotationType type, JobHandler job) {
331
		
372

  
332 373
		if (matches.size() == 0) {
333 374
			Log.warning("No lines selected. Aborting.");
334 375
			return;
335 376
		}
336
		
377

  
337 378
		if (type == null) {
338 379
			return;
339 380
		}
340
		
381

  
341 382
		try {
342 383
			if (annotManager != null && annotManager.deleteAnnotations(type, matches, job)) {
343 384
				if (Log.getLevel().intValue() < Level.INFO.intValue()) annotManager.checkData();
344
				
385

  
345 386
			}
346 387
			else {
347 388
				return;
......
352 393
			Log.printStackTrace(e1);
353 394
			return;
354 395
		}
355
		
396

  
356 397
		job.syncExec(new Runnable() {
357
			
398

  
358 399
			@Override
359 400
			public void run() {
360 401
				try {
361
					editor.refresh(false);
402
					updateHighlights(null);
403
					editor.updateWordStyles();
362 404
				}
363 405
				catch (Exception e) {
364 406
					Log.printStackTrace(e);
......
366 408
			}
367 409
		});
368 410
	}
369
	
411

  
370 412
	protected void affectAnnotationsToMatches(final List<? extends Match> matches) {
371 413
		final AnnotationType type = getSelectedAnnotationType();
372 414
		final String svalue = annotationValuesText.getText();
373
		
415

  
374 416
		JobHandler job = new JobHandler(Messages.annotatingConcordanceSelection, true) {
375
			
417

  
376 418
			@Override
377 419
			protected IStatus run(IProgressMonitor monitor) {
378 420
				this.runInit(monitor);
379 421
				try {
380 422
					affectAnnotationValues(matches, type, svalue, this);
423
					updateHighlights(null);
424
					
425
					this.syncExec(new Runnable() {
426
						
427
						@Override
428
						public void run() {
429
							editor.updateWordStyles();
430
						}
431
					});
432
					
381 433
				}
382 434
				catch (Exception e) {
383 435
					Log.severe(NLS.bind(Messages.errorWhileAnnotatingConcordanceSelectionColonP0, e));
......
388 440
					Log.info(Messages.annotationCanceledByUser);
389 441
					return Status.CANCEL_STATUS;
390 442
				}
391
				
443

  
392 444
				return Status.OK_STATUS;
393 445
			}
394 446
		};
395 447
		job.startJob(true);
396 448
	}
397
	
449

  
398 450
	@Override
399 451
	public boolean install(TXMEditor<? extends TXMResult> txmeditor, AnnotationExtension ext, Composite parent, int position) throws Exception {
400
		
452

  
401 453
		this.extension = ext;
402 454
		this.editor = (SynopticEditionEditor) txmeditor;
403 455
		this.corpus = editor.getCorpus();
404 456
		this.annotManager = KRAnnotationEngine.getAnnotationManager(corpus);
405 457
		this.annotations = new EditionAnnotations(this.editor);
406
		
458

  
407 459
		// TODO install browser listeners here
408
		
460

  
409 461
		List<KnowledgeRepository> krs = InitializeKnowledgeRepository.get(corpus.getMainCorpus());
410 462
		typesList.clear();
411 463
		Log.fine("Corpus KRs: " + krs); //$NON-NLS-1$
412
		
464

  
413 465
		currentKnowledgeRepository = KnowledgeRepositoryManager.getKnowledgeRepository(corpus.getMainCorpus().getID());
414 466
		if (currentKnowledgeRepository == null) {
415 467
			HashMap<String, HashMap<String, ?>> conf = new HashMap<>();
......
419 471
			conf.put(KRAnnotationEngine.KNOWLEDGE_TYPES, fields);
420 472
			HashMap<String, HashMap<String, String>> strings = new HashMap<>();
421 473
			conf.put(KRAnnotationEngine.KNOWLEDGE_STRINGS, strings);
422
			
474

  
423 475
			access.put("mode", DatabasePersistenceManager.ACCESS_FILE); //$NON-NLS-1$
424 476
			access.put("version", "0"); //$NON-NLS-1$ //$NON-NLS-2$
425 477
			currentKnowledgeRepository = KnowledgeRepositoryManager.createKnowledgeRepository(corpus.getMainCorpus().getID(), conf);
426 478
			KnowledgeRepositoryManager.registerKnowledgeRepository(currentKnowledgeRepository);
427 479
			// KRAnnotationEngine.registerKnowledgeRepositoryName(corpus, corpus.getMainCorpus().getID());
428 480
		}
429
		
481

  
430 482
		List<WordProperty> wordProperties = corpus.getProperties();
431 483
		for (WordProperty p : wordProperties) {
432 484
			if (p.getName().equals("id")) continue; //$NON-NLS-1$
......
439 491
				type.setEffect(AnnotationEffect.TOKEN);
440 492
			}
441 493
		}
442
		
494

  
443 495
		Log.fine("KR: " + currentKnowledgeRepository); //$NON-NLS-1$
444 496
		List<AnnotationType> krtypes = currentKnowledgeRepository.getAllAnnotationTypes();
445 497
		for (AnnotationType type : krtypes) {
......
447 499
				typesList.add(type);
448 500
			}
449 501
		}
450
		
502

  
451 503
		Log.fine(NLS.bind(Messages.availableAnnotationTypesColonP0, typesList));
452
		
504

  
453 505
		annotationArea = new GLComposite(parent, SWT.NONE, Messages.concordanceAnnotationArea);
454 506
		annotationArea.getLayout().numColumns = 12;
455 507
		annotationArea.getLayout().horizontalSpacing = 2;
456 508
		annotationArea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
457
		
509

  
458 510
		GridData gdata = new GridData(SWT.CENTER, SWT.CENTER, false, false);
459 511
		gdata.widthHint = 90;
460
		
512

  
461 513
		new Label(annotationArea, SWT.NONE).setText(TXMCoreMessages.common_property);
462
		
514

  
463 515
		// Display combo with list of Annotation Type
464 516
		annotationTypesCombo = new ComboViewer(annotationArea, SWT.READ_ONLY);
465 517
		annotationTypesCombo.setContentProvider(new ArrayContentProvider());
466 518
		annotationTypesCombo.setLabelProvider(new SimpleLabelProvider() {
467
			
519

  
468 520
			@Override
469 521
			public String getColumnText(Object element, int columnIndex) {
470 522
				return ((AnnotationType) element).getName();
471 523
			}
472
			
524

  
473 525
			@Override
474 526
			public String getText(Object element) {
475 527
				return ((AnnotationType) element).getName();
......
498 550
		// @Override
499 551
		// public void keyPressed(KeyEvent e) { }
500 552
		// });
501
		
553

  
502 554
		gdata = new GridData(SWT.CENTER, SWT.CENTER, false, false);
503 555
		gdata.widthHint = 200;
504
		
556

  
505 557
		annotationTypesCombo.getCombo().setLayoutData(gdata);
506 558
		annotationTypesCombo.setInput(typesList);
507 559
		annotationTypesCombo.getCombo().select(0);
......
513 565
		// annotationColumn.setText(name);
514 566
		// }
515 567
		// }
516
		
568

  
517 569
		annotationTypesCombo.addSelectionChangedListener(new ISelectionChangedListener() {
518
			
570

  
519 571
			@Override
520 572
			public void selectionChanged(SelectionChangedEvent event) {
521 573
				onAnnotationTypeSelected(event);
522 574
			}
523 575
		});
524
		
576

  
525 577
		addAnnotationTypeLink = new Button(annotationArea, SWT.PUSH);
526 578
		addAnnotationTypeLink.setToolTipText(Messages.addANewCategory);
527 579
		addAnnotationTypeLink.setImage(IImageKeys.getImage(IImageKeys.ACTION_ADD));
528 580
		addAnnotationTypeLink.setEnabled(true);
529 581
		addAnnotationTypeLink.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
530 582
		addAnnotationTypeLink.addSelectionListener(new SelectionListener() {
531
			
583

  
532 584
			@Override
533 585
			public void widgetSelected(SelectionEvent e) {
534 586
				if (currentKnowledgeRepository == null) return;
535 587
				if (!(currentKnowledgeRepository instanceof LocalKnowledgeRepository)) return;
536
				
588

  
537 589
				LocalKnowledgeRepository kr = (LocalKnowledgeRepository) currentKnowledgeRepository;
538
				
590

  
539 591
				InputDialog dialog = new InputDialog(e.widget.getDisplay().getActiveShell(), "New property", "Enter the new property name", "", null);
540 592
				if (dialog.open() == InputDialog.OK) {
541 593
					String name = dialog.getValue();
......
549 601
					}
550 602
					AnnotationType type = kr.addType(name, id, "", AnnotationEffect.TOKEN); //$NON-NLS-1$
551 603
					typesList.add(type);
552
					
604

  
553 605
					if (annotationTypesCombo != null) annotationTypesCombo.refresh();
554 606
					if (typesList.size() == 1) {
555 607
						if (annotationTypesCombo != null) annotationTypesCombo.getCombo().select(typesList.size() - 1);
556
						
608

  
557 609
						annotations.setViewAnnotation(type);
558 610
						annotations.setAnnotationOverlap(true);
559 611
						try {
......
564 616
							e1.printStackTrace();
565 617
						}
566 618
						annotationArea.layout(true);
567
						
619

  
568 620
					}
569 621
					else {
570 622
						if (typesList.size() > 1) {
......
583 635
					Log.info("Creation aborted.");
584 636
				}
585 637
			}
586
			
638

  
587 639
			@Override
588 640
			public void widgetDefaultSelected(SelectionEvent e) {}
589 641
		});
590
		
642

  
591 643
		equalLabel = new Label(annotationArea, SWT.NONE);
592 644
		equalLabel.setText("="); //$NON-NLS-1$
593 645
		equalLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
594
		
646

  
595 647
		annotationValuesText = new Text(annotationArea, SWT.BORDER);
596 648
		annotationValuesText.setToolTipText(Messages.enterAValueForAnId);
597 649
		GridData gdata2 = new GridData(SWT.FILL, SWT.CENTER, false, false);
598 650
		gdata2.widthHint = 200;
599 651
		annotationValuesText.setLayoutData(gdata2);
600 652
		annotationValuesText.addKeyListener(new KeyListener() {
601
			
653

  
602 654
			@Override
603 655
			public void keyReleased(KeyEvent e) {
604 656
				if (e.keyCode == SWT.CR || e.keyCode == SWT.KEYPAD_CR) {
605 657
					affectAnnotationToSelection(editor.getEditionPanel(0).getWordSelection());
606 658
				}
607 659
			}
608
			
660

  
609 661
			@Override
610 662
			public void keyPressed(KeyEvent e) {}
611 663
		});
612
		
664

  
613 665
		addTypedValueLink = new Button(annotationArea, SWT.PUSH);
614 666
		addTypedValueLink.setText("..."); //$NON-NLS-1$
615 667
		addTypedValueLink.setToolTipText(Messages.selectAValueAmongTheList);
616 668
		addTypedValueLink.setEnabled(true);
617 669
		addTypedValueLink.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
618 670
		addTypedValueLink.addSelectionListener(new SelectionListener() {
619
			
671

  
620 672
			@Override
621 673
			public void widgetSelected(SelectionEvent e) {
622 674
				if (currentKnowledgeRepository == null) return;
623 675
				if (!(currentKnowledgeRepository instanceof LocalKnowledgeRepository)) return;
624
				
676

  
625 677
				AnnotationType type = getSelectedAnnotationType();
626 678
				if (type == null) return;
627
				
679

  
628 680
				LocalKnowledgeRepository kr = (LocalKnowledgeRepository) currentKnowledgeRepository;
629
				
681

  
630 682
				ListDialog dialog = new ListDialog(e.widget.getDisplay().getActiveShell());
631 683
				String title = currentKnowledgeRepository.getString(editor.getCorpus().getLang(), "ConcordancesEditor_100"); //$NON-NLS-1$
632 684
				if (title == null) title = Messages.availableValuesForP0;
633 685
				dialog.setTitle(ConcordanceUIMessages.bind(title, type.getName()));// +"valeurs de "+type.getName());
634 686
				dialog.setContentProvider(new ArrayContentProvider());
635 687
				dialog.setLabelProvider(new SimpleLabelProvider() {
636
					
688

  
637 689
					@Override
638 690
					public String getColumnText(Object element, int columnIndex) {
639 691
						if (element instanceof TypedValue) {
......
655 707
					TypedValue value = (TypedValue) dialog.getResult()[0];
656 708
					String name = value.getId();
657 709
					if (name.trim().length() == 0) return;
658
					
710

  
659 711
					annotationValuesText.setText(name);
660 712
				}
661 713
				else {
662
					
714

  
663 715
				}
664 716
			}
665
			
717

  
666 718
			@Override
667 719
			public void widgetDefaultSelected(SelectionEvent e) {}
668 720
		});
669
		
721

  
670 722
		new Label(annotationArea, SWT.NONE).setText(" ");
671
		
723

  
672 724
		affectAnnotationButton = new Button(annotationArea, SWT.PUSH);
673 725
		affectAnnotationButton.setText(Messages.oK);
674 726
		affectAnnotationButton.setToolTipText(Messages.proceedToAnnotation);
675 727
		affectAnnotationButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
676 728
		affectAnnotationButton.addSelectionListener(new SelectionListener() {
677
			
729

  
678 730
			@Override
679 731
			public void widgetSelected(SelectionEvent e) {
680 732
				affectAnnotationToSelection(editor.getEditionPanel(0).getWordSelection());
681 733
			}
682
			
734

  
683 735
			@Override
684 736
			public void widgetDefaultSelected(SelectionEvent e) {}
685 737
		});
686
		
738

  
687 739
		deleteAnnotationButton = new Button(annotationArea, SWT.PUSH);
688 740
		deleteAnnotationButton.setText(Messages.delete);
689 741
		deleteAnnotationButton.setToolTipText(Messages.delete);
690 742
		deleteAnnotationButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
691 743
		deleteAnnotationButton.addSelectionListener(new SelectionListener() {
692
			
744

  
693 745
			@Override
694 746
			public void widgetSelected(SelectionEvent e) {
695 747
				deleteAnnotationValues(editor.getEditionPanel(0).getWordSelection());
748
				
696 749
			}
697
			
750

  
698 751
			@Override
699 752
			public void widgetDefaultSelected(SelectionEvent e) {}
700 753
		});
701
		
754

  
702 755
		Button closeButton = new Button(annotationArea, SWT.PUSH);
703 756
		closeButton.setToolTipText(Messages.closeTheToolbarWithoutSaving);
704 757
		closeButton.setImage(IImageKeys.getImage(IImageKeys.ACTION_DELETE));
705
		
758

  
706 759
		closeButton.addSelectionListener(new SelectionListener() {
707
			
760

  
708 761
			@Override
709 762
			public void widgetSelected(SelectionEvent e) {
710 763
				extension.closeArea(WordAnnotationToolbar.this, true);
711 764
			}
712
			
765

  
713 766
			@Override
714 767
			public void widgetDefaultSelected(SelectionEvent e) {}
715 768
		});
716
		
769

  
770

  
771
		colorsLabel = new Label(annotationArea, SWT.NONE);
772
		colorsLabel.setText("Colors"); //$NON-NLS-1$
773
		colorsLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
774

  
775
		colorsValuesText = new Text(annotationArea, SWT.BORDER);
776
		colorsValuesText.setToolTipText(Messages.enterAValueForAnId);
777
		gdata2 = new GridData(SWT.FILL, SWT.CENTER, false, false);
778
		gdata2.widthHint = 200;
779
		colorsValuesText.setLayoutData(gdata2);
780
		colorsValuesText.addKeyListener(new KeyListener() {
781

  
782
			@Override
783
			public void keyReleased(KeyEvent e) {
784
				if (e.keyCode == SWT.CR || e.keyCode == SWT.KEYPAD_CR) {
785
					
786
					updateHighlights(colorsValuesText.getText());
787
					
788
					editor.updateWordStyles();
789
				}
790
			}
791

  
792
			@Override
793
			public void keyPressed(KeyEvent e) {}
794
		});
795

  
796

  
717 797
		updateAnnotationWidgetStates();
718 798
		editor.layout(true);
719
//		ext.getSaveButton().setEnabled(true);
799
		//		ext.getSaveButton().setEnabled(true);
720 800
		return true;
721 801
	}
722 802
	
803
	HashMap<RGBA, String> colorsRules;
804
	public void updateHighlights(String rules) {
805
		
806
		if (rules != null) {
807
			String[] couples = rules.split(",");
808
			
809
			colorsRules = new HashMap<RGBA, String>();
810
			if (couples.length > 0) {
811
				for (String couple : couples) {
812
					String[] colorValue = couple.split("=", 2);
813

  
814
					if (colorValue[0].startsWith("#")) {
815
						colorsRules.put(new RGBA(colorValue[0]), colorValue[1]);
816
					} else {
817
						colorsRules.put(new RGBA(RGBA.nameToHex(colorValue[0])), colorValue[1]);
818
					}
819
				}
820
			}
821
		}
822
		
823
		if (colorsRules == null) return; // nothing to do
824
		
825
		clearHighlight();
826

  
827
		AbstractCqiClient CQI = CQPSearchEngine.getCqiClient();
828
		
829
		try {
830
			WordProperty property = corpus.getProperty(getSelectedAnnotationType().getId());
831
			WordProperty idproperty = corpus.getProperty("id");
832
			
833
//			// Page word positions range (start, end)
834
//			String idstart = editor.getEditionPanel(0).getCurrentPage().getWordId();
835
//			String idend = editor.getEditionPanel(0).getCurrentPage().getLastWordID();
836
//			
837
//			int pStart = CQI.str2Id(idproperty.getQualifiedName(), new String[] {idstart})[0];
838
//			int pEnd = corpus.getSize()-1;
839
//			if (!idstart.equals(idend)) {
840
//				pEnd = CQI.str2Id(idproperty.getQualifiedName(), new String[] {idend})[0];
841
//			} else {
842
//				String text = editor.getEditionPanel(0).getCurrentText().getName();
843
//				org.txm.objects.Text nextText = editor.getEditionPanel(0).getNextText();
844
//				String nextTextName = nextText.getName();
845
//				if (!text.equals(nextTextName)) {
846
//					idend = nextText.getEdition(editor.getEditionPanel(0).getEdition().getName()).getFirstPage().getWordId();
847
//					pEnd = CQI.str2Id(idproperty.getQualifiedName(), new String[] {idend})[0];
848
//				}
849
//			}
850
//			//System.out.println("start="+pStart+" end="+pEnd);
851
//			
852
//			List<Match> matches = new ArrayList<Match>();
853
//			for (int p = pStart ; p <=pEnd ; p++) {
854
//				matches.add(new Match2P(p));
855
//			}
856
			
857
			List<Annotation> annotations = annotManager.getAnnotations(getSelectedAnnotationType(), false);
858
						
859
			//System.out.println("annotations="+annotations);
860
			previousSelectedTypeUnitIDS = new HashMap<RGBA, HashSet<String>>();
861
			for (RGBA color : colorsRules.keySet()) {
862
				
863
				Pattern regex = Pattern.compile(colorsRules.get(color));
864
				// get words per value
865
//				System.out.println("FIND WORDS FOR COLOR AND VALUE "+color+"="+colorsRules.get(color));
866
//				int[] ids = CQI.regex2Id(property.getQualifiedName(), colorsRules.get(color));
867
//				System.out.println("ids="+Arrays.toString(ids));
868
//				int[] positions = CQI.idList2Cpos(property.getQualifiedName(), ids);
869
//				System.out.println("positions="+Arrays.toString(positions));
870
				
871
				// get annotations for the current page range and select those who matches the
872
				List<Integer> positionsList = new ArrayList<Integer>();
873
				
874
				for (Annotation annot : annotations) {
875
					if (regex.matcher(annot.getValue()).matches()) {
876
						positionsList.add(annot.getStart());
877
					}
878
				}
879
				
880
				int[] positions = new int[positionsList.size()];
881
				for (int i = 0 ; i < positionsList.size() ; i++) {
882
					positions[i] = positionsList.get(i);
883
				}
884
				String[] wordIds = CQI.cpos2Str(idproperty.getQualifiedName(), positions);
885
				HashSet<String> h = new HashSet<String>();
886
				for (String a : wordIds) {
887
					h.add(a);
888
				}
889
				//System.out.println("h="+h);
890
				
891
				previousSelectedTypeUnitIDS.put(color, h);
892
				editor.setHighlightWordsById(color, h);
893
				//System.out.println("SET "+h);
894
			}
895
		} catch (Exception e1) {
896
			// TODO Auto-generated catch block
897
			e1.printStackTrace();
898
		}
899
	}
900

  
723 901
	protected void onAnnotationTypeSelected(SelectionChangedEvent event) {
724
		
902

  
725 903
		IStructuredSelection sel = (IStructuredSelection) annotationTypesCombo.getSelection();
726 904
		AnnotationType type = (AnnotationType) sel.getFirstElement();
727 905
		if (type == null) return;
728
		
906

  
729 907
		if (type.getSize() != AnnotationType.ValuesSize.LARGE) {
730 908
			try {
731 909
				KnowledgeRepository kr = KnowledgeRepositoryManager.getKnowledgeRepository(type.getKnowledgeRepository());
......
736 914
				e.printStackTrace();
737 915
			}
738 916
		}
739
		
917

  
740 918
		annotations.setViewAnnotation(type);
741 919
		annotations.setAnnotationOverlap(true);
742 920
		try {
......
746 924
			// TODO Auto-generated catch block
747 925
			e.printStackTrace();
748 926
		}
749
		
927

  
750 928
		updateAnnotationWidgetStates();
751 929
	}
752
	
930

  
753 931
	protected void createNewType(TypedEvent e, String typeName) {
754
		
932

  
755 933
		if (currentKnowledgeRepository == null) return;
756 934
		if (!(currentKnowledgeRepository instanceof LocalKnowledgeRepository)) return;
757
		
935

  
758 936
		LocalKnowledgeRepository kr = (LocalKnowledgeRepository) currentKnowledgeRepository;
759 937
		if (typeName == null) typeName = ""; //$NON-NLS-1$
760 938
		InputDialog dialog = new InputDialog(e.widget.getDisplay().getActiveShell(), Messages.nouvelleProprit, Messages.nomDeLaPropritPatternEqualsazaz09Plus, typeName,
......
773 951
			annotationTypesCombo.refresh();
774 952
			StructuredSelection selection = new StructuredSelection(type);
775 953
			annotationTypesCombo.setSelection(selection, true);
776
			
954

  
777 955
			// if (annotationTypesCombo != null) annotationTypesCombo.refresh();
778 956
			// if (typesList.size() == 1) {
779 957
			// if (annotationTypesCombo != null) annotationTypesCombo.getCombo().select(0);
......
795 973
			// }
796 974
			// KRView.refresh();
797 975
			// updateAnnotationWidgetStates();
798
			
976

  
799 977
			// onAnnotationTypeSelected(null);
800 978
		}
801 979
		else {
802 980
			Log.info("Creation aborted.");
803 981
		}
804 982
	}
805
	
983

  
806 984
	@Override
807 985
	public boolean save() {
808 986
		try {
......
828 1006
			return false;
829 1007
		}
830 1008
	}
831
	
1009

  
832 1010
	@Override
833 1011
	public boolean hasChanges() {
834 1012
		AnnotationManager am;
......
847 1025
			return false;
848 1026
		}
849 1027
	}
850
	
1028

  
851 1029
	@Override
852 1030
	public boolean notifyStartOfCompute() throws Exception {
853 1031
		if (annotationArea == null) return false;
854 1032
		if (annotationArea.isDisposed()) return false;
855
		
1033

  
856 1034
		AnnotationType type = getSelectedAnnotationType();
857 1035
		if (type != null) {
858 1036
			annotations.setViewAnnotation(type);
859 1037
			annotations.setAnnotationOverlap(true);
860 1038
		}
861
		
1039

  
862 1040
		return true;
863 1041
	}
864
	
1042

  
865 1043
	@Override
866 1044
	public boolean notifyEndOfCompute() throws Exception {
867 1045
		return true;
868 1046
	}
869
	
1047

  
870 1048
	@Override
871 1049
	public boolean isAnnotationEnable() {
872 1050
		return annotationArea != null;
873 1051
	}
874
	
1052

  
875 1053
	@Override
876 1054
	public void notifyStartOfRefresh() throws Exception {
877 1055
		if (annotationArea == null) return;
878 1056
		if (annotationArea.isDisposed()) return;
879
		
1057

  
880 1058
		Page currentPage = editor.getEditionPanel(0).getCurrentPage();
881 1059
		if (currentPage == null) return;
882
		
1060

  
883 1061
		String startID = currentPage.getWordId();
884 1062
		Page nextPage = currentPage.getEdition().getNextPage(currentPage);
885 1063
		String endID = nextPage.getWordId();
886
		
1064

  
887 1065
		annotations.computeStrings(startID, endID);
888
		
1066

  
889 1067
		updateAnnotationWidgetStates();
890
		
1068

  
891 1069
	}
892
	
1070

  
893 1071
	@Override
894 1072
	protected void _close() {
895 1073
		if (!annotationArea.isDisposed()) annotationArea.dispose();
896 1074
		extension.layout();
897 1075
	}
898
	
1076

  
899 1077
	@Override
900 1078
	public void notifyEndOfRefresh() throws Exception {
901 1079
		// TODO Auto-generated method stub
902 1080
	}
903
	
1081

  
904 1082
	@Override
905 1083
	public void notifyStartOfCreatePartControl() throws Exception {
906 1084
		// TODO Auto-generated method stub
907 1085
	}
908
	
1086

  
909 1087
	@Override
910 1088
	public Class<? extends TXMResult> getAnnotatedTXMResultClass() {
911 1089
		return org.txm.objects.Text.class;
912 1090
	}
913
	
1091

  
914 1092
	@Override
915 1093
	public boolean isDirty() {
916 1094
		if (annotManager != null) {
......
918 1096
		}
919 1097
		return false;
920 1098
	}
921
	
1099

  
922 1100
	@Override
923 1101
	public boolean discardChanges() {
924 1102
		return false;
925 1103
	}
926
	
1104

  
927 1105
	@Override
928 1106
	public boolean needToUpdateIndexes() {
929 1107
		return KRAnnotationPreferences.getInstance().getBoolean(KRAnnotationPreferences.UPDATE);
930 1108
	}
931
	
1109

  
932 1110
	@Override
933 1111
	public boolean needToUpdateEditions() {
934 1112
		return KRAnnotationPreferences.getInstance().getBoolean(KRAnnotationPreferences.UPDATE_EDITION);
TXM/trunk/bundles/org.txm.annotation.kr.rcp/plugin.xml (revision 4027)
395 395
           class="org.txm.annotation.kr.rcp.concordance.SimpleKRAnnotation"
396 396
           position="2">
397 397
     </annotationtoolbar>
398
     <annotationtoolbar
399
           class="org.txm.annotation.kr.rcp.edition.WordAnnotationToolbar"
400
           position="3">
401
     </annotationtoolbar>
398 402
  </extension>
399 403
</plugin>

Formats disponibles : Unified diff