4 package eu
.etaxonomy
.taxeditor
.forms
;
8 import org
.eclipse
.jface
.action
.Action
;
9 import org
.eclipse
.jface
.action
.IAction
;
10 import org
.eclipse
.swt
.SWT
;
11 import org
.eclipse
.swt
.events
.SelectionAdapter
;
12 import org
.eclipse
.swt
.events
.SelectionEvent
;
13 import org
.eclipse
.swt
.widgets
.Button
;
14 import org
.eclipse
.swt
.widgets
.Composite
;
15 import org
.eclipse
.ui
.forms
.widgets
.Section
;
17 import eu
.etaxonomy
.cdm
.model
.common
.AnnotatableEntity
;
18 import eu
.etaxonomy
.cdm
.model
.common
.Annotation
;
19 import eu
.etaxonomy
.cdm
.model
.common
.AnnotationType
;
20 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
21 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
27 public class AnnotationSection
extends AbstractEntitySetSection
<AnnotatableEntity
> {
33 protected AnnotationSection(Composite parent
, AnnotatableEntity annotatableEntity
, int style
) {
34 super(parent
, annotatableEntity
, Section
.TWISTIE
| Section
.COMPACT
| style
);
36 setText("Annotations");
42 * @see eu.etaxonomy.taxeditor.forms.AbstractEntitySetSection#createDynamicContents()
45 public void createDynamicContents() {
47 Set
<Annotation
> annotations
= null;
48 if(getEntity() != null){
49 annotations
= getEntity().getAnnotations();
52 if(annotations
== null || annotations
.size() == 0){
53 toolkit
.createLabel(container
, "No annotations yet.");
55 for(Annotation annotation
: annotations
){
57 toolkit
.createAnnotationComposite(container
, annotation
, SWT
.NULL
);
59 Button button_remove
= toolkit
.createButton(container
, "Remove", SWT
.PUSH
);
60 button_remove
.addSelectionListener(new RemoveListener(annotation
));
65 private class RemoveListener
extends SelectionAdapter
{
66 private Annotation annotation
;
68 public RemoveListener(Annotation annotation
){
69 this.annotation
= annotation
;
73 * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
76 public void widgetSelected(SelectionEvent e
) {
77 getEntity().removeAnnotation(annotation
);
78 internalUpdateSection(true);
85 * @see eu.etaxonomy.taxeditor.forms.AbstractEntitySetSection#getAddAction()
88 protected IAction
getAddAction() {
89 Action addAnnotation
= new Action("add", Action
.AS_PUSH_BUTTON
){
91 * @see org.eclipse.jface.action.Action#run()
96 AnnotationType type
= AnnotationType
.EDITORIAL();
97 Language language
= CdmStore
.getDefaultLanguage();
99 Annotation annotation
= Annotation
.NewInstance(text
, type
, language
);
100 getEntity().addAnnotation(annotation
);
101 internalUpdateSection(true);
102 if(! getSection().isExpanded())
103 getSection().setExpanded(true);
104 internalUpdateSection(true);
107 addAnnotation
.setToolTipText("Create a new annotation");
108 return addAnnotation
;