Revision 501

tmp/org.txm.annotation.rcp/build.properties (revision 501)
1
source.. = src/
2
output.. = bin/
3
bin.includes = META-INF/,\
4
               .,\
5
               plugin.xml
0 6

  
tmp/org.txm.annotation.rcp/plugin.xml (revision 501)
1
<?xml version="1.0" encoding="UTF-8"?>
2
<?eclipse version="3.4"?>
3
<plugin>
4
   <extension
5
         point="org.eclipse.ui.commands">
6
               <command
7
            categoryId="org.txm.rcp.category.txm"
8
            defaultHandler="org.txm.rcp.commands.workspace.RecodeCorpus"
9
            id="org.txm.rcp.commands.workspace.RecodeCorpus"
10
            name="%command.name.100">
11
      </command>
12
            <command
13
            categoryId="org.txm.rcp.category.txm"
14
            defaultHandler="org.txm.annotation.rcp.commands.SaveAnnotations"
15
            id="org.txm.rcp.commands.annotation.SaveAnnotations"
16
            name="%command.name.97">
17
      </command>
18
            <command
19
            defaultHandler="org.txm.annotation.rcp.commands.krview.OpenKRView"
20
            id="org.txm.rcp.commands.krview.OpenKRView"
21
            name="%command.name.99">
22
      </command>
23
      <command
24
            defaultHandler="org.txm.annotation.rcp.commands.krview.Copy"
25
            id="org.txm.rcp.commands.krview.Copy"
26
            name="%command.name.101">
27
      </command>
28
      <command
29
            defaultHandler="org.txm.annotation.rcp.commands.krview.Reload"
30
            id="org.txm.rcp.commands.krview.Reload"
31
            name="%command.name.102">
32
      </command>
33
      <command
34
            defaultHandler="org.txm.annotation.rcp.commands.krview.Informations"
35
            id="org.txm.rcp.commands.krview.Informations"
36
            name="%command.name.103">
37
      </command>
38
      <command
39
            defaultHandler="org.txm.annotation.rcp.commands.krview.Delete"
40
            id="org.txm.rcp.commands.krview.Delete"
41
            name="%command.name.104">
42
      </command>
43
      <command
44
            defaultHandler="org.txm.annotation.rcp.commands.krview.Add"
45
            id="org.txm.rcp.commands.krview.Add"
46
            name="%command.name.105">
47
      </command>
48
      <command
49
            defaultHandler="org.txm.annotation.rcp.commands.ExportStandoff"
50
            id="org.txm.rcp.commands.annotation.ExportStandoff"
51
            name="%command.name.107">
52
      </command>
53
   </extension>
54
  <extension
55
        point="org.eclipse.ui.preferencePages">
56
     <page
57
           category="org.txm.rcp.preferences.UserPreferencePage"
58
           class="org.txm.annotation.rcp.preferences.AnnotationPreferencePage"
59
           id="org.txm.rcp.preferences.AnnotationPreferencePage"
60
           name="%page.name.23">
61
     </page>
62
  </extension>
63
  <extension
64
         point="org.eclipse.ui.bindings">
65
      <key
66
            commandId="org.txm.rcp.commands.krview.Add"
67
            contextId="org.txm.rcp.annotation.krview"
68
            schemeId="org.txm.rcp.scheme"
69
            sequence="Ctrl+A">
70
      </key>
71
      <key
72
            commandId="org.txm.rcp.commands.krview.Reload"
73
            contextId="org.txm.rcp.annotation.krview"
74
            schemeId="org.txm.rcp.scheme"
75
            sequence="Ctrl+R">
76
      </key>
77
      <key
78
            commandId="org.txm.rcp.commands.krview.Informations"
79
            contextId="org.txm.rcp.annotation.krview"
80
            schemeId="org.txm.rcp.scheme"
81
            sequence="Ctrl+I">
82
      </key>
83
      <key
84
            commandId="org.txm.rcp.commands.krview.Copy"
85
            contextId="org.txm.rcp.annotation.krview"
86
            schemeId="org.txm.rcp.scheme"
87
            sequence="Ctrl+C">
88
      </key>
89
      <key
90
            commandId="org.txm.rcp.commands.krview.Delete"
91
            contextId="org.txm.rcp.annotation.krview"
92
            schemeId="org.txm.rcp.scheme"
93
            sequence="Ctrl+D">
94
      </key>
95
   </extension>
96
  <extension
97
        point="org.eclipse.ui.menus">
98
     <menuContribution
99
           allPopups="false"
100
           locationURI="menu:menu.display.views">
101
           <command
102
                     commandId="org.txm.rcp.commands.krview.OpenKRView"
103
                     label="%command.label.150"
104
                     style="push">
105
               </command>
106
     </menuContribution>
107
     <menuContribution
108
            locationURI="popup:org.txm.rcp.views.knowledgerepositories.KRView">
109
         <command
110
               commandId="org.txm.rcp.commands.krview.Copy"
111
               label="%command.label.188"
112
               style="push"
113
               tooltip="%command.tooltip.89">
114
         </command>
115
         <command
116
               commandId="org.txm.rcp.commands.krview.Reload"
117
               label="%command.label.189"
118
               style="push"
119
               tooltip="%command.tooltip.90">
120
            <visibleWhen
121
                  checkEnabled="false">
122
               <reference
123
                     definitionId="OneKRSelected">
124
               </reference>
125
            </visibleWhen>
126
         </command>
127
         <command
128
               commandId="org.txm.rcp.commands.krview.Informations"
129
               label="%command.label.190"
130
               style="push"
131
               tooltip="%command.tooltip.93">
132
         </command>
133
         <command
134
               commandId="org.txm.rcp.commands.krview.Add"
135
               label="%command.label.191"
136
               style="push"
137
               tooltip="%command.tooltip.94">
138
            <visibleWhen
139
                  checkEnabled="false">
140
               <or>
141
                  <reference
142
                        definitionId="OneLocalKRSelected">
143
                  </reference>
144
                  <reference
145
                        definitionId="OneAnnotationTypeSelected">
146
                  </reference>
147
               </or>
148
            </visibleWhen>
149
         </command>
150
         <command
151
               commandId="org.txm.rcp.commands.krview.Delete"
152
               label="%command.label.192"
153
               style="push"
154
               tooltip="%command.tooltip.95">
155
            <visibleWhen
156
                  checkEnabled="false">
157
               <or>
158
                  <reference
159
                        definitionId="OneAnnotationTypeSelected">
160
                  </reference>
161
                  <reference
162
                        definitionId="OneTypedValueSelected">
163
                  </reference>
164
               </or>
165
            </visibleWhen>
166
         </command>
167
      </menuContribution>
168
     <menuContribution
169
           allPopups="false"
170
           locationURI="menu:menu.file.export">
171
           <command
172
                     commandId="org.txm.rcp.commands.annotation.ExportStandoff"
173
                     id="menu.file.export.exporttei"
174
                     label="%command.label.193"
175
                     style="push">
176
                  <visibleWhen
177
                        checkEnabled="false">
178
                     <reference
179
                           definitionId="OneMainCorpusSelected">
180
                     </reference>
181
                  </visibleWhen>
182
               </command>
183
     </menuContribution>
184
     <menuContribution
185
           allPopups="false"
