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
.ArrayList
;
13 import java
.util
.Collection
;
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
32 * {@link AbstractEntityCollectionSection} by creating an
33 * {@link AbstractEntityCollectionElement} for an ELEMENT which is not directly
34 * added the the model ENTITY.<br>
36 * This is useful if the ELEMENT is created after the creation of the
37 * AbstractEntityCollectionElement itself and not in this class and also if you
38 * do not want to create empty elements. <br>
40 * <b>Note:</b> In sub classes: do <b>not</b> override {@link #getCollection(Object)}. Use
41 * {@link #getEntityCollection(Object)} instead
46 public abstract class AbstractUnboundEntityCollectionSection
<ENTITY
, ELEMENT
> extends AbstractEntityCollectionSection
<ENTITY
, ELEMENT
> {
48 private boolean addUnboundElement
= false;
53 * @param parentElement
57 public AbstractUnboundEntityCollectionSection(CdmFormFactory formFactory
, ConversationHolder conversation
, ICdmFormElement parentElement
, String title
, int style
) {
58 super(formFactory
, conversation
, parentElement
, title
, style
);
62 * @deprecated this method should not be extended in sub classes of {@link AbstractUnboundEntityCollectionSection}.<br>
66 public Collection
<ELEMENT
> getCollection(ENTITY entity
) {
67 Collection
<ELEMENT
> elements
= getEntityCollection(entity
);
68 if(addUnboundElement
){
69 //cloning to avoid saving the dummy element
70 Collection
<ELEMENT
> clonedElements
= new ArrayList
<ELEMENT
>();
71 clonedElements
.addAll(elements
);
72 clonedElements
.add(createNewElement()); //add dummy element which is not bound to entity
73 return clonedElements
;
79 protected Control
createToolbar() {
80 ToolBarManager toolBarManager
= new ToolBarManager(SWT
.FLAT
);
82 Action addAction
= new Action("add", IAction
.AS_PUSH_BUTTON
){
84 * @see org.eclipse.jface.action.Action#run()
88 addUnboundElement
= true;
89 if(! getSection().isExpanded()) {
90 getSection().setExpanded(true);
92 internalUpdateSection(false);
93 addUnboundElement
= false;
96 addAction
.setImageDescriptor(new ImageDescriptor() {
99 public ImageData
getImageData() {
100 return ImageResources
.getImage(ImageResources
.ADD_ICON
).getImageData();
103 addAction
.setToolTipText(getTooltipString());
105 toolBarManager
.add(addAction
);
107 return toolBarManager
.createControl(this);
111 * Get all the elements that are represented by this section.
112 * @param entity the entity which is represented by the parent section
113 * @return a collection of the elements belonging to the entity
115 protected abstract Collection
<ELEMENT
> getEntityCollection(ENTITY entity
);