Revision 288183cd
Added by Niels Hoffmann over 12 years ago
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/container/AbstractGroupedContainer.java | ||
---|---|---|
67 | 67 |
import eu.etaxonomy.taxeditor.preference.Resources; |
68 | 68 |
|
69 | 69 |
/** |
70 |
* Formats <code>GroupedComposite</code> with cosmetic and layout properties specific to the |
|
71 |
* Editor. This should be used to maintain a consistent look and feel for all Editor |
|
72 |
* freetext area components, such as DescriptionElementComposite. |
|
70 |
* Formats <code>GroupedComposite</code> with cosmetic and layout properties |
|
71 |
* specific to the Editor. This should be used to maintain a consistent look and |
|
72 |
* feel for all Editor freetext area components, such as |
|
73 |
* DescriptionElementComposite. |
|
73 | 74 |
* <p> |
74 |
* Requires an <code>IManagedForm</code>, whose <code>input</code> is set to the contents
|
|
75 |
* of {@link #getData()} when the <code>GroupedComposite</code> gets focus, i.e. to
|
|
76 |
* populate the property sheet with the data. |
|
75 |
* Requires an <code>IManagedForm</code>, whose <code>input</code> is set to the |
|
76 |
* contents of {@link #getData()} when the <code>GroupedComposite</code> gets
|
|
77 |
* focus, i.e. to populate the property sheet with the data.
|
|
77 | 78 |
* </p> |
78 | 79 |
* <p> |
79 |
* The <code>IManagedForm</code> is also required to have a <code>Taxon</code> in its
|
|
80 |
* own <code>getData()</code>. |
|
80 |
* The <code>IManagedForm</code> is also required to have a <code>Taxon</code> |
|
81 |
* in its own <code>getData()</code>.
|
|
81 | 82 |
* </p> |
82 | 83 |
* <p> |
83 |
* The <code>IManagedForm</code> can also used for drawing borders by calling the method
|
|
84 |
* <code>createBorderSupport()</code>. |
|
84 |
* The <code>IManagedForm</code> can also used for drawing borders by calling |
|
85 |
* the method <code>createBorderSupport()</code>.
|
|
85 | 86 |
* </p> |
86 |
* |
|
87 |
*
|
|
87 | 88 |
* @author p.ciardelli |
88 | 89 |
* @author n.hoffmann |
89 | 90 |
* @created 02.06.2008 |
90 | 91 |
* @version 1.0 |
91 | 92 |
*/ |
92 |
abstract public class AbstractGroupedContainer<T extends TaxonBase> implements IFormPart, IContainerConstants, IElementHasDetails { |
|
93 |
abstract public class AbstractGroupedContainer<T extends TaxonBase> implements |
|
94 |
IFormPart, IContainerConstants, IElementHasDetails { |
|
93 | 95 |
|
94 | 96 |
protected ParseHandler parseHandler; |
95 |
|
|
97 |
|
|
96 | 98 |
private FocusListener nameCompositeFocusListener; |
97 | 99 |
private ModifyListener nameCompositeModifyListener; |
98 | 100 |
|
99 | 101 |
protected NameViewer nameViewer; |
100 |
|
|
102 |
|
|
101 | 103 |
private AbstractGroup group; |
102 |
|
|
104 |
|
|
103 | 105 |
private Label nonEditableInfoLabel; |
104 | 106 |
private DefaultToolTip nonEditableInfoHover; |
105 |
|
|
107 |
|
|
106 | 108 |
private static AbstractGroupedContainer selection; |
107 |
|
|
109 |
|
|
108 | 110 |
private FocusListener focusListener; |
109 | 111 |
private LineBreakListener lineBreakListener; |
110 | 112 |
|
... | ... | |
114 | 116 |
|
115 | 117 |
private Color backgroundColor; |
116 | 118 |
private boolean isDirty; |
117 |
|
|
118 |
|
|
119 |
|
|
119 | 120 |
/** |
120 |
* <p>Constructor for AbstractGroupedContainer.</p> |
|
121 |
* |
|
122 |
* @param editor a {@link eu.etaxonomy.taxeditor.editor.name.TaxonNameEditor} object. |
|
123 |
* @param group a {@link eu.etaxonomy.taxeditor.editor.name.container.AbstractGroup} object. |
|
124 |
* @param taxonBase a T object. |
|
125 |
* @param <T> a T object. |
|
121 |
* <p> |
|
122 |
* Constructor for AbstractGroupedContainer. |
|
123 |
* </p> |
|
124 |
* |
|
125 |
* @param editor |
|
126 |
* a {@link eu.etaxonomy.taxeditor.editor.name.TaxonNameEditor} |
|
127 |
* object. |
|
128 |
* @param group |
|
129 |
* a |
|
130 |
* {@link eu.etaxonomy.taxeditor.editor.name.container.AbstractGroup} |
|
131 |
* object. |
|
132 |
* @param taxonBase |
|
133 |
* a T object. |
|
134 |
* @param <T> |
|
135 |
* a T object. |
|
126 | 136 |
*/ |
127 |
public AbstractGroupedContainer(T taxonBase){ |
|
137 |
public AbstractGroupedContainer(T taxonBase) {
|
|
128 | 138 |
setData(taxonBase); |
129 | 139 |
parseHandler = ParseHandler.NewInstance(taxonBase.getName()); |
130 | 140 |
} |
131 |
|
|
132 |
public void createContent(){ |
|
141 |
|
|
142 |
public void createContent() {
|
|
133 | 143 |
createControl(); |
134 |
|
|
144 |
|
|
135 | 145 |
createTextViewer(); |
136 | 146 |
createLineWrapSupport(); |
137 | 147 |
createLineBreakListener(); |
138 | 148 |
|
139 | 149 |
setMenu(getEditor().getMenu()); |
140 |
|
|
141 |
setDraggableControl(new Control[]{getControl(), getNameViewer().getRulerControl()}); |
|
142 |
|
|
150 |
|
|
151 |
setDraggableControl(new Control[] { getControl(), |
|
152 |
getNameViewer().getRulerControl() }); |
|
153 |
|
|
143 | 154 |
createEmptyViewerPrompt(EMPTY_NAME_PROMPT); |
144 |
|
|
145 |
|
|
155 |
|
|
146 | 156 |
initializeComposite(); |
147 |
|
|
157 |
|
|
148 | 158 |
createListener(); |
149 | 159 |
|
150 |
isFreeTextEnabled();
|
|
160 |
enableFreeText();
|
|
151 | 161 |
} |
152 | 162 |
|
153 |
|
|
154 |
|
|
155 | 163 |
/** |
156 |
* <p>createListener</p> |
|
164 |
* <p> |
|
165 |
* createListener |
|
166 |
* </p> |
|
157 | 167 |
*/ |
158 |
protected void createListener(){ |
|
159 |
nameCompositeModifyListener = new ModifyListener(){ |
|
160 |
|
|
168 |
protected void createListener() {
|
|
169 |
nameCompositeModifyListener = new ModifyListener() {
|
|
170 |
|
|
161 | 171 |
public void modifyText(ModifyEvent e) { |
162 | 172 |
// mark the composite dirty |
163 | 173 |
setDirty(true); |
164 | 174 |
// parse the text |
165 | 175 |
String text = nameViewer.getTextWidget().getText(); |
166 |
|
|
176 |
|
|
167 | 177 |
NonViralName name = parseHandler.parse(text); |
168 | 178 |
getTaxonBase().setName(name); |
169 | 179 |
getTaxonBase().setTitleCache((getTaxonBase().generateTitle())); |
170 |
|
|
180 |
|
|
171 | 181 |
// show errors resulting from parsing |
172 | 182 |
calculateAnnotations(); |
173 |
// store the position of the cursor
|
|
183 |
// store the position of the cursor |
|
174 | 184 |
storeCursor(); |
175 | 185 |
// notify selection listener |
176 | 186 |
setDelayedSelection(); |
177 | 187 |
} |
178 | 188 |
}; |
179 |
nameCompositeFocusListener = new FocusAdapter(){ |
|
180 |
|
|
181 |
/* (non-Javadoc) |
|
182 |
* @see org.eclipse.swt.events.FocusAdapter#focusLost(org.eclipse.swt.events.FocusEvent) |
|
189 |
nameCompositeFocusListener = new FocusAdapter() { |
|
190 |
|
|
191 |
/* |
|
192 |
* (non-Javadoc) |
|
193 |
* |
|
194 |
* @see |
|
195 |
* org.eclipse.swt.events.FocusAdapter#focusLost(org.eclipse.swt |
|
196 |
* .events.FocusEvent) |
|
183 | 197 |
*/ |
184 | 198 |
@Override |
185 | 199 |
public void focusLost(FocusEvent e) { |
186 | 200 |
super.focusLost(e); |
187 | 201 |
|
188 | 202 |
persistName(); |
189 |
}
|
|
203 |
} |
|
190 | 204 |
}; |
191 |
|
|
205 |
|
|
192 | 206 |
addListener(); |
193 | 207 |
} |
194 |
|
|
195 |
private void addListener(){ |
|
196 |
getNameViewer().getTextWidget().addModifyListener(nameCompositeModifyListener); |
|
197 |
getNameViewer().getTextWidget().addFocusListener(nameCompositeFocusListener); |
|
208 |
|
|
209 |
private void addListener() { |
|
210 |
getNameViewer().getTextWidget().addModifyListener( |
|
211 |
nameCompositeModifyListener); |
|
212 |
getNameViewer().getTextWidget().addFocusListener( |
|
213 |
nameCompositeFocusListener); |
|
198 | 214 |
} |
199 |
|
|
200 |
private void removeListener(){ |
|
201 |
getNameViewer().getTextWidget().removeModifyListener(nameCompositeModifyListener); |
|
202 |
getNameViewer().getTextWidget().removeFocusListener(nameCompositeFocusListener); |
|
215 |
|
|
216 |
private void removeListener() { |
|
217 |
getNameViewer().getTextWidget().removeModifyListener( |
|
218 |
nameCompositeModifyListener); |
|
219 |
getNameViewer().getTextWidget().removeFocusListener( |
|
220 |
nameCompositeFocusListener); |
|
203 | 221 |
} |
204 |
|
|
222 |
|
|
205 | 223 |
/** |
206 | 224 |
* Initialize the composite specific code |
207 | 225 |
*/ |
208 | 226 |
protected abstract void initializeComposite(); |
209 |
|
|
227 |
|
|
210 | 228 |
/** |
211 |
* <p>getEmptyTextPrompt</p> |
|
212 |
* |
|
229 |
* <p> |
|
230 |
* getEmptyTextPrompt |
|
231 |
* </p> |
|
232 |
* |
|
213 | 233 |
* @return a {@link java.lang.String} object. |
214 | 234 |
*/ |
215 | 235 |
protected String getEmptyTextPrompt() { |
216 | 236 |
return EMPTY_NAME_PROMPT; |
217 | 237 |
} |
218 |
|
|
238 |
|
|
219 | 239 |
/** |
220 | 240 |
* |
221 | 241 |
*/ |
... | ... | |
224 | 244 |
if (name == null) { |
225 | 245 |
return; |
226 | 246 |
} |
227 |
|
|
228 |
ILabelImageStrategy strategy = LabelImageProvider.getLabelStrategy(name); |
|
247 |
|
|
248 |
ILabelImageStrategy strategy = LabelImageProvider |
|
249 |
.getLabelStrategy(name); |
|
229 | 250 |
LabelImageProvider labelProvider = new LabelImageProvider(strategy); |
230 |
|
|
251 |
|
|
231 | 252 |
Set<NameRelationship> nameRelations = name.getNameRelations(); |
232 | 253 |
if (nameRelations.size() == 0) { |
233 | 254 |
return; |
234 | 255 |
} |
235 |
// for (NameRelationship nameRelation : nameRelations) { |
|
236 |
// String typeLabel = null; |
|
237 |
// TaxonNameBase<?, ?> relatedName = null; |
|
238 |
// |
|
239 |
// if (name.equals(nameRelation.getFromName())) { |
|
240 |
// typeLabel = labelProvider.getNameRelationTypeLabel( |
|
241 |
// nameRelation.getType()); |
|
242 |
// relatedName = nameRelation.getToName(); |
|
243 |
// } else { |
|
244 |
// typeLabel = labelProvider.getNameRelationTypeInverseLabel( |
|
245 |
// nameRelation.getType()); |
|
246 |
// relatedName = nameRelation.getFromName(); |
|
247 |
// } |
|
248 |
// |
|
249 |
// setNonEditableInfo(typeLabel + " " + NameHelper.getDisplayName(relatedName)); |
|
250 |
// } |
|
251 |
} |
|
252 |
|
|
256 |
// for (NameRelationship nameRelation : nameRelations) { |
|
257 |
// String typeLabel = null; |
|
258 |
// TaxonNameBase<?, ?> relatedName = null; |
|
259 |
// |
|
260 |
// if (name.equals(nameRelation.getFromName())) { |
|
261 |
// typeLabel = labelProvider.getNameRelationTypeLabel( |
|
262 |
// nameRelation.getType()); |
|
263 |
// relatedName = nameRelation.getToName(); |
|
264 |
// } else { |
|
265 |
// typeLabel = labelProvider.getNameRelationTypeInverseLabel( |
|
266 |
// nameRelation.getType()); |
|
267 |
// relatedName = nameRelation.getFromName(); |
|
268 |
// } |
|
269 |
// |
|
270 |
// setNonEditableInfo(typeLabel + " " + |
|
271 |
// NameHelper.getDisplayName(relatedName)); |
|
272 |
// } |
|
273 |
} |
|
274 |
|
|
253 | 275 |
/** |
254 |
* <p>initTextViewer</p> |
|
276 |
* <p> |
|
277 |
* initTextViewer |
|
278 |
* </p> |
|
255 | 279 |
*/ |
256 | 280 |
protected void initTextViewer() { |
257 |
|
|
258 |
// showNameRelations();
|
|
259 |
|
|
281 |
|
|
282 |
// showNameRelations();
|
|
283 |
|
|
260 | 284 |
updateIndent(); |
261 |
|
|
285 |
|
|
262 | 286 |
updateIcon(); |
263 |
|
|
287 |
|
|
264 | 288 |
String text = NameHelper.getDisplayNameWithRef(getData()); |
265 |
|
|
289 |
|
|
266 | 290 |
if (text.length() == 0) { |
267 | 291 |
initEmptyText(); |
268 | 292 |
} else { |
... | ... | |
271 | 295 |
} |
272 | 296 |
calculateAnnotations(); |
273 | 297 |
} |
274 |
|
|
298 |
|
|
275 | 299 |
/** |
276 |
* <p>calculateErrors</p> |
|
300 |
* <p> |
|
301 |
* calculateErrors |
|
302 |
* </p> |
|
277 | 303 |
*/ |
278 | 304 |
synchronized protected void calculateAnnotations() { |
279 | 305 |
getNameViewer().clearAnnotations(); |
... | ... | |
284 | 310 |
* |
285 | 311 |
*/ |
286 | 312 |
public void showAnnotations() { |
287 |
|
|
288 |
if(getName().hasProblem()){
|
|
313 |
|
|
314 |
if (getName().hasProblem()) {
|
|
289 | 315 |
showParsingProblems(); |
290 | 316 |
} |
291 |
|
|
292 |
if(!isNameParsable()){ |
|
293 |
getNameViewer().addAnnotation( |
|
294 |
new EditorAnnotation(EditorAnnotationType.WARNING, 0, "This name may only be edited in the details view.")); |
|
317 |
|
|
318 |
if (!isNameParsable()) { |
|
319 |
getNameViewer() |
|
320 |
.addAnnotation( |
|
321 |
new EditorAnnotation(EditorAnnotationType.WARNING, |
|
322 |
0, |
|
323 |
"This name may only be edited in the details view.")); |
|
295 | 324 |
} |
296 |
|
|
297 |
if(isNameUsedMultipleTimes()){ |
|
298 |
getNameViewer().addAnnotation(new EditorAnnotation(EditorAnnotationType.WARNING, 0, "This taxons name is used multiple times.")); |
|
325 |
|
|
326 |
if (isNameUsedMultipleTimes()) { |
|
327 |
getNameViewer().addAnnotation( |
|
328 |
new EditorAnnotation(EditorAnnotationType.WARNING, 0, |
|
329 |
"This taxons name is used multiple times.")); |
|
299 | 330 |
} |
300 |
|
|
301 |
|
|
331 |
|
|
302 | 332 |
} |
303 | 333 |
|
304 | 334 |
/** |
... | ... | |
306 | 336 |
*/ |
307 | 337 |
private void showParsingProblems() { |
308 | 338 |
String text = getNameViewer().getTextWidget().getText(); |
309 |
|
|
339 |
|
|
310 | 340 |
List<ParserProblem> parsingProblems = getName().getParsingProblems(); |
311 |
|
|
341 |
|
|
312 | 342 |
for (ParserProblem problem : parsingProblems) { |
313 |
getNameViewer().addAnnotation(new EditorAnnotation(problem), getParsingProblemPosition()); |
|
314 |
} |
|
343 |
getNameViewer().addAnnotation(new EditorAnnotation(problem), |
|
344 |
getParsingProblemPosition()); |
|
345 |
} |
|
315 | 346 |
} |
316 |
|
|
317 |
private Position getParsingProblemPosition(){ |
|
347 |
|
|
348 |
private Position getParsingProblemPosition() {
|
|
318 | 349 |
String text = getNameViewer().getTextWidget().getText(); |
319 |
|
|
350 |
|
|
320 | 351 |
if (getName().hasProblem() && text.length() > 0) { |
321 | 352 |
int start = getName().getProblemStarts(); |
322 | 353 |
int length = getName().getProblemEnds() - start; |
323 |
|
|
354 |
|
|
324 | 355 |
if (start == -1 || getName().getProblemEnds() == -1) { |
325 | 356 |
return null; |
326 | 357 |
} |
327 |
|
|
358 |
|
|
328 | 359 |
// Don't let squigglies try to draw beyond the end of the text |
329 | 360 |
if (text.length() < start + length) { |
330 | 361 |
length = text.length() - start; |
331 | 362 |
} |
332 |
|
|
363 |
|
|
333 | 364 |
return new Position(start, length); |
334 | 365 |
} |
335 | 366 |
return null; |
336 | 367 |
} |
337 | 368 |
|
338 | 369 |
/** |
339 |
* <p>handleSplitText</p> |
|
340 |
* |
|
341 |
* @param text a {@link java.lang.String} object. |
|
370 |
* <p> |
|
371 |
* handleSplitText |
|
372 |
* </p> |
|
373 |
* |
|
374 |
* @param text |
|
375 |
* a {@link java.lang.String} object. |
|
342 | 376 |
*/ |
343 | 377 |
protected void handleSplitText(String text) { |
344 | 378 |
// Create a synonym in a new homotypic group using text as name |
345 |
TaxonNameBase synonymName = ParseHandler.parseReferencedName(text, null); |
|
346 |
|
|
347 |
EditorUtil.executeOperation(new CreateSynonymInNewGroupOperation |
|
348 |
("New Heterotypic Synonym", getEditor().getUndoContext(), getEditor().getTaxon(), synonymName, getEditor())); |
|
379 |
TaxonNameBase synonymName = ParseHandler |
|
380 |
.parseReferencedName(text, null); |
|
381 |
|
|
382 |
EditorUtil.executeOperation(new CreateSynonymInNewGroupOperation( |
|
383 |
"New Heterotypic Synonym", getEditor().getUndoContext(), |
|
384 |
getEditor().getTaxon(), synonymName, getEditor())); |
|
349 | 385 |
} |
350 | 386 |
|
351 | 387 |
/** |
352 | 388 |
* Refreshes the display with latest data from the model. |
353 |
* |
|
389 |
*
|
|
354 | 390 |
* Note: Will not parse the text and not calculate errors! |
355 | 391 |
*/ |
356 | 392 |
public void refresh() { |
357 |
// showNameRelations();
|
|
358 |
|
|
393 |
// showNameRelations();
|
|
394 |
|
|
359 | 395 |
String text = NameHelper.getDisplayNameWithRef(getTaxonBase()); |
360 |
|
|
361 |
if(getNameViewer().getTextWidget() == null){
|
|
396 |
|
|
397 |
if (getNameViewer().getTextWidget() == null) {
|
|
362 | 398 |
// we might get here via dnd. Look slike it can be ignored |
363 | 399 |
return; |
364 | 400 |
} |
365 |
|
|
401 |
|
|
366 | 402 |
if (text.length() == 0) { |
367 | 403 |
initEmptyText(); |
368 |
} else if(! getNameViewer().getTextWidget().getText().equals(text)) {
|
|
404 |
} else if (!getNameViewer().getTextWidget().getText().equals(text)) {
|
|
369 | 405 |
removeListener(); |
370 | 406 |
getNameViewer().getTextWidget().setText(text); |
371 | 407 |
addListener(); |
372 | 408 |
} |
373 |
|
|
409 |
|
|
374 | 410 |
updateNonEditableInfo(); |
375 |
|
|
411 |
|
|
376 | 412 |
updateIcon(); |
377 |
// placeCursor();
|
|
413 |
// placeCursor();
|
|
378 | 414 |
updateIndent(); |
379 |
|
|
380 |
isFreeTextEnabled();
|
|
415 |
|
|
416 |
enableFreeText();
|
|
381 | 417 |
} |
382 | 418 |
|
383 | 419 |
/** |
... | ... | |
385 | 421 |
*/ |
386 | 422 |
protected abstract void updateIcon(); |
387 | 423 |
|
388 |
|
|
389 | 424 |
protected abstract void updateIndent(); |
390 | 425 |
|
391 |
|
|
392 | 426 |
/** |
393 |
* <p>updateNonEditableInfo</p> |
|
427 |
* <p> |
|
428 |
* updateNonEditableInfo |
|
429 |
* </p> |
|
394 | 430 |
*/ |
395 | 431 |
protected abstract void updateNonEditableInfo(); |
396 |
|
|
432 |
|
|
397 | 433 |
/** |
398 | 434 |
* |
399 | 435 |
*/ |
400 |
private void isFreeTextEnabled() { |
|
401 |
// Decide whether editing of freetext is allowed or not. |
|
402 |
if (freetextEditingAllowed()) { |
|
403 |
|
|
404 |
// set editable |
|
405 |
getNameViewer().getTextWidget().setEditable(true); |
|
406 |
|
|
407 |
// restore foreground font color again |
|
408 |
getNameViewer().getTextWidget().setForeground(control.getForeground()); |
|
409 |
} else { |
|
410 |
// set non-editable |
|
411 |
getNameViewer().getTextWidget().setEditable(false); |
|
412 |
|
|
413 |
// grey out text as a non-editable indicator |
|
414 |
getNameViewer().getTextWidget().setForeground(EditorUtil.getColor(Resources.COLOR_DISABLED_EDITOR)); |
|
415 |
} |
|
436 |
private void enableFreeText() { |
|
437 |
setEnabled(isFreetextEditingAllowed()); |
|
416 | 438 |
} |
417 |
|
|
418 | 439 |
|
419 | 440 |
/** |
420 |
* Checks whether the freetext should be editable based on specific empty fields. |
|
441 |
* Checks whether the freetext should be editable based on specific empty |
|
442 |
* fields. |
|
443 |
* |
|
421 | 444 |
* @return |
422 | 445 |
*/ |
423 |
private boolean freetextEditingAllowed() { |
|
424 |
NonViralName name = (NonViralName) HibernateProxyHelper.deproxy(getName()); |
|
446 |
private boolean isFreetextEditingAllowed() { |
|
447 |
NonViralName name = (NonViralName) HibernateProxyHelper |
|
448 |
.deproxy(getName()); |
|
425 | 449 |
boolean enableFreetext = true; |
426 | 450 |
|
427 | 451 |
enableFreetext |= isNameUsedMultipleTimes(); |
428 | 452 |
enableFreetext &= isNameParsable(); |
429 |
|
|
453 |
|
|
430 | 454 |
return enableFreetext; |
431 | 455 |
} |
432 |
|
|
433 |
private boolean isNameUsedMultipleTimes(){ |
|
434 |
if(getName().getTaxonBases().size() > 1){
|
|
456 |
|
|
457 |
private boolean isNameUsedMultipleTimes() {
|
|
458 |
if (getName().getTaxonBases().size() > 1) {
|
|
435 | 459 |
return true; |
436 | 460 |
} |
437 | 461 |
return false; |
438 | 462 |
} |
439 |
|
|
440 |
private boolean isNameParsable(){ |
|
463 |
|
|
464 |
private boolean isNameParsable() {
|
|
441 | 465 |
TaxonNameBase name = getName(); |
442 |
|
|
443 |
boolean isParsable = true;
|
|
444 |
isParsable &= CdmUtils.isEmpty(name.getAppendedPhrase()); //taxonFieldsEmpty(); |
|
445 |
|
|
446 |
if(name instanceof NonViralName){
|
|
466 |
|
|
467 |
boolean isParsable = true; |
|
468 |
isParsable &= CdmUtils.isEmpty(name.getAppendedPhrase()); // taxonFieldsEmpty();
|
|
469 |
|
|
470 |
if (name instanceof NonViralName) {
|
|
447 | 471 |
NonViralName nonViralName = (NonViralName) name; |
448 |
isParsable &= ! nonViralName.isProtectedAuthorshipCache();
|
|
449 |
isParsable &= ! nonViralName.isProtectedNameCache();
|
|
472 |
isParsable &= !nonViralName.isProtectedAuthorshipCache(); |
|
473 |
isParsable &= !nonViralName.isProtectedNameCache(); |
|
450 | 474 |
} |
451 |
|
|
475 |
|
|
452 | 476 |
return isParsable; |
453 | 477 |
} |
454 | 478 |
|
455 | 479 |
/** |
456 | 480 |
* Parse the text and calculate errors |
457 | 481 |
*/ |
458 |
public void parseAndCalculateAnnotations(){ |
|
482 |
public void parseAndCalculateAnnotations() {
|
|
459 | 483 |
removeListener(); |
460 | 484 |
String unparsedNameString = getNameViewer().getTextWidget().getText(); |
461 | 485 |
parseHandler.parse(unparsedNameString); |
... | ... | |
464 | 488 |
} |
465 | 489 |
|
466 | 490 |
/** |
467 |
* <p>getTaxonBase</p> |
|
468 |
* |
|
491 |
* <p> |
|
492 |
* getTaxonBase |
|
493 |
* </p> |
|
494 |
* |
|
469 | 495 |
* @return the taxonBase |
470 | 496 |
*/ |
471 | 497 |
public T getTaxonBase() { |
472 | 498 |
return getData(); |
473 | 499 |
} |
474 |
|
|
500 |
|
|
475 | 501 |
/** |
476 |
* <p>getName</p> |
|
477 |
* |
|
502 |
* <p> |
|
503 |
* getName |
|
504 |
* </p> |
|
505 |
* |
|
478 | 506 |
* @return a {@link eu.etaxonomy.cdm.model.name.TaxonNameBase} object. |
479 | 507 |
*/ |
480 |
public TaxonNameBase getName(){ |
|
481 |
return (TaxonNameBase) HibernateProxyHelper.deproxy(getTaxonBase().getName()); |
|
508 |
public TaxonNameBase getName() { |
|
509 |
return (TaxonNameBase) HibernateProxyHelper.deproxy(getTaxonBase() |
|
510 |
.getName()); |
|
482 | 511 |
} |
483 | 512 |
|
484 | 513 |
/** |
485 |
* <p>persistName</p> |
|
514 |
* <p> |
|
515 |
* persistName |
|
516 |
* </p> |
|
486 | 517 |
*/ |
487 |
public void persistName(){ |
|
488 |
if(isDirty()){
|
|
518 |
public void persistName() {
|
|
519 |
if (isDirty()) {
|
|
489 | 520 |
getNameViewer().getTextWidget().setEnabled(false); |
490 |
final String unparsedNameString = getNameViewer().getTextWidget().getText(); |
|
491 |
// Job job = new Job("Persisting Name"){ |
|
492 |
// |
|
493 |
// @Override |
|
494 |
// protected IStatus run(IProgressMonitor monitor) { |
|
495 |
// |
|
496 |
final NonViralName name = parseHandler.parseAndResolveDuplicates(unparsedNameString); |
|
497 |
// |
|
498 |
// Display.getDefault().asyncExec(new Runnable(){ |
|
499 |
// public void run() { |
|
500 |
getTaxonBase().setName(name); |
|
501 |
getTaxonBase().setTitleCache((getTaxonBase().generateTitle())); |
|
502 |
setDirty(false); |
|
503 |
getNameViewer().getTextWidget().setEnabled(true); |
|
504 |
// }; |
|
505 |
// }); |
|
506 |
// |
|
507 |
// |
|
508 |
// return Status.OK_STATUS; |
|
509 |
// } |
|
510 |
// |
|
511 |
// }; |
|
512 |
// |
|
513 |
// job.setPriority(Job.DECORATE); |
|
514 |
// job.schedule(); |
|
521 |
final String unparsedNameString = getNameViewer().getTextWidget() |
|
522 |
.getText(); |
|
523 |
// Job job = new Job("Persisting Name"){ |
|
524 |
// |
|
525 |
// @Override |
|
526 |
// protected IStatus run(IProgressMonitor monitor) { |
|
527 |
// |
|
528 |
final NonViralName name = parseHandler |
|
529 |
.parseAndResolveDuplicates(unparsedNameString); |
|
530 |
// |
|
531 |
// Display.getDefault().asyncExec(new Runnable(){ |
|
532 |
// public void run() { |
|
533 |
getTaxonBase().setName(name); |
|
534 |
getTaxonBase().setTitleCache((getTaxonBase().generateTitle())); |
|
535 |
setDirty(false); |
|
536 |
getNameViewer().getTextWidget().setEnabled(true); |
|
537 |
// }; |
|
538 |
// }); |
|
539 |
// |
|
540 |
// |
|
541 |
// return Status.OK_STATUS; |
|
542 |
// } |
|
543 |
// |
|
544 |
// }; |
|
545 |
// |
|
546 |
// job.setPriority(Job.DECORATE); |
|
547 |
// job.schedule(); |
|
515 | 548 |
} |
516 | 549 |
} |
517 |
|
|
550 |
|
|
518 | 551 |
/** |
519 |
* <p>Getter for the field <code>group</code>.</p> |
|
520 |
* |
|
521 |
* @return a {@link eu.etaxonomy.taxeditor.editor.name.container.AbstractGroup} object. |
|
552 |
* <p> |
|
553 |
* Getter for the field <code>group</code>. |
|
554 |
* </p> |
|
555 |
* |
|
556 |
* @return a |
|
557 |
* {@link eu.etaxonomy.taxeditor.editor.name.container.AbstractGroup} |
|
558 |
* object. |
|
522 | 559 |
*/ |
523 |
public AbstractGroup getGroup(){ |
|
524 |
if(group == null){
|
|
560 |
public AbstractGroup getGroup() {
|
|
561 |
if (group == null) {
|
|
525 | 562 |
throw new IllegalStateException("Group shall not be null."); |
526 | 563 |
} |
527 | 564 |
return group; |
528 | 565 |
} |
529 |
|
|
566 |
|
|
530 | 567 |
/** |
531 |
* <p>remove</p> |
|
568 |
* <p> |
|
569 |
* remove |
|
570 |
* </p> |
|
532 | 571 |
*/ |
533 |
public void remove(){ |
|
572 |
public void remove() {
|
|
534 | 573 |
getGroup().remove(this); |
535 | 574 |
} |
536 |
|
|
575 |
|
|
537 | 576 |
/** |
538 |
* <p>createControl</p> |
|
577 |
* <p> |
|
578 |
* createControl |
|
579 |
* </p> |
|
539 | 580 |
*/ |
540 | 581 |
protected void createControl() { |
541 |
control = getEditor().getToolkit().createComposite(getGroup().getControl()); |
|
542 |
|
|
582 |
control = getEditor().getToolkit().createComposite( |
|
583 |
getGroup().getControl()); |
|
584 |
|
|
543 | 585 |
control.setLayoutData(new TableWrapData(TableWrapData.FILL_GRAB)); |
544 | 586 |
TableWrapLayout layout = new TableWrapLayout(); |
545 | 587 |
layout.leftMargin = 0; |
546 | 588 |
layout.rightMargin = 0; |
547 | 589 |
layout.topMargin = 5; |
548 | 590 |
layout.bottomMargin = 5; |
549 |
|
|
591 |
|
|
550 | 592 |
layout.verticalSpacing = 0; |
551 | 593 |
layout.horizontalSpacing = 0; |
552 |
|
|
594 |
|
|
553 | 595 |
control.setLayout(layout); |
554 |
|
|
596 |
|
|
555 | 597 |
} |
556 |
|
|
598 |
|
|
557 | 599 |
/** |
558 | 600 |
* @return |
559 | 601 |
*/ |
... | ... | |
562 | 604 |
} |
563 | 605 |
|
564 | 606 |
/** |
565 |
* <p>Getter for the field <code>control</code>.</p> |
|
566 |
* |
|
607 |
* <p> |
|
608 |
* Getter for the field <code>control</code>. |
|
609 |
* </p> |
|
610 |
* |
|
567 | 611 |
* @return a {@link org.eclipse.swt.widgets.Composite} object. |
568 | 612 |
*/ |
569 |
public Composite getControl(){ |
|
613 |
public Composite getControl() {
|
|
570 | 614 |
return control; |
571 | 615 |
} |
572 |
|
|
616 |
|
|
573 | 617 |
/** |
574 |
* <p>createLineWrapSupport</p> |
|
618 |
* <p> |
|
619 |
* createLineWrapSupport |
|
620 |
* </p> |
|
575 | 621 |
*/ |
576 | 622 |
protected void createLineWrapSupport() { |
577 | 623 |
new LineWrapSupport(getNameViewer(), getEditor().getManagedForm()); |
578 | 624 |
} |
579 |
|
|
580 |
|
|
625 |
|
|
581 | 626 |
/** |
582 |
* <p>createTextViewer</p> |
|
627 |
* <p> |
|
628 |
* createTextViewer |
|
629 |
* </p> |
|
583 | 630 |
*/ |
584 | 631 |
protected void createTextViewer() { |
585 | 632 |
nameViewer = new NameViewer(control); |
586 |
|
|
633 |
|
|
587 | 634 |
focusListener = new FocusAdapter() { |
588 | 635 |
@Override |
589 | 636 |
public void focusGained(FocusEvent e) { |
590 |
for(AbstractGroupedContainer container : getEditor().getGroupedContainers()){ |
|
637 |
if(!enabled){ |
|
638 |
return; |
|
639 |
} |
|
640 |
for (AbstractGroupedContainer container : getEditor() |
|
641 |
.getGroupedContainers()) { |
|
591 | 642 |
container.colorSelected(NOT_SELECTED); |
592 | 643 |
} |
593 |
getEditor().getManagedForm().setInput(AbstractGroupedContainer.this); |
|
644 |
getEditor().getManagedForm().setInput( |
|
645 |
AbstractGroupedContainer.this); |
|
594 | 646 |
placeCursor(); |
595 | 647 |
colorSelected(SELECTED_FOCUS); |
596 | 648 |
} |
597 | 649 |
}; |
598 | 650 |
nameViewer.getTextWidget().addFocusListener(focusListener); |
599 |
|
|
600 |
//
|
|
651 |
|
|
652 |
//
|
|
601 | 653 |
MouseAdapter mouseListener = new MouseAdapter() { |
602 | 654 |
@Override |
603 | 655 |
public void mouseDown(MouseEvent e) { |
... | ... | |
608 | 660 |
nameViewer.getRulerControl().addMouseListener(mouseListener); |
609 | 661 |
nameViewer.getTextWidget().addMouseListener(mouseListener); |
610 | 662 |
} |
611 |
|
|
663 |
|
|
612 | 664 |
/** |
613 |
* <p>setIcon</p> |
|
614 |
* |
|
615 |
* @param icon a {@link org.eclipse.swt.graphics.Image} object. |
|
665 |
* <p> |
|
666 |
* setIcon |
|
667 |
* </p> |
|
668 |
* |
|
669 |
* @param icon |
|
670 |
* a {@link org.eclipse.swt.graphics.Image} object. |
|
616 | 671 |
*/ |
617 | 672 |
public void setIcon(Image icon) { |
618 | 673 |
getNameViewer().setIcon(icon); |
619 | 674 |
} |
620 |
|
|
675 |
|
|
621 | 676 |
/** |
622 |
* <p>setIndent</p> |
|
623 |
* |
|
624 |
* @param indent a int. |
|
677 |
* <p> |
|
678 |
* setIndent |
|
679 |
* </p> |
|
680 |
* |
|
681 |
* @param indent |
|
682 |
* a int. |
|
625 | 683 |
*/ |
626 | 684 |
public void setIndent(int indent) { |
627 | 685 |
if (control.getLayout() instanceof TableWrapLayout) { |
... | ... | |
631 | 689 |
control.setLayout(layout); |
632 | 690 |
control.layout(); |
633 | 691 |
} else { |
634 |
new RuntimeException("Couldn't indent - composite's layout must be TableWrapLayout."); |
|
692 |
new RuntimeException( |
|
693 |
"Couldn't indent - composite's layout must be TableWrapLayout."); |
|
635 | 694 |
} |
636 |
}
|
|
637 |
|
|
695 |
} |
|
696 |
|
|
638 | 697 |
/** |
639 |
* <p>setSelected</p> |
|
698 |
* <p> |
|
699 |
* setSelected |
|
700 |
* </p> |
|
640 | 701 |
*/ |
641 | 702 |
public void setSelected() { |
642 | 703 |
getNameViewer().getTextWidget().setFocus(); |
643 | 704 |
} |
644 |
|
|
705 |
|
|
645 | 706 |
/** |
646 |
* <p>isSelected</p> |
|
647 |
* |
|
707 |
* <p> |
|
708 |
* isSelected |
|
709 |
* </p> |
|
710 |
* |
|
648 | 711 |
* @return a boolean. |
649 | 712 |
*/ |
650 |
public boolean isSelected(){ |
|
713 |
public boolean isSelected() {
|
|
651 | 714 |
return getEditor().getSelectedContainer() == this; |
652 | 715 |
} |
653 |
|
|
716 |
|
|
654 | 717 |
/** |
655 |
* <p>colorSelected</p> |
|
656 |
* |
|
657 |
* @param mode a int. |
|
718 |
* <p> |
|
719 |
* colorSelected |
|
720 |
* </p> |
|
721 |
* |
|
722 |
* @param mode |
|
723 |
* a int. |
|
658 | 724 |
*/ |
659 |
public void colorSelected(int mode){ |
|
660 |
if(!control.isDisposed()){
|
|
725 |
public void colorSelected(int mode) {
|
|
726 |
if (!control.isDisposed()) {
|
|
661 | 727 |
String colorString = null; |
662 |
|
|
663 |
switch(mode){
|
|
728 |
|
|
729 |
switch (mode) {
|
|
664 | 730 |
case SELECTED_FOCUS: |
665 | 731 |
colorString = Resources.COLOR_CONTROL_SELECTED_FOCUS; |
666 | 732 |
break; |
... | ... | |
670 | 736 |
default: |
671 | 737 |
colorString = Resources.COLOR_COMPOSITE_BACKGROUND; |
672 | 738 |
} |
673 |
|
|
739 |
|
|
674 | 740 |
backgroundColor = EditorUtil.getColor(colorString); |
675 |
|
|
741 |
|
|
676 | 742 |
setBackground(backgroundColor); |
677 | 743 |
} |
678 | 744 |
} |
679 | 745 |
|
680 |
|
|
681 | 746 |
/** |
682 |
* <p>setDelayedSelection</p> |
|
747 |
* <p> |
|
748 |
* setDelayedSelection |
|
749 |
* </p> |
|
683 | 750 |
*/ |
684 |
protected void setDelayedSelection(){ |
|
685 |
//TODO this might be done better |
|
686 |
// this is the quickest solution i could come up with and it improves performance |
|
751 |
protected void setDelayedSelection() { |
|
752 |
// TODO this might be done better |
|
753 |
// this is the quickest solution i could come up with and it improves |
|
754 |
// performance |
|
687 | 755 |
// please reimplement if you know better. |
688 | 756 |
selection = this; |
689 |
|
|
757 |
|
|
690 | 758 |
// start timer |
691 | 759 |
Display display = Display.getCurrent(); |
692 | 760 |
Runnable runnable = new Runnable() { |
693 |
|
|
761 |
|
|
694 | 762 |
public void run() { |
695 | 763 |
getEditor().getManagedForm().setInput(selection); |
696 | 764 |
} |
697 | 765 |
}; |
698 | 766 |
display.timerExec(1000, runnable); |
699 |
|
|
767 |
|
|
700 | 768 |
} |
701 |
|
|
769 |
|
|
702 | 770 |
/** |
703 |
* <p>setBackground</p> |
|
704 |
* |
|
705 |
* @param color a {@link org.eclipse.swt.graphics.Color} object. |
|
771 |
* <p> |
|
772 |
* setBackground |
|
773 |
* </p> |
|
774 |
* |
|
775 |
* @param color |
|
776 |
* a {@link org.eclipse.swt.graphics.Color} object. |
|
706 | 777 |
*/ |
707 | 778 |
public void setBackground(Color color) { |
708 | 779 |
control.setBackground(color); |
709 |
|
|
710 |
for(Control child : control.getChildren()){
|
|
780 |
|
|
781 |
for (Control child : control.getChildren()) {
|
|
711 | 782 |
child.setBackground(color); |
712 | 783 |
} |
713 |
|
|
784 |
|
|
714 | 785 |
getNameViewer().setBackground(color); |
715 | 786 |
} |
716 | 787 |
|
717 |
/* (non-Javadoc) |
|
718 |
* @see org.eclipse.swt.widgets.Control#setFont(org.eclipse.swt.graphics.Font) |
|
788 |
/* |
|
789 |
* (non-Javadoc) |
|
790 |
* |
|
791 |
* @see |
|
792 |
* org.eclipse.swt.widgets.Control#setFont(org.eclipse.swt.graphics.Font) |
|
719 | 793 |
*/ |
720 | 794 |
/** |
721 |
* <p>setFont</p> |
|
722 |
* |
|
723 |
* @param font a {@link org.eclipse.swt.graphics.Font} object. |
|
795 |
* <p> |
|
796 |
* setFont |
|
797 |
* </p> |
|
798 |
* |
|
799 |
* @param font |
|
800 |
* a {@link org.eclipse.swt.graphics.Font} object. |
|
724 | 801 |
*/ |
725 | 802 |
public void setFont(Font font) { |
726 | 803 |
getNameViewer().getTextWidget().setFont(font); |
727 | 804 |
} |
728 |
|
|
805 |
|
|
729 | 806 |
/** |
730 |
* <p>Getter for the field <code>nameViewer</code>.</p> |
|
731 |
* |
|
732 |
* @return a {@link eu.etaxonomy.taxeditor.editor.name.container.NameViewer} object. |
|
807 |
* <p> |
|
808 |
* Getter for the field <code>nameViewer</code>. |
|
809 |
* </p> |
|
810 |
* |
|
811 |
* @return a {@link eu.etaxonomy.taxeditor.editor.name.container.NameViewer} |
|
812 |
* object. |
|
733 | 813 |
*/ |
734 | 814 |
public NameViewer getNameViewer() { |
735 |
if (nameViewer == null){ |
|
736 |
throw new RuntimeException("The Name Viewer is corrupt for Name Container: " + getTaxonBase().getName().getTitleCache()); |
|
815 |
if (nameViewer == null) { |
|
816 |
throw new RuntimeException( |
|
817 |
"The Name Viewer is corrupt for Name Container: " |
|
818 |
+ getTaxonBase().getName().getTitleCache()); |
|
737 | 819 |
} |
738 | 820 |
return nameViewer; |
739 | 821 |
} |
740 |
|
|
822 |
|
|
741 | 823 |
/** |
742 | 824 |
* If <code>textViewer</code> has already been set, it will show a |
743 |
* <code>prompt</code> along the lines of "Click here to start entering data" |
|
744 |
* when empty. |
|
745 |
* |
|
746 |
* @param prompt a {@link java.lang.String} object. |
|
825 |
* <code>prompt</code> along the lines of |
|
826 |
* "Click here to start entering data" when empty. |
|
827 |
* |
|
828 |
* @param prompt |
|
829 |
* a {@link java.lang.String} object. |
|
747 | 830 |
*/ |
748 | 831 |
public void createEmptyViewerPrompt(final String prompt) { |
749 |
|
|
832 |
|
|
750 | 833 |
Assert.isNotNull(getNameViewer()); |
751 |
|
|
834 |
|
|
752 | 835 |
final StyledText textControl = getNameViewer().getTextWidget(); |
753 | 836 |
final IDocument document = getNameViewer().getDocument(); |
754 |
|
|
837 |
|
|
755 | 838 |
setFocusListener(new FocusListener() { |
756 | 839 |
|
757 |
|
|
758 | 840 |
public void focusGained(FocusEvent e) { |
759 | 841 |
if (document.get().equals(prompt)) { |
760 | 842 |
textControl.setFont(getViewerFont()); |
... | ... | |
762 | 844 |
} |
763 | 845 |
} |
764 | 846 |
|
765 |
|
|
766 | 847 |
public void focusLost(FocusEvent e) { |
767 | 848 |
if (document.getLength() == 0) { |
768 | 849 |
initEmptyText(); |
769 | 850 |
} |
770 | 851 |
} |
771 |
|
|
852 |
|
|
772 | 853 |
}); |
773 | 854 |
textControl.addFocusListener(getFocusListener()); |
774 |
|
|
855 |
|
|
775 | 856 |
if (document.getLength() == 0) { |
776 |
textControl.setFont(EditorUtil.getFont(Resources.FONT_DEFAULT_PROMPT)); |
|
857 |
textControl.setFont(EditorUtil |
|
858 |
.getFont(Resources.FONT_DEFAULT_PROMPT)); |
|
777 | 859 |
document.set(prompt); |
778 | 860 |
} |
779 | 861 |
} |
780 |
|
|
862 |
|
|
781 | 863 |
/** |
782 |
* <p>getViewerFont</p> |
|
783 |
* |
|
864 |
* <p> |
|
865 |
* getViewerFont |
|
866 |
* </p> |
|
867 |
* |
|
784 | 868 |
* @return a {@link org.eclipse.swt.graphics.Font} object. |
785 | 869 |
*/ |
786 | 870 |
abstract protected Font getViewerFont(); |
787 | 871 |
|
788 | 872 |
/** |
789 |
* <p>initEmptyText</p> |
|
873 |
* <p> |
|
874 |
* initEmptyText |
|
875 |
* </p> |
|
790 | 876 |
*/ |
791 | 877 |
protected void initEmptyText() { |
792 | 878 |
Font defaultFont = EditorUtil.getFont(Resources.FONT_DEFAULT_PROMPT); |
793 | 879 |
getNameViewer().getTextWidget().setFont(defaultFont); |
794 |
|
|
880 |
|
|
795 | 881 |
getNameViewer().getDocument().set(getEmptyTextPrompt()); |
796 | 882 |
placeCursor(); |
797 | 883 |
} |
798 | 884 |
|
799 | 885 |
/** |
800 |
* <p>Setter for the field <code>focusListener</code>.</p> |
|
801 |
* |
|
802 |
* @param focusListener a {@link org.eclipse.swt.events.FocusListener} object. |
|
886 |
* <p> |
|
887 |
* Setter for the field <code>focusListener</code>. |
|
888 |
* </p> |
|
889 |
* |
|
890 |
* @param focusListener |
|
891 |
* a {@link org.eclipse.swt.events.FocusListener} object. |
|
803 | 892 |
*/ |
804 | 893 |
protected void setFocusListener(FocusListener focusListener) { |
805 | 894 |
this.focusListener = focusListener; |
... | ... | |
810 | 899 |
} |
811 | 900 |
|
812 | 901 |
/** |
813 |
* <p>setDirty</p> |
|
814 |
* |
|
815 |
* @param isDirty a boolean. |
|
902 |
* <p> |
|
903 |
* setDirty |
|
904 |
* </p> |
|
905 |
* |
|
906 |
* @param isDirty |
|
907 |
* a boolean. |
|
816 | 908 |
*/ |
817 | 909 |
public void setDirty(boolean isDirty) { |
818 |
if(isDirty){
|
|
910 |
if (isDirty) {
|
|
819 | 911 |
getEditor().getManagedForm().dirtyStateChanged(); |
820 | 912 |
} |
821 | 913 |
this.isDirty = isDirty; |
822 | 914 |
} |
823 |
|
|
915 |
|
|
824 | 916 |
/** |
825 |
* <p>isDirty</p> |
|
826 |
* |
|
917 |
* <p> |
|
918 |
* isDirty |
|
919 |
* </p> |
|
920 |
* |
|
827 | 921 |
* @return a boolean. |
828 | 922 |
*/ |
829 |
public boolean isDirty(){ |
|
923 |
public boolean isDirty() {
|
|
830 | 924 |
return isDirty; |
831 | 925 |
} |
832 |
|
|
926 |
|
|
833 | 927 |
/** |
834 |
* <p>setMenu</p> |
|
835 |
* |
|
836 |
* @param menu a {@link org.eclipse.swt.widgets.Menu} object. |
|
928 |
* <p> |
|
929 |
* setMenu |
|
930 |
* </p> |
|
931 |
* |
|
932 |
* @param menu |
|
933 |
* a {@link org.eclipse.swt.widgets.Menu} object. |
|
837 | 934 |
*/ |
838 |
public void setMenu (Menu menu) {
|
|
935 |
public void setMenu(Menu menu) { |
|
839 | 936 |
control.setMenu(menu); |
840 |
|
|
937 |
|
|
841 | 938 |
getNameViewer().setMenu(menu); |
842 | 939 |
} |
843 |
|
|
940 |
|
|
844 | 941 |
private Control[] draggableControls; |
845 |
|
|
942 |
|
|
846 | 943 |
/** |
847 |
* <p>setDraggableControl</p> |
|
848 |
* |
|
849 |
* @param controls an array of {@link org.eclipse.swt.widgets.Control} objects. |
|
944 |
* <p> |
|
945 |
* setDraggableControl |
|
946 |
* </p> |
|
947 |
* |
|
948 |
* @param controls |
|
949 |
* an array of {@link org.eclipse.swt.widgets.Control} objects. |
|
850 | 950 |
*/ |
851 | 951 |
protected void setDraggableControl(Control[] controls) { |
852 | 952 |
draggableControls = controls; |
853 | 953 |
} |
854 |
|
|
954 |
|
|
855 | 955 |
/** |
856 |
* <p>setIsDraggable</p> |
|
857 |
* |
|
858 |
* @param draggable a boolean. |
|
956 |
* <p> |
|
957 |
* setIsDraggable |
|
958 |
* </p> |
|
959 |
* |
|
960 |
* @param draggable |
|
961 |
* a boolean. |
|
859 | 962 |
*/ |
860 | 963 |
public void setIsDraggable(boolean draggable) { |
861 | 964 |
|
... | ... | |
865 | 968 |
throw new NullPointerException( |
866 | 969 |
"Draggable controls must be set to add draggability"); |
867 | 970 |
} |
868 |
|
|
869 |
Transfer[] types = new Transfer[] { CdmDataTransfer.getInstance() };
|
|
971 |
|
|
972 |
Transfer[] types = new Transfer[] { CdmDataTransfer.getInstance() }; |
|
870 | 973 |
int operations = DND.DROP_MOVE; |
871 | 974 |
|
872 |
for(Control draggableControl : draggableControls){ |
|
873 |
DragSource dragSource = new DragSource(draggableControl, operations); |
|
975 |
for (Control draggableControl : draggableControls) { |
|
976 |
DragSource dragSource = new DragSource(draggableControl, |
|
977 |
operations); |
|
874 | 978 |
dragSource.setTransfer(types); |
875 |
|
|
979 |
|
|
876 | 980 |
dragSource.addDragListener(new NameEditorDragListener(this)); |
877 |
dragSource.setDragSourceEffect(new NameEditorDragSourceEffect(control)); |
|
981 |
dragSource.setDragSourceEffect(new NameEditorDragSourceEffect( |
|
982 |
control)); |
|
878 | 983 |
} |
879 |
}
|
|
984 |
} |
|
880 | 985 |
} |
881 | 986 |
|
882 | 987 |
private String nonEditableText; |
883 | 988 |
|
884 | 989 |
ControlListener nonEditableResizeListener = new ControlAdapter() { |
885 |
|
|
990 |
|
|
886 | 991 |
int width = 0; |
887 |
|
|
992 |
|
|
888 | 993 |
@Override |
889 | 994 |
public void controlResized(ControlEvent e) { |
890 | 995 |
if (nonEditableInfoLabel.getBounds().width == width) { |
... | ... | |
892 | 997 |
} |
893 | 998 |
width = nonEditableInfoLabel.getBounds().width; |
894 | 999 |
if (nonEditableInfoLabel.getBounds().width > 0) { |
895 |
nonEditableInfoLabel.setText( |
|
896 |
Dialog.shortenText(nonEditableText.toUpperCase(), |
|
897 |
nonEditableInfoLabel)); |
|
1000 |
nonEditableInfoLabel.setText(Dialog.shortenText( |
|
1001 |
nonEditableText.toUpperCase(), nonEditableInfoLabel)); |
|
898 | 1002 |
} |
899 | 1003 |
} |
900 | 1004 |
}; |
... | ... | |
904 | 1008 |
private LabelEllipsisListener nonEditableLabelEllipsisListener; |
905 | 1009 |
|
906 | 1010 |
private T data; |
907 |
|
|
1011 |
|
|
1012 |
private boolean enabled; |
|
1013 |
|
|
908 | 1014 |
/** |
909 | 1015 |
* nonEditableInfo is a label displayed underneath a GroupedComposite's |
910 |
* input field. For instance, NameComposites display things like name relations, |
|
911 |
* sec. references, etc. here. |
|
912 |
* |
|
913 |
* @param info the text to display in the label |
|
914 |
* @param append whether the string should be appended to text that is already shown in the label |
|
1016 |
* input field. For instance, NameComposites display things like name |
|
1017 |
* relations, sec. references, etc. here. |
|
1018 |
* |
|
1019 |
* @param info |
|
1020 |
* the text to display in the label |
|
1021 |
* @param append |
|
1022 |
* whether the string should be appended to text that is already |
|
1023 |
* shown in the label |
|
915 | 1024 |
*/ |
916 | 1025 |
public void setNonEditableInfo(String info, boolean append) { |
917 |
// TODO non editable info should only be drawn once, when everything else is drawn |
|
1026 |
// TODO non editable info should only be drawn once, when everything |
|
1027 |
// else is drawn |
|
918 | 1028 |
info = info.toUpperCase(); |
919 |
|
|
920 |
if(append){
|
|
1029 |
|
|
1030 |
if (append) {
|
|
921 | 1031 |
nonEditableText += ", " + info; |
922 | 1032 |
nonEditableHoverText += "\n" + info; |
923 |
}else{
|
|
1033 |
} else {
|
|
924 | 1034 |
nonEditableText = info; |
925 | 1035 |
nonEditableHoverText = info; |
926 | 1036 |
} |
927 |
|
|
1037 |
|
|
928 | 1038 |
if (nonEditableInfoLabel == null) { |
929 |
nonEditableInfoLabel = getEditor().getToolkit().createLabel(control, ""); |
|
930 |
TableWrapData layoutData = new TableWrapData(TableWrapData.FILL_GRAB, TableWrapData.TOP); |
|
931 |
// Set indent to viewer ruler's width |
|
1039 |
nonEditableInfoLabel = getEditor().getToolkit().createLabel( |
|
1040 |
control, ""); |
|
1041 |
TableWrapData layoutData = new TableWrapData( |
|
1042 |
TableWrapData.FILL_GRAB, TableWrapData.TOP); |
|
1043 |
// Set indent to viewer ruler's width |
|
932 | 1044 |
if (getNameViewer().getRulerControl() != null) { |
933 | 1045 |
// TODO right justify |
934 | 1046 |
layoutData.indent = NameViewer.RULER_WIDTH; |
935 | 1047 |
} |
936 | 1048 |
nonEditableInfoLabel.setLayoutData(layoutData); |
937 |
|
|
938 | 1049 |
|
939 |
|
|
940 |
nonEditableLabelEllipsisListener = new LabelEllipsisListener(nonEditableInfoLabel) {
|
|
1050 |
nonEditableLabelEllipsisListener = new LabelEllipsisListener( |
|
1051 |
nonEditableInfoLabel) {
|
|
941 | 1052 |
@Override |
942 | 1053 |
public String getLabelText() { |
943 | 1054 |
return nonEditableText.toUpperCase(); |
944 | 1055 |
} |
945 |
}; |
|
946 |
nonEditableInfoLabel.addControlListener(nonEditableLabelEllipsisListener); |
|
947 |
|
|
1056 |
}; |
|
1057 |
nonEditableInfoLabel |
|
1058 |
.addControlListener(nonEditableLabelEllipsisListener); |
|
1059 |
|
|
948 | 1060 |
nonEditableInfoHover = new DefaultToolTip(nonEditableInfoLabel); |
949 | 1061 |
nonEditableInfoHover.setRespectDisplayBounds(true); |
950 |
|
|
951 |
}
|
|
1062 |
|
|
1063 |
} |
|
952 | 1064 |
nonEditableInfoHover.setText(nonEditableHoverText); |
953 | 1065 |
nonEditableInfoLabel.setText(nonEditableText); |
954 |
|
|
1066 |
|
|
955 | 1067 |
calculateAnnotations(); |
956 | 1068 |
} |
957 |
|
|
1069 |
|
|
958 | 1070 |
/** |
959 |
* <p>Getter for the field <code>data</code>.</p> |
|
960 |
* |
|
1071 |
* <p> |
|
1072 |
* Getter for the field <code>data</code>. |
|
1073 |
* </p> |
|
1074 |
* |
|
961 | 1075 |
* @return a T object. |
962 | 1076 |
*/ |
963 |
public T getData(){ |
|
1077 |
public T getData() {
|
|
964 | 1078 |
return data; |
965 | 1079 |
} |
966 |
|
|
1080 |
|
|
967 | 1081 |
/** |
968 |
* <p>Setter for the field <code>data</code>.</p> |
|
969 |
* |
|
970 |
* @param data a T object. |
|
1082 |
* <p> |
|
1083 |
* Setter for the field <code>data</code>. |
|
1084 |
* </p> |
|
1085 |
* |
|
1086 |
* @param data |
|
1087 |
* a T object. |
|
971 | 1088 |
*/ |
972 |
public void setData(T data){ |
|
973 |
this.data = (T) HibernateProxyHelper.deproxy(data);
|
|
1089 |
public void setData(T data) {
|
|
1090 |
this.data = (T) HibernateProxyHelper.deproxy(data); |
|
974 | 1091 |
} |
975 | 1092 |
|
976 | 1093 |
/** |
977 | 1094 |
* If the user hitting carriage return should cause something to happen - |
978 |
* i.e. the creation of a new composite - call this method and override |
|
979 |
* the method handleSplitText().
|
|
1095 |
* i.e. the creation of a new composite - call this method and override the
|
|
1096 |
* method handleSplitText(). |
|
980 | 1097 |
*/ |
981 | 1098 |
protected void createLineBreakListener() { |
982 | 1099 |
lineBreakListener = new LineBreakListener() { |
983 | 1100 |
@Override |
984 | 1101 |
public void handleSplitText(String text) { |
985 |
AbstractGroupedContainer.this.handleSplitText(text);
|
|
1102 |
AbstractGroupedContainer.this.handleSplitText(text); |
|
986 | 1103 |
} |
987 | 1104 |
}; |
988 |
|
|
1105 |
|
|
989 | 1106 |
getNameViewer().getTextWidget().addVerifyListener(lineBreakListener); |
990 | 1107 |
} |
991 |
|
|
1108 |
|
|
992 | 1109 |
abstract class LabelEllipsisListener extends ControlAdapter { |
993 |
|
|
1110 |
|
|
994 | 1111 |
private final Label label; |
995 | 1112 |
int width = 0; |
996 | 1113 |
|
997 | 1114 |
LabelEllipsisListener(Label label) { |
998 | 1115 |
this.label = label; |
999 | 1116 |
} |
1000 |
|
|
1117 |
|
|
1001 | 1118 |
abstract public String getLabelText(); |
1002 |
|
|
1119 |
|
|
1003 | 1120 |
@Override |
1004 | 1121 |
public void controlResized(ControlEvent e) { |
1005 | 1122 |
if (label.getBounds().width == width) { |
... | ... | |
1013 | 1130 |
} |
1014 | 1131 |
|
1015 | 1132 |
/** |
1016 |
* <p>storeCursor</p> |
|
1133 |
* <p> |
|
1134 |
* storeCursor |
|
1135 |
* </p> |
|
1017 | 1136 |
*/ |
1018 | 1137 |
public void storeCursor() { |
1019 | 1138 |
this.cursorPosition = getNameViewer().getCursorPosition(); |
1020 | 1139 |
} |
1021 |
|
|
1140 |
|
|
1022 | 1141 |
/** |
1023 | 1142 |
* Puts the cursor to the position it was last seen on or to the end of line |
1024 | 1143 |
* if no former position is known. |
1025 | 1144 |
*/ |
1026 |
public void placeCursor(){ |
|
1027 |
if(cursorPosition == 0){
|
|
1145 |
public void placeCursor() {
|
|
1146 |
if (cursorPosition == 0) {
|
|
1028 | 1147 |
getNameViewer().setCursorToEOL(); |
1029 |
}else{
|
|
1148 |
} else {
|
|
1030 | 1149 |
getNameViewer().setCursorPosition(cursorPosition); |
1031 | 1150 |
} |
1032 | 1151 |
} |
1033 | 1152 |
|
1034 |
|
|
1035 |
|
|
1036 | 1153 |
/** |
1037 |
* <p>Setter for the field <code>group</code>.</p> |
|
1038 |
* |
|
1039 |
* @param group a {@link eu.etaxonomy.taxeditor.editor.name.container.AbstractGroup} object. |
|
1154 |
* <p> |
|
1155 |
* Setter for the field <code>group</code>. |
|
1156 |
* </p> |
|
1157 |
* |
|
1158 |
* @param group |
|
1159 |
* a |
|
1160 |
* {@link eu.etaxonomy.taxeditor.editor.name.container.AbstractGroup} |
|
1161 |
* object. |
|
1040 | 1162 |
*/ |
1041 | 1163 |
public void setGroup(AbstractGroup group) { |
1042 | 1164 |
this.group = group; |
1043 | 1165 |
} |
1044 | 1166 |
|
1045 |
|
|
1046 |
|
|
1047 | 1167 |
/** |
1048 |
* <p>restoreColor</p> |
|
1168 |
* <p> |
|
1169 |
* restoreColor |
|
1170 |
* </p> |
|
1049 | 1171 |
*/ |
1050 | 1172 |
public void restoreColor() { |
1051 | 1173 |
setBackground(backgroundColor); |
1052 | 1174 |
} |
1053 |
|
|
1054 |
|
|
1055 | 1175 |
|
1056 |
/* (non-Javadoc) |
|
1057 |
* @see org.eclipse.ui.forms.IFormPart#initialize(org.eclipse.ui.forms.IManagedForm) |
|
1176 |
/* |
|
1177 |
* (non-Javadoc) |
|
1178 |
* |
|
1179 |
* @see |
|
1180 |
* org.eclipse.ui.forms.IFormPart#initialize(org.eclipse.ui.forms.IManagedForm |
|
1181 |
* ) |
Also available in: Unified diff
Upgraded to cdmlib-3.0.9, working on error warning for unsavable editor