186
           locationURI="menu:menu.corpus?after=menu.corpus.build">
187
           <command
188
                  commandId="org.txm.rcp.commands.annotation.SaveAnnotations"
189
                  icon="icons/functions/save.png"
190
                  label="%command.label.111"
191
                  style="push">
192
               <visibleWhen
193
                     checkEnabled="false">
194
                  <reference
195
                        definitionId="NeedToSaveAnnotations">
196
                  </reference>
197
               </visibleWhen>
198
            </command>
199
     </menuContribution>
200
     <menuContribution
201
           allPopups="false"
202
           locationURI="toolbar:org.txm.rcp.toolbarcorpus?after=org.txm.rcp.toolbarcorpus.annotation">
203
           <command
204
                  commandId="org.txm.rcp.commands.annotation.SaveAnnotations"
205
                  icon="icons/functions/save.png"
206
                  label="%command.label.151"
207
                  style="push">
208
               <visibleWhen
209
                     checkEnabled="false">
210
                  <reference
211
                        definitionId="NeedToSaveAnnotations">
212
                  </reference>
213
               </visibleWhen>
214
            </command>
215
     </menuContribution>
216
     <menuContribution
217
           allPopups="false"
218
           locationURI="menu:corporaview.menu.file.export?after=org.txm.rcp.views.corpora.CorporaView.annotation">
219
            <command
220
                  commandId="org.txm.rcp.commands.annotation.ExportStandoff"
221
                  label="%command.label.193"
222
                  style="push">
223
               <visibleWhen
224
                     checkEnabled="false">
225
                  <reference
226
                        definitionId="OneMainCorpusSelected">
227
                  </reference>
228
               </visibleWhen>
229
            </command>
230
     </menuContribution>
231
     <menuContribution
232
           allPopups="false"
233
           locationURI="popup:org.txm.rcp.views.corpora.CorporaView">
234
        <command
235
              commandId="org.txm.rcp.commands.annotation.SaveAnnotations"
236
              icon="icons/functions/save.png"
237
              label="%command.label.154"
238
              style="push">
239
           <visibleWhen
240
                 checkEnabled="false">
241
              <reference
242
                    definitionId="NeedToSaveAnnotations">
243
              </reference>
244
           </visibleWhen>
245
        </command>
246
     </menuContribution>
247
  </extension>
248
  <extension
249
         point="org.eclipse.ui.contexts">
250
      <context
251
            description="%context.description"
252
            id="org.txm.rcp.annotation.krview"
253
            name="%context.name">
254
      </context>
255
   </extension>
256
  <extension
257
        point="org.eclipse.core.expressions.definitions">
258
     <definition
259
                  id="OneKRSelected">
260
               <with
261
                     variable="selection">
262
                  <iterate
263
                        ifEmpty="false"
264
                        operator="and">
265
                     <instanceof
266
                           value="org.txm.annotation.KnowledgeRepository">
267
                     </instanceof>
268
                  </iterate>
269
               </with>
270
            </definition>
271
            <definition
272
                  id="OneLocalKRSelected">
273
               <with
274
                     variable="selection">
275
                  <iterate
276
                        ifEmpty="false"
277
                        operator="and">
278
                     <instanceof
279
                           value="org.txm.annotation.repository.LocalKnowledgeRepository">
280
                     </instanceof>
281
                  </iterate>
282
               </with>
283
            </definition>
284
                        <definition
285
                  id="OneAnnotationTypeSelected">
286
               <with
287
                     variable="selection">
288
                  <iterate
289
                        ifEmpty="false"
290
                        operator="and">
291
                     <instanceof
292
                           value="org.txm.annotation.repository.AnnotationType">
293
                     </instanceof>
294
                  </iterate>
295
               </with>
296
            </definition>
297
            <definition
298
                  id="OneTypedValueSelected">
299
               <with
300
                     variable="selection">
301
                  <iterate
302
                        ifEmpty="false"
303
                        operator="and">
304
                     <instanceof
305
                           value="org.txm.annotation.repository.TypedValue">
306
                     </instanceof>
307
                  </iterate>
308
               </with>
309
            </definition>
310
  </extension>
311
</plugin>
0 312

  
tmp/org.txm.annotation.rcp/.settings/org.eclipse.jdt.core.prefs (revision 501)
1
eclipse.preferences.version=1
2
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
4
org.eclipse.jdt.core.compiler.compliance=1.6
5
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
6
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
7
org.eclipse.jdt.core.compiler.source=1.6
0 8

  
tmp/org.txm.annotation.rcp/.classpath (revision 501)
1
<?xml version="1.0" encoding="UTF-8"?>
2
<classpath>
3
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
4
	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
5
	<classpathentry kind="src" path="src"/>
6
	<classpathentry kind="output" path="bin"/>
7
</classpath>
0 8

  
tmp/org.txm.annotation.rcp/META-INF/MANIFEST.MF (revision 501)
1
Manifest-Version: 1.0
2
Bundle-ManifestVersion: 2
3
Bundle-Name: Annoration RCP
4
Bundle-SymbolicName: org.txm.annotation.rcp;singleton:=true
5
Bundle-Version: 1.0.0.qualifier
6
Bundle-Vendor: textometrie.org
7
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
8
Require-Bundle: org.txm.annotation.core;bundle-version="1.0.0";visibility:=reexport,
9
 org.eclipse.core.commands,
10
 org.eclipse.jface,
11
 org.eclipse.ui.workbench;visibility:=reexport,
12
 org.txm.rcp;bundle-version="0.8.0";visibility:=reexport
13
Export-Package: org.txm.annotation.rcp.commands,
14
 org.txm.annotation.rcp.commands.krview,
15
 org.txm.annotation.rcp.views.knowledgerepositories,
16
 org.txm.rcp.tests
0 17

  
tmp/org.txm.annotation.rcp/.project (revision 501)
1
<?xml version="1.0" encoding="UTF-8"?>
2
<projectDescription>
3
	<name>org.txm.annotation.rcp</name>
4
	<comment></comment>
5
	<projects>
6
	</projects>
7
	<buildSpec>
8
		<buildCommand>
9
			<name>org.eclipse.jdt.core.javabuilder</name>
10
			<arguments>
11
			</arguments>
12
		</buildCommand>
13
		<buildCommand>
14
			<name>org.eclipse.pde.ManifestBuilder</name>
15
			<arguments>
16
			</arguments>
17
		</buildCommand>
18
		<buildCommand>
19
			<name>org.eclipse.pde.SchemaBuilder</name>
20
			<arguments>
21
			</arguments>
22
		</buildCommand>
23
	</buildSpec>
24
	<natures>
25
		<nature>org.eclipse.pde.PluginNature</nature>
26
		<nature>org.eclipse.jdt.core.javanature</nature>
27
	</natures>
