Révision 860

tmp/org.txm.rcp/src/main/java/org/txm/rcp/IImageKeys.java (revision 860)
229 229
	public static final String PENCIL_CLOSE = "icons/functions/pencil_close.png"; //$NON-NLS-1$
230 230
	
231 231
	public static final String ACTION_ADD = "icons/add.png";//$NON-NLS-1$
232
	public static final String ACTION_REMOVE = "icons/remove.png";//$NON-NLS-1$
232 233
	public static final String WORLD = "icons/world.png";
233 234

  
234 235
	public static final String TXM_ICON = "icons/logo/TXM logo.png";
......
237 238
	public static final String OPEN_DECORATOR = "icons/decorators/bullet_arrow_down.png";
238 239
	public static final String CLOSE_DECORATOR = "icons/decorators/bullet_arrow_up.png";
239 240

  
241

  
242

  
240 243
	/**
241 244
	 * Gets the image.
242 245
	 *
tmp/org.txm.annotation.rcp/src/org/txm/annotation/rcp/editor/AnnotationArea.java (revision 860)
40 40
	 * @return
41 41
	 * @throws Exception 
42 42
	 */
43
	public abstract boolean install(TXMEditor<? extends TXMResult> editor, AnnotationExtension extension, Composite parent) throws Exception;
43
	public abstract boolean install(TXMEditor<? extends TXMResult> editor, AnnotationExtension extension, Composite parent, int position) throws Exception;
44 44
	
45 45
	/**
46 46
	 * use this to dispose your extension widgets (and save eventually)
tmp/org.txm.annotation.rcp/src/org/txm/annotation/rcp/editor/AnnotationExtension.java (revision 860)
26 26
	private SelectionListener defaultListener;
27 27

  
28 28
	private ToolItem saveButton;
29
	
30
	public static final String GROUP_NAME = "Annotation";
29 31

  
30 32
	@Override
31 33
	public String getName() {
32
		return "Annotation";
34
		return GROUP_NAME;
33 35
	}
34 36

  
35 37
	/**
......
76 78
					public void widgetSelected(SelectionEvent e) {
77 79
						try {
78 80
							Object o = celement.createExecutableExtension("class"); //$NON-NLS-1$
79
							openAnnotationMode(o);
81
							openAnnotationMode((AnnotationArea)o, -1);
80 82
						} catch (Exception e1) {
81 83
							// TODO Auto-generated catch block
82 84
							e1.printStackTrace();
......
111 113

  
112 114
		defaultListener = listeners.get(0);
113 115
		String defaultMode = modes.get(0);
114
		controlArea = editor.getTopToolbar().installAlternativesGroup("Annotation", "annotation tools: "+defaultMode,
116
		controlArea = editor.getTopToolbar().installAlternativesGroup(GROUP_NAME, "annotation tools: "+defaultMode,
115 117
				"platform:/plugin/org.txm.rcp/icons/functions/pencil_open.png", 
116 118
				"platform:/plugin/org.txm.rcp/icons/functions/pencil_close.png", false, 
117 119
				openCloseSelectionListener, modes, listeners);
......
136 138
		saveButton.setEnabled(false);
137 139
	}
138 140

  
139
	protected void openAnnotationMode(Object o) throws Exception {
140
		AnnotationArea aa = (AnnotationArea)o;
141
	public void openAnnotationMode(AnnotationArea aa, int position) throws Exception {
142
		//AnnotationArea aa = (AnnotationArea)o;
141 143
		if (!aa.allowMultipleAnnotations()) {
142 144
			for (AnnotationArea a : annotationAreas) {
143
				if (a.getClass().equals(aa.getClass())) {
144
					return; // already opened
145
				}
145
				a.close();
146 146
			}
147

  
147
			annotationAreas.clear();
148
		} else { // close the other annotation modes
148 149
			for (AnnotationArea a : annotationAreas) {
149
				a.close();
150
				if (!a.getClass().equals(aa.getClass())) {
151
					a._close();
152
				}
150 153
			}
151
			annotationAreas.clear();
152 154
		}
153 155

  
154
		System.out.println("Starting "+aa.getName());
156
		//System.out.println("Starting "+aa.getName());
155 157

  
156
		aa.install(editor, AnnotationExtension.this, controlArea);
158
		aa.install(editor, AnnotationExtension.this, controlArea, position);
157 159

  
158
		editor.getTopToolbar().setVisible("annotation", true);
160
		editor.getTopToolbar().setVisible(GROUP_NAME, true);
159 161
		annotationAreas.add(aa);
160 162
		editor.refresh(false); // refresh the concordance display
161 163
	}
......
164 166
		annotationAreas.remove(aa);
165 167
		aa._close();
166 168
		if (annotationAreas.size() == 0) {
167
			editor.getTopToolbar().setVisible("Annotation", false);
169
			editor.getTopToolbar().setVisible(GROUP_NAME, false);
168 170
		}
169 171
	}
170 172
	
tmp/org.txm.analec.rcp/src/org/txm/analec/toolbar/UnitToolbar.java (revision 860)
97 97
	public UnitToolbar() { }
98 98

  
99 99
	@Override
100
	public boolean install(TXMEditor<? extends TXMResult> txmeditor, AnnotationExtension extension, Composite parent) throws Exception {
101
		super.install(txmeditor, extension, parent);
100
	public boolean install(TXMEditor<? extends TXMResult> txmeditor, AnnotationExtension extension, Composite parent, int position) throws Exception {
101
		super.install(txmeditor, extension, parent, position);
102 102
		
103 103
		annotationArea.getLayout().numColumns = 10;
104 104
		annotationArea.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false));
tmp/org.txm.analec.rcp/src/org/txm/analec/toolbar/SchemaToolbar.java (revision 860)
86 86
	public SchemaToolbar() { }
87 87

  
88 88
	@Override
89
	public boolean install(TXMEditor<? extends TXMResult> txmeditor, AnnotationExtension extension, Composite parent) throws Exception {
90
		super.install(txmeditor, extension, parent);
89
	public boolean install(TXMEditor<? extends TXMResult> txmeditor, AnnotationExtension extension, Composite parent, int position) throws Exception {
90
		super.install(txmeditor, extension, parent, position);
91 91
		
92 92
		annotationArea.getLayout().numColumns = 7;
93 93
		annotationArea.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false));
tmp/org.txm.analec.rcp/src/org/txm/analec/toolbar/URSAnnotationToolbar.java (revision 860)
65 65
	public abstract void select(Element currentElement);
66 66

  
67 67
	@Override
68
	public boolean install(TXMEditor<? extends TXMResult> txmeditor, AnnotationExtension extension, Composite parent) throws Exception {
68
	public boolean install(TXMEditor<? extends TXMResult> txmeditor, AnnotationExtension extension, Composite parent, int position) throws Exception {
69 69

  
70 70
		this.editor = (SynopticEditionEditor) txmeditor;
71 71
		this.maincorpus = (MainCorpus) this.editor.getCorpus();
tmp/org.txm.annotation.kr.rcp/src/org/txm/annotation/kr/rcp/concordance/SimpleKRAnnotation.java (revision 860)
113 113
	public String getName() {
114 114
		return "Tag Annotation";
115 115
	}
116
	
116
		
117 117
	@Override
118
	public boolean allowMultipleAnnotations() {
119
		return true;
120
	}
121
	
122
	@Override
123
	public boolean install(TXMEditor<? extends TXMResult> txmeditor, AnnotationExtension ext, Composite parent) throws Exception {
118
	public boolean install(TXMEditor<? extends TXMResult> txmeditor, AnnotationExtension ext, Composite parent, int position) throws Exception {
124 119

  
125 120
		this.extension = ext;
126 121
		this.editor = (ConcordanceEditor)txmeditor;
......
133 128

  
134 129
		// RESULT
135 130

  
136
		int position = 3+extension.getNumberOfAnnotationArea(); // after keyword column and previous annotation columns
131
		if (position < 0) {
132
			position = 3+extension.getNumberOfAnnotationArea(); // after keyword column and previous annotation columns
133
		}
134
		
137 135
		TableViewerColumn annotationColumnViewer = new TableViewerColumn(viewer, SWT.CENTER, position);
138 136
		annotationColumn = annotationColumnViewer.getColumn();
139 137
		annotationColumn.setText(ConcordanceUIMessages.ConcordancesEditor_15);
tmp/org.txm.annotation.kr.rcp/src/org/txm/annotation/kr/rcp/concordance/KRAnnotation.java (revision 860)
130 130
	public String getName() {
131 131
		return "KR Annotation";
132 132
	}
133

  
134
	@Override
135
	public boolean allowMultipleAnnotations() {
136
		return true;
137
	}
138 133
	
139 134
	@Override
140
	public boolean install(TXMEditor<? extends TXMResult> txmeditor, AnnotationExtension ext, Composite parent) throws Exception {
135
	public boolean install(TXMEditor<? extends TXMResult> txmeditor, AnnotationExtension ext, Composite parent, int position) throws Exception {
141 136

  
142 137
		this.extension = ext;
143 138
		this.editor = (ConcordanceEditor)txmeditor;
......
150 145

  
151 146
		// RESULT
152 147

  
153
		int position = 3+extension.getNumberOfAnnotationArea(); // after keyword column and previous annotation columns
148
		if (position < 0) {
149
			position = 3+extension.getNumberOfAnnotationArea(); // after keyword column and previous annotation columns
150
		}
154 151
		TableViewerColumn annotationColumnViewer = new TableViewerColumn(viewer, SWT.CENTER, position);
155 152
		annotationColumn = annotationColumnViewer.getColumn();
156 153
		annotationColumn.setText(ConcordanceUIMessages.ConcordancesEditor_15);
tmp/org.txm.annotation.kr.rcp/src/org/txm/annotation/kr/rcp/concordance/WordAnnotationToolbar.java (revision 860)
25 25
import org.eclipse.swt.events.KeyListener;
26 26
import org.eclipse.swt.events.SelectionEvent;
27 27
import org.eclipse.swt.events.SelectionListener;
28
import org.eclipse.swt.events.TypedEvent;
28 29
import org.eclipse.swt.layout.GridData;
29 30
import org.eclipse.swt.widgets.Button;
30 31
import org.eclipse.swt.widgets.Composite;
......
111 112

  
112 113
	protected Concordance concordance;
113 114
	private Corpus corpus;
115
	private TableViewerColumn annotationColumnViewer;
114 116

  
115 117
	public String getName() {
116 118
		return "Word properties";
......
318 320
	}
319 321

  
320 322
	@Override
321
	public boolean install(TXMEditor<? extends TXMResult> txmeditor, AnnotationExtension ext, Composite parent) throws Exception {
323
	public boolean install(TXMEditor<? extends TXMResult> txmeditor, AnnotationExtension ext, Composite parent, int position) throws Exception {
322 324

  
323 325
		this.extension = ext;
324 326
		this.editor = (ConcordanceEditor)txmeditor;
......
331 333

  
332 334
		// RESULT
333 335

  
334
		int position = 3+extension.getNumberOfAnnotationArea(); // after keyword column and previous annotation columns
335
		TableViewerColumn annotationColumnViewer = new TableViewerColumn(viewer, SWT.CENTER, position);
336
		if (position < 0) {
337
			position = 3 + extension.getNumberOfAnnotationArea(); // after keyword column and previous annotation columns
338
		}
339
		annotationColumnViewer = new TableViewerColumn(viewer, SWT.CENTER, position);
336 340
		annotationColumn = annotationColumnViewer.getColumn();
337 341
		annotationColumn.setText("Property");
338 342
		annotationColumn.setToolTipText(ConcordanceUIMessages.ConcordancesEditor_17);
......
388 392

  
389 393
		List<WordProperty> wordProperties = corpus.getProperties();
390 394
		for (WordProperty p : wordProperties) {
395
			if (p.getName().equals("id")) continue;
391 396
			AnnotationType type = currentKnowledgeRepository.getType(p.getName());
392 397
			if (type == null) {
393 398
				AnnotationType t = currentKnowledgeRepository.addType(p.getName(), p.getName());
......
412 417
		gdata.widthHint = 90;
413 418

  
414 419
		//Display combo with list of Annotation Type 
415
		annotationTypesCombo = new ComboViewer(annotationArea, SWT.READ_ONLY);
420
		annotationTypesCombo = new ComboViewer(annotationArea, SWT.SINGLE);
416 421
		annotationTypesCombo.setContentProvider(new ArrayContentProvider());
417 422
		annotationTypesCombo.setLabelProvider(new SimpleLabelProvider() {
418 423
			@Override
......
424 429
				return ((AnnotationType)element).getName(); //$NON-NLS-1$
425 430
			}
426 431
		});
432
		annotationTypesCombo.getCombo().addKeyListener(new KeyListener() {
433
			
434
			@Override
435
			public void keyReleased(KeyEvent e) {
436
				if (e.keyCode == SWT.CR || e.keyCode == SWT.KEYPAD_CR) {
437
					String name = annotationTypesCombo.getCombo().getText();
438
					if (currentKnowledgeRepository.getType(name) == null) {
439
						createNewType(e, name);
440
					}
441
				}
442
			}
443
			
444
			@Override
445
			public void keyPressed(KeyEvent e) { }
446
		});
427 447
	
428 448
		gdata = new GridData(SWT.CENTER, SWT.CENTER, false, false);
429 449
		gdata.widthHint = 200;
......
464 484
			}
465 485
		});
466 486

  
467
		addAnnotationTypeButton = new Button(annotationArea, SWT.PUSH);
468
		addAnnotationTypeButton.setToolTipText(ConcordanceUIMessages.ConcordancesEditor_115);
469
		addAnnotationTypeButton.setImage(IImageKeys.getImage(IImageKeys.ACTION_ADD));
470
		addAnnotationTypeButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
471
		addAnnotationTypeButton.addSelectionListener(new SelectionListener() {
472
			@Override
473
			public void widgetSelected(SelectionEvent e) {
474
				if (currentKnowledgeRepository == null) return;
475
				if (!(currentKnowledgeRepository instanceof LocalKnowledgeRepository)) return;
476

  
477
				LocalKnowledgeRepository kr = (LocalKnowledgeRepository)currentKnowledgeRepository;
478

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

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

  
519
			@Override
520
			public void widgetDefaultSelected(SelectionEvent e) { }
521
		});
522

  
523 487
		equalLabel = new Label(annotationArea, SWT.NONE);
524 488
		equalLabel.setText("="); //$NON-NLS-1$
525 489
		equalLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
......
577 541
			public void widgetDefaultSelected(SelectionEvent e) { }
578 542
		});
579 543
		
544
		addAnnotationTypeButton = new Button(annotationArea, SWT.PUSH);
545
		addAnnotationTypeButton.setLayoutData(new GridData(GridData.END, GridData.CENTER, true, false));
546
		addAnnotationTypeButton.setToolTipText(ConcordanceUIMessages.ConcordancesEditor_115);
547
		addAnnotationTypeButton.setImage(IImageKeys.getImage(IImageKeys.ACTION_ADD));
548
		addAnnotationTypeButton.addSelectionListener(new SelectionListener() {
549
			@Override
550
			public void widgetSelected(SelectionEvent e) {
551
				try {
552
					int position = -1;
553
					TableColumn[] columns = editor.getLineTableViewer().getTable().getColumns();
554
					TableColumn column = annotationColumnViewer.getColumn();
555
					for (int i = 0 ; i < columns.length ; i++) {
556
						if (columns[i] == column) {
557
							position = i +1; // after the current column
558
						}
559
					}
560
					extension.openAnnotationMode(new WordAnnotationToolbar(), position);
561
				} catch (Exception e1) {
562
					// TODO Auto-generated catch block
563
					e1.printStackTrace();
564
				}
565
			}
566

  
567
			@Override
568
			public void widgetDefaultSelected(SelectionEvent e) { }
569
		});
570
		
580 571
		Button closeButton = new Button(annotationArea, SWT.PUSH);
581 572
		closeButton.setToolTipText("Close the toolbar without saving");
582
		closeButton.setImage(IImageKeys.getImage(IImageKeys.ACTION_DELETE));
583
		closeButton.setLayoutData(new GridData(GridData.END, GridData.CENTER, true, false));
573
		closeButton.setImage(IImageKeys.getImage(IImageKeys.ACTION_REMOVE));
574
		
584 575
		closeButton.addSelectionListener(new SelectionListener() {
585 576
			
586 577
			@Override
......
591 582
			@Override
592 583
			public void widgetDefaultSelected(SelectionEvent e) {}
593 584
		});
585
		
586
		
594 587

  
595 588
		updateAnnotationWidgetStates();
596 589
		editor.layout(true);
......
598 591
		return true;
599 592
	}
600 593

  
594
	protected void createNewType(TypedEvent e, String typeName) {
595
		
596
		if (currentKnowledgeRepository == null) return;
597
		if (!(currentKnowledgeRepository instanceof LocalKnowledgeRepository)) return;
598

  
599
		LocalKnowledgeRepository kr = (LocalKnowledgeRepository)currentKnowledgeRepository;
600
		if (typeName == null) typeName = "";
601
		InputDialog dialog = new InputDialog(e.widget.getDisplay().getActiveShell(), "Nouvelle propriété", "Nom de la propriété pattern=[a-z][-a-z0-9]+", typeName, null); //$NON-NLS-3$
602
		if (dialog.open() == InputDialog.OK) {
603
			String name = dialog.getValue();
604
			if (name.trim().length() == 0) return;
605
			String baseid = AsciiUtils.buildId(name);
606
			String id = AsciiUtils.buildId(name);
607
			int c = 1;
608
			while (kr.getType(id) != null) {
609
				id = baseid+"_"+(c++); //$NON-NLS-1$
610
			}
611
			AnnotationType type = kr.addType(name, id, ""); //$NON-NLS-1$
612
			type.setEffect(AnnotationEffect.TOKEN);
613
			typesList.add(type);
614

  
615
			if (annotationTypesCombo != null) annotationTypesCombo.refresh();
616
			if (typesList.size() == 1) {
617
				if (annotationTypesCombo != null) annotationTypesCombo.getCombo().select(0);
618
				annotations.setViewAnnotation(type);
619
				annotations.setAnnotationOverlap(true);
620
				try {
621
					editor.refresh(false);
622
				} catch (Exception e1) {
623
					// TODO Auto-generated catch block
624
					e1.printStackTrace();
625
				}
626
				annotationArea.layout(true);
627
			} else {
628
				if (typesList.size() > 1) {
629
					if (annotationTypesCombo != null) {
630
						annotationTypesCombo.getCombo().select(typesList.size()-1);
631
					}
632
				}
633
			}
634
			KRView.refresh();
635
			updateAnnotationWidgetStates();
636
		} else {
637
			System.out.println("Creation aborted."); //$NON-NLS-1$
638
		}
639
	}
640

  
601 641
	@Override
602 642
	public boolean save() {
603 643
		try {

Formats disponibles : Unified diff