Révision 2914
| tmp/org.txm.rcp/src/main/java/org/txm/rcp/testers/IsCorpusAnnotated.java (revision 2914) | ||
|---|---|---|
| 1 |
package org.txm.rcp.testers; |
|
| 2 |
|
|
| 3 |
import java.util.List; |
|
| 4 |
|
|
| 5 |
import org.eclipse.core.expressions.PropertyTester; |
|
| 6 |
import org.txm.searchengine.cqp.corpus.CQPCorpus; |
|
| 7 |
|
|
| 8 |
@SuppressWarnings("unchecked")
|
|
| 9 |
public class IsCorpusAnnotated extends PropertyTester {
|
|
| 10 |
|
|
| 11 |
public static final String PROPERTY_NAMESPACE = "org.txm.rcp.testers.annotate"; //$NON-NLS-1$ |
|
| 12 |
public static final String PROPERTY_CAN_SAVE = "canSave"; |
|
| 13 |
|
|
| 14 |
@Override |
|
| 15 |
public boolean test(Object receiver, String property, Object[] args, |
|
| 16 |
Object expectedValue) {
|
|
| 17 |
|
|
| 18 |
if (receiver instanceof List) {
|
|
| 19 |
|
|
| 20 |
List<Object> list = (List<Object>)receiver; |
|
| 21 |
if (list.size() == 0) return false; |
|
| 22 |
receiver = list.get(0); |
|
| 23 |
} |
|
| 24 |
|
|
| 25 |
if (receiver instanceof CQPCorpus) {
|
|
| 26 |
CQPCorpus c = (CQPCorpus) receiver; |
|
| 27 |
boolean ret = false;//c.getMainCorpus().needToSaveAnnotations(); |
|
| 28 |
//System.out.println(" Corpus:"+receiver+" need save: "+ret);
|
|
| 29 |
return ret; |
|
| 30 |
} |
|
| 31 |
return false; |
|
| 32 |
} |
|
| 33 |
} |
|
| tmp/org.txm.rcp/src/main/java/org/txm/rcp/testers/IsParentVisible.java (revision 2914) | ||
|---|---|---|
| 7 | 7 |
|
| 8 | 8 |
|
| 9 | 9 |
public class IsParentVisible extends PropertyTester {
|
| 10 |
|
|
| 10 |
|
|
| 11 | 11 |
@Override |
| 12 | 12 |
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
|
| 13 |
|
|
| 13 |
|
|
| 14 | 14 |
if (receiver instanceof List) {
|
| 15 |
List list = (List)receiver; |
|
| 15 |
List list = (List) receiver;
|
|
| 16 | 16 |
if (list.size() == 0) return true; |
| 17 | 17 |
receiver = list.get(0); |
| 18 | 18 |
} |
| 19 | 19 |
if (receiver instanceof TXMResult) {
|
| 20 |
return ((TXMResult)receiver).getParent().isVisible(); |
|
| 20 |
return ((TXMResult) receiver).getParent().isVisible();
|
|
| 21 | 21 |
} |
| 22 | 22 |
|
| 23 | 23 |
return true; |
| tmp/org.txm.rcp/src/main/java/org/txm/rcp/commands/OpenWelcomePage.java (revision 2914) | ||
|---|---|---|
| 62 | 62 |
String version = Platform.getBundle(Activator.PLUGIN_ID).getVersion().toString(); |
| 63 | 63 |
int idx = version.lastIndexOf("."); //$NON-NLS-1$
|
| 64 | 64 |
if (idx > 0) version = version.substring(0, idx); // remove the "qualifier" part |
| 65 |
version += "beta"; |
|
| 65 |
|
|
| 66 |
// version += "beta"; |
|
| 67 |
|
|
| 66 | 68 |
if ("fr".equals(locale)) {
|
| 67 |
return OpenBrowser.openfile(WELCOME+version) != null; |
|
| 68 |
} else {
|
|
| 69 |
return OpenBrowser.openfile(OpenLocalizedWebPage.getValidURL(WELCOME+version+"/"+locale, (WELCOME+version))) != null; |
|
| 69 |
return OpenBrowser.openfile(WELCOME + version) != null; |
|
| 70 | 70 |
} |
| 71 |
else {
|
|
| 72 |
return OpenBrowser.openfile(OpenLocalizedWebPage.getValidURL(WELCOME + version + "/" + locale, (WELCOME + version))) != null; |
|
| 73 |
} |
|
| 71 | 74 |
} |
| 72 | 75 |
} |
| tmp/org.txm.analec.rcp/src/org/txm/annotation/urs/URSCorpora.java (revision 2914) | ||
|---|---|---|
| 22 | 22 |
* |
| 23 | 23 |
*/ |
| 24 | 24 |
public class URSCorpora extends AnnotationEngine {
|
| 25 |
|
|
| 26 |
private static final HashMap<CorpusBuild, Corpus> corpora = new HashMap<CorpusBuild, Corpus>(); |
|
| 27 |
private static final HashMap<CorpusBuild, Vue> vues = new HashMap<CorpusBuild, Vue>(); |
|
| 28 |
|
|
| 25 |
|
|
| 26 |
private static final HashMap<CorpusBuild, Corpus> corpora = new HashMap<>(); |
|
| 27 |
|
|
| 28 |
private static final HashMap<CorpusBuild, Vue> vues = new HashMap<>(); |
|
| 29 |
|
|
| 29 | 30 |
/** |
| 30 | 31 |
* Create the ec file if needed, store a reference to the corpus if not already done. |
| 31 | 32 |
* |
| ... | ... | |
| 34 | 35 |
*/ |
| 35 | 36 |
public static Corpus getCorpus(CorpusBuild mcorpus) {
|
| 36 | 37 |
mcorpus = mcorpus.getRootCorpusBuild(); // ensure this is the root CorpusBuild |
| 37 |
File fichierCorpus = new File(mcorpus.getProjectDirectory(), "analec/"+mcorpus.getID()+".ec"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
| 38 |
File fichierVue = new File(mcorpus.getProjectDirectory(), "analec/"+mcorpus.getID()+".ecv"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
| 38 |
File fichierCorpus = new File(mcorpus.getProjectDirectory(), "analec/" + mcorpus.getID() + ".ec"); //$NON-NLS-1$ //$NON-NLS-2$
|
|
| 39 |
File fichierVue = new File(mcorpus.getProjectDirectory(), "analec/" + mcorpus.getID() + ".ecv"); //$NON-NLS-1$ //$NON-NLS-2$
|
|
| 39 | 40 |
Corpus corpus = null; |
| 40 | 41 |
if (URSCorpora.corpora.containsKey(mcorpus)) {
|
| 41 | 42 |
corpus = URSCorpora.corpora.get(mcorpus); |
| 42 |
} else {
|
|
| 43 |
} |
|
| 44 |
else {
|
|
| 43 | 45 |
corpus = new Corpus(); |
| 44 |
|
|
| 46 |
|
|
| 45 | 47 |
if (fichierCorpus.exists()) {
|
| 46 | 48 |
if (!FichiersJava.ouvrirCorpus(corpus, fichierCorpus, false)) {
|
| 47 | 49 |
System.out.println(NLS.bind(Messages.URSCorpora_3, fichierCorpus)); |
| 48 | 50 |
return null; |
| 49 | 51 |
} |
| 50 |
} else {
|
|
| 52 |
} |
|
| 53 |
else {
|
|
| 51 | 54 |
fichierCorpus.getParentFile().mkdirs(); |
| 52 |
|
|
| 55 |
|
|
| 53 | 56 |
if (!FichiersJava.enregistrerCorpus(corpus, fichierCorpus)) {
|
| 54 | 57 |
System.out.println(NLS.bind(Messages.URSCorpora_4, fichierCorpus)); |
| 55 | 58 |
return null; |
| 56 | 59 |
} |
| 57 | 60 |
} |
| 58 |
|
|
| 61 |
|
|
| 59 | 62 |
URSCorpora.corpora.put(mcorpus, corpus); |
| 60 |
|
|
| 63 |
|
|
| 61 | 64 |
Vue vue = getVue(mcorpus); |
| 62 |
|
|
| 63 |
//TODO: does not work :(
|
|
| 65 |
|
|
| 66 |
// TODO: does not work :(
|
|
| 64 | 67 |
if (fichierVue.exists()) {
|
| 65 | 68 |
if (!FichiersJava.ouvrirVue(vue, fichierVue)) {
|
| 66 |
System.out.println("Warning: Fail to open corpus Vue file: "+fichierVue);
|
|
| 67 |
//return null; |
|
| 69 |
System.out.println("Warning: Fail to open corpus Vue file: " + fichierVue);
|
|
| 70 |
// return null;
|
|
| 68 | 71 |
} |
| 69 | 72 |
String[] types = vue.getTypesUnitesAVoir(); |
| 70 | 73 |
if (types == null || types.length == 0) {
|
| 71 | 74 |
vue.retablirVueParDefaut(); |
| 72 | 75 |
} |
| 73 |
} else {
|
|
| 74 |
vue.retablirVueParDefaut(); // |
|
| 76 |
} |
|
| 77 |
else {
|
|
| 78 |
vue.retablirVueParDefaut(); // |
|
| 75 | 79 |
if (!FichiersJava.enregistrerVue(vue, fichierVue)) {
|
| 76 |
System.out.println("Warning: Fail to create corpus Vue file: "+fichierVue);
|
|
| 77 |
//return null; |
|
| 80 |
System.out.println("Warning: Fail to create corpus Vue file: " + fichierVue);
|
|
| 81 |
// return null;
|
|
| 78 | 82 |
} |
| 79 | 83 |
} |
| 80 | 84 |
} |
| 81 | 85 |
return corpus; |
| 82 | 86 |
} |
| 83 |
|
|
| 87 |
|
|
| 84 | 88 |
public static boolean isAnnotationStructureReady(CorpusBuild mcorpus) {
|
| 85 |
|
|
| 89 |
|
|
| 86 | 90 |
mcorpus = mcorpus.getRootCorpusBuild(); // ensure this is the root CorpusBuild |
| 87 |
|
|
| 91 |
|
|
| 88 | 92 |
if (URSCorpora.corpora.containsKey(mcorpus)) {
|
| 89 | 93 |
return !URSCorpora.corpora.get(mcorpus).getStructure().isVide(); |
| 90 |
} else {
|
|
| 91 |
File fichierCorpus = new File(mcorpus.getProjectDirectory(), "analec/"+mcorpus.getID()+".ec"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
|
| 94 |
} |
|
| 95 |
else {
|
|
| 96 |
File fichierCorpus = new File(mcorpus.getProjectDirectory(), "analec/" + mcorpus.getID() + ".ec"); //$NON-NLS-1$ //$NON-NLS-2$ |
|
| 92 | 97 |
if (fichierCorpus.exists()) {
|
| 93 | 98 |
return !getCorpus(mcorpus).getStructure().isVide(); |
| 94 |
} else {
|
|
| 99 |
} |
|
| 100 |
else {
|
|
| 95 | 101 |
return false; |
| 96 | 102 |
} |
| 97 | 103 |
} |
| 98 | 104 |
} |
| 99 |
|
|
| 105 |
|
|
| 100 | 106 |
/** |
| 101 | 107 |
* need the corpus to be loaded |
| 102 | 108 |
* |
| ... | ... | |
| 105 | 111 |
*/ |
| 106 | 112 |
public static Vue getVue(CorpusBuild mcorpus) {
|
| 107 | 113 |
mcorpus = mcorpus.getRootCorpusBuild(); // ensure this is the root CorpusBuild |
| 108 |
|
|
| 114 |
|
|
| 109 | 115 |
if (!vues.containsKey(mcorpus)) {
|
| 110 | 116 |
if (!corpora.containsKey(mcorpus)) {
|
| 111 | 117 |
getCorpus(mcorpus); |
| ... | ... | |
| 116 | 122 |
} |
| 117 | 123 |
return vues.get(mcorpus); |
| 118 | 124 |
} |
| 119 |
|
|
| 125 |
|
|
| 120 | 126 |
/** |
| 121 | 127 |
* Save the associated AnalecCorpus |
| 128 |
* |
|
| 122 | 129 |
* @param mcorpus |
| 123 | 130 |
* @return true if the annotations have been saved |
| 124 | 131 |
*/ |
| ... | ... | |
| 126 | 133 |
mcorpus = mcorpus.getRootCorpusBuild(); // ensure this is the root CorpusBuild |
| 127 | 134 |
Corpus corpus = getCorpus(mcorpus); |
| 128 | 135 |
Vue vue = getVue(mcorpus); |
| 129 |
File dir = new File(mcorpus.getProjectDirectory(), "analec/"); //$NON-NLS-1$ //$NON-NLS-2$
|
|
| 136 |
File dir = new File(mcorpus.getProjectDirectory(), "analec/"); //$NON-NLS-1$ |
|
| 130 | 137 |
dir.mkdir(); |
| 131 |
File fichierCorpus = new File(dir, mcorpus+".ec"); //$NON-NLS-1$
|
|
| 132 |
File fichierVueCorpus = new File(dir, mcorpus+".ecv"); //$NON-NLS-1$
|
|
| 133 |
return FichiersJava.enregistrerCorpus(corpus, fichierCorpus)
|
|
| 138 |
File fichierCorpus = new File(dir, mcorpus + ".ec"); //$NON-NLS-1$
|
|
| 139 |
File fichierVueCorpus = new File(dir, mcorpus + ".ecv"); //$NON-NLS-1$
|
|
| 140 |
return FichiersJava.enregistrerCorpus(corpus, fichierCorpus) |
|
| 134 | 141 |
&& FichiersJava.enregistrerVue(vue, fichierVueCorpus); |
| 135 | 142 |
} |
| 136 |
|
|
| 143 |
|
|
| 137 | 144 |
public static Vue getVue(Corpus corpus) {
|
| 138 | 145 |
for (CorpusBuild mcorpus : corpora.keySet()) {
|
| 139 | 146 |
if (corpora.get(mcorpus) == corpus) return vues.get(mcorpus); |
| 140 | 147 |
} |
| 141 | 148 |
return null; |
| 142 | 149 |
} |
| 143 |
|
|
| 150 |
|
|
| 144 | 151 |
public static boolean saveCorpus(Corpus corpus) {
|
| 145 | 152 |
for (CorpusBuild mcorpus : corpora.keySet()) {
|
| 146 | 153 |
if (corpora.get(mcorpus) == corpus) return saveCorpus(mcorpus); |
| 147 | 154 |
} |
| 148 | 155 |
return false; |
| 149 | 156 |
} |
| 150 |
|
|
| 157 |
|
|
| 151 | 158 |
public static void removeCorpus(CorpusBuild mcorpus) {
|
| 152 | 159 |
mcorpus = mcorpus.getRootCorpusBuild(); // ensure this is the root CorpusBuild |
| 153 | 160 |
|
| 154 |
if (!vues.containsKey(mcorpus)) {vues.remove(mcorpus);}
|
|
| 155 |
if (!corpora.containsKey(mcorpus)) {corpora.remove(mcorpus);}
|
|
| 161 |
if (!vues.containsKey(mcorpus)) {
|
|
| 162 |
vues.remove(mcorpus); |
|
| 163 |
} |
|
| 164 |
if (!corpora.containsKey(mcorpus)) {
|
|
| 165 |
corpora.remove(mcorpus); |
|
| 166 |
} |
|
| 156 | 167 |
} |
| 157 |
|
|
| 168 |
|
|
| 158 | 169 |
public static void revert(CorpusBuild mcorpus) {
|
| 159 | 170 |
mcorpus = mcorpus.getRootCorpusBuild(); // ensure this is the root CorpusBuild |
| 160 | 171 |
corpora.remove(mcorpus); |
| 161 | 172 |
vues.remove(mcorpus); |
| 162 | 173 |
mcorpus.setIsModified(false); |
| 163 | 174 |
} |
| 164 |
|
|
| 175 |
|
|
| 165 | 176 |
@Override |
| 166 | 177 |
public boolean isRunning() {
|
| 167 | 178 |
return true; |
| 168 | 179 |
} |
| 169 |
|
|
| 180 |
|
|
| 170 | 181 |
@Override |
| 171 | 182 |
public boolean initialize() throws Exception {
|
| 172 | 183 |
return true; |
| 173 | 184 |
} |
| 174 |
|
|
| 185 |
|
|
| 175 | 186 |
@Override |
| 176 | 187 |
public boolean start(IProgressMonitor monitor) throws Exception {
|
| 177 | 188 |
return true; |
| 178 | 189 |
} |
| 179 |
|
|
| 190 |
|
|
| 180 | 191 |
@Override |
| 181 | 192 |
public boolean stop() throws Exception {
|
| 182 | 193 |
return true; |
| 183 | 194 |
} |
| 184 |
|
|
| 195 |
|
|
| 185 | 196 |
@Override |
| 186 | 197 |
public void notify(TXMResult r, String state) {
|
| 187 | 198 |
if (r instanceof CorpusBuild && "clean".equals(state)) { // $NON-NLS
|
| 188 |
CorpusBuild mcorpus = (CorpusBuild)r; |
|
| 199 |
CorpusBuild mcorpus = (CorpusBuild) r;
|
|
| 189 | 200 |
mcorpus = mcorpus.getRootCorpusBuild(); // ensure this is the root CorpusBuild |
| 190 | 201 |
|
| 191 | 202 |
URSCorpora.removeCorpus(mcorpus); |
| 192 |
|
|
| 193 |
File fichierCorpus = new File(mcorpus.getProjectDirectory(), "analec/"+mcorpus.getID()+".ec"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
| 194 |
File fichierVue = new File(mcorpus.getProjectDirectory(), "analec/"+mcorpus.getID()+".ecv"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
|
| 203 |
|
|
| 204 |
File fichierCorpus = new File(mcorpus.getProjectDirectory(), "analec/" + mcorpus.getID() + ".ec"); //$NON-NLS-1$ //$NON-NLS-2$
|
|
| 205 |
File fichierVue = new File(mcorpus.getProjectDirectory(), "analec/" + mcorpus.getID() + ".ecv"); //$NON-NLS-1$ //$NON-NLS-2$
|
|
| 195 | 206 |
fichierCorpus.delete(); |
| 196 | 207 |
fichierVue.delete(); |
| 197 |
} else if (r instanceof Project) {
|
|
| 198 |
Project project = ((Project)r); |
|
| 208 |
} |
|
| 209 |
else if (r instanceof Project) {
|
|
| 210 |
Project project = ((Project) r); |
|
| 199 | 211 |
if ("clean".equals(state)) {
|
| 200 | 212 |
File analecDir = new File(project.getProjectDirectory(), "analec"); |
| 201 | 213 |
if (analecDir.exists()) {
|
| 202 | 214 |
DeleteDir.deleteDirectory(analecDir); |
| 203 | 215 |
} |
| 204 |
} else if ("save".equals(state)) {
|
|
| 216 |
} |
|
| 217 |
else if ("save".equals(state)) {
|
|
| 205 | 218 |
for (TXMResult c : project.getChildren(CorpusBuild.class)) {
|
| 206 |
URSCorpora.saveCorpus((CorpusBuild)c); |
|
| 219 |
URSCorpora.saveCorpus((CorpusBuild) c);
|
|
| 207 | 220 |
} |
| 208 | 221 |
} |
| 209 | 222 |
} |
| 210 | 223 |
} |
| 211 |
|
|
| 224 |
|
|
| 212 | 225 |
@Override |
| 213 | 226 |
public String getName() {
|
| 214 | 227 |
return "Analec"; |
| 215 | 228 |
} |
| 216 |
|
|
| 229 |
|
|
| 217 | 230 |
@Override |
| 218 | 231 |
public boolean isAutomatic() {
|
| 219 | 232 |
return false; |
| 220 | 233 |
} |
| 221 |
|
|
| 234 |
|
|
| 222 | 235 |
@Override |
| 223 | 236 |
public boolean processFile(File xmlFile, File binaryCorpusDirectory, HashMap<String, Object> parameters) {
|
| 224 | 237 |
return false; |
| 225 | 238 |
} |
| 226 |
|
|
| 239 |
|
|
| 227 | 240 |
@Override |
| 228 | 241 |
public String getDetails() {
|
| 229 | 242 |
return corpora.toString(); |
| 230 | 243 |
} |
| 244 |
|
|
| 245 |
@Override |
|
| 246 |
public boolean hasAnnotationsToSave(CorpusBuild mcorpus) {
|
|
| 247 |
if (URSCorpora.hasCorpus(mcorpus)) return false; // no corpus instanced -> no annotations to save |
|
| 248 |
return URSCorpora.getCorpus(mcorpus).isModifie(); |
|
| 249 |
} |
|
| 250 |
|
|
| 251 |
/** |
|
| 252 |
* |
|
| 253 |
* @param mcorpus |
|
| 254 |
* @return true is an Analec corpus is already instanced |
|
| 255 |
*/ |
|
| 256 |
private static boolean hasCorpus(CorpusBuild mcorpus) {
|
|
| 257 |
return corpora.containsKey(mcorpus); |
|
| 258 |
} |
|
| 231 | 259 |
} |
| tmp/org.txm.annotation.kr.rcp/src/org/txm/rcp/testers/IsCorpusDirty.java (revision 2914) | ||
|---|---|---|
| 1 |
package org.txm.rcp.testers; |
|
| 2 |
|
|
| 3 |
import java.util.List; |
|
| 4 |
|
|
| 5 |
import org.eclipse.core.expressions.PropertyTester; |
|
| 6 |
import org.txm.annotation.kr.core.KRAnnotationEngine; |
|
| 7 |
import org.txm.searchengine.cqp.corpus.MainCorpus; |
|
| 8 |
|
|
| 9 |
|
|
| 10 |
public class IsCorpusDirty extends PropertyTester {
|
|
| 11 |
|
|
| 12 |
@Override |
|
| 13 |
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
|
|
| 14 |
|
|
| 15 |
if (receiver instanceof List) {
|
|
| 16 |
List list = (List) receiver; |
|
| 17 |
if (list.size() == 0) return true; |
|
| 18 |
receiver = list.get(0); |
|
| 19 |
} |
|
| 20 |
if (receiver instanceof MainCorpus) {
|
|
| 21 |
return KRAnnotationEngine.needToSaveAnnotations(((MainCorpus) receiver)); |
|
| 22 |
} |
|
| 23 |
|
|
| 24 |
return false; |
|
| 25 |
} |
|
| 26 |
} |
|
| 0 | 27 | |
| tmp/org.txm.annotation.kr.rcp/src/org/txm/annotation/kr/rcp/concordance/SimpleKRAnnotation.java (revision 2914) | ||
|---|---|---|
| 73 | 73 |
* |
| 74 | 74 |
*/ |
| 75 | 75 |
public class SimpleKRAnnotation extends AnnotationArea {
|
| 76 |
|
|
| 76 |
|
|
| 77 | 77 |
ConcordanceEditor editor; |
| 78 | 78 |
|
| 79 | 79 |
public SimpleKRAnnotation() {
|
| 80 | 80 |
|
| 81 | 81 |
} |
| 82 |
|
|
| 82 |
|
|
| 83 | 83 |
/** |
| 84 | 84 |
* the limit number of annotation when a confirm dialog box is shown |
| 85 | 85 |
*/ |
| 86 | 86 |
protected static final int NALERTAFFECTANNOTATIONS = 100; |
| 87 |
|
|
| 87 | 88 |
public static final String EMPTYTEXT = ""; //$NON-NLS-1$ |
| 88 |
|
|
| 89 |
|
|
| 89 | 90 |
/** The annotation service */ |
| 90 | 91 |
protected AnnotationManager annotManager; |
| 91 |
|
|
| 92 |
//boolean annotation_expert_mode = TxmPreferences.getBoolean(AnnotationPreferencePage.MODE, false); |
|
| 93 |
|
|
| 92 |
|
|
| 93 |
// boolean annotation_expert_mode = TxmPreferences.getBoolean(AnnotationPreferencePage.MODE, false);
|
|
| 94 |
|
|
| 94 | 95 |
protected Point annotationSize; |
| 95 |
|
|
| 96 |
|
|
| 96 | 97 |
protected Text annotationValuesText; |
| 98 |
|
|
| 97 | 99 |
protected ComboViewer annotationTypesCombo; |
| 98 |
|
|
| 100 |
|
|
| 99 | 101 |
protected TableColumn annotationColumn; |
| 100 |
|
|
| 102 |
|
|
| 101 | 103 |
protected Combo addRemoveCombo; |
| 104 |
|
|
| 102 | 105 |
protected Combo affectCombo; |
| 106 |
|
|
| 103 | 107 |
protected Button affectAnnotationButton; |
| 104 |
|
|
| 108 |
|
|
| 105 | 109 |
protected KnowledgeRepository currentKnowledgeRepository = null; |
| 106 |
protected Vector<AnnotationType> typesList = new Vector<AnnotationType>(); |
|
| 107 |
|
|
| 110 |
|
|
| 111 |
protected Vector<AnnotationType> typesList = new Vector<>(); |
|
| 112 |
|
|
| 108 | 113 |
protected Label withLabel; |
| 109 |
|
|
| 114 |
|
|
| 110 | 115 |
protected AnnotationType tagAnnotationType; // the tag annotation type if annotation mode is simple |
| 111 |
|
|
| 116 |
|
|
| 112 | 117 |
protected TypedValue value_to_add; |
| 113 |
|
|
| 118 |
|
|
| 114 | 119 |
protected Concordance concordance; |
| 115 |
|
|
| 120 |
|
|
| 116 | 121 |
private CQPCorpus corpus; |
| 117 |
|
|
| 122 |
|
|
| 118 | 123 |
private ConcordanceAnnotations annotations = null; |
| 124 |
|
|
| 119 | 125 |
private Button addTypedValueLink; |
| 120 |
|
|
| 126 |
|
|
| 121 | 127 |
@Override |
| 122 | 128 |
public String getName() {
|
| 123 | 129 |
return KRAnnotationUIMessages.squencesDeMotsCatgorie; |
| 124 | 130 |
} |
| 125 |
|
|
| 131 |
|
|
| 126 | 132 |
@Override |
| 127 | 133 |
public boolean install(TXMEditor<? extends TXMResult> txmeditor, AnnotationExtension ext, Composite parent, int position) throws Exception {
|
| 128 |
|
|
| 134 |
|
|
| 129 | 135 |
this.extension = ext; |
| 130 |
this.editor = (ConcordanceEditor)txmeditor; |
|
| 136 |
this.editor = (ConcordanceEditor) txmeditor;
|
|
| 131 | 137 |
this.concordance = this.editor.getConcordance(); |
| 132 | 138 |
this.corpus = concordance.getCorpus(); |
| 133 | 139 |
this.annotations = new ConcordanceAnnotations(this.editor.getConcordance()); |
| 134 | 140 |
this.annotManager = KRAnnotationEngine.getAnnotationManager(corpus); |
| 135 |
|
|
| 141 |
|
|
| 136 | 142 |
TableViewer viewer = this.editor.getLineTableViewer(); |
| 137 |
|
|
| 143 |
|
|
| 138 | 144 |
// RESULT |
| 139 |
|
|
| 145 |
|
|
| 140 | 146 |
if (position < 0) {
|
| 141 | 147 |
position = 3 + extension.getNumberOfAnnotationArea(); // after keyword column and previous annotation columns |
| 142 | 148 |
} |
| ... | ... | |
| 147 | 153 |
annotationColumn.setToolTipText(KRAnnotationUIMessages.keywordsAnnotation); |
| 148 | 154 |
annotationColumn.pack(); |
| 149 | 155 |
annotationColumn.setAlignment(SWT.CENTER); |
| 150 |
|
|
| 156 |
|
|
| 151 | 157 |
annotationColumn.addControlListener(new ConcordanceColumnSizeControlListener(annotationColumn)); |
| 152 | 158 |
annotationColumnViewer.setLabelProvider(new ColumnLabelProvider() {
|
| 153 |
|
|
| 159 |
|
|
| 154 | 160 |
@Override |
| 155 | 161 |
public String getText(Object element) {
|
| 156 |
Line line = (Line)element; |
|
| 162 |
Line line = (Line) element;
|
|
| 157 | 163 |
AnnotationLine annotationLine = annotations.getAnnotationLine(line); |
| 158 |
if (annotationLine == null) return EMPTYTEXT ;
|
|
| 159 |
if (annotationLine.getAnnotation()!=null) {
|
|
| 164 |
if (annotationLine == null) return EMPTYTEXT; |
|
| 165 |
if (annotationLine.getAnnotation() != null) {
|
|
| 160 | 166 |
String value = annotationLine.getAnnotationValue().getStandardName(); |
| 161 | 167 |
Annotation a = annotationLine.getAnnotation(); |
| 162 | 168 |
if (value == null) value = a.getValue(); |
| 163 |
|
|
| 169 |
|
|
| 164 | 170 |
if (a.getStart() < line.matchGetStart() - line.getLeftContextSize()) {
|
| 165 |
value = "… "+value; //$NON-NLS-1$
|
|
| 171 |
value = "… " + value; //$NON-NLS-1$
|
|
| 166 | 172 |
} |
| 167 |
|
|
| 173 |
|
|
| 168 | 174 |
if (a.getEnd() > line.matchGetEnd() + line.getRightContextSize()) {
|
| 169 |
value = value+" …"; //$NON-NLS-1$
|
|
| 170 |
}
|
|
| 175 |
value = value + " …"; //$NON-NLS-1$
|
|
| 176 |
} |
|
| 171 | 177 |
return value; |
| 172 |
} else {
|
|
| 178 |
} |
|
| 179 |
else {
|
|
| 173 | 180 |
return EMPTYTEXT; |
| 174 | 181 |
} |
| 175 | 182 |
} |
| 176 | 183 |
}); |
| 177 |
|
|
| 184 |
|
|
| 178 | 185 |
List<KnowledgeRepository> krs = InitializeKnowledgeRepository.get(corpus.getMainCorpus()); |
| 179 | 186 |
typesList.clear(); |
| 180 |
Log.fine("Corpus KRs: "+krs); //$NON-NLS-1$
|
|
| 181 |
|
|
| 182 |
KnowledgeRepository kr = KnowledgeRepositoryManager.getKnowledgeRepository(corpus.getMainCorpus().getName());
|
|
| 187 |
Log.fine("Corpus KRs: " + krs); //$NON-NLS-1$
|
|
| 188 |
|
|
| 189 |
KnowledgeRepository kr = KnowledgeRepositoryManager.getKnowledgeRepository(corpus.getMainCorpus().getName()); |
|
| 183 | 190 |
if (kr == null) {
|
| 184 |
HashMap<String, HashMap<String, ?>> conf = new HashMap<String, HashMap<String, ?>>();
|
|
| 191 |
HashMap<String, HashMap<String, ?>> conf = new HashMap<>(); |
|
| 185 | 192 |
kr = KnowledgeRepositoryManager.createKnowledgeRepository(corpus.getMainCorpus().getName(), conf); |
| 186 | 193 |
} |
| 187 |
|
|
| 194 |
|
|
| 188 | 195 |
currentKnowledgeRepository = kr; |
| 189 |
Log.fine(" KR: "+kr); //$NON-NLS-1$
|
|
| 196 |
Log.fine(" KR: " + kr); //$NON-NLS-1$
|
|
| 190 | 197 |
List<AnnotationType> krtypes = kr.getAllAnnotationTypes(); |
| 191 |
|
|
| 198 |
|
|
| 192 | 199 |
boolean createTagAnnotationType = true; |
| 193 | 200 |
for (AnnotationType type : krtypes) {
|
| 194 | 201 |
if (type.getName().equals("span")) { //$NON-NLS-1$
|
| ... | ... | |
| 196 | 203 |
} |
| 197 | 204 |
} |
| 198 | 205 |
if (createTagAnnotationType) {
|
| 199 |
tagAnnotationType = kr.addType("span", "span");//corresponds to an "undef" type //$NON-NLS-1$ //$NON-NLS-2$
|
|
| 206 |
tagAnnotationType = kr.addType("span", "span");// corresponds to an "undef" type //$NON-NLS-1$ //$NON-NLS-2$
|
|
| 200 | 207 |
typesList.add(tagAnnotationType); |
| 201 |
} else {
|
|
| 208 |
} |
|
| 209 |
else {
|
|
| 202 | 210 |
tagAnnotationType = kr.getType("span"); //$NON-NLS-1$
|
| 203 | 211 |
} |
| 204 | 212 |
annotations.setViewAnnotation(tagAnnotationType); |
| 205 | 213 |
|
| 206 | 214 |
Log.fine(NLS.bind(KRAnnotationUIMessages.availableAnnotationTypesColonP0, typesList)); |
| 207 |
|
|
| 215 |
|
|
| 208 | 216 |
annotationArea = new GLComposite(parent, SWT.NONE, KRAnnotationUIMessages.concordanceAnnotationArea); |
| 209 | 217 |
annotationArea.getLayout().numColumns = 12; |
| 210 | 218 |
annotationArea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); |
| 211 |
|
|
| 219 |
|
|
| 212 | 220 |
addRemoveCombo = new Combo(annotationArea, SWT.READ_ONLY); |
| 213 | 221 |
String affectLabel = currentKnowledgeRepository.getString(getLocale(), "ConcordancesEditor_22"); //$NON-NLS-1$ |
| 214 |
if (affectLabel == null) affectLabel= KRAnnotationUIMessages.affect; |
|
| 222 |
if (affectLabel == null) affectLabel = KRAnnotationUIMessages.affect;
|
|
| 215 | 223 |
String removeLabel = currentKnowledgeRepository.getString(getLocale(), "ConcordancesEditor_24"); //$NON-NLS-1$ |
| 216 |
if (removeLabel == null) removeLabel= KRAnnotationUIMessages.delete; |
|
| 217 |
String items[] = {affectLabel, removeLabel};
|
|
| 224 |
if (removeLabel == null) removeLabel = KRAnnotationUIMessages.delete;
|
|
| 225 |
String items[] = { affectLabel, removeLabel };
|
|
| 218 | 226 |
addRemoveCombo.setItems(items); |
| 219 | 227 |
addRemoveCombo.select(0); |
| 220 | 228 |
addRemoveCombo.addSelectionListener(new SelectionListener() {
|
| 229 |
|
|
| 221 | 230 |
@Override |
| 222 | 231 |
public void widgetSelected(SelectionEvent e) {
|
| 223 | 232 |
if (addRemoveCombo.getSelectionIndex() == 0) { // add
|
| 224 | 233 |
annotationValuesText.setEnabled(true); |
| 225 | 234 |
String withLabelText = currentKnowledgeRepository.getString(getLocale(), "ConcordancesEditor_83"); //$NON-NLS-1$ |
| 226 |
if (withLabelText == null) withLabelText= KRAnnotationUIMessages.withTheCategory; |
|
| 235 |
if (withLabelText == null) withLabelText = KRAnnotationUIMessages.withTheCategory;
|
|
| 227 | 236 |
withLabel.setText(withLabelText); |
| 228 |
} else { // remove
|
|
| 237 |
} |
|
| 238 |
else { // remove
|
|
| 229 | 239 |
annotationValuesText.setEnabled(false); |
| 230 | 240 |
withLabel.setText(""); //$NON-NLS-1$
|
| 231 | 241 |
} |
| ... | ... | |
| 233 | 243 |
annotationArea.layout(); |
| 234 | 244 |
updateAnnotationWidgetStates(); |
| 235 | 245 |
} |
| 246 |
|
|
| 236 | 247 |
@Override |
| 237 |
public void widgetDefaultSelected(SelectionEvent e) { }
|
|
| 248 |
public void widgetDefaultSelected(SelectionEvent e) {}
|
|
| 238 | 249 |
}); |
| 239 | 250 |
GridData gdata = new GridData(SWT.CENTER, SWT.CENTER, false, false); |
| 240 | 251 |
gdata.widthHint = 90; |
| 241 | 252 |
addRemoveCombo.setLayoutData(gdata); |
| 242 |
|
|
| 253 |
|
|
| 243 | 254 |
withLabel = new Label(annotationArea, SWT.NONE); |
| 244 | 255 |
String withLabelText = currentKnowledgeRepository.getString(getLocale(), "ConcordancesEditor_83"); //$NON-NLS-1$ |
| 245 |
if (withLabelText == null) withLabelText= KRAnnotationUIMessages.withTheCategory; |
|
| 256 |
if (withLabelText == null) withLabelText = KRAnnotationUIMessages.withTheCategory;
|
|
| 246 | 257 |
withLabel.setText(withLabelText); |
| 247 | 258 |
withLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false)); |
| 248 |
|
|
| 259 |
|
|
| 249 | 260 |
annotationValuesText = new Text(annotationArea, SWT.BORDER); |
| 250 | 261 |
annotationValuesText.setToolTipText(KRAnnotationUIMessages.enterAValueForAnId); |
| 251 | 262 |
GridData gdata2 = new GridData(SWT.FILL, SWT.CENTER, false, false); |
| 252 | 263 |
gdata2.widthHint = 200; |
| 253 | 264 |
annotationValuesText.setLayoutData(gdata2); |
| 254 | 265 |
annotationValuesText.addKeyListener(new KeyListener() {
|
| 266 |
|
|
| 255 | 267 |
@Override |
| 256 | 268 |
public void keyReleased(KeyEvent e) {
|
| 257 | 269 |
if (e.keyCode == SWT.CR || e.keyCode == SWT.KEYPAD_CR) {
|
| 258 | 270 |
affectAnnotationToSelection(editor.getLineTableViewer().getSelection()); |
| 259 | 271 |
} |
| 260 | 272 |
} |
| 261 |
|
|
| 273 |
|
|
| 262 | 274 |
@Override |
| 263 |
public void keyPressed(KeyEvent e) { }
|
|
| 275 |
public void keyPressed(KeyEvent e) {}
|
|
| 264 | 276 |
}); |
| 265 |
|
|
| 277 |
|
|
| 266 | 278 |
if (currentKnowledgeRepository instanceof LocalKnowledgeRepository) {
|
| 267 | 279 |
addTypedValueLink = new Button(annotationArea, SWT.PUSH); |
| 268 | 280 |
addTypedValueLink.setText("..."); //$NON-NLS-1$
|
| 269 | 281 |
addTypedValueLink.setToolTipText(KRAnnotationUIMessages.openTheListOfCategories); |
| 270 | 282 |
addTypedValueLink.setEnabled(true); |
| 271 |
addTypedValueLink.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
|
|
| 283 |
addTypedValueLink.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
|
|
| 272 | 284 |
addTypedValueLink.addSelectionListener(new SelectionListener() {
|
| 285 |
|
|
| 273 | 286 |
@Override |
| 274 | 287 |
public void widgetSelected(SelectionEvent e) {
|
| 275 | 288 |
if (currentKnowledgeRepository == null) return; |
| 276 | 289 |
if (!(currentKnowledgeRepository instanceof LocalKnowledgeRepository)) return; |
| 277 |
|
|
| 290 |
|
|
| 278 | 291 |
AnnotationType type = getSelectedAnnotationType(); |
| 279 | 292 |
if (type == null) return; |
| 280 |
|
|
| 281 |
LocalKnowledgeRepository kr = (LocalKnowledgeRepository)currentKnowledgeRepository; |
|
| 282 |
|
|
| 293 |
|
|
| 294 |
LocalKnowledgeRepository kr = (LocalKnowledgeRepository) currentKnowledgeRepository;
|
|
| 295 |
|
|
| 283 | 296 |
ListDialog dialog = new ListDialog(e.widget.getDisplay().getActiveShell()); |
| 284 |
dialog.setTitle(KRAnnotationUIMessages.listOfCategories);//+"valeurs de "+type.getName()); |
|
| 297 |
dialog.setTitle(KRAnnotationUIMessages.listOfCategories);// +"valeurs de "+type.getName());
|
|
| 285 | 298 |
dialog.setContentProvider(new ArrayContentProvider()); |
| 286 | 299 |
dialog.setLabelProvider(new SimpleLabelProvider() {
|
| 300 |
|
|
| 301 |
@Override |
|
| 287 | 302 |
public String getColumnText(Object element, int columnIndex) {
|
| 288 | 303 |
if (element instanceof TypedValue) |
| 289 |
return ((TypedValue)element).getId(); |
|
| 304 |
return ((TypedValue) element).getId();
|
|
| 290 | 305 |
return element.toString(); |
| 291 | 306 |
} |
| 292 | 307 |
}); |
| 293 | 308 |
List<TypedValue> values; |
| 294 | 309 |
try {
|
| 295 | 310 |
values = kr.getValues(type); |
| 296 |
} catch (Exception e1) {
|
|
| 311 |
} |
|
| 312 |
catch (Exception e1) {
|
|
| 297 | 313 |
e1.printStackTrace(); |
| 298 | 314 |
return; |
| 299 | 315 |
} |
| ... | ... | |
| 302 | 318 |
TypedValue value = (TypedValue) dialog.getResult()[0]; |
| 303 | 319 |
String name = value.getId(); |
| 304 | 320 |
if (name.trim().length() == 0) return; |
| 305 |
|
|
| 321 |
|
|
| 306 | 322 |
annotationValuesText.setText(name); |
| 307 |
} else {
|
|
| 308 |
|
|
| 309 | 323 |
} |
| 324 |
else {
|
|
| 325 |
|
|
| 326 |
} |
|
| 310 | 327 |
} |
| 311 |
|
|
| 328 |
|
|
| 312 | 329 |
@Override |
| 313 |
public void widgetDefaultSelected(SelectionEvent e) { }
|
|
| 330 |
public void widgetDefaultSelected(SelectionEvent e) {}
|
|
| 314 | 331 |
}); |
| 315 | 332 |
} |
| 316 |
|
|
| 333 |
|
|
| 317 | 334 |
affectCombo = new Combo(annotationArea, SWT.READ_ONLY); |
| 318 | 335 |
affectCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false)); |
| 319 |
String items2[] = {KRAnnotationUIMessages.selectedLines, KRAnnotationUIMessages.allLines};
|
|
| 336 |
String items2[] = { KRAnnotationUIMessages.selectedLines, KRAnnotationUIMessages.allLines };
|
|
| 320 | 337 |
affectCombo.setItems(items2); |
| 321 | 338 |
affectCombo.select(0); |
| 322 | 339 |
gdata = new GridData(SWT.CENTER, SWT.CENTER, false, false); |
| 323 | 340 |
gdata.widthHint = 140; |
| 324 | 341 |
affectCombo.setLayoutData(gdata); |
| 325 |
|
|
| 342 |
|
|
| 326 | 343 |
affectAnnotationButton = new Button(annotationArea, SWT.PUSH); |
| 327 | 344 |
affectAnnotationButton.setText(KRAnnotationUIMessages.oK); |
| 328 | 345 |
affectAnnotationButton.setToolTipText(KRAnnotationUIMessages.proceedToAnnotation); |
| 329 | 346 |
affectAnnotationButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false)); |
| 330 | 347 |
affectAnnotationButton.addSelectionListener(new SelectionListener() {
|
| 348 |
|
|
| 331 | 349 |
@Override |
| 332 | 350 |
public void widgetSelected(SelectionEvent e) {
|
| 333 | 351 |
int isel = affectCombo.getSelectionIndex(); |
| 334 | 352 |
if (isel == 0) { // selected line
|
| 335 | 353 |
affectAnnotationToSelection(editor.getLineTableViewer().getSelection()); |
| 336 |
} else { // all
|
|
| 354 |
} |
|
| 355 |
else { // all
|
|
| 337 | 356 |
try {
|
| 338 | 357 |
List<? extends Match> matches = concordance.getMatches(); |
| 339 | 358 |
affectMatchesToSelection(matches); |
| 340 |
} catch (Exception e1) {
|
|
| 359 |
} |
|
| 360 |
catch (Exception e1) {
|
|
| 341 | 361 |
Log.severe(NLS.bind(KRAnnotationUIMessages.errorWhileAnnotatingConcordanceColonP0, e1.getLocalizedMessage())); |
| 342 | 362 |
Log.printStackTrace(e1); |
| 343 | 363 |
return; |
| 344 | 364 |
} |
| 345 | 365 |
} |
| 346 | 366 |
} |
| 347 |
|
|
| 367 |
|
|
| 348 | 368 |
@Override |
| 349 |
public void widgetDefaultSelected(SelectionEvent e) { }
|
|
| 369 |
public void widgetDefaultSelected(SelectionEvent e) {}
|
|
| 350 | 370 |
}); |
| 351 | 371 |
|
| 352 | 372 |
Button closeButton = new Button(annotationArea, SWT.PUSH); |
| ... | ... | |
| 366 | 386 |
|
| 367 | 387 |
updateAnnotationWidgetStates(); |
| 368 | 388 |
editor.layout(true); |
| 369 |
|
|
| 389 |
|
|
| 370 | 390 |
ext.getSaveButton().setEnabled(true); |
| 371 | 391 |
return true; |
| 372 | 392 |
} |
| 373 |
|
|
| 393 |
|
|
| 374 | 394 |
protected void affectAnnotationToSelection(ISelection selection) {
|
| 375 |
|
|
| 395 |
|
|
| 376 | 396 |
final IStructuredSelection lineSelection = (IStructuredSelection) selection; |
| 377 | 397 |
List<Line> lines = lineSelection.toList(); |
| 378 |
ArrayList<Match> matches = new ArrayList<Match>();
|
|
| 398 |
ArrayList<Match> matches = new ArrayList<>(); |
|
| 379 | 399 |
for (Line l : lines) {
|
| 380 | 400 |
matches.add(l.getMatch()); |
| 381 | 401 |
} |
| 382 |
|
|
| 402 |
|
|
| 383 | 403 |
affectMatchesToSelection(matches); |
| 384 | 404 |
} |
| 385 |
|
|
| 405 |
|
|
| 386 | 406 |
protected AnnotationType getSelectedAnnotationType() {
|
| 387 | 407 |
if (annotationTypesCombo != null) {
|
| 388 |
IStructuredSelection isel = (IStructuredSelection)annotationTypesCombo.getSelection(); |
|
| 408 |
IStructuredSelection isel = (IStructuredSelection) annotationTypesCombo.getSelection();
|
|
| 389 | 409 |
if (isel.isEmpty()) {
|
| 390 | 410 |
return null; |
| 391 | 411 |
} |
| 392 | 412 |
return (AnnotationType) isel.getFirstElement(); |
| 393 |
} else { // simple mode
|
|
| 413 |
} |
|
| 414 |
else { // simple mode
|
|
| 394 | 415 |
return tagAnnotationType; |
| 395 | 416 |
} |
| 396 | 417 |
} |
| 397 |
|
|
| 418 |
|
|
| 398 | 419 |
protected void affectMatchesToSelection(final List<? extends Match> matches) {
|
| 399 | 420 |
final AnnotationType type = getSelectedAnnotationType(); |
| 400 | 421 |
final String svalue = annotationValuesText.getText(); |
| 401 | 422 |
final boolean doAffect = addRemoveCombo.getSelectionIndex() == 0; // add is default |
| 402 |
|
|
| 423 |
|
|
| 403 | 424 |
JobHandler job = new JobHandler(KRAnnotationUIMessages.annotatingConcordanceSelection, true) {
|
| 425 |
|
|
| 404 | 426 |
@Override |
| 405 | 427 |
protected IStatus run(IProgressMonitor monitor) {
|
| 406 | 428 |
this.runInit(monitor); |
| 407 | 429 |
try {
|
| 408 | 430 |
if (doAffect) {
|
| 409 | 431 |
affectAnnotationValues(matches, type, svalue, this); |
| 410 |
} else {
|
|
| 432 |
} |
|
| 433 |
else {
|
|
| 411 | 434 |
deleteAnnotationValues(matches, type, this); |
| 412 | 435 |
} |
| 413 |
} catch(Exception e) {
|
|
| 436 |
} |
|
| 437 |
catch (Exception e) {
|
|
| 414 | 438 |
Log.severe(NLS.bind(KRAnnotationUIMessages.errorWhileAnnotatingConcordanceSelectionColonP0, e)); |
| 415 | 439 |
Log.printStackTrace(e); |
| 416 | 440 |
return Status.CANCEL_STATUS; |
| 417 |
} catch(ThreadDeath td) {
|
|
| 441 |
} |
|
| 442 |
catch (ThreadDeath td) {
|
|
| 418 | 443 |
System.out.println(KRAnnotationUIMessages.annotationCanceledByUser); |
| 419 | 444 |
return Status.CANCEL_STATUS; |
| 420 | 445 |
} |
| 421 |
|
|
| 446 |
|
|
| 422 | 447 |
return Status.OK_STATUS; |
| 423 | 448 |
} |
| 424 | 449 |
}; |
| 425 | 450 |
job.startJob(true); |
| 426 | 451 |
} |
| 427 |
|
|
| 452 |
|
|
| 428 | 453 |
public void updateAnnotationWidgetStates() {
|
| 429 | 454 |
if (annotationArea == null) return; // :) |
| 430 | 455 |
annotationArea.getDisplay().syncExec(new Runnable() {
|
| ... | ... | |
| 432 | 457 |
@Override |
| 433 | 458 |
public void run() {
|
| 434 | 459 |
if (addRemoveCombo.getSelectionIndex() == 0) { // add is default
|
| 435 |
|
|
| 460 |
|
|
| 436 | 461 |
if (getSelectedAnnotationType() != null) {
|
| 437 | 462 |
annotationValuesText.setEnabled(true); |
| 438 |
|
|
| 463 |
|
|
| 439 | 464 |
affectAnnotationButton.setEnabled(true); |
| 440 | 465 |
affectCombo.setEnabled(true); |
| 441 |
} else {
|
|
| 466 |
} |
|
| 467 |
else {
|
|
| 442 | 468 |
annotationValuesText.setEnabled(false); |
| 443 |
|
|
| 469 |
|
|
| 444 | 470 |
affectAnnotationButton.setEnabled(false); |
| 445 | 471 |
affectCombo.setEnabled(false); |
| 446 | 472 |
} |
| 447 |
} else {
|
|
| 473 |
} |
|
| 474 |
else {
|
|
| 448 | 475 |
annotationValuesText.setEnabled(false); |
| 449 |
|
|
| 476 |
|
|
| 450 | 477 |
if (getSelectedAnnotationType() != null) {
|
| 451 | 478 |
affectAnnotationButton.setEnabled(true); |
| 452 | 479 |
affectCombo.setEnabled(true); |
| 453 |
} else {
|
|
| 480 |
} |
|
| 481 |
else {
|
|
| 454 | 482 |
affectAnnotationButton.setEnabled(false); |
| 455 | 483 |
affectCombo.setEnabled(false); |
| 456 | 484 |
} |
| 457 | 485 |
} |
| 458 |
|
|
| 459 |
|
|
| 486 |
|
|
| 487 |
|
|
| 460 | 488 |
if (addTypedValueLink != null) {
|
| 461 | 489 |
addTypedValueLink.setEnabled(getSelectedAnnotationType() != null); |
| 462 |
}
|
|
| 490 |
} |
|
| 463 | 491 |
} |
| 464 | 492 |
}); |
| 465 | 493 |
} |
| 466 |
|
|
| 494 |
|
|
| 467 | 495 |
protected void deleteAnnotationValues(List<? extends Match> matches, AnnotationType type, JobHandler job) {
|
| 468 |
|
|
| 496 |
|
|
| 469 | 497 |
if (matches.size() == 0) {
|
| 470 | 498 |
System.out.println("No lines selected. Aborting."); //$NON-NLS-1$
|
| 471 | 499 |
return; |
| 472 | 500 |
} |
| 473 |
|
|
| 501 |
|
|
| 474 | 502 |
if (type == null) {
|
| 475 | 503 |
return; |
| 476 | 504 |
} |
| 477 |
|
|
| 505 |
|
|
| 478 | 506 |
try {
|
| 479 | 507 |
if (annotManager != null && annotManager.deleteAnnotations(type, matches, job)) {
|
| 480 | 508 |
if (Log.getLevel().intValue() < Level.INFO.intValue()) annotManager.checkData(); |
| 481 | 509 |
editor.refresh(false); |
| 482 |
} else {
|
|
| 510 |
} |
|
| 511 |
else {
|
|
| 483 | 512 |
return; |
| 484 | 513 |
} |
| 485 |
} catch (Exception e1) {
|
|
| 514 |
} |
|
| 515 |
catch (Exception e1) {
|
|
| 486 | 516 |
System.out.println(NLS.bind(KRAnnotationUIMessages.errorWhileDeletingAnnotationColonP0, e1)); |
| 487 | 517 |
Log.printStackTrace(e1); |
| 488 | 518 |
return; |
| 489 | 519 |
} |
| 490 |
|
|
| 520 |
|
|
| 491 | 521 |
job.syncExec(new Runnable() {
|
| 522 |
|
|
| 492 | 523 |
@Override |
| 493 | 524 |
public void run() {
|
| 494 | 525 |
try {
|
| 495 | 526 |
editor.refresh(false); |
| 496 |
} catch (Exception e) {
|
|
| 527 |
} |
|
| 528 |
catch (Exception e) {
|
|
| 497 | 529 |
// TODO Auto-generated catch block |
| 498 | 530 |
e.printStackTrace(); |
| 499 | 531 |
} |
| 500 | 532 |
} |
| 501 | 533 |
}); |
| 502 | 534 |
} |
| 503 |
|
|
| 504 |
protected void affectAnnotationValues(final List<? extends Match> matches, final AnnotationType type, final String svalue, JobHandler job) {
|
|
| 535 |
|
|
| 536 |
protected void affectAnnotationValues(final List<? extends Match> matches, final AnnotationType type, final String svalue, JobHandler job) {
|
|
| 505 | 537 |
value_to_add = null; // reset |
| 506 | 538 |
if (matches == null || matches.size() == 0) {
|
| 507 | 539 |
System.out.println("No line selected. Aborting."); //$NON-NLS-1$
|
| 508 | 540 |
return; |
| 509 | 541 |
} |
| 510 | 542 |
if (type == null) return; // no type, no annotation |
| 511 |
|
|
| 543 |
|
|
| 512 | 544 |
job.syncExec(new Runnable() {
|
| 545 |
|
|
| 513 | 546 |
@Override |
| 514 | 547 |
public void run() {
|
| 515 | 548 |
if (matches.size() > NALERTAFFECTANNOTATIONS) {
|
| 516 |
ConfirmDialog dialog = new ConfirmDialog(Display.getCurrent().getActiveShell(),
|
|
| 549 |
ConfirmDialog dialog = new ConfirmDialog(Display.getCurrent().getActiveShell(), |
|
| 517 | 550 |
"confirm_annotate", //$NON-NLS-1$ |
| 518 |
KRAnnotationUIMessages.confirmAnnotationAffectation,
|
|
| 551 |
KRAnnotationUIMessages.confirmAnnotationAffectation, |
|
| 519 | 552 |
NLS.bind(KRAnnotationUIMessages.youAreAboutToAnnotateP0ElementsContinue, matches.size())); |
| 520 |
|
|
| 553 |
|
|
| 521 | 554 |
if (dialog.open() == ConfirmDialog.CANCEL) {
|
| 522 | 555 |
System.out.println("Annotation aborted by user."); //$NON-NLS-1$
|
| 523 | 556 |
matches.clear(); |
| ... | ... | |
| 525 | 558 |
} |
| 526 | 559 |
} |
| 527 | 560 |
}); |
| 528 |
|
|
| 561 |
|
|
| 529 | 562 |
// get value from combo text value |
| 530 | 563 |
Log.fine(NLS.bind(KRAnnotationUIMessages.lookingForTypedValueWithIdEqualsP0, svalue)); |
| 531 | 564 |
final KnowledgeRepository kr = KnowledgeRepositoryManager.getKnowledgeRepository(type.getKnowledgeRepository()); |
| 532 | 565 |
value_to_add = kr.getValue(type, svalue); |
| 533 |
|
|
| 534 |
|
|
| 566 |
|
|
| 567 |
|
|
| 535 | 568 |
if (value_to_add == null && kr instanceof LocalKnowledgeRepository) { // create or not the annotation is simple mode
|
| 536 | 569 |
job.syncExec(new Runnable() {
|
| 570 |
|
|
| 537 | 571 |
@Override |
| 538 | 572 |
public void run() {
|
| 539 | 573 |
String title = kr.getString(getLocale(), "ConcordancesEditor_110"); //$NON-NLS-1$ |
| 540 | 574 |
String content = kr.getString(getLocale(), "ConcordancesEditor_112"); //$NON-NLS-1$ |
| 541 |
if (title == null ) title = KRAnnotationUIMessages.newValueP0ForCategoryP1;
|
|
| 542 |
if (content == null ) content = KRAnnotationUIMessages.theValueP0IsNotAssociatedWithTheCategoryP1AssociateIt;
|
|
| 543 |
ConfirmDialog dialog = new ConfirmDialog(Display.getCurrent().getActiveShell(),
|
|
| 575 |
if (title == null) title = KRAnnotationUIMessages.newValueP0ForCategoryP1; |
|
| 576 |
if (content == null) content = KRAnnotationUIMessages.theValueP0IsNotAssociatedWithTheCategoryP1AssociateIt; |
|
| 577 |
ConfirmDialog dialog = new ConfirmDialog(Display.getCurrent().getActiveShell(), |
|
| 544 | 578 |
"create_value", //$NON-NLS-1$ |
| 545 |
ConcordanceUIMessages.bind(title, svalue, type.getName()),
|
|
| 579 |
ConcordanceUIMessages.bind(title, svalue, type.getName()), |
|
| 546 | 580 |
ConcordanceUIMessages.bind(content, svalue, type.getName())); |
| 547 | 581 |
if (dialog.open() == ConfirmDialog.CANCEL) {
|
| 548 | 582 |
System.out.println("Annotation aborted by user."); //$NON-NLS-1$
|
| 549 | 583 |
return; |
| 550 |
} else {
|
|
| 584 |
} |
|
| 585 |
else {
|
|
| 551 | 586 |
value_to_add = kr.addValue(svalue, svalue, type.getId()); |
| 552 | 587 |
KRView.refresh(); |
| 553 | 588 |
} |
| 554 | 589 |
} |
| 555 | 590 |
}); |
| 556 | 591 |
} |
| 557 |
|
|
| 592 |
|
|
| 558 | 593 |
if (value_to_add == null && kr instanceof LocalKnowledgeRepository) return; // canceled |
| 559 |
|
|
| 560 |
if (value_to_add == null) {
|
|
| 594 |
|
|
| 595 |
if (value_to_add == null) {
|
|
| 561 | 596 |
job.syncExec(new Runnable() {
|
| 597 |
|
|
| 562 | 598 |
@Override |
| 563 | 599 |
public void run() {
|
| 564 | 600 |
String mess = ConcordanceUIMessages.bind(KRAnnotationUIMessages.noValueFoundWithTheP0Id, svalue); |
| ... | ... | |
| 568 | 604 |
}); |
| 569 | 605 |
return; |
| 570 | 606 |
} |
| 571 |
|
|
| 607 |
|
|
| 572 | 608 |
Log.info(TXMCoreMessages.bind(KRAnnotationUIMessages.AffectP0ToSelectionEqualsP1, value_to_add.getId(), value_to_add.getTypeID(), matches.size())); |
| 573 |
|
|
| 609 |
|
|
| 574 | 610 |
// finally we can 'try' to create the annotations \o/ |
| 575 | 611 |
try {
|
| 576 | 612 |
HashMap<Match, List<Annotation>> existingAnnots = annotManager.createAnnotations(type, value_to_add, matches, job); |
| 577 |
|
|
| 613 |
|
|
| 578 | 614 |
// did we had problems ? |
| 579 |
if (existingAnnots!=null && existingAnnots.size() > 0) {
|
|
| 615 |
if (existingAnnots != null && existingAnnots.size() > 0) {
|
|
| 580 | 616 |
String message = NLS.bind(KRAnnotationUIMessages.couldNotAnnotateTheValueP0OnCertainSequences, value_to_add.getStandardName()); |
| 581 | 617 |
for (Match m : existingAnnots.keySet()) {
|
| 582 | 618 |
message += NLS.bind(KRAnnotationUIMessages.theSequenceP0IsOverlappingWith, m); |
| 583 |
|
|
| 619 |
|
|
| 584 | 620 |
for (Annotation existingAnnot : existingAnnots.get(m)) {
|
| 585 |
if (existingAnnot.getStart() < m.getStart()){
|
|
| 621 |
if (existingAnnot.getStart() < m.getStart()) {
|
|
| 586 | 622 |
message += TXMCoreMessages.bind(KRAnnotationUIMessages.theEndOfAStructureP0AtP1P2, existingAnnot.getType(), existingAnnot.getStart(), existingAnnot.getEnd()); |
| 587 |
} else {
|
|
| 623 |
} |
|
| 624 |
else {
|
|
| 588 | 625 |
message += TXMCoreMessages.bind(KRAnnotationUIMessages.theStartOfAStructureP0AtP1P2, existingAnnot.getType(), existingAnnot.getStart(), existingAnnot.getEnd()); |
| 589 | 626 |
} |
| 590 | 627 |
} |
| 591 | 628 |
} |
| 592 | 629 |
final String final_message = message; |
| 593 | 630 |
job.syncExec(new Runnable() {
|
| 631 |
|
|
| 594 | 632 |
@Override |
| 595 | 633 |
public void run() {
|
| 596 | 634 |
MessageDialog.openInformation(editor.getSite().getShell(), KRAnnotationUIMessages.aboutAnnotations, final_message); |
| 597 | 635 |
} |
| 598 | 636 |
}); |
| 599 | 637 |
} |
| 600 |
|
|
| 638 |
|
|
| 601 | 639 |
if (Log.getLevel().intValue() < Level.INFO.intValue() && annotManager != null) {
|
| 602 | 640 |
annotManager.checkData(); |
| 603 | 641 |
} |
| 604 |
} catch (Exception e1) {
|
|
| 642 |
} |
|
| 643 |
catch (Exception e1) {
|
|
| 605 | 644 |
System.out.println(NLS.bind(KRAnnotationUIMessages.errorWhileAffectionAnnotationColonP0, e1)); |
| 606 | 645 |
Log.printStackTrace(e1); |
| 607 | 646 |
return; |
| 608 | 647 |
} |
| 609 |
|
|
| 648 |
|
|
| 610 | 649 |
job.syncExec(new Runnable() {
|
| 650 |
|
|
| 611 | 651 |
@Override |
| 612 | 652 |
public void run() {
|
| 613 | 653 |
try {
|
| 614 | 654 |
editor.refresh(false); |
| 615 | 655 |
CorporaView.refreshObject(corpus); |
| 616 |
} catch (Exception e) {
|
|
| 656 |
} |
|
| 657 |
catch (Exception e) {
|
|
| 617 | 658 |
// TODO Auto-generated catch block |
| 618 | 659 |
e.printStackTrace(); |
| 619 | 660 |
} |
| 620 | 661 |
} |
| 621 | 662 |
}); |
| 622 | 663 |
} |
| 623 |
|
|
| 664 |
|
|
| 665 |
@Override |
|
| 624 | 666 |
public boolean notifyStartOfCompute() throws Exception {
|
| 625 | 667 |
if (annotationArea != null) {
|
| 626 | 668 |
annotationArea.getDisplay().syncExec(new Runnable() {
|
| 669 |
|
|
| 627 | 670 |
@Override |
| 628 | 671 |
public void run() {
|
| 629 | 672 |
AnnotationType type = getSelectedAnnotationType(); |
| ... | ... | |
| 637 | 680 |
} |
| 638 | 681 |
return true; |
| 639 | 682 |
} |
| 640 |
|
|
| 683 |
|
|
| 684 |
@Override |
|
| 641 | 685 |
public boolean notifyEndOfCompute() throws Exception {
|
| 642 | 686 |
updateAnnotationWidgetStates(); |
| 643 |
|
|
| 687 |
|
|
| 644 | 688 |
// update annotation column width |
| 645 | 689 |
if (annotationArea != null) {
|
| 646 | 690 |
annotationArea.getDisplay().syncExec(new Runnable() {
|
| 691 |
|
|
| 647 | 692 |
@Override |
| 648 | 693 |
public void run() {
|
| 649 | 694 |
annotationColumn.pack(); |
| 650 | 695 |
annotationColumn.setResizable(true); |
| 651 | 696 |
} |
| 652 | 697 |
}); |
| 653 |
} else {
|
|
| 698 |
} |
|
| 699 |
else {
|
|
| 654 | 700 |
annotationColumn.setWidth(0); |
| 655 | 701 |
} |
| 656 |
|
|
| 702 |
|
|
| 657 | 703 |
return true; |
| 658 | 704 |
} |
| 659 |
|
|
| 660 |
|
|
| 705 |
|
|
| 706 |
|
|
| 707 |
@Override |
|
| 661 | 708 |
public boolean isAnnotationEnable() {
|
| 662 | 709 |
return annotationArea != null; |
| 663 | 710 |
} |
| 664 |
|
|
| 711 |
|
|
| 712 |
@Override |
|
| 665 | 713 |
public void notifyStartOfRefresh() throws Exception {
|
| 666 |
List<Line> lines = concordance.getLines(concordance.getTopIndex(), concordance.getTopIndex()+concordance.getNLinePerPage());
|
|
| 714 |
List<Line> lines = concordance.getLines(concordance.getTopIndex(), concordance.getTopIndex() + concordance.getNLinePerPage());
|
|
| 667 | 715 |
annotations.computeLines(lines); |
| 668 | 716 |
} |
| 669 |
|
|
| 717 |
|
|
| 670 | 718 |
@Override |
| 671 | 719 |
public boolean save() {
|
| 672 | 720 |
try {
|
| 673 | 721 |
AnnotationManager am = KRAnnotationEngine.getAnnotationManager(corpus); |
| 674 | 722 |
if (am != null && am.hasChanges()) {
|
| 675 |
// && MessageDialog.openConfirm(e.display.getActiveShell(), "Confirm annotation save", "Saving annotation will close this editor. Are you sure you want to save annotations right now ?") |
|
| 723 |
// && MessageDialog.openConfirm(e.display.getActiveShell(), "Confirm annotation save", "Saving annotation will close this editor. Are you sure you want to save annotations right now |
|
| 724 |
// ?") |
|
| 676 | 725 |
JobHandler saveJob = SaveAnnotations.save(corpus.getMainCorpus()); |
| 677 | 726 |
if (saveJob == null || saveJob.getResult() == Status.CANCEL_STATUS) {
|
| 678 | 727 |
// update editor corpus |
| 679 | 728 |
System.out.println("Fail to save annotations of the corpus."); //$NON-NLS-1$
|
| 680 | 729 |
return false; |
| 681 |
} else {
|
|
| 730 |
} |
|
| 731 |
else {
|
|
| 682 | 732 |
if (annotationColumn != null && !annotationColumn.isDisposed()) {
|
| 683 | 733 |
annotationColumn.setText(annotations.getViewAnnotation().getName()); |
| 684 | 734 |
} |
| 685 | 735 |
return true; // something was saved |
| 686 | 736 |
} |
| 687 |
} else {
|
|
| 737 |
} |
|
| 738 |
else {
|
|
| 688 | 739 |
return false; |
| 689 | 740 |
} |
| 690 |
} catch(Exception ex) {
|
|
| 741 |
} |
|
| 742 |
catch (Exception ex) {
|
|
| 691 | 743 |
ex.printStackTrace(); |
| 692 | 744 |
return false; |
| 693 | 745 |
} |
| 694 | 746 |
} |
| 695 |
|
|
| 747 |
|
|
| 696 | 748 |
@Override |
| 697 | 749 |
protected void _close() {
|
| 698 | 750 |
if (!annotationColumn.isDisposed()) annotationColumn.dispose(); |
| 699 | 751 |
if (!annotationArea.isDisposed()) annotationArea.dispose(); |
| 700 | 752 |
extension.layout(); |
| 701 | 753 |
} |
| 702 |
|
|
| 754 |
|
|
| 703 | 755 |
@Override |
| 704 | 756 |
public boolean hasChanges() {
|
| 705 | 757 |
AnnotationManager am; |
| ... | ... | |
| 707 | 759 |
am = KRAnnotationEngine.getAnnotationManager(corpus); |
| 708 | 760 |
if (am != null && am.hasChanges()) {
|
| 709 | 761 |
return am.hasChanges(); |
| 710 |
} else {
|
|
| 762 |
} |
|
| 763 |
else {
|
|
| 711 | 764 |
return false; |
| 712 | 765 |
} |
| 713 |
} catch (Exception e) {
|
|
| 766 |
} |
|
| 767 |
catch (Exception e) {
|
|
| 714 | 768 |
// TODO Auto-generated catch block |
| 715 | 769 |
e.printStackTrace(); |
| 716 | 770 |
return false; |
| 717 | 771 |
} |
| 718 | 772 |
} |
| 773 |
|
|
| 719 | 774 |
@Override |
| 720 | 775 |
public void notifyEndOfRefresh() throws Exception {
|
| 721 | 776 |
// TODO Auto-generated method stub |
| 722 | 777 |
} |
| 723 |
|
|
| 778 |
|
|
| 724 | 779 |
@Override |
| 725 | 780 |
public void notifyStartOfCreatePartControl() throws Exception {
|
| 726 | 781 |
// TODO Auto-generated method stub |
| 727 | 782 |
|
| 728 | 783 |
} |
| 729 |
|
|
| 784 |
|
|
| 730 | 785 |
@Override |
| 731 | 786 |
public Class<? extends TXMResult> getAnnotatedTXMResultClass() {
|
| 732 | 787 |
return Concordance.class; |
| 733 | 788 |
} |
| 734 |
|
|
| 789 |
|
|
| 735 | 790 |
@Override |
| 736 | 791 |
public boolean isDirty() {
|
| 737 | 792 |
return annotManager.isDirty(); |
| 738 | 793 |
} |
| 739 |
|
|
| 794 |
|
|
| 740 | 795 |
@Override |
| 741 | 796 |
public boolean discardChanges() {
|
| 742 | 797 |
return false; |
| 743 | 798 |
} |
| 744 |
|
|
| 799 |
|
|
| 745 | 800 |
@Override |
| 746 | 801 |
public boolean needToUpdateIndexes() {
|
| 747 | 802 |
return true; |
| 748 | 803 |
} |
| 749 |
} |
|
| 804 |
} |
|
| tmp/org.txm.annotation.kr.rcp/src/org/txm/annotation/kr/rcp/concordance/WordAnnotationToolbar.java (revision 2914) | ||
|---|---|---|
| 75 | 75 |
import org.txm.utils.logger.Log; |
| 76 | 76 |
|
| 77 | 77 |
public class WordAnnotationToolbar extends AnnotationArea {
|
| 78 |
|
|
| 78 |
|
|
| 79 | 79 |
/** |
| 80 | 80 |
* the limit number of annotation when a confirm dialog box is shown |
| 81 | 81 |
*/ |
| 82 | 82 |
protected static final int NALERTAFFECTANNOTATIONS = 100; |
| 83 |
|
|
| 83 | 84 |
public static final String EMPTYTEXT = ""; //$NON-NLS-1$ |
| 84 |
|
|
| 85 |
|
|
| 85 | 86 |
/** The annotation service */ |
| 86 | 87 |
protected AnnotationManager annotManager; |
| 87 |
|
|
| 88 |
|
|
| 88 | 89 |
protected ConcordanceEditor editor; |
| 89 |
|
|
| 90 |
|
|
| 90 | 91 |
/** |
| 91 | 92 |
* The concordance annotations to show in the concordance column table |
| 92 | 93 |
*/ |
| 93 | 94 |
private ConcordanceAnnotations annotations = null; |
| 94 |
|
|
| 95 |
|
|
| 95 | 96 |
/** |
| 96 | 97 |
* All available annotation types |
| 97 | 98 |
*/ |
| 98 | 99 |
protected List<TypedValue> typeValuesList; |
| 99 |
|
|
| 100 |
|
|
| 100 | 101 |
/** |
| 101 | 102 |
* display the annotation values of the current shown concordance lines |
| 102 | 103 |
*/ |
| 103 | 104 |
protected TableColumn annotationColumn; |
| 104 |
|
|
| 105 |
|
|
| 105 | 106 |
protected ComboViewer annotationTypesCombo; |
| 107 |
|
|
| 106 | 108 |
/** add a new type of annotation */ |
| 107 | 109 |
private Button addAnnotationTypeButton; |
| 110 |
|
|
| 108 | 111 |
protected Label equalLabel; |
| 112 |
|
|
| 109 | 113 |
protected Text annotationValuesText; |
| 114 |
|
|
| 110 | 115 |
protected Button affectAnnotationButton; |
| 116 |
|
|
| 111 | 117 |
protected Button deleteAnnotationButton; |
| 118 |
|
|
| 112 | 119 |
private Button affectAllAnnotationButton; |
| 113 |
|
|
| 120 |
|
|
| 114 | 121 |
protected KnowledgeRepository currentKnowledgeRepository = null; |
| 115 |
protected Vector<AnnotationType> typesList = new Vector<AnnotationType>(); |
|
| 116 |
|
|
| 122 |
|
|
| 123 |
protected Vector<AnnotationType> typesList = new Vector<>(); |
|
| 124 |
|
|
| 117 | 125 |
protected AnnotationType tagAnnotationType; // the tag annotation type if annotation mode is simple |
| 118 |
|
|
| 126 |
|
|
| 119 | 127 |
protected TypedValue value_to_add; |
| 120 |
|
|
| 128 |
|
|
| 121 | 129 |
protected Concordance concordance; |
| 130 |
|
|
| 122 | 131 |
private CQPCorpus corpus; |
| 132 |
|
|
| 123 | 133 |
private TableViewerColumn annotationColumnViewer; |
| 134 |
|
|
| 124 | 135 |
private Font annotationColummnFont; |
| 136 |
|
|
| 125 | 137 |
private Font defaultColummnFont; |
| 138 |
|
|
| 126 | 139 |
private Button addAnnotationTypeLink; |
| 140 |
|
|
| 127 | 141 |
private Button addTypedValueLink; |
| 128 |
|
|
| 142 |
|
|
| 143 |
@Override |
|
| 129 | 144 |
public String getName() {
|
| 130 | 145 |
return KRAnnotationUIMessages.motsPropritsInfDfaut; |
| 131 | 146 |
} |
| 132 |
|
|
| 147 |
|
|
| 133 | 148 |
@Override |
| 134 | 149 |
public boolean allowMultipleAnnotations() {
|
| 135 | 150 |
return true; |
| 136 | 151 |
} |
| 137 |
|
|
| 138 |
public WordAnnotationToolbar() {
|
|
| 139 |
} |
|
| 140 |
|
|
| 152 |
|
|
| 153 |
public WordAnnotationToolbar() {}
|
|
| 154 |
|
|
| 141 | 155 |
protected AnnotationType getSelectedAnnotationType() {
|
| 142 | 156 |
return annotations.getViewAnnotation(); |
| 143 | 157 |
} |
| 144 |
|
|
| 158 |
|
|
| 145 | 159 |
public void updateAnnotationWidgetStates() {
|
| 146 | 160 |
if (annotationArea == null) return; // :) |
| 147 |
|
|
| 161 |
|
|
| 148 | 162 |
if (getSelectedAnnotationType() != null) {
|
| 149 | 163 |
annotationValuesText.setEnabled(true); |
| 150 | 164 |
affectAnnotationButton.setEnabled(true); |
| 151 | 165 |
deleteAnnotationButton.setEnabled(true); |
| 152 |
} else {
|
|
| 166 |
} |
|
| 167 |
else {
|
|
| 153 | 168 |
annotationValuesText.setEnabled(false); |
| 154 | 169 |
affectAnnotationButton.setEnabled(false); |
| 155 | 170 |
deleteAnnotationButton.setEnabled(false); |
| 156 | 171 |
} |
| 157 | 172 |
} |
| 158 |
|
|
| 173 |
|
|
| 159 | 174 |
protected void affectAnnotationToSelection(ISelection selection) {
|
| 160 |
|
|
| 175 |
|
|
| 161 | 176 |
final IStructuredSelection lineSelection = (IStructuredSelection) selection; |
| 162 | 177 |
List<Line> lines = lineSelection.toList(); |
| 163 |
ArrayList<Match> matches = new ArrayList<Match>();
|
|
| 178 |
ArrayList<Match> matches = new ArrayList<>(); |
|
| 164 | 179 |
for (Line l : lines) {
|
| 165 | 180 |
matches.add(l.getMatch()); |
| 166 | 181 |
} |
| 167 |
|
|
| 182 |
|
|
| 168 | 183 |
affectAnnotationsToMatches(matches); |
| 169 | 184 |
} |
| 170 |
|
|
| 171 |
protected void affectAnnotationValues(final List<? extends Match> matches, final AnnotationType type, final String svalue, JobHandler job) {
|
|
| 185 |
|
|
| 186 |
protected void affectAnnotationValues(final List<? extends Match> matches, final AnnotationType type, final String svalue, JobHandler job) {
|
|
| 172 | 187 |
value_to_add = null; // reset |
| 173 | 188 |
if (matches == null || matches.size() == 0) {
|
| 174 | 189 |
System.out.println("No line selected. Aborting."); //$NON-NLS-1$
|
| 175 | 190 |
return; |
| 176 | 191 |
} |
| 177 | 192 |
if (type == null) return; // no type, no annotation |
| 178 |
|
|
| 193 |
|
|
| 179 | 194 |
job.syncExec(new Runnable() {
|
| 195 |
|
|
| 180 | 196 |
@Override |
| 181 | 197 |
public void run() {
|
| 182 | 198 |
if (matches.size() > NALERTAFFECTANNOTATIONS) {
|
| 183 |
ConfirmDialog dialog = new ConfirmDialog(Display.getCurrent().getActiveShell(),
|
|
| 199 |
ConfirmDialog dialog = new ConfirmDialog(Display.getCurrent().getActiveShell(), |
|
| 184 | 200 |
"confirm_annotate", //$NON-NLS-1$ |
| 185 |
KRAnnotationUIMessages.confirmAnnotationAffectation,
|
|
| 201 |
KRAnnotationUIMessages.confirmAnnotationAffectation, |
|
| 186 | 202 |
NLS.bind(KRAnnotationUIMessages.youAreAboutToAnnotateP0ElementsContinue, matches.size())); |
| 187 |
|
|
| 203 |
|
|
| 188 | 204 |
if (dialog.open() == ConfirmDialog.CANCEL) {
|
| 189 | 205 |
System.out.println("Annotation aborted by user."); //$NON-NLS-1$
|
| 190 | 206 |
matches.clear(); |
| ... | ... | |
| 192 | 208 |
} |
| 193 | 209 |
} |
| 194 | 210 |
}); |
| 195 |
|
|
| 211 |
|
|
| 196 | 212 |
// get value from combo text value |
| 197 | 213 |
Log.fine(NLS.bind(KRAnnotationUIMessages.lookingForTypedValueWithIdEqualsP0, svalue)); |
| 198 | 214 |
final KnowledgeRepository kr = KnowledgeRepositoryManager.getKnowledgeRepository(type.getKnowledgeRepository()); |
| 199 | 215 |
value_to_add = kr.getValue(type, svalue); |
| 200 |
|
|
| 201 |
|
|
| 216 |
|
|
| 217 |
|
|
| 202 | 218 |
if (value_to_add == null && kr instanceof LocalKnowledgeRepository) { // create or not the annotation is simple mode
|
| 203 | 219 |
value_to_add = kr.addValue(svalue, svalue, type.getId()); |
| 204 | 220 |
} |
| 205 |
|
|
| 206 |
if (value_to_add == null) {
|
|
| 221 |
|
|
| 222 |
if (value_to_add == null) {
|
|
| 207 | 223 |
job.syncExec(new Runnable() {
|
| 224 |
|
|
| 208 | 225 |
@Override |
| 209 | 226 |
public void run() {
|
| 210 | 227 |
String mess = KRAnnotationUIMessages.bind(KRAnnotationUIMessages.noValueFoundWithTheP0Id, svalue); |
| ... | ... | |
| 214 | 231 |
}); |
| 215 | 232 |
return; |
| 216 | 233 |
} |
| 217 |
|
|
| 234 |
|
|
Formats disponibles : Unified diff