28
</projectDescription>
0 29

  
tmp/org.txm.annotation.rcp/src/org/txm/rcp/tests/AnnotationLookUp.java (revision 501)
1
package org.txm.rcp.tests;
2

  
3
import java.util.ArrayList;
4
import java.util.Arrays;
5
import java.util.HashMap;
6
import java.util.LinkedHashMap;
7
import java.util.List;
8

  
9
import org.txm.annotation.core.Annotation;
10
import org.txm.annotation.core.AnnotationManager;
11
import org.txm.annotation.core.CQPAnnotationManager;
12
import org.txm.annotation.core.KRAnnotationEngine;
13
import org.txm.annotation.core.repository.AnnotationType;
14
import org.txm.annotation.core.repository.KnowledgeRepository;
15
import org.txm.annotation.core.repository.KnowledgeRepositoryManager;
16
import org.txm.annotation.core.repository.TypedValue;
17
import org.txm.annotation.core.storage.temporary.TemporaryAnnotationManager;
18
import org.txm.annotation.rcp.commands.InitializeKnowledgeRepository;
19
import org.txm.searchengine.cqp.corpus.CorpusManager;
20
import org.txm.searchengine.cqp.corpus.MainCorpus;
21
import org.txm.searchengine.cqp.corpus.query.Match;
22

  
23
public class AnnotationLookUp {
24

  
25
	////JPA Annotation Manager (only among temporary annotations)
26

  
27
	public static void writingAnnotations(KnowledgeRepository kr, MainCorpus c, AnnotationManager am){
28
		TemporaryAnnotationManager jpamanager = am.getTemporaryManager();
29
		try {
30

  
31
			List<Annotation> annotsOverlapped;
32
			AnnotationType T1 = kr.getType("T1");
33
			AnnotationType T2 = kr.getType("T2");
34

  
35
			if (T1 == null || T2 == null) {
36
				System.out.println("Annotation types are NULL !!!");
37
				return;
38
			} 
39

  
40
			TypedValue val1 = kr.getValue(T1, "V1");
41
			TypedValue val2 = kr.getValue(T1, "V2");
42
			TypedValue val3 = kr.getValue(T1, "V3");
43
			TypedValue val4 = kr.getValue(T1, "V4");
44
			TypedValue val5 = kr.getValue(T2, "V5");
45

  
46
			TypedValue val6 = kr.getValue(T2, "V6");
47
			TypedValue val7 = kr.getValue(T2, "V7");
48
			TypedValue val8 = kr.getValue(T2, "V8");
49

  
50
			if(val1!= null && val2!=null && val3!=null && val4!= null && 
51
					val5!=null && val6!=null && val7!= null && val8!=null) {
52
				//OK
53
				System.out.println("============== Creation with no overlap ==============");
54
				annotsOverlapped = jpamanager.createAnnotation(T1, val1, 3, 3); 
55
				System.out.println("No overlap for [val1] ? colision = "+annotsOverlapped);
56
				annotsOverlapped = jpamanager.createAnnotation(T1, val2, 10, 12); 
57
				System.out.println("No overlap for [val2] ? colision = "+annotsOverlapped);
58
				annotsOverlapped = jpamanager.createAnnotation(T2, val3, 24, 29); 
59
				System.out.println("No overlap for [val2] ? colision = "+annotsOverlapped);
60
				annotsOverlapped = jpamanager.createAnnotation(T2, val4, 11, 11); 
61
				System.out.println("One overlap for [val4] ? colision = "+annotsOverlapped);
62
				annotsOverlapped = jpamanager.createAnnotation(T2, val5, 2, 5); 
63
				System.out.println("One overlap for [val5] ? colision = "+annotsOverlapped);
64
				jpamanager.checkData();
65
				am.saveAnnotations();		
66
			}
67

  
68
		} catch (Exception e) {
69
			// TODO Bloc catch généré automatiquement
70
			e.printStackTrace();
71
		}
72
	}
73

  
74
	public static class Test {
75
		public AnnotationType type;
76
		public TypedValue value;
77
		public List<Match> matches;
78
		public String comment;
79
		public Test(AnnotationType type, TypedValue value, List<Match> matches, String comment) {
80
			this.type = type;
81
			this.value = value;
82
			this.matches = matches;
83
			this.comment = comment;
84
		}
85

  
86
		public String toString() { return value.toString()+" at "+matches; }
87
	}
88

  
89
	public static void checkingAnnotationManager(KnowledgeRepository kr, MainCorpus c, AnnotationManager am){
90

  
91
		try {
92
			HashMap<Match, List<Annotation>> annotsOverlapped;
93
			AnnotationType T1 = kr.getType("T1");
94
			AnnotationType T2 = kr.getType("T2");
95

  
96
			if (T1 == null || T2 == null) {
97
				System.out.println("Annotation types are NULL !!!");
98
				return;
99
			}		
100

  
101
			TypedValue V1 = kr.getValue(T1, "V1");
102
			TypedValue V2 = kr.getValue(T1, "V2");
103
			TypedValue V5 = kr.getValue(T2, "V5");
104

  
105
			LinkedHashMap<String, ArrayList<Test>> testSuits = new LinkedHashMap<String, ArrayList<Test>>();
106
			ArrayList<Test> tests = null;
107

  
108
			tests = new ArrayList<Test>();
109
			tests.add(new Test(T1, V1, Arrays.asList(new Match(3, 3)), "no overlap"));
110
			tests.add(new Test(T1, V1, Arrays.asList(new Match(10, 12)), "no overlap"));
111
			testSuits.put("No overlap, diff types", tests);
112

  
113
			tests = new ArrayList<Test>();
114
			tests.add(new Test(T1, V1, Arrays.asList(new Match(9, 10)), "ON START impossible"));
115
			tests.add(new Test(T1, V1, Arrays.asList(new Match(12, 13)), "ON END impossible"));
116
			tests.add(new Test(T1, V1, Arrays.asList(new Match(9, 13)), "OUTTER impossible"));
117
			tests.add(new Test(T1, V1, Arrays.asList(new Match(11, 11)), "INNER impossible"));
118
			testSuits.put("Creation overlap with same type", tests);
119

  
120
			tests = new ArrayList<Test>();
121
			tests.add(new Test(T1, V1, Arrays.asList(new Match(23, 24)), "overlap"));
122
			tests.add(new Test(T1, V1, Arrays.asList(new Match(45, 50)), "no overlap"));
123
			testSuits.put("No overlap, diff types, pls words", tests);
124

  
125
			tests = new ArrayList<Test>();
126
			tests.add(new Test(T2, V5, Arrays.asList(new Match(9, 11)), "ON START impossible"));
127
			tests.add(new Test(T2, V5, Arrays.asList(new Match(11, 14)), "ON END impossible"));
128
			tests.add(new Test(T2, V5, Arrays.asList(new Match(22, 26)), "OUTTER possible")); // a tester avec une annotation T1 isolée
129
			tests.add(new Test(T2, V5, Arrays.asList(new Match(47, 47)), "INNER possible"));
130
			testSuits.put("Creation overlap with another type", tests);
131

  
132
			tests = new ArrayList<Test>();
133
			tests.add(new Test(T1, V2, Arrays.asList(new Match(47, 47)), "REPLACE TEMP"));
134
			tests.add(new Test(T1, V2, Arrays.asList(new Match(3, 3)), "REPLACE CQP"));
135
			testSuits.put("Updating values", tests);
136

  
137

  
138
			LinkedHashMap<String, ArrayList<Test>> testSuits2 = new LinkedHashMap<String, ArrayList<Test>>();
139
			tests = new ArrayList<Test>();
140
			tests.add(new Test(T2, V2, Arrays.asList(new Match(7, 7)), "DELETE TEMP"));
141
			tests.add(new Test(T1, V2, Arrays.asList(new Match(3, 3)), "DELETE CQP #del"));
142
			testSuits2.put("Updating values", tests);
143

  
144
			System.out.println("============== Create&Update ==============");
145
			for (String suit : testSuits.keySet()) {
146
				tests = testSuits.get(suit);
147
				System.out.println("======== "+suit+" ========");
148
				for (Test test : tests) {
149
					System.out.println("Test "+test);
150
					annotsOverlapped = am.createAnnotations(test.type, test.value, test.matches, null); //Annotation on three words : "cela va marcher"
151
					System.out.println("--> "+test.comment+" for "+test.value+" at "+test.matches+" ? colision = "+annotsOverlapped);
152
					am.checkData();
153
				}
154
			}
155

  
156
			System.out.println("============== Deleting ==============");
157
			for (String suit : testSuits2.keySet()) {
158
				tests = testSuits2.get(suit);
159
				for (Test test : tests) {
160
					System.out.println(test.comment+test.type+" at "+test.matches);
161
					am.deleteAnnotations(test.type, test.matches, null);
162
					am.checkData();
163
				}
164
			}
165

  
166
			System.out.println("============== CLean all ==============");
167
			am.getTemporaryManager().deleteAnnotations();
168
		} catch (Exception e) {
169
			// TODO Bloc catch généré automatiquement
170
			e.printStackTrace();
171
		}
172
	}
173

  
174
	public static void checkingJPAManager(KnowledgeRepository kr, MainCorpus c, AnnotationManager am){
175

  
176
		TemporaryAnnotationManager jpamanager = am.getTemporaryManager();
177
		try {
178
			List<Annotation> annotsOverlapped;
179
			AnnotationType T1 = kr.getType("T1");
180
			AnnotationType T2 = kr.getType("T2");
181

  
182
			if (T1 == null || T2 == null) {
183
				System.out.println("Annotation types are NULL !!!");
184
				return;
185
			}
186

  
187
			TypedValue val1 = kr.getValue(T1, "V1");
188
			TypedValue val2 = kr.getValue(T1, "V2");
189
			TypedValue val3 = kr.getValue(T1, "V3");
190
			TypedValue val4 = kr.getValue(T1, "V4");
191

  
192
			TypedValue val5 = kr.getValue(T2, "V5");
193
			TypedValue val6 = kr.getValue(T2, "V6");
194
			TypedValue val7 = kr.getValue(T2, "V7");
195
			TypedValue val8 = kr.getValue(T2, "V8");
196

  
197
			TypedValue val9 = kr.getValue(T1, "V9");
198

  
199
			if(val1!= null && val2!=null && val3!=null && val4!= null && 
200
					val5!=null && val6!=null && val7!= null && val8!=null) {
201
				//OK
202
				System.out.println("============== Creation with no overlap ==============");
203
				annotsOverlapped = jpamanager.createAnnotation(T1, val1, 3, 3); //Annotation on one word : "annoter"
204
				System.out.println("No overlap for [val1] ? colision = "+annotsOverlapped);
205
				annotsOverlapped = jpamanager.createAnnotation(T1, val2, 10, 12); //Annotation on three words : "cela va marcher"
206
				System.out.println("No overlap for [val2] ? colision = "+annotsOverlapped);
207

  
208
				jpamanager.checkData();
209

  
210
				//ECHEC normalement car OVERLAP sur même type
211
				//OVERLAP CASE with same type (on start with val2) => not authorized
212
				System.out.println("");
213
				System.out.println("============== Creation overlap with same type ==============");
214
				annotsOverlapped = jpamanager.createAnnotation(T1, val3, 9, 12); //Annotation on three words : "si cela va marcher"
215
				System.out.println("ON START impossible [val3:9-12], colision = "+annotsOverlapped);
216
				jpamanager.checkData();
217
				//OVERLAP CASE with same type (on end with val2) => not authorized
218
				annotsOverlapped = jpamanager.createAnnotation(T1, val3, 12, 13); //Annotation on two words : "marcher mais"
219
				System.out.println("ON END impossible [val3:12-13], colision = "+annotsOverlapped);
220
				//OVERLAP CASE with same type (outterwrap with val2) => not authorized
221
				annotsOverlapped = jpamanager.createAnnotation(T1, val3, 9, 13); //Annotation on five words : "si cela va marcher mais"
222
				System.out.println("OUTTER impossible [val3:9-13], colision = "+annotsOverlapped);
223
				//OVERLAP CASE with same type (innerwrap with val2) => not authorized
224
				annotsOverlapped = jpamanager.createAnnotation(T1, val3, 11, 11); //Annotation on one words : "va"
225
				System.out.println("INNER impossible [val3:11], colision = "+annotsOverlapped);
226

  
227
				jpamanager.checkData();
228

  
229
				//OK 
230
				annotsOverlapped = jpamanager.createAnnotation(T1, val3, 23, 24); //Annotation on two words : ??
231
				System.out.println("No overlap for [val3] ? colision = "+annotsOverlapped);
232
				annotsOverlapped = jpamanager.createAnnotation(T1, val4, 45, 50);//Annotation on six words : "annotations seront bien prises en compte"
233
				System.out.println("No overlap for [val4] ? colision = "+annotsOverlapped);
234

  
235
				jpamanager.checkData();
236

  
237
				System.out.println("");
238
				System.out.println("============== Creation overlap with another type =============");
239
				//OVERLAP CASE with another type (on start with val2:10-12) => not authorized
240
				annotsOverlapped = jpamanager.createAnnotation(T2, val4, 9, 11); //Annotation on three words : "si cela va"
241
				System.out.println("ON START impossible with [val2:10-12], for [val4:9-11], colision = "+annotsOverlapped);
242

  
243
				jpamanager.checkData();
244

  
245
				//OVERLAP CASE with another type (on end with val1) => should be fine 
246
				annotsOverlapped = jpamanager.createAnnotation(T2, val5, 11, 14); //Annotation on three words : "annoter et je"
247
				System.out.println("ON END impossible with [val2:10-12], for [val5:11-14], colision = "+annotsOverlapped);
248

  
249
				jpamanager.checkData();
250
				//OVERLAP CASE with another type (outterwrap with val3) => should be fine 
251
				annotsOverlapped = jpamanager.createAnnotation(T2, val6, 22, 26); //Annotation on five words : "est pas trop difficile, car"
252
				System.out.println("OUTTER possible with [val3:23-24], for [val6:22-26], colision = "+annotsOverlapped);
253

  
254
				jpamanager.checkData();
255
				//OVERLAP CASE with another type (innerwrap with val4) => should be fine 
256
				annotsOverlapped = jpamanager.createAnnotation(T2, val7, 47, 47); //Annotation on one word : "bien"
257
				System.out.println("INNER possible with [val4:45-50], for [val7:47], colision = "+annotsOverlapped);
258
				jpamanager.checkData();
259

  
260

  
261
				///////////////////// UPDATE ///////////////////////////
262
				System.out.println("");
263
				System.out.println("============== Updating ==============");
264
				//UPDATE val10, need to have the same startPos and endPos and refType
265
				List<Annotation> annots = jpamanager.getAnnotations(T1, 23, 25);
266
				System.out.println("Annot BEFORE UPDATING : "+annots.size());
267
				annotsOverlapped = jpamanager.createAnnotation(T1, val9, 23, 25); 
268
				annots = jpamanager.getAnnotations(T1, 23, 25);
269
				for(Annotation annot : annots){
270
					System.out.println("Annot AFTER UPDATING : "+annot.toString());
271
				}
272

  
273
				//DELETE val8
274
				System.out.println("");
275
				System.out.println("============== Deleting ==============");
276
				annotsOverlapped = jpamanager.createAnnotation(T2, val8, 17, 19); //Annotation on three words : "En même temps"
277
				System.out.println("creating [val8] ? overlap colision = "+annotsOverlapped);
278

  
279
				annots = jpamanager.getAnnotations(T2, 17, 19);
280
				for(Annotation annot : annots){
281
					System.out.println("Annot BEFORE DELETING : "+annot);
282
				}
283

  
284
				jpamanager.deleteAnnotation(T2, 17, 19); 
285
				annots = jpamanager.getAnnotations(T2, 17, 19);
286
				System.out.println("Annot AFTER DELETING : "+annots.size());
287

  
288
				jpamanager.deleteAnnotations();
289

  
290
			}else {
291
				System.out.println("Valued Types are NULL !!!");
292
			}
293

  
294
		} catch (Exception e) {
295
			// TODO Bloc catch généré automatiquement
296
			e.printStackTrace();
297
		}
298
	}
299

  
300
	public static class TestCQP {
301
		public int start;
302
		public int end;
303
		public TestCQP(int start, int end) {
304
			this.start = start;
305
			this.end = end;
306
		}
307

  
308
		public String toString() { return "["+start+", "+end+"]"; }
309
	}
310

  
311
	private static void checkingCQPManager(KnowledgeRepository kr, MainCorpus c, AnnotationManager am) {
312
		CQPAnnotationManager cqpmanager = am.getCQPManager();
313

  
314
		try {
315
			List<Annotation> annotsOverlapped;
316
			List<AnnotationType> types = kr.getAllAnnotationTypes();
317
			for (AnnotationType type : types) {
318
				List<Annotation> annotations = cqpmanager.getAnnotations(type);
319
				System.out.println(type.getId()+" : "+annotations.size());
320
				for(Annotation a : annotations){
321
					System.out.println("\t"+a.toString());
322
				}
323
			}
324

  
325
			ArrayList<TestCQP> tests = new ArrayList<TestCQP>();
326

  
327
			tests.add(new TestCQP(2,2));
328
			tests.add(new TestCQP(4,4));
329
			tests.add(new TestCQP(3,3));
330
			tests.add(new TestCQP(2,3));
331
			tests.add(new TestCQP(3,4));
332
			tests.add(new TestCQP(2,5));
333

  
334
			ArrayList<TestCQP> tests2 = new ArrayList<TestCQP>();
335
			tests2.add(new TestCQP(9,9));
336
			tests2.add(new TestCQP(13,13));
337
			tests2.add(new TestCQP(11,11));
338
			tests2.add(new TestCQP(10,11));
339
			tests2.add(new TestCQP(11,12));
340
			tests2.add(new TestCQP(9,10));
341
			tests2.add(new TestCQP(9,11));
342
			tests2.add(new TestCQP(12,14));
343
			tests2.add(new TestCQP(9,10));
344
			tests2.add(new TestCQP(9,13));
345

  
346
			System.out.println("============== Get overlapping of annotations for a type ==============");
347
			System.out.println(tests);
348
			types = kr.getAllAnnotationTypes();
349
			for (AnnotationType type : types) {
350
				for (TestCQP  match : tests) {
351
					annotsOverlapped = cqpmanager.getAnnotations(type, match.start, match.end, true);//jpamanager.createAnnotation(T1, val4, 3, 3); 
352
					System.out.println("Overlaps for "+type+" at "+match+" ? "+annotsOverlapped);
353
				}
354
			}
355

  
356
			System.out.println("============== Get overlapping of annotations for a type ==============");
357
			System.out.println(tests2);
358
			types = kr.getAllAnnotationTypes();
359
			for (AnnotationType type : types) {
360
				for (TestCQP match : tests2) {
361
					annotsOverlapped = cqpmanager.getAnnotations(type, match.start, match.end, true);//jpamanager.createAnnotation(T1, val4, 3, 3); 
362
					System.out.println("Overlaps for "+type+" at "+match+" ? "+annotsOverlapped);
363
				}
364
			}
365

  
366
			System.out.println("============== Get ALL overlapping annotations of annotations ==============");
367
			System.out.println(tests);
368

  
369
			for (TestCQP  match : tests) {
370
				annotsOverlapped = cqpmanager.getAnnotations(null, match.start, match.end, true);//jpamanager.createAnnotation(T1, val4, 3, 3); 
371
				System.out.println("Overlaps at "+match+" ? "+annotsOverlapped);
372
			}
373

  
374
			System.out.println("============== Get ALL overlapping annotations of annotations==============");
375
			System.out.println(tests2);
376

  
377
			for (TestCQP  match : tests2) {
378
				annotsOverlapped = cqpmanager.getAnnotations(null, match.start, match.end, true);//jpamanager.createAnnotation(T1, val4, 3, 3); 
379
				System.out.println("Overlaps at "+match+" ? "+annotsOverlapped);
380
			}
381

  
382
		} catch (Exception e) {
383
			// TODO Bloc catch généré automatiquement
384
			e.printStackTrace();
385
		}
386
	}
387

  
388
	public static void main(String [] args){
389

  
390
		try {
391

  
392
			MainCorpus c = CorpusManager.getCorpusManager().getCorpus("ANNOTATION");	
393
			if (c == null) return;
394
			InitializeKnowledgeRepository.get(c);
395
			KnowledgeRepository kr = KnowledgeRepositoryManager.getKnowledgeRepository("localkrfortesting", c);
396
			AnnotationManager am = KRAnnotationEngine.getAnnotationManager(c);
397

  
398
			for (String test : args) {
399
				System.out.println("******************** *** ********************");
400
				System.out.println("******************** "+test+" ********************");
401
				System.out.println("******************** *** ********************");
402
				if (test.matches("JPA")) {
403
					checkingJPAManager(kr, c, am);
404
				} else if (test.matches("CQP")) {
405
					checkingCQPManager(kr, c, am);
406
				} else if (test.matches("ALL")) {
407
					checkingAnnotationManager(kr, c, am);
408
				}
409
			}
410
		} catch (Exception e) {
411
			e.printStackTrace();
412
		}
413
	}
414
}
0 415

  
tmp/org.txm.annotation.rcp/src/org/txm/annotation/rcp/editors/imports/sections/AnnotationSection.java (revision 501)
1
package org.txm.annotation.rcp.editors.imports.sections;
2

  
3
import java.util.List;
4

  
5
import org.eclipse.swt.SWT;
6
import org.eclipse.swt.widgets.Composite;
7
import org.eclipse.swt.widgets.Label;
8
import org.eclipse.swt.widgets.Text;
9
import org.eclipse.ui.forms.events.ExpansionAdapter;
10
import org.eclipse.ui.forms.events.ExpansionEvent;
11
import org.eclipse.ui.forms.widgets.FormToolkit;
12
import org.eclipse.ui.forms.widgets.ScrolledForm;
13
import org.eclipse.ui.forms.widgets.TableWrapData;
14
import org.eclipse.ui.forms.widgets.TableWrapLayout;
15
import org.txm.annotation.core.KRAnnotationEngine;
16
import org.txm.objects.BaseParameters;
17
import org.txm.rcp.editors.imports.sections.ImportEditorSection;
18

  
19
public class AnnotationSection extends ImportEditorSection {
20
	
21
	private static final int SECTION_SIZE = 1;
22
	public static final String DEFAULTNAMESUFFIX = "KR";
23
	
24
	Text nameText;
25
	
26
	public AnnotationSection(FormToolkit toolkit2, ScrolledForm form2, Composite parent, int style) {
27
		super(toolkit2, form2, parent, style);
28

  
29
		this.section.setText("Annotation");
30
		TableWrapLayout layout = new TableWrapLayout();
31
		layout.makeColumnsEqualWidth = true;
32
		this.section.setLayout(layout);
33
		this.section.setLayoutData(getSectionGridData(SECTION_SIZE));
34
		this.section.setEnabled(false);
35

  
36
		this.section.addExpansionListener(new ExpansionAdapter() {
37
			@Override
38
			public void expansionStateChanged(ExpansionEvent e) {form.layout(true);}
39
		});
40

  
41
		//filesection.setDescription("Select how to find source files");
42
		Composite sectionClient = toolkit.createComposite(this.section);
43
		TableWrapLayout slayout = new TableWrapLayout();
44
		slayout.makeColumnsEqualWidth = false;
45
		slayout.numColumns = 2;
46
		sectionClient.setLayout(slayout);
47
		this.section.setClient(sectionClient);
48

  
49
		Label l = toolkit.createLabel(sectionClient, "Knowledge repository name", SWT.WRAP);
50
		l.setLayoutData(new TableWrapData(TableWrapData.LEFT, TableWrapData.MIDDLE));
51

  
52
		nameText = new Text(sectionClient, SWT.BORDER);
53
	}
54

  
55
	@Override
56
	public void update(BaseParameters params) {
57
		if (this.section.isDisposed()) return;
58
		if (params == null) return;
59
		List<String> values = KRAnnotationEngine.getKnowledgeRepositoryNames(params);
60
		
61
		String value = params.getCorpusName()+DEFAULTNAMESUFFIX;
62
		if (values.size() > 0) {
63
			value = values.get(0);
64
		}
65
		nameText.setText(value);
66
	}
67

  
68
	@Override
69
	public boolean save(BaseParameters params) {
70
		if (!this.section.isDisposed()) {
71
			String value = nameText.getText();
72
						
73
			return true;
74
		}
75
		return false;
76
	}
77

  
78
	@Override
79
	public boolean checkFields() {
80
		return true;
81
	}
82

  
83
	@Override
84
	public int getSectionSize() {
85
		return SECTION_SIZE;
86
	}
87
}
0 88

  
tmp/org.txm.annotation.rcp/src/org/txm/annotation/rcp/views/knowledgerepositories/KRView.java (revision 501)
1
// Copyright © 2010-2013 ENS de Lyon.
2
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of
3
// Lyon 2, University of Franche-Comté, University of Nice
4
// Sophia Antipolis, University of Paris 3.
5
// 
6
// The TXM platform is free software: you can redistribute it
7
// and/or modify it under the terms of the GNU General Public
8
// License as published by the Free Software Foundation,
9
// either version 2 of the License, or (at your option) any
10
// later version.
11
// 
12
// The TXM platform is distributed in the hope that it will be
13
// useful, but WITHOUT ANY WARRANTY; without even the implied
14
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15
// PURPOSE. See the GNU General Public License for more
16
// details.
17
// 
18
// You should have received a copy of the GNU General
19
// Public License along with the TXM platform. If not, see
20
// http://www.gnu.org/licenses.
21
// 
22
// 
23
// 
24
// $LastChangedDate:$
25
// $LastChangedRevision:$
26
// $LastChangedBy:$ 
27
//
28
package org.txm.annotation.rcp.views.knowledgerepositories;
29

  
30
import java.util.ArrayList;
31
import java.util.List;
32
import java.util.Arrays;
33

  
34

  
35

  
36

  
37

  
38

  
39

  
40

  
41

  
42

  
43
import org.eclipse.jface.action.MenuManager;
44
import org.eclipse.jface.viewers.AbstractTreeViewer;
45
import org.eclipse.jface.viewers.DoubleClickEvent;
46
import org.eclipse.jface.viewers.IDoubleClickListener;
47
import org.eclipse.jface.viewers.ITreeContentProvider;
48
import org.eclipse.jface.viewers.LabelProvider;
49
import org.eclipse.jface.viewers.StructuredSelection;
50
import org.eclipse.jface.viewers.TreeSelection;
51
import org.eclipse.jface.viewers.TreeViewer;
52
import org.eclipse.jface.viewers.TreeViewerColumn;
53
import org.eclipse.jface.viewers.Viewer;
54
import org.eclipse.osgi.util.NLS;
55
import org.eclipse.swt.SWT;
56
import org.eclipse.swt.events.KeyEvent;
57
import org.eclipse.swt.events.KeyListener;
58
import org.eclipse.swt.events.SelectionEvent;
59
import org.eclipse.swt.events.SelectionListener;
60
import org.eclipse.swt.graphics.Image;
61
import org.eclipse.swt.layout.GridData;
62
import org.eclipse.swt.layout.GridLayout;
63
import org.eclipse.swt.widgets.Button;
64
import org.eclipse.swt.widgets.Composite;
65
import org.eclipse.swt.widgets.Control;
66
import org.eclipse.swt.widgets.Menu;
67
import org.eclipse.ui.PlatformUI;
68
import org.eclipse.ui.contexts.IContextService;
69
import org.eclipse.ui.part.ViewPart;
70
import org.txm.annotation.core.repository.AnnotationType;
71
import org.txm.annotation.core.repository.KnowledgeRepository;
72
import org.txm.annotation.core.repository.KnowledgeRepositoryManager;
73
import org.txm.annotation.core.repository.LocalKnowledgeRepository;
74
import org.txm.annotation.core.repository.SQLKnowledgeRepository;
75
import org.txm.annotation.core.repository.TypedValue;
76
import org.txm.annotation.rcp.commands.InitializeKnowledgeRepository;
77
import org.txm.annotation.rcp.commands.krview.Copy;
78
import org.txm.annotation.rcp.commands.krview.Informations;
79
import org.txm.annotation.rcp.commands.krview.Reload;
80
import org.txm.rcp.IImageKeys;
81
import org.txm.rcp.Messages;
82
import org.txm.searchengine.cqp.clientExceptions.CqiClientException;
83
import org.txm.searchengine.cqp.corpus.CorpusManager;
84
import org.txm.searchengine.cqp.corpus.MainCorpus;
85
import org.txm.utils.logger.Log;
86

  
87
/**
88
 * Display the Knowledge repositories currently loaded
89
 * 
90
 * author mdecorde.
91
 */
92
public class KRView extends ViewPart {
93

  
94
	/** The empty list to filled the view at startup. */
95
	ArrayList<Object> empty = new ArrayList<Object>();
96

  
97
	/** The composites. */
98
	Control[] composites = new Control[3];
99

  
100
	/** The tv. */
101
	TreeViewer tv;
102

  
103
	/** The ID. */
104
	public static String ID = "org.txm.rcp.views.knowledgerepositories.KRView"; //$NON-NLS-1$
105

  
106
	/**
107
	 * Instantiates a new queries view.
108
	 */
109
	public KRView() {
110
		// System.out.println(Messages.ObjectExplorer_9);
111
	}
112

  
113
	/**
114
	 * Refresh.
115
	 */
116
	public static void refresh() {
117
		KRView baseView = (KRView) PlatformUI.getWorkbench()
118
				.getActiveWorkbenchWindow().getActivePage().findView(
119
						KRView.ID);
120
		if (baseView != null)
121
			baseView.tv.refresh();
122
	}
123

  
124
	/**
125
	 * Reload.
126
	 */
127
	public static void reload() {
128
		KRView baseView = (KRView) PlatformUI.getWorkbench()
129
				.getActiveWorkbenchWindow().getActivePage().findView(
130
						KRView.ID);
131
		if (baseView != null)
132
			baseView._reload();
133
	}
134

  
135
	/**
136
	 * _reload.
137
	 */
138
	public void _reload() {
139
		
140
		KnowledgeRepository[] repos = KnowledgeRepositoryManager.getKnowledgeRepositories();
141
		if (repos == null) return;
142
		if (tv != null) { 
143
			tv.setInput(repos);
144
			refresh();
145
		}
146
	}
147

  
148
	/* (non-Javadoc)
149
	 * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
150
	 */
151
	@Override
152
	public void createPartControl(Composite parent) {
153
		// System.out.println(Messages.ObjectExplorer_9);
154

  
155
		parent.setLayout(new GridLayout(1, true));
156
		Button refresh = new Button(parent, SWT.PUSH);
157
		refresh.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true,
158
				false));
159
		refresh.setText("⟲");
160
		refresh.addSelectionListener(new SelectionListener() {
161
			@Override
162
			public void widgetSelected(SelectionEvent arg0) {
163
				// force loading KR of all corpora
164
				try {
165
					for (MainCorpus corpus : CorpusManager.getCorpusManager().getCorpora()) {
166
						for (KnowledgeRepository kr : InitializeKnowledgeRepository.get(corpus.getMainCorpus())) {
167
							kr.checkConnection();
168
						}
169
					}
170
				} catch (CqiClientException e) {
171
					e.printStackTrace();
172
					return;
173
				}
174

  
175
				_reload();
176
			}
177

  
178
			@Override
179
			public void widgetDefaultSelected(SelectionEvent arg0) { }
180
		});
181

  
182
		tv = new TreeViewer(parent);
183
		tv.getTree().setLayoutData(
184
				new GridData(GridData.FILL, GridData.FILL, true, true));
185
		
186
		tv.setContentProvider(new KRTreeProvider());
187
		tv.setLabelProvider(new KRLabelProvider());
188
		
189
		_reload();
190

  
191
		tv.addDoubleClickListener(new IDoubleClickListener() {
192
			@Override
193
			public void doubleClick(DoubleClickEvent event) {
194
				TreeSelection selection = (TreeSelection) tv.getSelection();
195
				Informations.show(selection);
196
			}
197
		});
198

  
199
//		TreeViewerColumn name = new TreeViewerColumn(tv, SWT.NONE);
200
//		name.getColumn().setText("name");
201
//		TreeViewerColumn desc = new TreeViewerColumn(tv, SWT.NONE);
202
//		desc.getColumn().setText("desc");
203
		
204
		MenuManager menuManager = new MenuManager();
205
		Menu menu = menuManager.createContextMenu(tv.getTree());
206

  
207
		// Set the MenuManager
208
		tv.getTree().setMenu(menu);
209
		getSite().registerContextMenu(menuManager, tv);
210
		// Make the selection available
211
		getSite().setSelectionProvider(tv);
212
		
213
		IContextService contextService = (IContextService)getSite().getService(IContextService.class);
214
		contextService.activateContext("org.txm.rcp.annotation.krview");
215
	}
216

  
217
	/* (non-Javadoc)
218
	 * @see org.eclipse.ui.part.WorkbenchPart#setFocus()
219
	 */
220
	@Override
221
	public void setFocus() {
222
		
223
	}
224

  
225
	/**
226
	 * The Class TxmObjectLabelProvider.
227
	 */
228
	public class KRLabelProvider extends LabelProvider {
229

  
230
		/* (non-Javadoc)
231
		 * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object)
232
		 */
233
		@Override
234
		public String getText(Object element) {
235
			if (element instanceof KnowledgeRepository)
236
				return ((KnowledgeRepository) element).getName();
237
			else if (element instanceof AnnotationType)
238
				return ((AnnotationType) element).getId()+((AnnotationType) element).getEffect().toSuffix();
239
			else if (element instanceof TypedValue)
240
				return ((TypedValue) element).getStandardName();
241
			return NLS.bind(Messages.QueriesView_10, element);
242
		}
243

  
244
		/* (non-Javadoc)
245
		 * @see org.eclipse.jface.viewers.LabelProvider#getImage(java.lang.Object)
246
		 */
247
		@Override
248
		public final Image getImage(Object element) {
249
			if (element instanceof SQLKnowledgeRepository)
250
				return IImageKeys.getImage(IImageKeys.WORLD);
251
			return null;
252
		}
253
	}
254

  
255
	/**
256
	 * The Class TxmObjectTreeProvider.
257
	 */
258
	public class KRTreeProvider implements ITreeContentProvider {
259

  
260
		/* (non-Javadoc)
261
		 * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
262
		 */
263
		@Override
264
		public Object[] getChildren(Object element) {
265
			if (element instanceof KnowledgeRepository) {
266
				KnowledgeRepository kr = ((KnowledgeRepository) element);
267
				List<AnnotationType> types = kr.getAllAnnotationTypes();
268

  
269
				return types.toArray();
270
			} else if (element instanceof AnnotationType) {
271
				AnnotationType t = ((AnnotationType) element);
272
				KnowledgeRepository kr = KnowledgeRepositoryManager.getKnowledgeRepository(t.getKnowledgeRepository());
273
				if (kr instanceof LocalKnowledgeRepository) {
274
					LocalKnowledgeRepository krl = (LocalKnowledgeRepository) kr;
275
					try {
276
						return krl.getValues(t).toArray();
277
					} catch (Exception e) {
278
						System.out.println("Error while reading KR values: "+kr+ " for type="+t);
279
						Log.printStackTrace(e);
280
					}
281
				}
282
				return new Object[0];
283
			} else {
284
				return new Object[0];
285
			}
286
		}
287

  
288
		/* (non-Javadoc)
289
		 * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
290
		 */
291
		@Override
292
		public Object getParent(Object element) {
293
			if (element instanceof KnowledgeRepository) {
294
				return null;
295
			} else if (element instanceof AnnotationType) {
296
				return ((AnnotationType)element).getKnowledgeRepository();
297
			} else {
298
				return null;
299
			}
300
		}
301

  
302
		/* (non-Javadoc)
303
		 * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object)
304
		 */
305
		@Override
306
		public boolean hasChildren(Object element) {
307
			if (element instanceof KnowledgeRepository) {
308
				KnowledgeRepository kr = ((KnowledgeRepository) element);
309
				List<AnnotationType> types = kr.getAllAnnotationTypes();
310
				return types.size() > 0;
311
			} else if (element instanceof KnowledgeRepository[]) {
312
				return ((KnowledgeRepository[])element).length > 0;
313
			} else if (element instanceof AnnotationType) {
314
				AnnotationType t = ((AnnotationType) element);
315
				KnowledgeRepository kr = KnowledgeRepositoryManager.getKnowledgeRepository(t.getKnowledgeRepository());
316
				
317
				if (kr instanceof LocalKnowledgeRepository) {
318
					LocalKnowledgeRepository krl = (LocalKnowledgeRepository) kr;
319
					try {
320
						return krl.hasValues(t);
321
					} catch (Exception e) {
322
						System.out.println("Error while reading KR values: "+krl+ " for type="+t);
323
						Log.printStackTrace(e);
324
					}
325
				}
326
				return false;
327
			}  else {
328
				return false;
329
			}
330
		}
331

  
332
		/* (non-Javadoc)
333
		 * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
334
		 */
335
		@Override
336
		public Object[] getElements(Object element) {
337
			if (element instanceof KnowledgeRepository) {
338
				KnowledgeRepository kr = ((KnowledgeRepository) element);
339
				List<AnnotationType> types = kr.getAllAnnotationTypes();
340
				return types.toArray();
341
			} else if (element instanceof KnowledgeRepository[]) {
342
				return ((KnowledgeRepository[])element);
343
			} else {
344
				return new Object[0];
345
			}
346
		}
347

  
348
		/* (non-Javadoc)
349
		 * @see org.eclipse.jface.viewers.IContentProvider#dispose()
350
		 */
351
		@Override
352
		public void dispose() { }
353

  
354
		/* (non-Javadoc)
355
		 * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
356
		 */
357
		@Override
358
		public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {	}
359
	}
360

  
361
	public static void showType(AnnotationType type) {
362
		
363
		TreeViewer tv = getTree();
364
		if (tv != null) {
365
			StructuredSelection selection = new StructuredSelection(type);
366
			tv.expandToLevel(selection, AbstractTreeViewer.ALL_LEVELS);
367
			tv.setSelection(selection);
368
		} else {
369
			// call org.eclipse.ui.handlers.ShowViewHandler
370
			// extends the command to select the type ?
371
		}
372
	}
373

  
374
	public static TreeViewer getTree() {
375
		KRView baseView = (KRView) PlatformUI.getWorkbench()
376
				.getActiveWorkbenchWindow().getActivePage().findView(
377
						KRView.ID);
378
		if (baseView != null)
379
			return baseView.tv;
380
		
381
		return null;
382
	}
383
}
0 384

  
tmp/org.txm.annotation.rcp/src/org/txm/annotation/rcp/commands/SaveAnnotations.java (revision 501)
1
package org.txm.annotation.rcp.commands;
2

  
3
import org.eclipse.core.commands.AbstractHandler;
4
import org.eclipse.core.commands.ExecutionEvent;
5
import org.eclipse.core.commands.ExecutionException;
6
import org.eclipse.core.runtime.IProgressMonitor;
7
import org.eclipse.core.runtime.IStatus;
8
import org.eclipse.core.runtime.Status;
9
import org.eclipse.jface.dialogs.MessageDialog;
10
import org.eclipse.jface.viewers.ISelection;
11
import org.eclipse.jface.viewers.IStructuredSelection;
12
import org.eclipse.swt.widgets.Display;
13
import org.eclipse.swt.widgets.MessageBox;
14
import org.eclipse.ui.handlers.HandlerUtil;
15
import org.txm.annotation.core.AnnotationManager;
16
import org.txm.annotation.core.KRAnnotationEngine;
17
import org.txm.rcp.Messages;
18
import org.txm.rcp.commands.CloseEditorsUsing;
19
import org.txm.rcp.commands.workspace.UpdateCorpus;
20
import org.txm.rcp.utils.JobHandler;
21
import org.txm.rcp.views.corpora.CorporaView;
22
import org.txm.searchengine.cqp.corpus.MainCorpus;
23
import org.txm.utils.logger.Log;
24

  
25
public class SaveAnnotations extends AbstractHandler {
26

  
27
	public static final String ID = SaveAnnotations.class.getCanonicalName();
28

  
29
	@Override
30
	public Object execute(ExecutionEvent event) throws ExecutionException {
31

  
32
		ISelection sel = (IStructuredSelection) HandlerUtil.getCurrentSelection(event);
33
		if (!(sel instanceof IStructuredSelection)) return null;
34
		IStructuredSelection selection = (IStructuredSelection) sel;
35

  
36
		Object s = selection.getFirstElement();
37
		if (!(s instanceof MainCorpus))
38
			return null;
39
		MainCorpus corpus = (MainCorpus) s;
40
		save(corpus);
41

  
42
		return corpus;
43
	}
44

  
45
	public static JobHandler save(final MainCorpus corpus) {
46
		final AnnotationManager am = KRAnnotationEngine.getAnnotationManager(corpus);
47
		if (am == null) return null; // nothing to do
48
		
49
		if (!KRAnnotationEngine.needToSaveAnnotations(corpus)) {
50
			return null;
51
		}
52

  
53
		//System.out.println("DISPLAY="+Display.getDefault());
54
		Display.getDefault().syncExec(new Runnable() {
55
			@Override
56
			public void run() {
57
				if (!MessageDialog.openConfirm(Display.getDefault().getActiveShell(), "Before saving annotations...", "All editors using this corpus are going to be closed. Continue ?")) {
58
					return;
59
				}
60
			}
61
		});
62

  
63
		JobHandler jobhandler = new JobHandler("Saving annotations of "+corpus) { //$NON-NLS-1$
64
			@Override
65
			protected IStatus run(IProgressMonitor monitor) {
66
				this.runInit(monitor);
67
				try {
68
					monitor.beginTask("Saving annotations", 100);
69

  
70
					monitor.setTaskName("writing annotations in XML-TXM files");
71
					boolean rez = am.saveAnnotations();
72
					monitor.worked(30);
73

  
74
					if (rez) {
75
						System.out.println("Annotations are saved in XML-TXM files. Updating corpus indexes and editions");
76

  
77
						monitor.setTaskName("updating corpus indexes and editions");
78
						if (UpdateCorpus.update(corpus) != null) {
79
							monitor.worked(50);
80
							this.syncExec(new Runnable() {
81
								public void run() {CorporaView.refreshObject(corpus);}
82
							});
83
						} else {
84
							monitor.worked(50);
85
							System.out.println("Fail to update corpus. Aborting");
86
							System.out.println("Fix XML-TXM files and call command 'UpdateCorpus'");
87
						}
88
					} else {
89
						System.out.println("Error while saving annotations (see logs above).");
90
					}
91

  
92
				} catch(Exception e) {
93
					System.out.println("Error while saving annotations: "+e);
94
					Log.printStackTrace(e);
95
					return Status.CANCEL_STATUS;
96
				}
97
				return Status.OK_STATUS;
98
			}
99
		};
100

  
101
		jobhandler.startJob(true);
102

  
103
		return jobhandler;
104
	}
105
}
0 106

  
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff