Revision 858

tmp/org.txm.annotation.rcp/src/org/txm/annotation/rcp/editor/AnnotationArea.java (revision 858)
75 75
		return editor;
76 76
	}
77 77
	
78
	public boolean allowMultipleAnnotations() {
79
		return false;
80
	}
81
	
78 82
	/**
79 83
	 * Called BEFORE the TXMResult is computed
80 84
	 * 
tmp/org.txm.annotation.rcp/src/org/txm/annotation/rcp/editor/AnnotationExtension.java (revision 858)
20 20
public class AnnotationExtension extends TXMEditorExtension<TXMResult> {
21 21

  
22 22
	/** The annotation area. */
23
	protected AnnotationArea annotationArea;
23
	protected ArrayList<AnnotationArea> annotationAreas = new ArrayList<AnnotationArea>();
24 24

  
25 25
	private Group controlArea;
26 26
	private SelectionListener defaultListener;
......
31 31
	public String getName() {
32 32
		return "Annotation";
33 33
	}
34
	
34

  
35 35
	/**
36 36
	 * use this to enable/disable the button
37 37
	 * @return
......
76 76
					public void widgetSelected(SelectionEvent e) {
77 77
						try {
78 78
							Object o = celement.createExecutableExtension("class"); //$NON-NLS-1$
79
							AnnotationArea aa = (AnnotationArea)o;
80

  
81
							if (annotationArea!= null && annotationArea.getClass() == aa.getClass()) {
82
								return; // already opened
83
							}
84

  
85
							if (annotationArea != null) {
86
								annotationArea.close();
87
								annotationArea = null;
88
							}
89
							System.out.println("Starting "+aa.getName());
90

  
91
							aa.install(editor, AnnotationExtension.this, controlArea);
92

  
93
							editor.getTopToolbar().setVisible("annotation", true);
94
							annotationArea = aa;
95
							editor.refresh(false); // refresh the concordance display
79
							openAnnotationMode(o);
96 80
						} catch (Exception e1) {
97 81
							// TODO Auto-generated catch block
98 82
							e1.printStackTrace();
......
114 98
		SelectionListener openCloseSelectionListener = new SelectionListener() {
115 99
			@Override
116 100
			public void widgetSelected(SelectionEvent e) {
117
				if (annotationArea != null) {
101
				if (annotationAreas.size() > 0) {
118 102
					return; // do nothing
119 103
				} else {
120 104
					openDefaultAnnotationMode(e);
......
127 111

  
128 112
		defaultListener = listeners.get(0);
129 113
		String defaultMode = modes.get(0);
130
		controlArea = editor.getTopToolbar().installAlternativesGroup("annotation", "annotation tools: "+defaultMode,
114
		controlArea = editor.getTopToolbar().installAlternativesGroup("Annotation", "annotation tools: "+defaultMode,
131 115
				"platform:/plugin/org.txm.rcp/icons/functions/pencil_open.png", 
132 116
				"platform:/plugin/org.txm.rcp/icons/functions/pencil_close.png", false, 
133 117
				openCloseSelectionListener, modes, listeners);
......
139 123

  
140 124
			@Override
141 125
			public void widgetSelected(SelectionEvent e) {
142
				if (annotationArea != null) {
143
					annotationArea.save();
126
				if (annotationAreas != null) {
127
					for (AnnotationArea aa : annotationAreas) {
128
						aa.save();
129
					}
144 130
				}
145 131
			}
146 132

  
......
150 136
		saveButton.setEnabled(false);
151 137
	}
152 138

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

  
148
			for (AnnotationArea a : annotationAreas) {
149
				a.close();
150
			}
151
			annotationAreas.clear();
152
		}
153

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

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

  
158
		editor.getTopToolbar().setVisible("annotation", true);
159
		annotationAreas.add(aa);
160
		editor.refresh(false); // refresh the concordance display
161
	}
162

  
163
	public void removeAnnotationArea(AnnotationArea aa) {
164
		annotationAreas.remove(aa);
165
		aa._close();
166
		if (annotationAreas.size() == 0) {
167
			editor.getTopToolbar().setVisible("Annotation", false);
168
		}
169
	}
170
	
153 171
	protected void openDefaultAnnotationMode(SelectionEvent e) {
154 172
		defaultListener.widgetSelected(e);
155 173
	}
156 174

  
157 175
	@Override
158 176
	public void notifyStartOfCompute() throws Exception {
159
		if (annotationArea != null) {
160
			annotationArea.notifyStartOfCompute();
177
		for (AnnotationArea aa : annotationAreas) {
178
			aa.notifyStartOfCompute();
161 179
		}
162 180
	}
163 181

  
164 182
	@Override
165 183
	public void notifyEndOfCompute() throws Exception {
166
		if (annotationArea != null) {
167
			annotationArea.notifyEndOfCompute();
184
		for (AnnotationArea aa : annotationAreas) {
185
			aa.notifyEndOfCompute();
168 186
		}
169 187
	}
170 188

  
171 189

  
172 190
	public boolean isAnnotationEnable() {
173
		return annotationArea != null;
191
		return annotationAreas != null;
174 192
	}
175 193

  
176 194
	@Override
177 195
	public void notifyEndOfRefresh() throws Exception {
178
		if (annotationArea != null) {
179
			annotationArea.notifyEndOfRefresh();
196
		for (AnnotationArea aa : annotationAreas) {
197
			aa.notifyEndOfRefresh();
180 198
		}
181 199
	}
182 200

  
183 201
	@Override
184 202
	public void notifyStartOfCreatePartControl() throws Exception {
185
		if (annotationArea != null) {
186
			annotationArea.notifyStartOfCreatePartControl();
203
		for (AnnotationArea aa : annotationAreas) {
204
			aa.notifyStartOfCreatePartControl();
187 205
		}
188 206
	}
189 207

  
190 208
	@Override
191 209
	public void notifyStartOfRefresh() throws Exception {
192
		if (annotationArea != null) {
193
			annotationArea.notifyStartOfRefresh();
210
		for (AnnotationArea aa : annotationAreas) {
211
			aa.notifyStartOfRefresh();
194 212
		}
195 213
	}
196 214

  
197 215
	@Override
198 216
	public boolean isDirty() throws Exception {
199
		if (annotationArea != null) {
200
			return annotationArea.isDirty();
217
		boolean dirty = false;
218
		for (AnnotationArea aa : annotationAreas) {
219
			dirty = dirty || aa.isDirty();
201 220
		}
202
		return false;
221
		return dirty;
203 222
	}
204 223

  
205 224
	@Override
206 225
	public void notifydoSave() throws Exception {
207
		if (annotationArea != null) {
208
			annotationArea.save();
226
		for (AnnotationArea aa : annotationAreas) {
227
			aa.save();
209 228
		}
210 229
	}
211 230

  
212 231
	@Override
213 232
	public void notifyDispose() throws Exception {
214
		if (annotationArea != null) {
215
			annotationArea._close();
233
		for (AnnotationArea aa : annotationAreas) {
234
			aa._close();
216 235
		}
217 236
	}
237

  
238
	public void layout() {
239
		if (!controlArea.isDisposed()) {
240
			editor.layout(true);
241
		}
242
	}
243

  
244
	public int getNumberOfAnnotationArea() {
245
		return annotationAreas.size();
246
	}
218 247
}
tmp/org.txm.annotation.kr.rcp/src/org/txm/annotation/kr/rcp/concordance/SimpleKRAnnotation.java (revision 858)
108 108

  
109 109
	private ConcordanceAnnotations annotations = null;
110 110
	private Button addTypedValueLink;
111
	private AnnotationExtension ext;
112 111

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

  
116
	
118 117
	@Override
118
	public boolean allowMultipleAnnotations() {
119
		return true;
120
	}
121
	
122
	@Override
119 123
	public boolean install(TXMEditor<? extends TXMResult> txmeditor, AnnotationExtension ext, Composite parent) throws Exception {
120 124

  
121
		this.ext = ext;
125
		this.extension = ext;
122 126
		this.editor = (ConcordanceEditor)txmeditor;
123 127
		this.concordance = this.editor.getConcordance();
124 128
		this.corpus = concordance.getCorpus();
......
129 133

  
130 134
		// RESULT
131 135

  
132
		int position = 3; // after keyword column
136
		int position = 3+extension.getNumberOfAnnotationArea(); // after keyword column and previous annotation columns
133 137
		TableViewerColumn annotationColumnViewer = new TableViewerColumn(viewer, SWT.CENTER, position);
134 138
		annotationColumn = annotationColumnViewer.getColumn();
135 139
		annotationColumn.setText(ConcordanceUIMessages.ConcordancesEditor_15);
......
338 342
			public void widgetDefaultSelected(SelectionEvent e) { }
339 343
		});
340 344
		
345
		Button closeButton = new Button(annotationArea, SWT.PUSH);
346
		closeButton.setToolTipText("Close the toolbar without saving");
347
		closeButton.setImage(IImageKeys.getImage(IImageKeys.ACTION_DELETE));
348
		closeButton.setLayoutData(new GridData(GridData.END, GridData.CENTER, true, false));
349
		closeButton.addSelectionListener(new SelectionListener() {
350
			
351
			@Override
352
			public void widgetSelected(SelectionEvent e) {
353
				extension.removeAnnotationArea(SimpleKRAnnotation.this);
354
			}
355
			
356
			@Override
357
			public void widgetDefaultSelected(SelectionEvent e) {}
358
		});
359
		
341 360
		updateAnnotationWidgetStates();
342 361
		editor.layout(true);
343 362

  
......
647 666

  
648 667
	@Override
649 668
	protected void _close() {
650
		annotationColumn.dispose();
669
		if (!annotationColumn.isDisposed()) annotationColumn.dispose();
670
		if (!annotationArea.isDisposed()) annotationArea.dispose();
671
		extension.layout();
651 672
	}
652 673

  
653 674
	@Override
tmp/org.txm.annotation.kr.rcp/src/org/txm/annotation/kr/rcp/concordance/KRAnnotation.java (revision 858)
122 122
	private ConcordanceAnnotations annotations = null;
123 123

  
124 124
	ConcordanceEditor editor;
125
	private AnnotationExtension ext;
126 125

  
127 126
	public KRAnnotation() {
128 127

  
......
133 132
	}
134 133

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

  
138
		this.ext = ext;
142
		this.extension = ext;
139 143
		this.editor = (ConcordanceEditor)txmeditor;
140 144
		this.concordance = this.editor.getConcordance();
141 145
		this.corpus = concordance.getCorpus();
......
146 150

  
147 151
		// RESULT
148 152

  
149
		int position = 3; // after keyword column
153
		int position = 3+extension.getNumberOfAnnotationArea(); // after keyword column and previous annotation columns
150 154
		TableViewerColumn annotationColumnViewer = new TableViewerColumn(viewer, SWT.CENTER, position);
151 155
		annotationColumn = annotationColumnViewer.getColumn();
152 156
		annotationColumn.setText(ConcordanceUIMessages.ConcordancesEditor_15);
......
541 545
			@Override
542 546
			public void widgetDefaultSelected(SelectionEvent e) { }
543 547
		});
544

  
548
		
549
		Button closeButton = new Button(annotationArea, SWT.PUSH);
550
		closeButton.setToolTipText("Close the toolbar without saving");
551
		closeButton.setImage(IImageKeys.getImage(IImageKeys.ACTION_DELETE));
552
		closeButton.setLayoutData(new GridData(GridData.END, GridData.CENTER, true, false));
553
		closeButton.addSelectionListener(new SelectionListener() {
554
			
555
			@Override
556
			public void widgetSelected(SelectionEvent e) {
557
				extension.removeAnnotationArea(KRAnnotation.this);
558
			}
559
			
560
			@Override
561
			public void widgetDefaultSelected(SelectionEvent e) {}
562
		});
563
		
545 564
		updateAnnotationWidgetStates();
546 565
		editor.layout(true);
547 566

  
......
853 872

  
854 873
	@Override
855 874
	protected void _close() {
856
		annotationColumn.dispose();
875
		if (!annotationColumn.isDisposed()) annotationColumn.dispose();
876
		if (!annotationArea.isDisposed()) {
877
			annotationArea.dispose();
878
		}
879
		extension.layout();
857 880
	}
858 881

  
859 882
	@Override
tmp/org.txm.annotation.kr.rcp/src/org/txm/annotation/kr/rcp/concordance/WordAnnotationToolbar.java (revision 858)
111 111

  
112 112
	protected Concordance concordance;
113 113
	private Corpus corpus;
114
	private AnnotationExtension ext;
115 114

  
116 115
	public String getName() {
117 116
		return "Word properties";
118 117
	}
118
	
119
	@Override
120
	public boolean allowMultipleAnnotations() {
121
		return true;
122
	}
119 123

  
120 124
	public WordAnnotationToolbar() {
121 125
	}
......
316 320
	@Override
317 321
	public boolean install(TXMEditor<? extends TXMResult> txmeditor, AnnotationExtension ext, Composite parent) throws Exception {
318 322

  
319
		this.ext = ext;
323
		this.extension = ext;
320 324
		this.editor = (ConcordanceEditor)txmeditor;
321 325
		this.concordance = this.editor.getConcordance();
322 326
		this.corpus = concordance.getCorpus();
......
327 331

  
328 332
		// RESULT
329 333

  
330
		int position = 3; // after keyword column
334
		int position = 3+extension.getNumberOfAnnotationArea(); // after keyword column and previous annotation columns
331 335
		TableViewerColumn annotationColumnViewer = new TableViewerColumn(viewer, SWT.CENTER, position);
332 336
		annotationColumn = annotationColumnViewer.getColumn();
333 337
		annotationColumn.setText("Property");
......
572 576
			@Override
573 577
			public void widgetDefaultSelected(SelectionEvent e) { }
574 578
		});
579
		
580
		Button closeButton = new Button(annotationArea, SWT.PUSH);
581
		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));
584
		closeButton.addSelectionListener(new SelectionListener() {
585
			
586
			@Override
587
			public void widgetSelected(SelectionEvent e) {
588
				extension.removeAnnotationArea(WordAnnotationToolbar.this);
589
			}
590
			
591
			@Override
592
			public void widgetDefaultSelected(SelectionEvent e) {}
593
		});
575 594

  
576 595
		updateAnnotationWidgetStates();
577 596
		editor.layout(true);
......
639 658

  
640 659
	@Override
641 660
	protected void _close() {
642
		annotationColumn.dispose();
661
		if (!annotationColumn.isDisposed()) annotationColumn.dispose();
662
		if (!annotationArea.isDisposed()) annotationArea.dispose();
663
		extension.layout();
643 664
	}
644 665

  
645 666
	@Override

Also available in: Unified diff