4 package eu
.etaxonomy
.taxeditor
.forms
.entitysections
;
8 import org
.eclipse
.jface
.action
.Action
;
9 import org
.eclipse
.jface
.action
.IAction
;
10 import org
.eclipse
.jface
.util
.IPropertyChangeListener
;
11 import org
.eclipse
.swt
.SWT
;
12 import org
.eclipse
.swt
.events
.SelectionAdapter
;
13 import org
.eclipse
.swt
.events
.SelectionEvent
;
14 import org
.eclipse
.swt
.widgets
.Composite
;
16 import eu
.etaxonomy
.cdm
.model
.common
.AnnotatableEntity
;
17 import eu
.etaxonomy
.cdm
.model
.common
.Annotation
;
18 import eu
.etaxonomy
.cdm
.model
.common
.AnnotationType
;
19 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
20 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
25 * @created Nov 5, 2009
28 public class AnnotationSection
extends AbstractEntitySetSection
<AnnotatableEntity
>{
34 public AnnotationSection(Composite parent
, AnnotatableEntity annotatableEntity
, IPropertyChangeListener listener
, int style
) {
35 super(parent
, annotatableEntity
, "Annotations", listener
, style
);
41 * @see eu.etaxonomy.taxeditor.forms.AbstractEntitySetSection#createDynamicContents()
44 public void createDynamicContents() {
46 Set
<Annotation
> annotations
= null;
47 if(getEntity() != null){
48 annotations
= getEntity().getAnnotations();
51 if(annotations
== null || annotations
.size() == 0){
52 toolkit
.createLabel(container
, "No annotations yet.");
54 for(Annotation annotation
: annotations
){
55 new AnnotationComposite(container
, annotation
, new RemoveListener(annotation
), this, SWT
.NULL
);
60 protected class RemoveListener
extends SelectionAdapter
{
61 private Annotation annotation
;
63 public RemoveListener(Annotation annotation
){
64 this.annotation
= annotation
;
68 * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
71 public void widgetSelected(SelectionEvent e
) {
72 getEntity().removeAnnotation(annotation
);
73 internalUpdateSection(true);
80 * @see eu.etaxonomy.taxeditor.forms.AbstractEntitySetSection#getAddAction()
83 protected IAction
getAddAction() {
84 Action addAnnotation
= new Action("add", Action
.AS_PUSH_BUTTON
){
86 * @see org.eclipse.jface.action.Action#run()
91 AnnotationType type
= AnnotationType
.EDITORIAL();
92 Language language
= CdmStore
.getDefaultLanguage();
94 Annotation annotation
= Annotation
.NewInstance(text
, type
, language
);
95 getEntity().addAnnotation(annotation
);
96 if(! getSection().isExpanded())
97 getSection().setExpanded(true);
98 internalUpdateSection(true);
101 addAnnotation
.setToolTipText("Create a new annotation");
102 return addAnnotation
;