Revision 844

tmp/org.txm.analec.rcp/src/org/txm/analec/toolbarbutton/StartButton.java (revision 844)
1 1
package org.txm.analec.toolbarbutton;
2 2

  
3
import java.util.Arrays;
4

  
3 5
import org.eclipse.core.runtime.IProgressMonitor;
4 6
import org.eclipse.core.runtime.IStatus;
5 7
import org.eclipse.core.runtime.Status;
......
148 150
			public void widgetDefaultSelected(SelectionEvent e) {}
149 151
		};
150 152
		SelectionListener[] modeListeners = {unitStartSelectionListener, schemaStartSelectionListener};
151
		annotationWidgetGroup = toolbar.installAlternativesGroup("URS annotation", "Start URS annotation", IImageKeys.PENCIL_OPEN, IImageKeys.PENCIL_CLOSE, true, openCloseSelectionListener, modes, modeListeners);
153
		annotationWidgetGroup = toolbar.installAlternativesGroup("URS annotation", "Start URS annotation", IImageKeys.PENCIL_OPEN, IImageKeys.PENCIL_CLOSE, true, openCloseSelectionListener, Arrays.asList(modes), Arrays.asList(modeListeners));
152 154
		annotationWidgetGroup.setLayout(GLComposite.createDefaultLayout(1));
153 155
		saveButton = new ToolItem(toolbar, SWT.PUSH);
154 156
		saveButton.setImage(IImageKeys.getImage(IImageKeys.PENCIL_SAVE));
tmp/org.txm.chartsengine.jfreechart.rcp/plugin.xml (revision 844)
27 27
               commandId="org.txm.chartsengine.jfreechart.rcp.handlers.OpenJFCChartPropertiesEditor"
28 28
               icon="icons/silk_chart_edit.png"
29 29
               style="push">
30
            <visibleWhen
31
                  checkEnabled="false">
32
               <test
33
                     property="org.txm.chartsengine.enginetype"
34
                     value="true">
35
               </test>
36
            </visibleWhen>
30 37
         </command>
31 38
      </menuContribution>
32 39
   </extension>
......
61 68
            name="JFC composite context">
62 69
      </context>
63 70
   </extension>
71
   <extension
72
         point="org.eclipse.core.expressions.propertyTesters">
73
      <propertyTester
74
            class="org.txm.chartsengine.jfreechart.rcp.testers.__IsJFCComposite"
75
            id="org.txm.chartsengine.jfreechart.rcp.testers.__IsJFCComposite"
76
            namespace="org.txm.chartsengine"
77
            properties="enginetype"
78
            type="java.lang.Object">
79
      </propertyTester>
80
   </extension>
64 81

  
65 82
</plugin>
tmp/org.txm.chartsengine.jfreechart.rcp/src/org/txm/chartsengine/jfreechart/rcp/testers/__IsJFCComposite.java (revision 844)
20 20
			Object expectedValue) {
21 21

  
22 22
		//FIXME: Debug
23
//		System.out.println("IsJFCComposite.test() recevier = " + receiver.getClass().getSimpleName());
24
//		System.out.println("IsJFCComposite.test() property = " + property);
25
//		System.out.println("IsJFCComposite.test() args = " + args);
26
//		System.out.println("IsJFCComposite.test() expectedValue = " + expectedValue);
27
		
23
		System.out.println("IsJFCComposite.test() recevier = " + receiver.getClass());
24
		System.out.println("IsJFCComposite.test() property = " + property);
25
		System.out.println("IsJFCComposite.test() args = " + args);
26
		System.out.println("IsJFCComposite.test() expectedValue = " + expectedValue);
27

  
28 28
//		ChartEditor editor = SWTChartsComponentsProvider.getActiveChartEditor(null);
29 29
//		return (editor != null && editor.getComposite() instanceof JFCComposite);
30 30
		return true;
tmp/org.txm.annotation.core/src/org/txm/annotation/core/repository/KnowledgeRepositoryManager.java (revision 844)
211 211
		return kr;
212 212
	}
213 213

  
214
	public static void registerKnowledgeRepository(KnowledgeRepository kr) {
215
		repositories.put(kr.getName(), kr);
216
	}
217
	
214 218
	public static boolean[] mustLoginToKnowledgeRepository(String kr_name,
215 219
			MainCorpus corpus) {
216 220

  
tmp/org.txm.annotation.core/src/org/txm/annotation/core/AnnotationInjector.java (revision 844)
140 140

  
141 141
	boolean mustChangeAnaValue = false;
142 142
	boolean inAna = false;
143
	private boolean inForm;
144
	private boolean mustChangeWordValue;
143 145

  
144 146
	protected void processStartElement() throws XMLStreamException, IOException {
145 147
		
......
197 199
			}
198 200

  
199 201
			super.processStartElement(); // write the tag
200
		} else if ("ana".equals(localname)) {
202
		
203
		} else if ("form".equals(localname) && inW) {
204
			if (currentTokenAnnotations.containsKey("word")) {
205
				Annotation a = currentTokenAnnotations.get("word");
206
				//System.out.println("Updating token annotation with: " + a);
207

  
208
				String value = a.getValue();
209
				if ("#del".equals(value))
210
					value = "";
211
				if (value == null)
212
					value = "ERROR";
213

  
214
				try {
215
					writer.writeStartElement("form");
216
					writer.writeCharacters(value);
217
					mustChangeWordValue = true;
218
				} catch (XMLStreamException e) {
219
					// TODO Auto-generated catch block
220
					e.printStackTrace();
221
				}
222

  
223
				currentTokenAnnotations.remove("word"); // annotation updated
224
			} else {
225
				super.processStartElement();
226
			}
227
		} else if ("ana".equals(localname) && inW) {
201 228
			inAna = true;
202 229
			String type = parser.getAttributeValue(null, "type").substring(1);
203 230
			if (currentTokenAnnotations.containsKey(type)) {
......
323 350
		if (inAna && mustChangeAnaValue) {
324 351
			// nothing content is already written
325 352
			//System.out.println("skip ana value because we replace it");
353
		} else if (inW && mustChangeWordValue) {
354
			// nothing content is already written
355
			//System.out.println("skip form value because we replace it");
326 356
		} else {
327 357
			super.processCharacters();
328 358
		}
......
384 414
			}
385 415

  
386 416
			position_counter++;
387
		} else if ("ana".equals(localname)) {
417
		} else if ("form".equals(localname) && inW) {
388 418
			//if (!mustChangeAnaValue)
389 419
				super.processEndElement();
420
				mustChangeWordValue = false;
421
			inForm = false;
422
		} else if ("ana".equals(localname) && inW) {
423
			//if (!mustChangeAnaValue)
424
				super.processEndElement();
390 425
			inAna = false;
391 426
			mustChangeAnaValue = false;
392 427
		} else if (previousEndAnnotations != null) { // force delete annotations
tmp/org.txm.annotation.rcp/plugin.xml (revision 844)
1 1
<?xml version="1.0" encoding="UTF-8"?>
2 2
<?eclipse version="3.4"?>
3 3
<plugin>
4
   <extension-point id="org.txm.annotation.rcp.editor.AnnotationArea" name="org.txm.annotation.rcp.editor.AnnotationArea" schema="schema/org.txm.annotation.rcp.editor.AnnotationArea.exsd"/>
4 5
   <extension
5 6
         point="org.eclipse.ui.commands">
6 7
               <command
......
320 321
           name="Annotation">
321 322
     </concextension>
322 323
  </extension>
324
  <extension
325
        point="org.txm.annotation.rcp.editor.AnnotationArea">
326
     <annotationtoolbar
327
           class="org.txm.annotation.rcp.concordance.KRAnnotation"
328
           position="3">
329
     </annotationtoolbar>
330
     <annotationtoolbar
331
           class="org.txm.annotation.rcp.concordance.WordAnnotationToolbar"
332
           position="1">
333
     </annotationtoolbar>
334
     <annotationtoolbar
335
           class="org.txm.annotation.rcp.concordance.SimpleKRAnnotation"
336
           position="2">
337
     </annotationtoolbar>
338
  </extension>
323 339
</plugin>
tmp/org.txm.annotation.rcp/schema/org.txm.annotation.rcp.editor.AnnotationArea.exsd (revision 844)
1
<?xml version='1.0' encoding='UTF-8'?>
2
<!-- Schema file written by PDE -->
3
<schema targetNamespace="org.txm.annotation.rcp" xmlns="http://www.w3.org/2001/XMLSchema">
4
<annotation>
5
      <appinfo>
6
         <meta.schema plugin="org.txm.annotation.rcp" id="org.txm.annotation.rcp.editor.AnnotationArea" name="org.txm.annotation.rcp.editor.AnnotationArea"/>
7
      </appinfo>
8
      <documentation>
9
         An annotation toolbar opened by the Annotation start button
10
      </documentation>
11
   </annotation>
12

  
13
   <element name="extension">
14
      <annotation>
15
         <appinfo>
16
            <meta.element />
17
         </appinfo>
18
      </annotation>
19
      <complexType>
20
         <choice minOccurs="1" maxOccurs="unbounded">
21
            <element ref="annotationtoolbar"/>
22
         </choice>
23
         <attribute name="point" type="string" use="required">
24
            <annotation>
25
               <documentation>
26
                  
27
               </documentation>
28
            </annotation>
29
         </attribute>
30
         <attribute name="id" type="string">
31
            <annotation>
32
               <documentation>
33
                  
34
               </documentation>
35
            </annotation>
36
         </attribute>
37
         <attribute name="name" type="string">
38
            <annotation>
39
               <documentation>
40
                  
41
               </documentation>
42
               <appinfo>
43
                  <meta.attribute translatable="true"/>
44
               </appinfo>
45
            </annotation>
46
         </attribute>
47
      </complexType>
48
   </element>
49

  
50
   <element name="annotationtoolbar">
51
      <complexType>
52
         <attribute name="class" type="string" use="required">
53
            <annotation>
54
               <documentation>
55
                  
56
               </documentation>
57
               <appinfo>
58
                  <meta.attribute kind="java" basedOn="org.txm.annotation.rcp.editor.AnnotationArea:"/>
59
               </appinfo>
60
            </annotation>
61
         </attribute>
62
         <attribute name="position" type="string" use="required">
63
            <annotation>
64
               <documentation>
65
                  
66
               </documentation>
67
               <appinfo>
68
                  <meta.attribute kind="java" basedOn="java.lang.Integer:"/>
69
               </appinfo>
70
            </annotation>
71
         </attribute>
72
      </complexType>
73
   </element>
74

  
75
   <annotation>
76
      <appinfo>
77
         <meta.section type="since"/>
78
      </appinfo>
79
      <documentation>
80
         [Enter the first release in which this extension point appears.]
81
      </documentation>
82
   </annotation>
83

  
84
   <annotation>
85
      <appinfo>
86
         <meta.section type="examples"/>
87
      </appinfo>
88
      <documentation>
89
         [Enter extension point usage example here.]
90
      </documentation>
91
   </annotation>
92

  
93
   <annotation>
94
      <appinfo>
95
         <meta.section type="apiinfo"/>
96
      </appinfo>
97
      <documentation>
98
         [Enter API information here.]
99
      </documentation>
100
   </annotation>
101

  
102
   <annotation>
103
      <appinfo>
104
         <meta.section type="implementation"/>
105
      </appinfo>
106
      <documentation>
107
         [Enter information about supplied implementation of this extension point.]
108
      </documentation>
109
   </annotation>
110

  
111

  
112
</schema>
0 113

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

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

  
9
import org.eclipse.core.runtime.IProgressMonitor;
10
import org.eclipse.core.runtime.IStatus;
11
import org.eclipse.core.runtime.Status;
12
import org.eclipse.jface.dialogs.InputDialog;
13
import org.eclipse.jface.dialogs.MessageDialog;
14
import org.eclipse.jface.viewers.ArrayContentProvider;
15
import org.eclipse.jface.viewers.ColumnLabelProvider;
16
import org.eclipse.jface.viewers.ComboViewer;
17
import org.eclipse.jface.viewers.ISelection;
18
import org.eclipse.jface.viewers.ISelectionChangedListener;
19
import org.eclipse.jface.viewers.IStructuredSelection;
20
import org.eclipse.jface.viewers.SelectionChangedEvent;
21
import org.eclipse.jface.viewers.TableViewer;
22
import org.eclipse.jface.viewers.TableViewerColumn;
23
import org.eclipse.swt.SWT;
24
import org.eclipse.swt.events.KeyEvent;
25
import org.eclipse.swt.events.KeyListener;
26
import org.eclipse.swt.events.SelectionEvent;
27
import org.eclipse.swt.events.SelectionListener;
28
import org.eclipse.swt.layout.GridData;
29
import org.eclipse.swt.widgets.Button;
30
import org.eclipse.swt.widgets.Combo;
31
import org.eclipse.swt.widgets.Composite;
32
import org.eclipse.swt.widgets.Display;
33
import org.eclipse.swt.widgets.Label;
34
import org.eclipse.swt.widgets.TableColumn;
35
import org.eclipse.swt.widgets.Text;
36
import org.txm.annotation.core.Annotation;
37
import org.txm.annotation.core.AnnotationManager;
38
import org.txm.annotation.core.DatabasePersistenceManager;
39
import org.txm.annotation.core.KRAnnotationEngine;
40
import org.txm.annotation.core.repository.AnnotationEffect;
41
import org.txm.annotation.core.repository.AnnotationType;
42
import org.txm.annotation.core.repository.KnowledgeRepository;
43
import org.txm.annotation.core.repository.KnowledgeRepositoryManager;
44
import org.txm.annotation.core.repository.LocalKnowledgeRepository;
45
import org.txm.annotation.core.repository.TypedValue;
46
import org.txm.annotation.rcp.commands.InitializeKnowledgeRepository;
47
import org.txm.annotation.rcp.commands.SaveAnnotations;
48
import org.txm.annotation.rcp.editor.AnnotationArea;
49
import org.txm.annotation.rcp.views.knowledgerepositories.KRView;
50
import org.txm.concordance.core.functions.Concordance;
51
import org.txm.concordance.core.functions.Line;
52
import org.txm.concordance.rcp.editors.ConcordanceEditor;
53
import org.txm.concordance.rcp.editors.ConcordanceEditor.ConcordanceColumnSizeControlListener;
54
import org.txm.concordance.rcp.messages.ConcordanceUIMessages;
55
import org.txm.core.results.TXMResult;
56
import org.txm.rcp.IImageKeys;
57
import org.txm.rcp.editors.TXMEditor;
58
import org.txm.rcp.swt.GLComposite;
59
import org.txm.rcp.swt.dialog.ConfirmDialog;
60
import org.txm.rcp.swt.provider.SimpleLabelProvider;
61
import org.txm.rcp.utils.JobHandler;
62
import org.txm.searchengine.cqp.clientExceptions.CqiClientException;
63
import org.txm.searchengine.cqp.corpus.Corpus;
64
import org.txm.searchengine.cqp.corpus.WordProperty;
65
import org.txm.searchengine.cqp.corpus.query.Match;
66
import org.txm.utils.AsciiUtils;
67
import org.txm.utils.logger.Log;
68

  
69
public class WordAnnotationToolbar extends AnnotationArea<Concordance> {
70

  
71
	/**
72
	 * the limit number of annotation when a confirm dialog box is shown
73
	 */
74
	protected static final int NALERTAFFECTANNOTATIONS = 100;
75
	public static final String EMPTYTEXT = "";
76

  
77
	/** The annotation service */
78
	protected AnnotationManager annotManager;
79

  
80
	protected ConcordanceEditor editor;
81

  
82
	/**
83
	 * The concordance annotations to show in the concordance column table
84
	 */
85
	private ConcordanceAnnotations annotations = null;
86

  
87
	/**
88
	 * All available annotation types
89
	 */
90
	protected List<TypedValue> typeValuesList;
91

  
92
	/**
93
	 * display the annotation values of the current shown concordance lines
94
	 */
95
	protected TableColumn annotationColumn;
96

  
97
	protected ComboViewer annotationTypesCombo;
98
	/** add a new type of annotation */
99
	private Button addAnnotationTypeButton;
100
	protected Label equalLabel;
101
	protected Text annotationValuesText;
102
	protected Button affectAnnotationButton;
103
	private Button affectAllAnnotationButton;
104

  
105
	protected KnowledgeRepository currentKnowledgeRepository = null;
106
	protected Vector<AnnotationType> typesList = new Vector<AnnotationType>(); 
107

  
108
	protected AnnotationType tagAnnotationType; // the tag annotation type if annotation mode is simple
109

  
110
	protected TypedValue value_to_add;
111

  
112
	protected Concordance concordance;
113
	private Corpus corpus;
114
	
115
	public String getName() {
116
		return "Word properties";
117
	}
118
	
119
	public WordAnnotationToolbar() {
120
	}
121

  
122
	protected AnnotationType getSelectedAnnotationType() {
123
		IStructuredSelection isel = (IStructuredSelection)annotationTypesCombo.getSelection();
124
		if (isel.isEmpty()) {
125
			return null;
126
		}
127
		return (AnnotationType) isel.getFirstElement();
128
	}
129

  
130
	public void updateAnnotationWidgetStates() {
131
		if (annotationArea == null) return; // :)
132

  
133
		if (getSelectedAnnotationType() != null) {
134
			annotationValuesText.setEnabled(true);
135
			affectAnnotationButton.setEnabled(true);
136
		} else {
137
			annotationValuesText.setEnabled(false);
138
			affectAnnotationButton.setEnabled(false);
139
		}
140
	}
141

  
142
	protected void affectAnnotationToSelection(ISelection selection) {
143

  
144
		final IStructuredSelection lineSelection = (IStructuredSelection) selection;
145
		List<Line> lines = lineSelection.toList();
146
		ArrayList<Match> matches = new ArrayList<Match>();
147
		for (Line l : lines) {
148
			matches.add(l.getMatch());
149
		}
150

  
151
		affectMatchesToSelection(matches);
152
	}
153

  
154
	protected void affectAnnotationValues(final List<Match> matches,  final AnnotationType type, final String svalue, JobHandler job) {
155
		value_to_add = null; // reset
156
		if (matches.size() == 0) {
157
			System.out.println("No line selected. Aborting."); //$NON-NLS-1$
158
			return;
159
		}
160
		if (type == null) return; // no type, no annotation
161

  
162
		job.syncExec(new Runnable() {
163
			@Override
164
			public void run() {
165
				if (matches.size() > NALERTAFFECTANNOTATIONS) {
166
					ConfirmDialog dialog = new ConfirmDialog(Display.getCurrent().getActiveShell(), 
167
							"confirm_annotate",  //$NON-NLS-1$
168
							ConcordanceUIMessages.ConcordancesEditor_86, 
169
							ConcordanceUIMessages.ConcordancesEditor_87+matches.size()+ConcordanceUIMessages.ConcordancesEditor_108);
170

  
171
					if (dialog.open() == ConfirmDialog.CANCEL) {
172
						System.out.println("Annotation aborted by user."); //$NON-NLS-1$
173
						matches.clear();
174
					}
175
				}
176
			}
177
		});
178

  
179
		// get value from combo text value
180
		Log.warning(ConcordanceUIMessages.ConcordancesEditor_57+svalue);
181
		final KnowledgeRepository kr = KnowledgeRepositoryManager.getKnowledgeRepository(type.getKnowledgeRepository());
182
		value_to_add = kr.getValue(type, svalue);
183

  
184

  
185
		if (value_to_add == null && kr instanceof LocalKnowledgeRepository) { // create or not the annotation is simple mode
186
			value_to_add = kr.addValue(svalue, svalue, type.getId());
187
		}
188

  
189
		if (value_to_add == null) {	
190
			job.syncExec(new Runnable() {
191
				@Override
192
				public void run() {
193
					String mess = ConcordanceUIMessages.bind(ConcordanceUIMessages.ConcordancesEditor_58, svalue);
194
					System.out.println(mess);
195
					MessageDialog.openError(Display.getCurrent().getActiveShell(), "Annotation canceled", mess); //$NON-NLS-1$
196
				}
197
			});
198
			return;
199
		}
200

  
201
		Log.info(ConcordanceUIMessages.ConcordancesEditor_59+value_to_add+ConcordanceUIMessages.ConcordancesEditor_60+matches);
202

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

  
207
			// did we had problems ?
208
			if (existingAnnots!=null && existingAnnots.size() > 0) {
209
				String message = ConcordanceUIMessages.ConcordancesEditor_61+value_to_add.getStandardName()+
210
						ConcordanceUIMessages.ConcordancesEditor_62;
211
				for (Match m : existingAnnots.keySet()) {
212
					message += ConcordanceUIMessages.ConcordancesEditor_63+m+ConcordanceUIMessages.ConcordancesEditor_64;
213

  
214
					for (Annotation existingAnnot : existingAnnots.get(m)) {
215
						if (existingAnnot.getStart() < m.getStart()){
216
							message += ConcordanceUIMessages.ConcordancesEditor_65+existingAnnot.getType()+ConcordanceUIMessages.ConcordancesEditor_66+existingAnnot.getStart()+ConcordanceUIMessages.ConcordancesEditor_67+existingAnnot.getEnd()+ConcordanceUIMessages.ConcordancesEditor_68;
217
						} else {
218
							message += ConcordanceUIMessages.ConcordancesEditor_69+existingAnnot.getType()+ConcordanceUIMessages.ConcordancesEditor_70+existingAnnot.getStart()+ConcordanceUIMessages.ConcordancesEditor_71+existingAnnot.getEnd()+ConcordanceUIMessages.ConcordancesEditor_72;
219
						}
220
					}
221
				}
222
				final String final_message = message;
223
				job.syncExec(new Runnable() {
224
					@Override
225
					public void run() {
226
						MessageDialog.openInformation(editor.getSite().getShell(), ConcordanceUIMessages.ConcordancesEditor_73, final_message);
227
					}
228
				});
229
			}
230
			//				if (history != null && !history.get(type).contains(value_to_add))
231
			//					history.get(type).add(value_to_add);
232

  
233
			if (Log.getLevel().intValue() < Level.WARNING.intValue() && annotManager != null) {
234
				annotManager.checkData();
235
			}
236
			concordance.reloadCurrentLines();
237
		} catch (Exception e1) {
238
			System.out.println(ConcordanceUIMessages.ConcordancesEditor_74+e1);
239
			Log.printStackTrace(e1);
240
			return;
241
		}
242

  
243
		job.syncExec(new Runnable() {
244
			@Override
245
			public void run() {
246
				try {
247
					editor.refresh(false);
248
				} catch (Exception e) {
249
					// TODO Auto-generated catch block
250
					e.printStackTrace();
251
				}
252
			}
253
		});
254
	}
255

  
256
	protected void deleteAnnotationValues(List<Match> matches, AnnotationType type, JobHandler job) {
257

  
258
		if (matches.size() == 0) {
259
			System.out.println("No lines selected. Aborting."); //$NON-NLS-1$
260
			return;
261
		}
262

  
263
		if (type == null) {
264
			return;
265
		}
266

  
267
		try {
268
			if (annotManager != null && annotManager.deleteAnnotations(type, matches, job)) {
269
				if (Log.getLevel().intValue() < Level.WARNING.intValue()) annotManager.checkData();
270
				concordance.reloadLines(editor.getTopLine(), editor.getBottomLine()+1);
271
			} else {
272
				return;
273
			}
274
		} catch (Exception e1) {
275
			System.out.println(ConcordanceUIMessages.ConcordancesEditor_54+e1);
276
			Log.printStackTrace(e1);
277
			return;
278
		}
279

  
280
		job.syncExec(new Runnable() {
281
			@Override
282
			public void run() {
283
				try {
284
					editor.refresh(false);
285
				} catch (Exception e) {
286
					// TODO Auto-generated catch block
287
					e.printStackTrace();
288
				}
289
			}
290
		});
291
	}
292

  
293
	protected void affectMatchesToSelection(final List<Match> matches) {
294
		final AnnotationType type = getSelectedAnnotationType();
295
		final String svalue = annotationValuesText.getText();
296

  
297
		JobHandler job = new JobHandler(ConcordanceUIMessages.ConcordancesEditor_36, true) {
298
			@Override
299
			protected IStatus run(IProgressMonitor monitor) {
300
				this.runInit(monitor);
301
				try {
302
					affectAnnotationValues(matches, type, svalue, this);
303
				} catch(Exception e) {
304
					Log.severe(ConcordanceUIMessages.ConcordancesEditor_40+e);
305
					Log.printStackTrace(e);
306
					return Status.CANCEL_STATUS;
307
				} catch(ThreadDeath td) {
308
					System.out.println("Annotation canceled by user.");
309
					return Status.CANCEL_STATUS;
310
				}
311

  
312
				return Status.OK_STATUS;
313
			}
314
		};
315
		job.startJob(true);
316
	}
317

  
318
	@Override
319
	public boolean install(TXMEditor<? extends TXMResult> ceditor, Corpus corpus, final Composite parent) throws Exception {
320
		//advanced_annotation_mode = "advanced".equals(TXMPreferences.getString(AnnotationPreferences.ANNOTATION_MODE, RCPPreferences.PREFERENCES_NODE));
321
		this.editor = (ConcordanceEditor)ceditor;
322
		this.corpus = corpus;
323
		this.concordance = editor.getConcordance();
324
		this.annotations = new ConcordanceAnnotations(editor.getConcordance());
325
		this.annotManager = KRAnnotationEngine.getAnnotationManager(corpus);
326
		TableViewer viewer = editor.getLineTableViewer();
327

  
328
		// RESULT
329

  
330
		int position = 3; // after keyword column
331
		TableViewerColumn annotationColumnViewer = new TableViewerColumn(viewer, SWT.CENTER, position);
332
		annotationColumn = annotationColumnViewer.getColumn();
333
		annotationColumn.setText("Property");
334
		annotationColumn.setToolTipText(ConcordanceUIMessages.ConcordancesEditor_17);
335
		annotationColumn.setAlignment(SWT.CENTER);
336
		annotationColumn.pack();
337
		annotationColumn.setResizable(true);
338
		annotationColumn.addControlListener(new ConcordanceColumnSizeControlListener(annotationColumn));
339
		annotationColumnViewer.setLabelProvider(new ColumnLabelProvider() {
340

  
341
			@Override
342
			public String getText(Object element) {
343
				Line line = (Line)element;
344
				AnnotationLine annotationLine = annotations.getAnnotationLine(line);
345
				if (annotationLine == null) return EMPTYTEXT ;
346
				if (annotationLine.getAnnotation()!=null) {
347
					String value = annotationLine.getAnnotationValue().getStandardName();
348
					Annotation a = annotationLine.getAnnotation();
349
					if (value == null) value = a.getValue();
350

  
351
					if (a.getStart() < line.matchGetStart() - line.getLeftContextSize()) {
352
						value = "… "+value;
353
					}
354

  
355
					if (a.getEnd() > line.matchGetEnd() + line.getRightContextSize()) {
356
						value = value+" …";
357
					} 
358
					return value;
359
				} else {
360
					return EMPTYTEXT;
361
				}
362
			}
363
		});
364
		
365
		List<KnowledgeRepository> krs = InitializeKnowledgeRepository.get(corpus.getMainCorpus());
366
		typesList.clear();
367
		Log.warning("Corpus KRs: "+krs); //$NON-NLS-1$
368

  
369
		currentKnowledgeRepository = KnowledgeRepositoryManager.getKnowledgeRepository(corpus.getMainCorpus().getName());
370
		if (currentKnowledgeRepository == null) {
371
			HashMap<String, HashMap<String, ?>> conf = new HashMap<String, HashMap<String, ?>>();
372
			HashMap<String, String> access = new HashMap<String, String>();
373
			conf.put(KRAnnotationEngine.KNOWLEDGE_ACCESS, access);
374
			HashMap<String, HashMap<String, String>> fields = new HashMap<String, HashMap<String, String>>(); 
375
			conf.put(KRAnnotationEngine.KNOWLEDGE_TYPES, fields);
376
			HashMap<String, HashMap<String, String>> strings = new HashMap<String, HashMap<String, String>>();
377
			conf.put(KRAnnotationEngine.KNOWLEDGE_STRINGS, strings);
378
			
379
			access.put("mode", DatabasePersistenceManager.ACCESS_FILE);
380
			access.put("version", "0");
381
			currentKnowledgeRepository = KnowledgeRepositoryManager.createKnowledgeRepository(corpus.getMainCorpus().getName(), conf);
382
			KnowledgeRepositoryManager.registerKnowledgeRepository(currentKnowledgeRepository);
383
		}
384

  
385
		List<WordProperty> wordProperties = corpus.getProperties();
386
		for (WordProperty p : wordProperties) {
387
			AnnotationType type = currentKnowledgeRepository.getType(p.getName());
388
			if (type == null) {
389
				AnnotationType t = currentKnowledgeRepository.addType(p.getName(), p.getName());
390
				t.setEffect(AnnotationEffect.TOKEN);
391
			} else if (type != null) {
392
				type.setEffect(AnnotationEffect.TOKEN);
393
			}
394
		}
395

  
396
		Log.warning("KR: "+currentKnowledgeRepository); //$NON-NLS-1$
397
		List<AnnotationType> krtypes = currentKnowledgeRepository.getAllAnnotationTypes();
398

  
399
		typesList.addAll(krtypes);
400
		
401
		Log.warning("Available annotation types: "+typesList);
402

  
403
		annotationArea = new GLComposite(parent, SWT.NONE, "Concordance Annotation area");
404
		annotationArea.getLayout().numColumns = 12;
405
		annotationArea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
406

  
407
		GridData gdata = new GridData(SWT.CENTER, SWT.CENTER, false, false);
408
		gdata.widthHint = 90;
409

  
410
		//Display combo with list of Annotation Type 
411
		annotationTypesCombo = new ComboViewer(annotationArea, SWT.READ_ONLY);
412
		annotationTypesCombo.setContentProvider(new ArrayContentProvider());
413
		annotationTypesCombo.setLabelProvider(new SimpleLabelProvider() {
414
			@Override
415
			public String getColumnText(Object element, int columnIndex) {
416
				return ((AnnotationType)element).getName(); //$NON-NLS-1$
417
			}
418
			@Override
419
			public String getText(Object element) {
420
				return ((AnnotationType)element).getName(); //$NON-NLS-1$
421
			}
422
		});
423
		gdata = new GridData(SWT.CENTER, SWT.CENTER, false, false);
424
		gdata.widthHint = 200;
425

  
426
		annotationTypesCombo.getCombo().setLayoutData(gdata);
427
		annotationTypesCombo.setInput(typesList);
428
		annotationTypesCombo.getCombo().select(0);
429
		annotations.setViewAnnotation(typesList.get(0));
430
		annotationColumn.setText(typesList.get(0).getName());
431
		
432
		annotationTypesCombo.addSelectionChangedListener(new ISelectionChangedListener() {
433
			@Override
434
			public void selectionChanged(SelectionChangedEvent event) {
435
				AnnotationType type = getSelectedAnnotationType();
436
				if (type == null) return;
437
				if (type.getSize() != AnnotationType.ValuesSize.LARGE) {
438
					try {
439
						KnowledgeRepository kr = KnowledgeRepositoryManager.getKnowledgeRepository(type.getKnowledgeRepository());
440
						typeValuesList = kr.getValues(type);
441
					} catch (Exception e) {
442
						// TODO Auto-generated catch block
443
						e.printStackTrace();
444
					}
445
				}
446

  
447
				annotationColumn.setText(type.getName());
448
				annotations.setViewAnnotation(type);
449
				annotations.setAnnotationOverlap(true);
450
				try {
451
					editor.refresh(false);
452
				} catch (Exception e) {
453
					// TODO Auto-generated catch block
454
					e.printStackTrace();
455
				}
456

  
457
				updateAnnotationWidgetStates();
458
			}
459
		});
460

  
461
		addAnnotationTypeButton = new Button(annotationArea, SWT.PUSH);
462
		addAnnotationTypeButton.setToolTipText(ConcordanceUIMessages.ConcordancesEditor_115);
463
		addAnnotationTypeButton.setImage(IImageKeys.getImage(IImageKeys.ACTION_ADD));
464
		addAnnotationTypeButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
465
		addAnnotationTypeButton.addSelectionListener(new SelectionListener() {
466
			@Override
467
			public void widgetSelected(SelectionEvent e) {
468
				if (currentKnowledgeRepository == null) return;
469
				if (!(currentKnowledgeRepository instanceof LocalKnowledgeRepository)) return;
470

  
471
				LocalKnowledgeRepository kr = (LocalKnowledgeRepository)currentKnowledgeRepository;
472

  
473
				InputDialog dialog = new InputDialog(e.widget.getDisplay().getActiveShell(), "Nouvelle propriété", "Nom de la propriété pattern=[a-z][-a-z0-9]+", "", null); //$NON-NLS-3$
474
				if (dialog.open() == InputDialog.OK) {
475
					String name = dialog.getValue();
476
					if (name.trim().length() == 0) return;
477
					String baseid = AsciiUtils.buildId(name);
478
					String id = AsciiUtils.buildId(name);
479
					int c = 1;
480
					while (kr.getType(id) != null) {
481
						id = baseid+"_"+(c++); //$NON-NLS-1$
482
					}
483
					AnnotationType type = kr.addType(name, id, ""); //$NON-NLS-1$
484
					type.setEffect(AnnotationEffect.TOKEN);
485
					typesList.add(type);
486

  
487
					if (annotationTypesCombo != null) annotationTypesCombo.refresh();
488
					if (typesList.size() == 1) {
489
						if (annotationTypesCombo != null) annotationTypesCombo.getCombo().select(0);
490
						annotations.setViewAnnotation(type);
491
						annotations.setAnnotationOverlap(true);
492
						try {
493
							editor.refresh(false);
494
						} catch (Exception e1) {
495
							// TODO Auto-generated catch block
496
							e1.printStackTrace();
497
						}
498
						annotationArea.layout(true);
499
					} else {
500
						if (typesList.size() > 1) {
501
							if (annotationTypesCombo != null) {
502
								annotationTypesCombo.getCombo().select(typesList.size()-1);
503
							}
504
						}
505
					}
506
					KRView.refresh();
507
					updateAnnotationWidgetStates();
508
				} else {
509
					System.out.println("Creation aborted."); //$NON-NLS-1$
510
				}
511
			}
512

  
513
			@Override
514
			public void widgetDefaultSelected(SelectionEvent e) { }
515
		});
516

  
517
		equalLabel = new Label(annotationArea, SWT.NONE);
518
		equalLabel.setText("="); //$NON-NLS-1$
519
		equalLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
520

  
521
		annotationValuesText = new Text(annotationArea, SWT.BORDER);
522
		annotationValuesText.setToolTipText(ConcordanceUIMessages.ConcordancesEditor_32);
523
		GridData gdata2 = new GridData(SWT.FILL, SWT.CENTER, false, false);
524
		gdata2.widthHint = 200;
525
		annotationValuesText.setLayoutData(gdata2);
526
		annotationValuesText.addKeyListener(new KeyListener() {
527
			@Override
528
			public void keyReleased(KeyEvent e) {
529
				if (e.keyCode == SWT.CR || e.keyCode == SWT.KEYPAD_CR) {
530
					affectAnnotationToSelection(editor.getLineTableViewer().getSelection());
531
				}
532
			}
533

  
534
			@Override
535
			public void keyPressed(KeyEvent e) { }
536
		});
537

  
538
		affectAnnotationButton = new Button(annotationArea, SWT.PUSH);
539
		affectAnnotationButton.setText(ConcordanceUIMessages.ConcordancesEditor_85);
540
		affectAnnotationButton.setToolTipText(ConcordanceUIMessages.ConcordancesEditor_116);
541
		affectAnnotationButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
542
		affectAnnotationButton.addSelectionListener(new SelectionListener() {
543
			@Override
544
			public void widgetSelected(SelectionEvent e) {
545
				affectAnnotationToSelection(editor.getLineTableViewer().getSelection());
546
			}
547

  
548
			@Override
549
			public void widgetDefaultSelected(SelectionEvent e) { }
550
		});
551
		
552
		affectAllAnnotationButton = new Button(annotationArea, SWT.PUSH);
553
		affectAllAnnotationButton.setText("All");
554
		affectAllAnnotationButton.setToolTipText(ConcordanceUIMessages.ConcordancesEditor_116);
555
		affectAllAnnotationButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
556
		affectAllAnnotationButton.addSelectionListener(new SelectionListener() {
557
			@Override
558
			public void widgetSelected(SelectionEvent e) {
559

  
560
				try {
561
					List<Match> matches = concordance.getMatches();
562
					affectMatchesToSelection(matches);
563
				} catch (CqiClientException e1) {
564
					Log.severe(ConcordanceUIMessages.ConcordancesEditor_53+e1);
565
					Log.printStackTrace(e1);
566
					return;
567
				}
568
			}
569

  
570
			@Override
571
			public void widgetDefaultSelected(SelectionEvent e) { }
572
		});
573
		
574
		Button saveAnnotateButton = new Button(annotationArea, SWT.PUSH);
575
		saveAnnotateButton.setToolTipText(ConcordanceUIMessages.ConcordancesEditor_76);
576
		saveAnnotateButton.setImage(IImageKeys.getImage(IImageKeys.PENCIL_SAVE));
577
		saveAnnotateButton.addSelectionListener(new SelectionListener() {
578
			@Override
579
			public void widgetSelected(SelectionEvent e) {
580

  
581
				save();
582
			}
583

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

  
588
		updateAnnotationWidgetStates();
589
		editor.layout(true);
590

  
591
		return true;
592
	}
593

  
594
	@Override
595
	public boolean save() {
596
		try {
597
			AnnotationManager am = KRAnnotationEngine.getAnnotationManager(WordAnnotationToolbar.this.corpus);
598
			if (am != null && am.hasChanges()) {
599
				// && MessageDialog.openConfirm(e.display.getActiveShell(), "Confirm annotation save", "Saving annotation will close this editor. Are you sure you want to save annotations right now ?")
600
				JobHandler saveJob = SaveAnnotations.save(WordAnnotationToolbar.this.corpus.getMainCorpus());
601
				if (saveJob.getResult() == Status.CANCEL_STATUS) {
602
					// update editor corpus
603
					System.out.println("Fail to save annotations of the corpus."); //$NON-NLS-1$
604
				}
605
			}
606
		} catch(Exception ex) {
607
			ex.printStackTrace();
608
			return false;
609
		}
610
		return true;
611
	}
612
	
613
	@Override
614
	public boolean notifyStartOfCompute() throws Exception {
615
		if (annotationArea != null) {
616
			AnnotationType type = getSelectedAnnotationType();
617
			if (type != null) {
618
				annotations.setViewAnnotation(type);
619
				annotations.setAnnotationOverlap(true);
620
			}
621
		}
622
		return true;
623
	}
624

  
625
	@Override
626
	public boolean notifyEndOfCompute() throws Exception {
627
		updateAnnotationWidgetStates();
628

  
629
		// update annotation column width
630
		if (annotationArea != null) {
631
			annotationColumn.pack();
632

  
633
			annotationColumn.setResizable(true);
634
		} else { 
635
			annotationColumn.setWidth(0);
636
		}
637

  
638
		return true;
639
	}
640

  
641
	public boolean isAnnotationEnable() {
642
		return annotationArea != null;
643
	}
644

  
645
	@Override
646
	public void update(List<Line> lines, int from, int to) throws Exception {
647
		annotations.getLines(lines, from, to);
648
	}
649

  
650
	@Override
651
	protected void _close() {
652
		annotationColumn.dispose();
653
	}
654
}
0 655

  
tmp/org.txm.annotation.rcp/src/org/txm/annotation/rcp/concordance/ConcordanceAnnotations.java (revision 844)
14 14
import org.txm.searchengine.cqp.corpus.query.Match;
15 15
import org.txm.utils.logger.Log;
16 16

  
17
/**
18
 * Annotation values to display in the current concordance shown lines
19
 * 
20
 * Call getLines(conclines, from, to) 
21
 * 
22
 * @author mdecorde
23
 *
24
 */
17 25
public class ConcordanceAnnotations {
18 26
	
19 27
	Concordance concordance;
tmp/org.txm.annotation.rcp/src/org/txm/annotation/rcp/concordance/SimpleKRAnnotation.java (revision 844)
1
package org.txm.annotation.rcp.concordance;
2

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

  
9
import org.eclipse.core.runtime.IProgressMonitor;
10
import org.eclipse.core.runtime.IStatus;
11
import org.eclipse.core.runtime.Status;
12
import org.eclipse.jface.dialogs.InputDialog;
13
import org.eclipse.jface.dialogs.MessageDialog;
14
import org.eclipse.jface.viewers.ArrayContentProvider;
15
import org.eclipse.jface.viewers.ColumnLabelProvider;
16
import org.eclipse.jface.viewers.ComboViewer;
17
import org.eclipse.jface.viewers.ISelection;
18
import org.eclipse.jface.viewers.IStructuredSelection;
19
import org.eclipse.jface.viewers.TableViewer;
20
import org.eclipse.jface.viewers.TableViewerColumn;
21
import org.eclipse.swt.SWT;
22
import org.eclipse.swt.events.KeyEvent;
23
import org.eclipse.swt.events.KeyListener;
24
import org.eclipse.swt.events.SelectionEvent;
25
import org.eclipse.swt.events.SelectionListener;
26
import org.eclipse.swt.graphics.Point;
27
import org.eclipse.swt.layout.GridData;
28
import org.eclipse.swt.widgets.Button;
29
import org.eclipse.swt.widgets.Combo;
30
import org.eclipse.swt.widgets.Composite;
31
import org.eclipse.swt.widgets.Display;
32
import org.eclipse.swt.widgets.Group;
33
import org.eclipse.swt.widgets.Label;
34
import org.eclipse.swt.widgets.TableColumn;
35
import org.eclipse.swt.widgets.Text;
36
import org.eclipse.ui.dialogs.ListDialog;
37
import org.txm.annotation.core.Annotation;
38
import org.txm.annotation.core.AnnotationManager;
39
import org.txm.annotation.core.KRAnnotationEngine;
40
import org.txm.annotation.core.repository.AnnotationType;
41
import org.txm.annotation.core.repository.KnowledgeRepository;
42
import org.txm.annotation.core.repository.KnowledgeRepositoryManager;
43
import org.txm.annotation.core.repository.LocalKnowledgeRepository;
44
import org.txm.annotation.core.repository.TypedValue;
45
import org.txm.annotation.rcp.commands.InitializeKnowledgeRepository;
46
import org.txm.annotation.rcp.commands.SaveAnnotations;
47
import org.txm.annotation.rcp.editor.AnnotationArea;
48
import org.txm.annotation.rcp.views.knowledgerepositories.KRView;
49
import org.txm.concordance.core.functions.Concordance;
50
import org.txm.concordance.core.functions.Line;
51
import org.txm.concordance.rcp.editors.ConcordanceEditor;
52
import org.txm.concordance.rcp.editors.ConcordanceEditor.ConcordanceColumnSizeControlListener;
53
import org.txm.concordance.rcp.messages.ConcordanceUIMessages;
54
import org.txm.core.results.TXMResult;
55
import org.txm.rcp.IImageKeys;
56
import org.txm.rcp.editors.TXMEditor;
57
import org.txm.rcp.swt.GLComposite;
58
import org.txm.rcp.swt.dialog.ConfirmDialog;
59
import org.txm.rcp.swt.provider.SimpleLabelProvider;
60
import org.txm.rcp.utils.JobHandler;
61
import org.txm.rcp.views.corpora.CorporaView;
62
import org.txm.searchengine.cqp.clientExceptions.CqiClientException;
63
import org.txm.searchengine.cqp.corpus.Corpus;
64
import org.txm.searchengine.cqp.corpus.query.Match;
65
import org.txm.utils.logger.Log;
66

  
67
public class SimpleKRAnnotation extends AnnotationArea<Concordance> {
68

  
69
	ConcordanceEditor editor;
70
	
71
	public SimpleKRAnnotation() {
72
		
73
	}
74

  
75
	/**
76
	 * the limit number of annotation when a confirm dialog box is shown
77
	 */
78
	protected static final int NALERTAFFECTANNOTATIONS = 100;
79
	public static final String EMPTYTEXT = "";
80

  
81
	/** The annotation service */
82
	protected AnnotationManager annotManager;
83

  
84
	//boolean annotation_expert_mode = TxmPreferences.getBoolean(AnnotationPreferencePage.MODE, false);
85

  
86
	protected Point annotationSize;
87

  
88
	protected Text annotationValuesText;
89
	protected ComboViewer annotationTypesCombo;
90

  
91
	protected TableColumn annotationColumn;
92

  
93
	protected Combo addRemoveCombo;
94
	protected Combo affectCombo;
95
	protected Button affectAnnotationButton;
96

  
97
	protected KnowledgeRepository currentKnowledgeRepository = null;
98
	protected Vector<AnnotationType> typesList = new Vector<AnnotationType>(); 
99

  
100
	protected Label withLabel;
101

  
102
	protected AnnotationType tagAnnotationType; // the tag annotation type if annotation mode is simple
103

  
104
	protected TypedValue value_to_add;
105

  
106
	protected Concordance concordance;
107

  
108
	private Corpus corpus;
109

  
110
	private ConcordanceAnnotations annotations = null;
111
	private Button addTypedValueLink;
112

  
113

  
114
	@Override
115
	public String getName() {
116
		return "Tag Annotation";
117
	}
118

  
119
	public boolean install(TXMEditor ceditor, final Corpus corpus, Composite parent) throws Exception{ 
120
		this.editor = (ConcordanceEditor)ceditor;
121
		this.corpus = corpus;
122
		this.concordance = editor.getConcordance();
123
		this.annotations = new ConcordanceAnnotations(editor.getConcordance());
124
		this.annotManager = KRAnnotationEngine.getAnnotationManager(corpus);
125

  
126
		TableViewer viewer = editor.getLineTableViewer();
127

  
128
		// RESULT
129

  
130
		int position = 3; // after keyword column
131
		TableViewerColumn annotationColumnViewer = new TableViewerColumn(viewer, SWT.CENTER, position);
132
		annotationColumn = annotationColumnViewer.getColumn();
133
		annotationColumn.setText(ConcordanceUIMessages.ConcordancesEditor_15);
134
		annotationColumn.setToolTipText(ConcordanceUIMessages.ConcordancesEditor_17);
135
		annotationColumn.pack();
136
		annotationColumn.setAlignment(SWT.CENTER);
137

  
138
		annotationColumn.addControlListener(new ConcordanceColumnSizeControlListener(annotationColumn));
139
		annotationColumnViewer.setLabelProvider(new ColumnLabelProvider() {
140

  
141
			@Override
142
			public String getText(Object element) {
143
				Line line = (Line)element;
144
				AnnotationLine annotationLine = annotations.getAnnotationLine(line);
145
				if (annotationLine == null) return EMPTYTEXT ;
146
				if (annotationLine.getAnnotation()!=null) {
147
					String value = annotationLine.getAnnotationValue().getStandardName();
148
					Annotation a = annotationLine.getAnnotation();
149
					if (value == null) value = a.getValue();
150

  
151
					if (a.getStart() < line.matchGetStart() - line.getLeftContextSize()) {
152
						value = "… "+value;
153
					}
154

  
155
					if (a.getEnd() > line.matchGetEnd() + line.getRightContextSize()) {
156
						value = value+" …";
157
					} 
158
					return value;
159
				} else {
160
					return EMPTYTEXT;
161
				}
162
			}
163
		});
164

  
165
		List<KnowledgeRepository> krs = InitializeKnowledgeRepository.get(corpus.getMainCorpus());
166
		typesList.clear();
167
		Log.warning("Corpus KRs: "+krs); //$NON-NLS-1$
168

  
169
		KnowledgeRepository kr  = KnowledgeRepositoryManager.getKnowledgeRepository(corpus.getMainCorpus().getName());
170
		if (kr == null) {
171
			HashMap<String, HashMap<String, ?>> conf = new HashMap<String, HashMap<String, ?>>();
172
			kr = KnowledgeRepositoryManager.createKnowledgeRepository(corpus.getMainCorpus().getName(), conf);
173
		}
174

  
175
		currentKnowledgeRepository = kr;
176
		Log.warning(" KR: "+kr); //$NON-NLS-1$
177
		List<AnnotationType> krtypes = kr.getAllAnnotationTypes();
178

  
179
		boolean createTagAnnotationType = true;
180
		for (AnnotationType type : krtypes) {
181
			if (type.getName().equals("span")) { //$NON-NLS-1$
182
				createTagAnnotationType = false;
183
			}
184
		}
185
		if (createTagAnnotationType) {
186
			tagAnnotationType = kr.addType("span", "span");//corresponds to an "undef" type //$NON-NLS-1$ //$NON-NLS-2$
187
			typesList.add(tagAnnotationType);
188
		} else {
189
			tagAnnotationType = kr.getType("span"); //$NON-NLS-1$
190
		}
191
		annotations.setViewAnnotation(tagAnnotationType);
192
		
193
		Log.warning("Available annotation types: "+typesList);
194

  
195
		annotationArea = new GLComposite(parent, SWT.NONE, "Concordance Annotation area");
196
		annotationArea.getLayout().numColumns = 12;
197
		annotationArea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
198

  
199
		addRemoveCombo = new Combo(annotationArea, SWT.READ_ONLY);
200
		String affectLabel = currentKnowledgeRepository.getString(getLocale(), "ConcordancesEditor_22");
201
		if (affectLabel == null) affectLabel= ConcordanceUIMessages.ConcordancesEditor_22;
202
		String removeLabel = currentKnowledgeRepository.getString(getLocale(), "ConcordancesEditor_24");
203
		if (removeLabel == null) removeLabel= ConcordanceUIMessages.ConcordancesEditor_24;
204
		String items[] = {affectLabel, removeLabel};
205
		addRemoveCombo.setItems(items);
206
		addRemoveCombo.select(0);
207
		addRemoveCombo.addSelectionListener(new SelectionListener() {
208
			@Override
209
			public void widgetSelected(SelectionEvent e) {
210
				if (addRemoveCombo.getSelectionIndex() == 0) { // add
211
					annotationValuesText.setEnabled(true);
212
					String withLabelText = currentKnowledgeRepository.getString(getLocale(), "ConcordancesEditor_83");
213
					if (withLabelText == null) withLabelText= ConcordanceUIMessages.ConcordancesEditor_83;
214
					withLabel.setText(withLabelText);
215
				} else { // remove
216
					annotationValuesText.setEnabled(false);
217
					withLabel.setText(""); //$NON-NLS-1$
218
				}
219
				withLabel.redraw();
220
				annotationArea.layout();
221
				updateAnnotationWidgetStates();
222
			}
223
			@Override
224
			public void widgetDefaultSelected(SelectionEvent e) { }
225
		});
226
		GridData gdata = new GridData(SWT.CENTER, SWT.CENTER, false, false);
227
		gdata.widthHint = 90;
228
		addRemoveCombo.setLayoutData(gdata);
229

  
230
		withLabel = new Label(annotationArea, SWT.NONE);
231
		String withLabelText = currentKnowledgeRepository.getString(getLocale(), "ConcordancesEditor_83");
232
		if (withLabelText == null) withLabelText= ConcordanceUIMessages.ConcordancesEditor_83;
233
		withLabel.setText(withLabelText);
234
		withLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
235

  
236
		annotationValuesText = new Text(annotationArea, SWT.BORDER);
237
		annotationValuesText.setToolTipText(ConcordanceUIMessages.ConcordancesEditor_32);
238
		GridData gdata2 = new GridData(SWT.FILL, SWT.CENTER, false, false);
239
		gdata2.widthHint = 200;
240
		annotationValuesText.setLayoutData(gdata2);
241
		annotationValuesText.addKeyListener(new KeyListener() {
242
			@Override
243
			public void keyReleased(KeyEvent e) {
244
				if (e.keyCode == SWT.CR || e.keyCode == SWT.KEYPAD_CR) {
245
					affectAnnotationToSelection(editor.getLineTableViewer().getSelection());
246
				}
247
			}
248

  
249
			@Override
250
			public void keyPressed(KeyEvent e) { }
251
		});
252

  
253
		if (currentKnowledgeRepository instanceof LocalKnowledgeRepository) {
254
			addTypedValueLink = new Button(annotationArea, SWT.PUSH);
255
			addTypedValueLink.setText("..."); //$NON-NLS-1$
256
			addTypedValueLink.setToolTipText(ConcordanceUIMessages.ConcordancesEditor_77);
257
			addTypedValueLink.setEnabled(true);
258
			addTypedValueLink.setLayoutData(new GridData(SWT.FILL,	SWT.CENTER, false, false));
259
			addTypedValueLink.addSelectionListener(new SelectionListener() {
260
				@Override
261
				public void widgetSelected(SelectionEvent e) {
262
					if (currentKnowledgeRepository == null) return;
263
					if (!(currentKnowledgeRepository instanceof LocalKnowledgeRepository)) return;
264

  
265
					AnnotationType type = getSelectedAnnotationType();
266
					if (type == null) return;
267

  
268
					LocalKnowledgeRepository kr = (LocalKnowledgeRepository)currentKnowledgeRepository;
269

  
270
					ListDialog dialog = new ListDialog(e.widget.getDisplay().getActiveShell());
271
					dialog.setTitle(ConcordanceUIMessages.ConcordancesEditor_99);//+"valeurs de "+type.getName());
272
					dialog.setContentProvider(new ArrayContentProvider());
273
					dialog.setLabelProvider(new SimpleLabelProvider() {
274
						public String getColumnText(Object element, int columnIndex) {
275
							if (element instanceof TypedValue)
276
								return ((TypedValue)element).getId();
277
							return element.toString();
278
						}
279
					});
280
					List<TypedValue> values;
281
					try {
282
						values = kr.getValues(type);
283
					} catch (Exception e1) {
284
						e1.printStackTrace();
285
						return;
286
					}
287
					dialog.setInput(values);
288
					if (dialog.open() == InputDialog.OK) {
289
						TypedValue value = (TypedValue) dialog.getResult()[0];
290
						String name = value.getId();
291
						if (name.trim().length() == 0) return;
292

  
293
						annotationValuesText.setText(name);
294
					} else {
295

  
296
					}
297
				}
298

  
299
				@Override
300
				public void widgetDefaultSelected(SelectionEvent e) { }
301
			});
302
		}
303

  
304
		affectCombo = new Combo(annotationArea, SWT.READ_ONLY);
305
		affectCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
306
		String items2[] = {ConcordanceUIMessages.ConcordancesEditor_35, ConcordanceUIMessages.ConcordancesEditor_49};
307
		affectCombo.setItems(items2);
308
		affectCombo.select(0);
309
		gdata = new GridData(SWT.CENTER, SWT.CENTER, false, false);
310
		gdata.widthHint = 140;
311
		affectCombo.setLayoutData(gdata);
312

  
313
		affectAnnotationButton = new Button(annotationArea, SWT.PUSH);
314
		affectAnnotationButton.setText(ConcordanceUIMessages.ConcordancesEditor_85);
315
		affectAnnotationButton.setToolTipText(ConcordanceUIMessages.ConcordancesEditor_116);
316
		affectAnnotationButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
317
		affectAnnotationButton.addSelectionListener(new SelectionListener() {
318
			@Override
319
			public void widgetSelected(SelectionEvent e) {
320
				int isel = affectCombo.getSelectionIndex();
321
				if (isel == 0) { // selected line
322
					affectAnnotationToSelection(editor.getLineTableViewer().getSelection());
323
				} else { // all
324
					try {
325
						List<Match> matches = concordance.getMatches();
326
						affectMatchesToSelection(matches);
327
					} catch (CqiClientException e1) {
328
						Log.severe(ConcordanceUIMessages.ConcordancesEditor_53+e1);
329
						Log.printStackTrace(e1);
330
						return;
331
					}
332
				}
333
			}
334

  
335
			@Override
336
			public void widgetDefaultSelected(SelectionEvent e) { }
337
		});
338
		Button saveAnnotationsButton = new Button(annotationArea, SWT.PUSH);
339
		saveAnnotationsButton.setToolTipText(ConcordanceUIMessages.ConcordancesEditor_76);
340
		saveAnnotationsButton.setImage(IImageKeys.getImage(IImageKeys.PENCIL_SAVE));
341

  
342
		saveAnnotationsButton.addSelectionListener(new SelectionListener() {
343
			@Override
344
			public void widgetSelected(SelectionEvent e) {
345
				save();
346
			}
347

  
348
			@Override
349
			public void widgetDefaultSelected(SelectionEvent e) { }
350
		});
351

  
352
		updateAnnotationWidgetStates();
353
		editor.layout(true);
354

  
355
		return true;
356
	}
357

  
358
	protected void affectAnnotationToSelection(ISelection selection) {
359

  
360
		final IStructuredSelection lineSelection = (IStructuredSelection) selection;
361
		List<Line> lines = lineSelection.toList();
362
		ArrayList<Match> matches = new ArrayList<Match>();
363
		for (Line l : lines) {
364
			matches.add(l.getMatch());
365
		}
366

  
367
		affectMatchesToSelection(matches);
368
	}
369

  
370
	protected AnnotationType getSelectedAnnotationType() {
371
		if (annotationTypesCombo != null) {
372
			IStructuredSelection isel = (IStructuredSelection)annotationTypesCombo.getSelection();
373
			if (isel.isEmpty()) {
374
				return null;
375
			}
376
			return (AnnotationType) isel.getFirstElement();
377
		} else { // simple mode
378
			return tagAnnotationType;
379
		}
380
	}
381

  
382
	protected void affectMatchesToSelection(final List<Match> matches) {
383
		final AnnotationType type = getSelectedAnnotationType();
384
		final String svalue = annotationValuesText.getText();
385
		final boolean doAffect = addRemoveCombo.getSelectionIndex() == 0; // add is default
386

  
387
		JobHandler job = new JobHandler(ConcordanceUIMessages.ConcordancesEditor_36, true) {
388
			@Override
389
			protected IStatus run(IProgressMonitor monitor) {
390
				this.runInit(monitor);
391
				try {
392
					if (doAffect) {
393
						affectAnnotationValues(matches, type, svalue, this);
394
					} else {
395
						deleteAnnotationValues(matches, type, this);
396
					}
397
				} catch(Exception e) {
398
					Log.severe(ConcordanceUIMessages.ConcordancesEditor_40+e);
399
					Log.printStackTrace(e);
400
					return Status.CANCEL_STATUS;
401
				} catch(ThreadDeath td) {
402
					System.out.println("Annotation canceled by user.");
403
					return Status.CANCEL_STATUS;
404
				}
405

  
406
				return Status.OK_STATUS;
407
			}
408
		};
409
		job.startJob(true);
410
	}
411

  
412
	public void updateAnnotationWidgetStates() {
413
		if (annotationArea == null) return; // :)
414

  
415
		if (addRemoveCombo.getSelectionIndex() == 0) { // add is default
416

  
417
			if (getSelectedAnnotationType() != null) {
418
				annotationValuesText.setEnabled(true);
419

  
420
				affectAnnotationButton.setEnabled(true);
421
				affectCombo.setEnabled(true);
422
			} else {
423
				annotationValuesText.setEnabled(false);
424

  
425
				affectAnnotationButton.setEnabled(false);
426
				affectCombo.setEnabled(false);
427
			}
428
		} else {
429
			annotationValuesText.setEnabled(false);
430

  
431
			if (getSelectedAnnotationType() != null) {
432
				affectAnnotationButton.setEnabled(true);
433
				affectCombo.setEnabled(true);
434
			} else {
435
				affectAnnotationButton.setEnabled(false);
436
				affectCombo.setEnabled(false);
437
			}
438
		}
439

  
440

  
441
		if (addTypedValueLink != null) {
442
			addTypedValueLink.setEnabled(getSelectedAnnotationType() != null);
443
		}
444
	}
445

  
446
	protected void deleteAnnotationValues(List<Match> matches, AnnotationType type, JobHandler job) {
447

  
448
		if (matches.size() == 0) {
449
			System.out.println("No lines selected. Aborting."); //$NON-NLS-1$
450
			return;
451
		}
452

  
453
		if (type == null) {
454
			return;
455
		}
456

  
457
		try {
458
			if (annotManager != null && annotManager.deleteAnnotations(type, matches, job)) {
459
				if (Log.getLevel().intValue() < Level.WARNING.intValue()) annotManager.checkData();
460
				editor.refresh(false);
461
			} else {
462
				return;
463
			}
464
		} catch (Exception e1) {
465
			System.out.println(ConcordanceUIMessages.ConcordancesEditor_54+e1);
466
			Log.printStackTrace(e1);
467
			return;
468
		}
469

  
470
		job.syncExec(new Runnable() {
471
			@Override
472
			public void run() {
473
				try {
474
					editor.refresh(false);
475
				} catch (Exception e) {
476
					// TODO Auto-generated catch block
477
					e.printStackTrace();
478
				}
479
			}
480
		});
481
	}
482

  
483
	protected void affectAnnotationValues(final List<Match> matches,  final AnnotationType type, final String svalue, JobHandler job) {
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff