| 1 |
|
package org.txm.annotation.rcp.concordance;
|
| 2 |
|
|
| 3 |
|
import java.io.File;
|
| 4 |
|
import java.util.ArrayList;
|
| 5 |
|
import java.util.HashMap;
|
| 6 |
|
import java.util.List;
|
| 7 |
|
import java.util.Vector;
|
| 8 |
|
import java.util.logging.Level;
|
| 9 |
|
|
| 10 |
|
import org.eclipse.core.runtime.IProgressMonitor;
|
| 11 |
|
import org.eclipse.core.runtime.IStatus;
|
| 12 |
|
import org.eclipse.core.runtime.Status;
|
| 13 |
|
import org.eclipse.jface.dialogs.InputDialog;
|
| 14 |
|
import org.eclipse.jface.dialogs.MessageDialog;
|
| 15 |
|
import org.eclipse.jface.viewers.ArrayContentProvider;
|
| 16 |
|
import org.eclipse.jface.viewers.ColumnLabelProvider;
|
| 17 |
|
import org.eclipse.jface.viewers.ComboViewer;
|
| 18 |
|
import org.eclipse.jface.viewers.ISelection;
|
| 19 |
|
import org.eclipse.jface.viewers.ISelectionChangedListener;
|
| 20 |
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
| 21 |
|
import org.eclipse.jface.viewers.SelectionChangedEvent;
|
| 22 |
|
import org.eclipse.jface.viewers.TableViewer;
|
| 23 |
|
import org.eclipse.jface.viewers.TableViewerColumn;
|
| 24 |
|
import org.eclipse.swt.SWT;
|
| 25 |
|
import org.eclipse.swt.events.KeyEvent;
|
| 26 |
|
import org.eclipse.swt.events.KeyListener;
|
| 27 |
|
import org.eclipse.swt.events.SelectionEvent;
|
| 28 |
|
import org.eclipse.swt.events.SelectionListener;
|
| 29 |
|
import org.eclipse.swt.graphics.Point;
|
| 30 |
|
import org.eclipse.swt.layout.GridData;
|
| 31 |
|
import org.eclipse.swt.layout.GridLayout;
|
| 32 |
|
import org.eclipse.swt.widgets.Button;
|
| 33 |
|
import org.eclipse.swt.widgets.Combo;
|
| 34 |
|
import org.eclipse.swt.widgets.Composite;
|
| 35 |
|
import org.eclipse.swt.widgets.Display;
|
| 36 |
|
import org.eclipse.swt.widgets.Label;
|
| 37 |
|
import org.eclipse.swt.widgets.TableColumn;
|
| 38 |
|
import org.eclipse.swt.widgets.Text;
|
| 39 |
|
import org.eclipse.ui.IWorkbenchWindow;
|
| 40 |
|
import org.eclipse.ui.PartInitException;
|
| 41 |
|
import org.eclipse.ui.dialogs.ListDialog;
|
| 42 |
|
import org.txm.annotation.core.Annotation;
|
| 43 |
|
import org.txm.annotation.core.AnnotationManager;
|
| 44 |
|
import org.txm.annotation.core.KRAnnotationEngine;
|
| 45 |
|
import org.txm.annotation.core.preferences.AnnotationPreferences;
|
| 46 |
|
import org.txm.annotation.core.repository.AnnotationType;
|
| 47 |
|
import org.txm.annotation.core.repository.KnowledgeRepository;
|
| 48 |
|
import org.txm.annotation.core.repository.KnowledgeRepositoryManager;
|
| 49 |
|
import org.txm.annotation.core.repository.LocalKnowledgeRepository;
|
| 50 |
|
import org.txm.annotation.core.repository.SQLKnowledgeRepository;
|
| 51 |
|
import org.txm.annotation.core.repository.TypedValue;
|
| 52 |
|
import org.txm.annotation.rcp.commands.InitializeKnowledgeRepository;
|
| 53 |
|
import org.txm.annotation.rcp.commands.SaveAnnotations;
|
| 54 |
|
import org.txm.annotation.rcp.commands.krview.OpenKRView;
|
| 55 |
|
import org.txm.annotation.rcp.messages.AnnotationUIMessages;
|
| 56 |
|
import org.txm.annotation.rcp.views.knowledgerepositories.KRView;
|
| 57 |
|
import org.txm.concordance.core.functions.Concordance;
|
| 58 |
|
import org.txm.concordance.core.functions.Line;
|
| 59 |
|
import org.txm.concordance.rcp.editors.ConcordanceEditor;
|
| 60 |
|
import org.txm.concordance.rcp.editors.ConcordanceEditor.ConcordanceColumnSizeControlListener;
|
| 61 |
|
import org.txm.concordance.rcp.editors.ConcordanceEditorExtension;
|
| 62 |
|
import org.txm.concordance.rcp.messages.ConcordanceUIMessages;
|
| 63 |
|
import org.txm.core.preferences.TXMPreferences;
|
| 64 |
|
import org.txm.rcp.IImageKeys;
|
| 65 |
|
import org.txm.rcp.commands.OpenBrowser;
|
| 66 |
|
import org.txm.rcp.messages.TXMUIMessages;
|
| 67 |
|
import org.txm.rcp.preferences.RCPPreferences;
|
| 68 |
|
import org.txm.rcp.swt.dialog.ConfirmDialog;
|
| 69 |
|
import org.txm.rcp.swt.provider.SimpleLabelProvider;
|
| 70 |
|
import org.txm.rcp.utils.JobHandler;
|
| 71 |
|
import org.txm.rcp.views.corpora.CorporaView;
|
| 72 |
|
import org.txm.searchengine.cqp.clientExceptions.CqiClientException;
|
| 73 |
|
import org.txm.searchengine.cqp.corpus.Corpus;
|
| 74 |
|
import org.txm.searchengine.cqp.corpus.query.Match;
|
| 75 |
|
import org.txm.utils.AsciiUtils;
|
| 76 |
|
import org.txm.utils.logger.Log;
|
| 77 |
|
|
| 78 |
|
public class ConcordanceAnnotationExtension extends ConcordanceEditorExtension {
|
| 79 |
|
|
| 80 |
|
/**
|
| 81 |
|
* the limit number of annotation when a confirm dialog box is shown
|
| 82 |
|
*/
|
| 83 |
|
protected static final int NALERTAFFECTANNOTATIONS = 100;
|
| 84 |
|
|
| 85 |
|
/** The annotation service */
|
| 86 |
|
protected AnnotationManager annotManager;
|
| 87 |
|
|
| 88 |
|
//boolean annotation_expert_mode = TxmPreferences.getBoolean(AnnotationPreferencePage.MODE, false);
|
| 89 |
|
|
| 90 |
|
/** The annotation area. */
|
| 91 |
|
protected Composite annotationArea;
|
| 92 |
|
|
| 93 |
|
protected Point annotationSize;
|
| 94 |
|
|
| 95 |
|
/** The annot btn. */
|
| 96 |
|
protected Button annotationButton;
|
| 97 |
|
private Button addAnnotationTypeLink;
|
| 98 |
|
|
| 99 |
|
protected Text annotationValuesText;
|
| 100 |
|
protected ComboViewer annotationTypesCombo;
|
| 101 |
|
|
| 102 |
|
protected List<TypedValue> typeValuesList;
|
| 103 |
|
|
| 104 |
|
protected Point annotSize;
|
| 105 |
|
|
| 106 |
|
protected TableColumn annotationColumn;
|
| 107 |
|
|
| 108 |
|
protected Combo addRemoveCombo;
|
| 109 |
|
protected Combo affectCombo;
|
| 110 |
|
protected Button affectAnnotationButton;
|
| 111 |
|
|
| 112 |
|
protected Button infosAnnotTypeSelectedLink;
|
| 113 |
|
|
| 114 |
|
protected HashMap<AnnotationType, ArrayList<TypedValue>> history = new HashMap<AnnotationType, ArrayList<TypedValue>>();
|
| 115 |
|
|
| 116 |
|
protected KnowledgeRepository currentKnowledgeRepository = null;
|
| 117 |
|
protected Vector<AnnotationType> typesList = new Vector<AnnotationType>();
|
| 118 |
|
|
| 119 |
|
protected Button addTypedValueLink;
|
| 120 |
|
|
| 121 |
|
protected Label withLabel;
|
| 122 |
|
|
| 123 |
|
protected AnnotationType tagAnnotationType; // the tag annotation type if annotation mode is simple
|
| 124 |
|
|
| 125 |
|
protected Label equalLabel;
|
| 126 |
|
protected Boolean advanced_annotation_mode = false;
|
| 127 |
|
|
| 128 |
|
protected TypedValue value_to_add;
|
| 129 |
|
|
| 130 |
|
protected Concordance concordance;
|
| 131 |
|
|
| 132 |
|
private Corpus corpus;
|
| 133 |
|
|
| 134 |
|
private ConcordanceAnnotations annotations;
|
| 135 |
|
|
| 136 |
|
public ConcordanceAnnotationExtension() {
|
| 137 |
|
|
| 138 |
|
}
|
| 139 |
|
|
| 140 |
|
@Override
|
| 141 |
|
public String getName() {
|
| 142 |
|
return "Annotation";
|
| 143 |
|
}
|
| 144 |
|
|
| 145 |
|
@Override
|
| 146 |
|
public boolean installWidgets() throws Exception {
|
| 147 |
|
|
| 148 |
|
final Composite controlArea = editor.getNavigationArea();
|
| 149 |
|
final Composite navigationArea = editor.getNavigationArea();
|
| 150 |
|
TableViewer viewer = editor.getLineTableViewer();
|
| 151 |
|
|
| 152 |
|
// CONTROLS
|
| 153 |
|
if (KRAnnotationEngine.getKnowledgeRepositoryNames(corpus).size() > 0) { // shown only if corpus has a registered KR
|
| 154 |
|
|
| 155 |
|
annotationButton = new Button(navigationArea, SWT.PUSH);
|
| 156 |
|
annotationButton.setToolTipText(ConcordanceUIMessages.ConcordancesEditor_75);
|
| 157 |
|
annotationButton.setImage(IImageKeys.getImage(IImageKeys.PENCIL));
|
| 158 |
|
annotationButton.addSelectionListener(new SelectionListener() {
|
| 159 |
|
@Override
|
| 160 |
|
public void widgetSelected(SelectionEvent e) {
|
| 161 |
|
if (annotationArea != null) {
|
| 162 |
|
AnnotationManager am = KRAnnotationEngine.getAnnotationManager(corpus);
|
| 163 |
|
if (am != null && am.hasChanges()) {
|
| 164 |
|
// && MessageDialog.openConfirm(e.display.getActiveShell(), "Confirm annotation save", "Saving annotation will close this editor. Are you sure you want to save annotations right now ?")
|
| 165 |
|
JobHandler saveJob = SaveAnnotations.save(corpus.getMainCorpus());
|
| 166 |
|
if (saveJob.getResult() == Status.CANCEL_STATUS) {
|
| 167 |
|
// update editor corpus
|
| 168 |
|
System.out.println("Fail to save annotations of the corpus."); //$NON-NLS-1$
|
| 169 |
|
}
|
| 170 |
|
}
|
| 171 |
|
|
| 172 |
|
} else {
|
| 173 |
|
if (annotationArea == null) composeAnnotationArea(controlArea);
|
| 174 |
|
if (annotationArea == null) return;
|
| 175 |
|
|
| 176 |
|
annotationColumn.pack();
|
| 177 |
|
annotationButton.setToolTipText(ConcordanceUIMessages.ConcordancesEditor_76);
|
| 178 |
|
annotationButton.setImage(IImageKeys.getImage(IImageKeys.PENCIL_SAVE));
|
| 179 |
|
|
| 180 |
|
annotSize = annotationArea.getSize();
|
| 181 |
|
Point size = controlArea.getSize();
|
| 182 |
|
controlArea.setSize(size.x, size.y + annotSize.y);
|
| 183 |
|
GridData data = (GridData) annotationArea.getLayoutData();
|
| 184 |
|
data.heightHint = annotSize.y;
|
| 185 |
|
data.minimumHeight = annotSize.y;
|
| 186 |
|
annotationArea.setSize(annotSize);
|
| 187 |
|
controlArea.layout(true);
|
| 188 |
|
controlArea.getParent().layout();
|
| 189 |
|
|
| 190 |
|
if (concordance != null) {
|
| 191 |
|
AnnotationType type = getSelectedAnnotationType();
|
| 192 |
|
if (type != null) {
|
| 193 |
|
annotations.setViewAnnotation(type);
|
| 194 |
|
annotations.setAnnotationOverlap(true);
|
| 195 |
|
editor.fillDisplayArea();
|
| 196 |
|
}
|
| 197 |
|
}
|
| 198 |
|
|
| 199 |
|
CorporaView.refreshObject(corpus);
|
| 200 |
|
}
|
| 201 |
|
}
|
| 202 |
|
|
| 203 |
|
@Override
|
| 204 |
|
public void widgetDefaultSelected(SelectionEvent e) { }
|
| 205 |
|
});
|
| 206 |
|
}
|
| 207 |
|
|
| 208 |
|
// RESULT
|
| 209 |
|
|
| 210 |
|
int position = 3;
|
| 211 |
|
TableViewerColumn annotationColumnViewer = new TableViewerColumn(viewer, SWT.CENTER, position);
|
| 212 |
|
annotationColumn = annotationColumnViewer.getColumn();
|
| 213 |
|
annotationColumn.setText(ConcordanceUIMessages.ConcordancesEditor_15);
|
| 214 |
|
annotationColumn.setToolTipText(ConcordanceUIMessages.ConcordancesEditor_17);
|
| 215 |
|
annotationColumn.setAlignment(SWT.CENTER);
|
| 216 |
|
|
| 217 |
|
annotationColumn.addControlListener(new ConcordanceColumnSizeControlListener(annotationColumn));
|
| 218 |
|
annotationColumnViewer.setLabelProvider(new ColumnLabelProvider() {
|
| 219 |
|
@Override
|
| 220 |
|
public String getText(Object element) {
|
| 221 |
|
Line line = (Line)element;
|
| 222 |
|
AnnotationLine annotationLine = annotations.getAnnotationLine(line);
|
| 223 |
|
if (annotationLine.getAnnotation()!=null) {
|
| 224 |
|
String value = annotationLine.getAnnotationValue().getStandardName();
|
| 225 |
|
Annotation a = annotationLine.getAnnotation();
|
| 226 |
|
if (value == null) value = a.getValue();
|
| 227 |
|
|
| 228 |
|
if (a.getStart() < line.matchGetStart() - line.getLeftContextSize()) {
|
| 229 |
|
value = "… "+value;
|
| 230 |
|
}
|
| 231 |
|
|
| 232 |
|
if (a.getEnd() > line.matchGetEnd() + line.getRightContextSize()) {
|
| 233 |
|
value = value+" …";
|
| 234 |
|
}
|
| 235 |
|
return value;
|
| 236 |
|
} else {
|
| 237 |
|
return "";
|
| 238 |
|
}
|
| 239 |
|
}
|
| 240 |
|
});
|
| 241 |
|
|
| 242 |
|
|
| 243 |
|
return true;
|
| 244 |
|
}
|
| 245 |
|
|
| 246 |
|
public boolean initialiseInput(ConcordanceEditor editor) throws Exception {
|
| 247 |
|
this.editor = editor;
|
| 248 |
|
concordance = editor.getConcordance();
|
| 249 |
|
annotations = new ConcordanceAnnotations(concordance);
|
| 250 |
|
corpus = concordance.getCorpus();
|
| 251 |
|
|
| 252 |
|
Corpus corpus = editor.getCorpus();
|
| 253 |
|
|
| 254 |
|
this.annotManager = KRAnnotationEngine.getAnnotationManager(corpus);
|
| 255 |
|
|
| 256 |
|
return true;
|
| 257 |
|
|
| 258 |
|
}
|
| 259 |
|
|
| 260 |
|
private void composeAnnotationArea(final Composite parent){
|
| 261 |
|
advanced_annotation_mode = "advanced".equals(TXMPreferences.getString(AnnotationPreferences.ANNOTATION_MODE, RCPPreferences.PREFERENCES_NODE));
|
| 262 |
|
|
| 263 |
|
List<KnowledgeRepository> krs = InitializeKnowledgeRepository.get(corpus.getMainCorpus());
|
| 264 |
|
typesList.clear();
|
| 265 |
|
Log.warning("Corpus KRs: "+krs); //$NON-NLS-1$
|
| 266 |
|
|
| 267 |
|
for (KnowledgeRepository kr : krs) {
|
| 268 |
|
if (kr == null) continue;
|
| 269 |
|
|
| 270 |
|
currentKnowledgeRepository = kr;
|
| 271 |
|
Log.warning(" KR: "+kr); //$NON-NLS-1$
|
| 272 |
|
List<AnnotationType> krtypes = kr.getAllAnnotationTypes();
|
| 273 |
|
Log.warning("Advanced annotation mode ? "+advanced_annotation_mode);
|
| 274 |
|
if (!advanced_annotation_mode) { // creates the "span" annotation type
|
| 275 |
|
boolean createTagAnnotationType = true;
|
| 276 |
|
for (AnnotationType type : krtypes) {
|
| 277 |
|
if (type.getName().equals("span")) { //$NON-NLS-1$
|
| 278 |
|
createTagAnnotationType = false;
|
| 279 |
|
}
|
| 280 |
|
}
|
| 281 |
|
if (createTagAnnotationType) {
|
| 282 |
|
tagAnnotationType = kr.addType("span", "span");//corresponds to an "undef" type //$NON-NLS-1$ //$NON-NLS-2$
|
| 283 |
|
typesList.add(tagAnnotationType);
|
| 284 |
|
} else {
|
| 285 |
|
tagAnnotationType = kr.getType("span"); //$NON-NLS-1$
|
| 286 |
|
}
|
| 287 |
|
} else {
|
| 288 |
|
typesList.addAll(krtypes);
|
| 289 |
|
}
|
| 290 |
|
Log.warning("Available annotation types: "+typesList);
|
| 291 |
|
break;
|
| 292 |
|
}
|
| 293 |
|
|
| 294 |
|
if (currentKnowledgeRepository == null) {
|
| 295 |
|
System.out.println("Error: no suitable KnowledgeRepository found");
|
| 296 |
|
return;
|
| 297 |
|
}
|
| 298 |
|
|
| 299 |
|
annotationArea = new Composite(parent, SWT.NONE);
|
| 300 |
|
annotationArea.setLayoutData(new GridData(SWT.FILL, SWT.LEFT, false, false));
|
| 301 |
|
|
| 302 |
|
GridLayout annotLayout = new GridLayout(12, false);
|
| 303 |
|
annotLayout.verticalSpacing = 0;
|
| 304 |
|
annotLayout.marginWidth = 0;
|
| 305 |
|
annotLayout.marginHeight = 0;
|
| 306 |
|
annotationArea.setLayout(annotLayout);
|
| 307 |
|
|
| 308 |
|
//init values history
|
| 309 |
|
for (AnnotationType type : typesList) {
|
| 310 |
|
history.put(type, new ArrayList<TypedValue>());
|
| 311 |
|
}
|
| 312 |
|
|
| 313 |
|
addRemoveCombo = new Combo(annotationArea, SWT.READ_ONLY);
|
| 314 |
|
String affectLabel = currentKnowledgeRepository.getString(editor.getLocale(), "ConcordancesEditor_22");
|
| 315 |
|
if (affectLabel == null) affectLabel= ConcordanceUIMessages.ConcordancesEditor_22;
|
| 316 |
|
String removeLabel = currentKnowledgeRepository.getString(editor.getLocale(), "ConcordancesEditor_24");
|
| 317 |
|
if (removeLabel == null) removeLabel= ConcordanceUIMessages.ConcordancesEditor_24;
|
| 318 |
|
String items[] = {affectLabel, removeLabel};
|
| 319 |
|
addRemoveCombo.setItems(items);
|
| 320 |
|
addRemoveCombo.select(0);
|
| 321 |
|
addRemoveCombo.addSelectionListener(new SelectionListener() {
|
| 322 |
|
@Override
|
| 323 |
|
public void widgetSelected(SelectionEvent e) {
|
| 324 |
|
if (addRemoveCombo.getSelectionIndex() == 0) { // add
|
| 325 |
|
annotationValuesText.setEnabled(true);
|
| 326 |
|
String withLabelText = currentKnowledgeRepository.getString(editor.getLocale(), "ConcordancesEditor_83");
|
| 327 |
|
if (withLabelText == null) withLabelText= ConcordanceUIMessages.ConcordancesEditor_83;
|
| 328 |
|
withLabel.setText(withLabelText);
|
| 329 |
|
if (equalLabel != null) equalLabel.setText("=");
|
| 330 |
|
} else { // remove
|
| 331 |
|
annotationValuesText.setEnabled(false);
|
| 332 |
|
withLabel.setText(""); //$NON-NLS-1$
|
| 333 |
|
if (equalLabel != null) equalLabel.setText("");
|
| 334 |
|
}
|
| 335 |
|
withLabel.redraw();
|
| 336 |
|
annotationArea.layout();
|
| 337 |
|
updateAnnotationWidgetStates();
|
| 338 |
|
}
|
| 339 |
|
@Override
|
| 340 |
|
public void widgetDefaultSelected(SelectionEvent e) { }
|
| 341 |
|
});
|
| 342 |
|
GridData gdata = new GridData(SWT.CENTER, SWT.CENTER, false, true);
|
| 343 |
|
gdata.widthHint = 90;
|
| 344 |
|
addRemoveCombo.setLayoutData(gdata);
|
| 345 |
|
|
| 346 |
|
withLabel = new Label(annotationArea, SWT.NONE);
|
| 347 |
|
String withLabelText = currentKnowledgeRepository.getString(editor.getLocale(), "ConcordancesEditor_83");
|
| 348 |
|
if (withLabelText == null) withLabelText= ConcordanceUIMessages.ConcordancesEditor_83;
|
| 349 |
|
withLabel.setText(withLabelText);
|
| 350 |
|
withLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
|
| 351 |
|
|
| 352 |
|
if (advanced_annotation_mode) {
|
| 353 |
|
equalLabel = new Label(annotationArea, SWT.NONE);
|
| 354 |
|
equalLabel.setText("="); //$NON-NLS-1$
|
| 355 |
|
equalLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
|
| 356 |
|
}
|
| 357 |
|
|
| 358 |
|
//Display combo with list of Annotation Type
|
| 359 |
|
if (advanced_annotation_mode) {
|
| 360 |
|
annotationTypesCombo = new ComboViewer(annotationArea, SWT.READ_ONLY);
|
| 361 |
|
annotationTypesCombo.setContentProvider(new ArrayContentProvider());
|
| 362 |
|
annotationTypesCombo.setLabelProvider(new SimpleLabelProvider() {
|
| 363 |
|
@Override
|
| 364 |
|
public String getColumnText(Object element, int columnIndex) {
|
| 365 |
|
return ((AnnotationType)element).getName(); //$NON-NLS-1$
|
| 366 |
|
}
|
| 367 |
|
@Override
|
| 368 |
|
public String getText(Object element) {
|
| 369 |
|
return ((AnnotationType)element).getName(); //$NON-NLS-1$
|
| 370 |
|
}
|
| 371 |
|
});
|
| 372 |
|
gdata = new GridData(SWT.CENTER, SWT.CENTER, false, true);
|
| 373 |
|
gdata.widthHint = 200;
|
| 374 |
|
|
| 375 |
|
annotationTypesCombo.getCombo().setLayoutData(gdata);
|
| 376 |
|
annotationTypesCombo.setInput(typesList);
|
| 377 |
|
if (advanced_annotation_mode.equals(AnnotationUIMessages.AnnotationPreferences_2)) {
|
| 378 |
|
annotationTypesCombo.getCombo().select(0);
|
| 379 |
|
}
|
| 380 |
|
|
| 381 |
|
annotationTypesCombo.addSelectionChangedListener(new ISelectionChangedListener() {
|
| 382 |
|
@Override
|
| 383 |
|
public void selectionChanged(SelectionChangedEvent event) {
|
| 384 |
|
AnnotationType type = getSelectedAnnotationType();
|
| 385 |
|
if (type == null) return;
|
| 386 |
|
if (type.getSize() != AnnotationType.ValuesSize.LARGE) {
|
| 387 |
|
try {
|
| 388 |
|
KnowledgeRepository kr = KnowledgeRepositoryManager.getKnowledgeRepository(type.getKnowledgeRepository());
|
| 389 |
|
typeValuesList = kr.getValues(type);
|
| 390 |
|
} catch (Exception e) {
|
| 391 |
|
// TODO Auto-generated catch block
|
| 392 |
|
e.printStackTrace();
|
| 393 |
|
}
|
| 394 |
|
} else { // set history values
|
| 395 |
|
typeValuesList = history.get(type);
|
| 396 |
|
}
|
| 397 |
|
|
| 398 |
|
annotationColumn.setText(type.getName());
|
| 399 |
|
if (concordance != null) {
|
| 400 |
|
annotations.setViewAnnotation(type);
|
| 401 |
|
annotations.setAnnotationOverlap(true);
|
| 402 |
|
editor.fillDisplayArea();
|
| 403 |
|
}
|
| 404 |
|
|
| 405 |
|
updateAnnotationWidgetStates();
|
| 406 |
|
}
|
| 407 |
|
});
|
| 408 |
|
}
|
| 409 |
|
|
| 410 |
|
if (advanced_annotation_mode) {
|
| 411 |
|
if (currentKnowledgeRepository instanceof SQLKnowledgeRepository) {
|
| 412 |
|
infosAnnotTypeSelectedLink = new Button(annotationArea, SWT.PUSH);
|
| 413 |
|
infosAnnotTypeSelectedLink.setImage(IImageKeys.getImage(IImageKeys.ACTION_INFO));
|
| 414 |
|
infosAnnotTypeSelectedLink.setEnabled(true);
|
| 415 |
|
infosAnnotTypeSelectedLink.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, true));
|
| 416 |
|
infosAnnotTypeSelectedLink.addSelectionListener(new SelectionListener() {
|
| 417 |
|
@Override
|
| 418 |
|
public void widgetSelected(SelectionEvent e) {
|
| 419 |
|
AnnotationType type = getSelectedAnnotationType();
|
| 420 |
|
if (type == null) return;
|
| 421 |
|
|
| 422 |
|
String typedValueURL = type.getURL(); // may be null/empty
|
| 423 |
|
if (typedValueURL != null && typedValueURL.length() > 0) {
|
| 424 |
|
KnowledgeRepository kr = KnowledgeRepositoryManager.getKnowledgeRepository(type.getKnowledgeRepository());
|
| 425 |
|
kr.getTypeURL(type);
|
| 426 |
|
}
|
| 427 |
|
if (typedValueURL != null && typedValueURL.length() > 0) {
|
| 428 |
|
OpenBrowser.openfile(typedValueURL, new File(typedValueURL).getName());
|
| 429 |
|
} else {
|
| 430 |
|
IWorkbenchWindow window = editor.getSite().getWorkbenchWindow();
|
| 431 |
|
try {
|
| 432 |
|
OpenKRView.openView(window, type);
|
| 433 |
|
} catch (PartInitException e1) {
|
| 434 |
|
e1.printStackTrace();
|
| 435 |
|
}
|
| 436 |
|
}
|
| 437 |
|
}
|
| 438 |
|
|
| 439 |
|
@Override
|
| 440 |
|
public void widgetDefaultSelected(SelectionEvent e) { }
|
| 441 |
|
});
|
| 442 |
|
}
|
| 443 |
|
|
| 444 |
|
if (currentKnowledgeRepository instanceof LocalKnowledgeRepository) {
|
| 445 |
|
addAnnotationTypeLink = new Button(annotationArea, SWT.PUSH);
|
| 446 |
|
addAnnotationTypeLink.setToolTipText(ConcordanceUIMessages.ConcordancesEditor_115);
|
| 447 |
|
addAnnotationTypeLink.setImage(IImageKeys.getImage(IImageKeys.ACTION_ADD));
|
| 448 |
|
addAnnotationTypeLink.setEnabled(true);
|
| 449 |
|
addAnnotationTypeLink.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, true));
|
| 450 |
|
addAnnotationTypeLink.addSelectionListener(new SelectionListener() {
|
| 451 |
|
@Override
|
| 452 |
|
public void widgetSelected(SelectionEvent e) {
|
| 453 |
|
if (currentKnowledgeRepository == null) return;
|
| 454 |
|
if (!(currentKnowledgeRepository instanceof LocalKnowledgeRepository)) return;
|
| 455 |
|
|
| 456 |
|
LocalKnowledgeRepository kr = (LocalKnowledgeRepository)currentKnowledgeRepository;
|
| 457 |
|
|
| 458 |
|
InputDialog dialog = new InputDialog(e.widget.getDisplay().getActiveShell(), ConcordanceUIMessages.ConcordancesEditor_82, ConcordanceUIMessages.ConcordancesEditor_81, "", null); //$NON-NLS-3$
|
| 459 |
|
if (dialog.open() == InputDialog.OK) {
|
| 460 |
|
String name = dialog.getValue();
|
| 461 |
|
if (name.trim().length() == 0) return;
|
| 462 |
|
String baseid = AsciiUtils.buildId(name);
|
| 463 |
|
String id = AsciiUtils.buildId(name);
|
| 464 |
|
int c = 1;
|
| 465 |
|
while (kr.getType(id) != null) {
|
| 466 |
|
id = baseid+"_"+(c++); //$NON-NLS-1$
|
| 467 |
|
}
|
| 468 |
|
AnnotationType type = kr.addType(name, id, ""); //$NON-NLS-1$
|
| 469 |
|
typesList.add(type);
|
| 470 |
|
history.put(type, new ArrayList<TypedValue>());
|
| 471 |
|
|
| 472 |
|
if (annotationTypesCombo != null) annotationTypesCombo.refresh();
|
| 473 |
|
if (typesList.size() == 1) {
|
| 474 |
|
if (annotationTypesCombo != null) annotationTypesCombo.getCombo().select(0);
|
| 475 |
|
if (concordance != null) {
|
| 476 |
|
annotations.setViewAnnotation(type);
|
| 477 |
|
annotations.setAnnotationOverlap(true);
|
| 478 |
|
editor.fillDisplayArea();
|
| 479 |
|
}
|
| 480 |
|
annotationArea.layout(true);
|
| 481 |
|
} else {
|
| 482 |
|
if (typesList.size() > 1) {
|
| 483 |
|
if (annotationTypesCombo != null) {
|
| 484 |
|
annotationTypesCombo.getCombo().select(typesList.size()-1);
|
| 485 |
|
}
|
| 486 |
|
}
|
| 487 |
|
}
|
| 488 |
|
KRView.refresh();
|
| 489 |
|
updateAnnotationWidgetStates();
|
| 490 |
|
} else {
|
| 491 |
|
System.out.println("Creation aborted."); //$NON-NLS-1$
|
| 492 |
|
}
|
| 493 |
|
}
|
| 494 |
|
|
| 495 |
|
@Override
|
| 496 |
|
public void widgetDefaultSelected(SelectionEvent e) { }
|
| 497 |
|
});
|
| 498 |
|
}
|
| 499 |
|
}
|
| 500 |
|
if (advanced_annotation_mode) {
|
| 501 |
|
Label valueLabel = new Label(annotationArea, SWT.NONE);
|
| 502 |
|
String valueLabelText = currentKnowledgeRepository.getString(editor.getLocale(), "ConcordancesEditor_80");
|
| 503 |
|
if (valueLabelText == null) {
|
| 504 |
|
valueLabelText= ConcordanceUIMessages.ConcordancesEditor_80;
|
| 505 |
|
}
|
| 506 |
|
valueLabel.setText(valueLabelText);
|
| 507 |
|
valueLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
|
| 508 |
|
}
|
| 509 |
|
|
| 510 |
|
annotationValuesText = new Text(annotationArea, SWT.BORDER);
|
| 511 |
|
annotationValuesText.setToolTipText(ConcordanceUIMessages.ConcordancesEditor_32);
|
| 512 |
|
GridData gdata2 = new GridData(SWT.FILL, SWT.CENTER, false, true);
|
| 513 |
|
gdata2.widthHint = 200;
|
| 514 |
|
annotationValuesText.setLayoutData(gdata2);
|
| 515 |
|
annotationValuesText.addKeyListener(new KeyListener() {
|
| 516 |
|
@Override
|
| 517 |
|
public void keyReleased(KeyEvent e) {
|
| 518 |
|
if (e.keyCode == SWT.CR || e.keyCode == SWT.KEYPAD_CR) {
|
| 519 |
|
affectAnnotationToSelection(editor.getLineTableViewer().getSelection());
|
| 520 |
|
}
|
| 521 |
|
}
|
| 522 |
|
|
| 523 |
|
@Override
|
| 524 |
|
public void keyPressed(KeyEvent e) { }
|
| 525 |
|
});
|
| 526 |
|
|
| 527 |
|
if (currentKnowledgeRepository instanceof LocalKnowledgeRepository) {
|
| 528 |
|
addTypedValueLink = new Button(annotationArea, SWT.PUSH);
|
| 529 |
|
addTypedValueLink.setText("..."); //$NON-NLS-1$
|
| 530 |
|
if (advanced_annotation_mode.equals(AnnotationUIMessages.AnnotationPreferences_2)) {
|
| 531 |
|
addTypedValueLink.setToolTipText(ConcordanceUIMessages.ConcordancesEditor_79);
|
| 532 |
|
} else {
|
| 533 |
|
addTypedValueLink.setToolTipText(ConcordanceUIMessages.ConcordancesEditor_77);
|
| 534 |
|
}
|
| 535 |
|
addTypedValueLink.setEnabled(true);
|
| 536 |
|
addTypedValueLink.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, true));
|
| 537 |
|
addTypedValueLink.addSelectionListener(new SelectionListener() {
|
| 538 |
|
@Override
|
| 539 |
|
public void widgetSelected(SelectionEvent e) {
|
| 540 |
|
if (currentKnowledgeRepository == null) return;
|
| 541 |
|
if (!(currentKnowledgeRepository instanceof LocalKnowledgeRepository)) return;
|
| 542 |
|
|
| 543 |
|
AnnotationType type = getSelectedAnnotationType();
|
| 544 |
|
if (type == null) return;
|
| 545 |
|
|
| 546 |
|
LocalKnowledgeRepository kr = (LocalKnowledgeRepository)currentKnowledgeRepository;
|
| 547 |
|
|
| 548 |
|
ListDialog dialog = new ListDialog(e.widget.getDisplay().getActiveShell());
|
| 549 |
|
if (advanced_annotation_mode.equals(AnnotationUIMessages.AnnotationPreferences_2)) {
|
| 550 |
|
String title = currentKnowledgeRepository.getString(editor.getLocale(), "ConcordancesEditor_100");
|
| 551 |
|
if (title == null) title = ConcordanceUIMessages.ConcordancesEditor_100;
|
| 552 |
|
dialog.setTitle(ConcordanceUIMessages.bind(title, type.getName()));//+"valeurs de "+type.getName());
|
| 553 |
|
} else {
|
| 554 |
|
dialog.setTitle(ConcordanceUIMessages.ConcordancesEditor_99);//+"valeurs de "+type.getName());
|
| 555 |
|
}
|
| 556 |
|
dialog.setContentProvider(new ArrayContentProvider());
|
| 557 |
|
dialog.setLabelProvider(new SimpleLabelProvider() {
|
| 558 |
|
public String getColumnText(Object element, int columnIndex) {
|
| 559 |
|
if (element instanceof TypedValue)
|
| 560 |
|
return ((TypedValue)element).getId();
|
| 561 |
|
return element.toString();
|
| 562 |
|
}
|
| 563 |
|
});
|
| 564 |
|
List<TypedValue> values;
|
| 565 |
|
try {
|
| 566 |
|
values = kr.getValues(type);
|
| 567 |
|
} catch (Exception e1) {
|
| 568 |
|
e1.printStackTrace();
|
| 569 |
|
return;
|
| 570 |
|
}
|
| 571 |
|
dialog.setInput(values);
|
| 572 |
|
if (dialog.open() == InputDialog.OK) {
|
| 573 |
|
TypedValue value = (TypedValue) dialog.getResult()[0];
|
| 574 |
|
String name = value.getId();
|
| 575 |
|
if (name.trim().length() == 0) return;
|
| 576 |
|
|
| 577 |
|
annotationValuesText.setText(name);
|
| 578 |
|
} else {
|
| 579 |
|
|
| 580 |
|
}
|
| 581 |
|
}
|
| 582 |
|
|
| 583 |
|
@Override
|
| 584 |
|
public void widgetDefaultSelected(SelectionEvent e) { }
|
| 585 |
|
});
|
| 586 |
|
}
|
| 587 |
|
|
| 588 |
|
affectCombo = new Combo(annotationArea, SWT.READ_ONLY);
|
| 589 |
|
affectCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, true));
|
| 590 |
|
String items2[] = {ConcordanceUIMessages.ConcordancesEditor_35, ConcordanceUIMessages.ConcordancesEditor_42, ConcordanceUIMessages.ConcordancesEditor_49};
|
| 591 |
|
affectCombo.setItems(items2);
|
| 592 |
|
affectCombo.select(0);
|
| 593 |
|
gdata = new GridData(SWT.CENTER, SWT.CENTER, false, true);
|
| 594 |
|
gdata.widthHint = 140;
|
| 595 |
|
affectCombo.setLayoutData(gdata);
|
| 596 |
|
|
| 597 |
|
affectAnnotationButton = new Button(annotationArea, SWT.PUSH);
|
| 598 |
|
affectAnnotationButton.setText(ConcordanceUIMessages.ConcordancesEditor_85);
|
| 599 |
|
affectAnnotationButton.setToolTipText(ConcordanceUIMessages.ConcordancesEditor_116);
|
| 600 |
|
affectAnnotationButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, true));
|
| 601 |
|
affectAnnotationButton.addSelectionListener(new SelectionListener() {
|
| 602 |
|
@Override
|
| 603 |
|
public void widgetSelected(SelectionEvent e) {
|
| 604 |
|
int isel = affectCombo.getSelectionIndex();
|
| 605 |
|
if (isel == 0) { // selected line
|
| 606 |
|
affectAnnotationToSelection(editor.getLineTableViewer().getSelection());
|
| 607 |
|
} else if (isel == 1) { // page
|
| 608 |
|
try {
|
| 609 |
|
List<Match> matches = concordance.getMatches().subList(editor.getTopLine(), editor.getBottomLine()+1);
|
| 610 |
|
affectMatchesToSelection(matches);
|
| 611 |
|
} catch (CqiClientException e1) {
|
| 612 |
|
Log.severe(ConcordanceUIMessages.ConcordancesEditor_53+e1);
|
| 613 |
|
Log.printStackTrace(e1);
|
| 614 |
|
return;
|
| 615 |
|
}
|
| 616 |
|
} else { // all
|
| 617 |
|
try {
|
| 618 |
|
List<Match> matches = concordance.getMatches();
|
| 619 |
|
affectMatchesToSelection(matches);
|
| 620 |
|
} catch (CqiClientException e1) {
|
| 621 |
|
Log.severe(ConcordanceUIMessages.ConcordancesEditor_53+e1);
|
| 622 |
|
Log.printStackTrace(e1);
|
| 623 |
|
return;
|
| 624 |
|
}
|
| 625 |
|
}
|
| 626 |
|
}
|
| 627 |
|
|
| 628 |
|
@Override
|
| 629 |
|
public void widgetDefaultSelected(SelectionEvent e) { }
|
| 630 |
|
});
|
| 631 |
|
Button cancelAnnotateButton = new Button(annotationArea, SWT.PUSH);
|
| 632 |
|
cancelAnnotateButton.setText(ConcordanceUIMessages.ConcordancesEditor_101);
|
| 633 |
|
cancelAnnotateButton.addSelectionListener(new SelectionListener() {
|
| 634 |
|
@Override
|
| 635 |
|
public void widgetSelected(SelectionEvent e) {
|
| 636 |
|
//@TODO Closing the annotation tool bar
|
| 637 |
|
//System.out.println("must hide");
|
| 638 |
|
annotationSize = annotationArea.getSize();
|
| 639 |
|
annotationArea.dispose();
|
| 640 |
|
annotationArea = null;
|
| 641 |
|
parent.layout(true);
|
| 642 |
|
parent.layout();
|
| 643 |
|
annotationButton.setToolTipText(ConcordanceUIMessages.ConcordancesEditor_75);
|
| 644 |
|
annotationButton.setImage(IImageKeys.getImage(IImageKeys.PENCIL));
|
| 645 |
|
annotationColumn.setWidth(0);
|
| 646 |
|
annotationColumn.setResizable(false);
|
| 647 |
|
}
|
| 648 |
|
|
| 649 |
|
@Override
|
| 650 |
|
public void widgetDefaultSelected(SelectionEvent e) { }
|
| 651 |
|
});
|
| 652 |
|
|
| 653 |
|
updateAnnotationWidgetStates();
|
| 654 |
|
|
| 655 |
|
parent.layout();
|
| 656 |
|
}
|
| 657 |
|
|
| 658 |
|
protected void affectAnnotationToSelection(ISelection selection) {
|
| 659 |
|
|
| 660 |
|
final IStructuredSelection lineSelection = (IStructuredSelection) selection;
|
| 661 |
|
List<Line> lines = lineSelection.toList();
|
| 662 |
|
ArrayList<Match> matches = new ArrayList<Match>();
|
| 663 |
|
for (Line l : lines) {
|
| 664 |
|
matches.add(l.getMatch());
|
| 665 |
|
}
|
| 666 |
|
|
| 667 |
|
affectMatchesToSelection(matches);
|
| 668 |
|
}
|
| 669 |
|
|
| 670 |
|
protected AnnotationType getSelectedAnnotationType() {
|
| 671 |
|
if (annotationTypesCombo != null) {
|
| 672 |
|
IStructuredSelection isel = (IStructuredSelection)annotationTypesCombo.getSelection();
|
| 673 |
|
if (isel.isEmpty()) {
|
| 674 |
|
return null;
|
| 675 |
|
}
|
| 676 |
|
return (AnnotationType) isel.getFirstElement();
|
| 677 |
|
} else { // simple mode
|
| 678 |
|
return tagAnnotationType;
|
| 679 |
|
}
|
| 680 |
|
}
|
| 681 |
|
|
| 682 |
|
protected void affectMatchesToSelection(final List<Match> matches) {
|
| 683 |
|
final AnnotationType type = getSelectedAnnotationType();
|
| 684 |
|
final String svalue = annotationValuesText.getText();
|
| 685 |
|
final boolean doAffect = addRemoveCombo.getSelectionIndex() == 0; // add is default
|
| 686 |
|
|
| 687 |
|
JobHandler job = new JobHandler(ConcordanceUIMessages.ConcordancesEditor_36, true) {
|
| 688 |
|
@Override
|
| 689 |
|
protected IStatus run(IProgressMonitor monitor) {
|
| 690 |
|
this.runInit(monitor);
|
| 691 |
|
try {
|
| 692 |
|
if (doAffect) {
|
| 693 |
|
affectAnnotationValues(matches, type, svalue, this);
|
| 694 |
|
} else {
|
| 695 |
|
deleteAnnotationValues(matches, type, this);
|
| 696 |
|
}
|
| 697 |
|
} catch(Exception e) {
|
| 698 |
|
Log.severe(ConcordanceUIMessages.ConcordancesEditor_40+e);
|
| 699 |
|
Log.printStackTrace(e);
|
| 700 |
|
return Status.CANCEL_STATUS;
|
| 701 |
|
} catch(ThreadDeath td) {
|
| 702 |
|
System.out.println("Annotation canceled by user.");
|
| 703 |
|
return Status.CANCEL_STATUS;
|
| 704 |
|
}
|
| 705 |
|
|
| 706 |
|
return Status.OK_STATUS;
|
| 707 |
|
}
|
| 708 |
|
};
|
| 709 |
|
job.startJob(true);
|
| 710 |
|
}
|
| 711 |
|
|
| 712 |
|
public void updateAnnotationWidgetStates() {
|
| 713 |
|
if (annotationArea == null) return; // :)
|
| 714 |
|
|
| 715 |
|
if (addRemoveCombo.getSelectionIndex() == 0) { // add is default
|
| 716 |
|
|
| 717 |
|
if (getSelectedAnnotationType() != null) {
|
| 718 |
|
annotationValuesText.setEnabled(true);
|
| 719 |
|
|
| 720 |
|
affectAnnotationButton.setEnabled(true);
|
| 721 |
|
affectCombo.setEnabled(true);
|
| 722 |
|
} else {
|
| 723 |
|
annotationValuesText.setEnabled(false);
|
| 724 |
|
|
| 725 |
|
affectAnnotationButton.setEnabled(false);
|
| 726 |
|
affectCombo.setEnabled(false);
|
| 727 |
|
}
|
| 728 |
|
} else {
|
| 729 |
|
annotationValuesText.setEnabled(false);
|
| 730 |
|
|
| 731 |
|
if (getSelectedAnnotationType() != null) {
|
| 732 |
|
affectAnnotationButton.setEnabled(true);
|
| 733 |
|
affectCombo.setEnabled(true);
|
| 734 |
|
} else {
|
| 735 |
|
affectAnnotationButton.setEnabled(false);
|
| 736 |
|
affectCombo.setEnabled(false);
|
| 737 |
|
}
|
| 738 |
|
}
|
| 739 |
|
|
| 740 |
|
if (advanced_annotation_mode.equals(AnnotationUIMessages.AnnotationPreferences_2)) {
|
| 741 |
|
if (infosAnnotTypeSelectedLink != null) {
|
| 742 |
|
infosAnnotTypeSelectedLink.setEnabled(getSelectedAnnotationType() != null);
|
| 743 |
|
}
|
| 744 |
|
}
|
| 745 |
|
if (addTypedValueLink != null) {
|
| 746 |
|
addTypedValueLink.setEnabled(getSelectedAnnotationType() != null);
|
| 747 |
|
}
|
| 748 |
|
|
| 749 |
|
if (concordance == null) {
|
| 750 |
|
affectAnnotationButton.setEnabled(false);
|
| 751 |
|
affectCombo.setEnabled(false);
|
| 752 |
|
}
|
| 753 |
|
}
|
| 754 |
|
|
| 755 |
|
protected void deleteAnnotationValues(List<Match> matches, AnnotationType type, JobHandler job) {
|
| 756 |
|
if (concordance == null) {
|
| 757 |
|
return;
|
| 758 |
|
}
|
| 759 |
|
|
| 760 |
|
if (matches.size() == 0) {
|
| 761 |
|
System.out.println("No lines selected. Aborting."); //$NON-NLS-1$
|
| 762 |
|
return;
|
| 763 |
|
}
|
| 764 |
|
|
| 765 |
|
if (type == null) {
|
| 766 |
|
return;
|
| 767 |
|
}
|
| 768 |
|
|
| 769 |
|
if (concordance != null) {
|
| 770 |
|
try {
|
| 771 |
|
if (annotManager != null && annotManager.deleteAnnotations(type, matches, job)) {
|
| 772 |
|
if (Log.getLevel().intValue() < Level.WARNING.intValue()) annotManager.checkData();
|
| 773 |
|
concordance.reloadLines(editor.getTopLine(), editor.getBottomLine()+1);
|
| 774 |
|
} else {
|
| 775 |
|
return;
|
| 776 |
|
}
|
| 777 |
|
} catch (Exception e1) {
|
| 778 |
|
System.out.println(ConcordanceUIMessages.ConcordancesEditor_54+e1);
|
| 779 |
|
Log.printStackTrace(e1);
|
| 780 |
|
return;
|
| 781 |
|
}
|
| 782 |
|
|
| 783 |
|
job.syncExec(new Runnable() {
|
| 784 |
|
@Override
|
| 785 |
|
public void run() {
|
| 786 |
|
editor.fillDisplayArea();
|
| 787 |
|
CorporaView.refreshObject(corpus);
|
| 788 |
|
}
|
| 789 |
|
});
|
| 790 |
|
}
|
| 791 |
|
}
|
| 792 |
|
|
| 793 |
|
protected void affectAnnotationValues(final List<Match> matches, final AnnotationType type, final String svalue, JobHandler job) {
|
| 794 |
|
value_to_add = null; // reset
|
| 795 |
|
if (concordance == null) {
|
| 796 |
|
System.out.println("No concordance done. Aborting."); //$NON-NLS-1$
|
| 797 |
|
return;
|
| 798 |
|
}
|
| 799 |
|
if (matches.size() == 0) {
|
| 800 |
|
System.out.println("No line selected. Aborting."); //$NON-NLS-1$
|
| 801 |
|
return;
|
| 802 |
|
}
|
| 803 |
|
if (type == null) return; // no type, no annotation
|
| 804 |
|
|
| 805 |
|
job.syncExec(new Runnable() {
|
| 806 |
|
@Override
|
| 807 |
|
public void run() {
|
| 808 |
|
if (matches.size() > NALERTAFFECTANNOTATIONS) {
|
| 809 |
|
ConfirmDialog dialog = new ConfirmDialog(Display.getCurrent().getActiveShell(),
|
| 810 |
|
"confirm_annotate", //$NON-NLS-1$
|
| 811 |
|
ConcordanceUIMessages.ConcordancesEditor_86,
|
| 812 |
|
ConcordanceUIMessages.ConcordancesEditor_87+matches.size()+ConcordanceUIMessages.ConcordancesEditor_108);
|
| 813 |
|
|
| 814 |
|
if (dialog.open() == ConfirmDialog.CANCEL) {
|
| 815 |
|
System.out.println("Annotation aborted by user."); //$NON-NLS-1$
|
| 816 |
|
matches.clear();
|
| 817 |
|
}
|
| 818 |
|
}
|
| 819 |
|
}
|
| 820 |
|
});
|
| 821 |
|
|
| 822 |
|
// get value from combo text value
|
| 823 |
|
Log.warning(ConcordanceUIMessages.ConcordancesEditor_57+svalue);
|
| 824 |
|
final KnowledgeRepository kr = KnowledgeRepositoryManager.getKnowledgeRepository(type.getKnowledgeRepository());
|
| 825 |
|
value_to_add = kr.getValue(type, svalue);
|
| 826 |
|
|
| 827 |
|
|
| 828 |
|
if (value_to_add == null && kr instanceof LocalKnowledgeRepository) { // create or not the annotation is simple mode
|
| 829 |
|
job.syncExec(new Runnable() {
|
| 830 |
|
@Override
|
| 831 |
|
public void run() {
|
| 832 |
|
String title = kr.getString(editor.getLocale(), "ConcordancesEditor_110");
|
| 833 |
|
String content = kr.getString(editor.getLocale(), "ConcordancesEditor_112");
|
| 834 |
|
if (title == null ) title = ConcordanceUIMessages.ConcordancesEditor_110;
|
| 835 |
|
if (content == null ) content = ConcordanceUIMessages.ConcordancesEditor_112;
|
| 836 |
|
ConfirmDialog dialog = new ConfirmDialog(Display.getCurrent().getActiveShell(),
|
| 837 |
|
"create_value", //$NON-NLS-1$
|
| 838 |
|
ConcordanceUIMessages.bind(title, svalue, type.getName()),
|
| 839 |
|
ConcordanceUIMessages.bind(content, svalue, type.getName()));
|
| 840 |
|
if (dialog.open() == ConfirmDialog.CANCEL) {
|
| 841 |
|
System.out.println("Annotation aborted by user."); //$NON-NLS-1$
|
| 842 |
|
return;
|
| 843 |
|
} else {
|
| 844 |
|
value_to_add = kr.addValue(svalue, svalue, type.getId());
|
| 845 |
|
KRView.refresh();
|
| 846 |
|
}
|
| 847 |
|
}
|
| 848 |
|
});
|
| 849 |
|
}
|
| 850 |
|
|
| 851 |
|
if (value_to_add == null && kr instanceof LocalKnowledgeRepository) return; // canceled
|
| 852 |
|
|
| 853 |
|
if (value_to_add == null) {
|
| 854 |
|
job.syncExec(new Runnable() {
|
| 855 |
|
@Override
|
| 856 |
|
public void run() {
|
| 857 |
|
String mess = ConcordanceUIMessages.bind(ConcordanceUIMessages.ConcordancesEditor_58, svalue);
|
| 858 |
|
System.out.println(mess);
|
| 859 |
|
MessageDialog.openError(Display.getCurrent().getActiveShell(), "Annotation canceled", mess); //$NON-NLS-1$
|
| 860 |
|
}
|
| 861 |
|
});
|
| 862 |
|
return;
|
| 863 |
|
}
|
| 864 |
|
|
| 865 |
|
Log.info(ConcordanceUIMessages.ConcordancesEditor_59+value_to_add+ConcordanceUIMessages.ConcordancesEditor_60+matches);
|
| 866 |
|
|
| 867 |
|
// finally we can 'try' to create the annotations \o/
|
| 868 |
|
try {
|
| 869 |
|
HashMap<Match, List<Annotation>> existingAnnots = annotManager.createAnnotations(type, value_to_add, matches, job);
|
| 870 |
|
|
| 871 |
|
// did we had problems ?
|
| 872 |
|
if (existingAnnots!=null && existingAnnots.size() > 0) {
|
| 873 |
|
String message = ConcordanceUIMessages.ConcordancesEditor_61+value_to_add.getStandardName()+
|
| 874 |
|
ConcordanceUIMessages.ConcordancesEditor_62;
|
| 875 |
|
for (Match m : existingAnnots.keySet()) {
|
| 876 |
|
message += ConcordanceUIMessages.ConcordancesEditor_63+m+ConcordanceUIMessages.ConcordancesEditor_64;
|
| 877 |
|
|
| 878 |
|
for (Annotation existingAnnot : existingAnnots.get(m)) {
|
| 879 |
|
if (existingAnnot.getStart() < m.getStart()){
|
| 880 |
|
message += ConcordanceUIMessages.ConcordancesEditor_65+existingAnnot.getType()+ConcordanceUIMessages.ConcordancesEditor_66+existingAnnot.getStart()+ConcordanceUIMessages.ConcordancesEditor_67+existingAnnot.getEnd()+ConcordanceUIMessages.ConcordancesEditor_68;
|
| 881 |
|
} else {
|
| 882 |
|
message += ConcordanceUIMessages.ConcordancesEditor_69+existingAnnot.getType()+ConcordanceUIMessages.ConcordancesEditor_70+existingAnnot.getStart()+ConcordanceUIMessages.ConcordancesEditor_71+existingAnnot.getEnd()+ConcordanceUIMessages.ConcordancesEditor_72;
|
| 883 |
|
}
|
| 884 |
|
}
|
| 885 |
|
}
|
| 886 |
|
final String final_message = message;
|
| 887 |
|
job.syncExec(new Runnable() {
|
| 888 |
|
@Override
|
| 889 |
|
public void run() {
|
| 890 |
|
MessageDialog.openInformation(editor.getSite().getShell(), ConcordanceUIMessages.ConcordancesEditor_73, final_message);
|
| 891 |
|
}
|
| 892 |
|
});
|
| 893 |
|
}
|
| 894 |
|
// if (history != null && !history.get(type).contains(value_to_add))
|
| 895 |
|
// history.get(type).add(value_to_add);
|
| 896 |
|
|
| 897 |
|
if (Log.getLevel().intValue() < Level.WARNING.intValue() && annotManager != null) annotManager.checkData();
|
| 898 |
|
concordance.reloadLines(editor.getTopLine(), editor.getBottomLine()+1);
|
| 899 |
|
} catch (Exception e1) {
|
| 900 |
|
System.out.println(ConcordanceUIMessages.ConcordancesEditor_74+e1);
|
| 901 |
|
Log.printStackTrace(e1);
|
| 902 |
|
return;
|
| 903 |
|
}
|
| 904 |
|
|
| 905 |
|
job.syncExec(new Runnable() {
|
| 906 |
|
@Override
|
| 907 |
|
public void run() {
|
| 908 |
|
editor.fillDisplayArea();
|
| 909 |
|
CorporaView.refreshObject(corpus);
|
| 910 |
|
}
|
| 911 |
|
});
|
| 912 |
|
|
| 913 |
|
}
|
| 914 |
|
|
| 915 |
|
@Override
|
| 916 |
|
public boolean notifyStartOfCompute() throws Exception {
|
| 917 |
|
if (annotationArea != null) {
|
| 918 |
|
AnnotationType type = getSelectedAnnotationType();
|
| 919 |
|
if (type != null) {
|
| 920 |
|
annotations.setViewAnnotation(type);
|
| 921 |
|
annotations.setAnnotationOverlap(true);
|
| 922 |
|
}
|
| 923 |
|
}
|
| 924 |
|
return true;
|
| 925 |
|
}
|
| 926 |
|
|
| 927 |
|
@Override
|
| 928 |
|
public boolean notifyEndOfCompute() throws Exception {
|
| 929 |
|
updateAnnotationWidgetStates();
|
| 930 |
|
|
| 931 |
|
// update annotation column width
|
| 932 |
|
if (annotationArea != null) {
|
| 933 |
|
annotationColumn.pack();
|
| 934 |
|
|
| 935 |
|
annotationColumn.setResizable(true);
|
| 936 |
|
} else {
|
| 937 |
|
annotationColumn.setWidth(0);
|
| 938 |
|
}
|
| 939 |
|
|
| 940 |
|
return true;
|
| 941 |
|
}
|
| 942 |
|
|
| 943 |
|
|
| 944 |
|
public boolean isAnnotationEnable() {
|
| 945 |
|
return annotationArea != null;
|
| 946 |
|
}
|
| 947 |
|
}
|