3 * Copyright (C) 2014 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.taxeditor
.ui
.section
.occurrence
.dna
;
12 import java
.util
.Collection
;
13 import java
.util
.HashSet
;
15 import org
.eclipse
.jface
.action
.Action
;
16 import org
.eclipse
.jface
.action
.IAction
;
17 import org
.eclipse
.jface
.action
.ToolBarManager
;
18 import org
.eclipse
.jface
.resource
.ImageDescriptor
;
19 import org
.eclipse
.swt
.SWT
;
20 import org
.eclipse
.swt
.graphics
.ImageData
;
21 import org
.eclipse
.swt
.widgets
.Control
;
23 import eu
.etaxonomy
.cdm
.api
.conversation
.ConversationHolder
;
24 import eu
.etaxonomy
.taxeditor
.model
.ImageResources
;
25 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmFormFactory
;
26 import eu
.etaxonomy
.taxeditor
.ui
.element
.ICdmFormElement
;
27 import eu
.etaxonomy
.taxeditor
.ui
.section
.AbstractEntityCollectionElement
;
28 import eu
.etaxonomy
.taxeditor
.ui
.section
.AbstractEntityCollectionSection
;
31 * This class extends the functionality of {@link AbstractEntityCollectionSection}
32 * by creating an {@link AbstractEntityCollectionElement} for an
33 * ELEMENT which is not directly added the the model ENTITY.<br>
35 * This is useful if the ELEMENT is created after the creation of the AbstractEntityCollectionElement itself
36 * and not in this class.
41 public abstract class AbstractUnboundEntityCollectionSection
<ENTITY
, ELEMENT
> extends AbstractEntityCollectionSection
<ENTITY
, ELEMENT
> {
43 private boolean addUnboundElement
= false;
48 * @param parentElement
52 public AbstractUnboundEntityCollectionSection(CdmFormFactory formFactory
, ConversationHolder conversation
, ICdmFormElement parentElement
, String title
, int style
) {
53 super(formFactory
, conversation
, parentElement
, title
, style
);
57 * @deprecated this method should not be extended in sub classes of {@link AbstractUnboundEntityCollectionSection}.<br>
61 public Collection
<ELEMENT
> getCollection(ENTITY entity
) {
62 Collection
<ELEMENT
> elements
= getEntityCollection(entity
);
63 if(addUnboundElement
){
64 //cloning to avoid saving the dummy element
65 Collection
<ELEMENT
> clonedElements
= new HashSet
<ELEMENT
>();
66 clonedElements
.addAll(elements
);
67 clonedElements
.add(createNewElement()); //add dummy element which is not bound to entity
68 return clonedElements
;
74 protected Control
createToolbar() {
75 ToolBarManager toolBarManager
= new ToolBarManager(SWT
.FLAT
);
77 Action addAction
= new Action("add", IAction
.AS_PUSH_BUTTON
){
79 * @see org.eclipse.jface.action.Action#run()
83 addUnboundElement
= true;
84 if(! getSection().isExpanded()) {
85 getSection().setExpanded(true);
87 internalUpdateSection(false);
88 addUnboundElement
= false;
91 addAction
.setImageDescriptor(new ImageDescriptor() {
94 public ImageData
getImageData() {
95 return ImageResources
.getImage(ImageResources
.ADD_ICON
).getImageData();
98 addAction
.setToolTipText(getTooltipString());
100 toolBarManager
.add(addAction
);
102 return toolBarManager
.createControl(this);
106 * Get all the elements that are represented by this section.
107 * @param entity the entity which is represented by the parent section
108 * @return a collection of the elements belonging to the entity
110 protected abstract Collection
<ELEMENT
> getEntityCollection(ENTITY entity
);