1 package eu
.etaxonomy
.taxeditor
.ui
.element
;
3 import org
.eclipse
.jface
.resource
.ResourceManager
;
4 import org
.eclipse
.jface
.util
.PropertyChangeEvent
;
5 import org
.eclipse
.swt
.SWT
;
6 import org
.eclipse
.swt
.events
.SelectionEvent
;
7 import org
.eclipse
.swt
.events
.SelectionListener
;
8 import org
.eclipse
.swt
.graphics
.Color
;
9 import org
.eclipse
.swt
.widgets
.Button
;
10 import org
.eclipse
.swt
.widgets
.Composite
;
11 import org
.eclipse
.swt
.widgets
.Layout
;
12 import org
.eclipse
.ui
.forms
.widgets
.FormToolkit
;
13 import org
.eclipse
.ui
.forms
.widgets
.TableWrapLayout
;
15 import eu
.etaxonomy
.cdm
.api
.conversation
.ConversationHolder
;
16 import eu
.etaxonomy
.cdm
.api
.conversation
.IConversationEnabled
;
17 import eu
.etaxonomy
.cdm
.persistence
.hibernate
.CdmDataChangeMap
;
19 public abstract class AbstractEntityCollectionElementComposite
<ENTITY
>
20 extends AbstractCdmFormElementComposite
21 implements IEntityElement
<ENTITY
>, SelectionListener
, IConversationEnabled
{
23 protected ENTITY entity
;
25 private final Composite container
;
27 private final Composite box
;
29 private final Button button_remove
;
31 private Color backgroundColor
;
34 * Create the composite.
39 public AbstractEntityCollectionElementComposite(Composite parent
, ICdmFormElement parentFormElement
, FormToolkit formFactory
, ENTITY entity
, SelectionListener removeListener
, int style
) {
40 super(parent
, parentFormElement
, style
);
42 box
= formFactory
.createComposite(parent
);
43 box
.setBackgroundMode(SWT
.INHERIT_DEFAULT
);
46 TableWrapLayout boxLayout
= LayoutConstants
.LAYOUT(2, false);
47 boxLayout
.topMargin
= 4;
48 boxLayout
.bottomMargin
= 4;
49 box
.setLayout(boxLayout
);
51 box
.setLayoutData(LayoutConstants
.FILL_HORIZONTALLY());
53 container
= formFactory
.createComposite(box
);
54 container
.setBackgroundMode(SWT
.INHERIT_DEFAULT
);
56 setLayoutComposite(container
);
58 addControl(container
);
59 Layout containerLayout
= LayoutConstants
.LAYOUT(2, false);
61 container
.setLayout(containerLayout
);
62 container
.setLayoutData(LayoutConstants
.FILL_HORIZONTALLY());
64 // if (removeListener != null) {
65 button_remove
= formFactory
.createButton(box
, null, SWT
.PUSH
);
66 addControl(button_remove
);
67 button_remove
.setLayoutData(LayoutConstants
.RIGHT());
68 button_remove
.setImage(ResourceManager
.getPluginImage("eu.etaxonomy.taxeditor.store", "icons/trash.gif"));
69 button_remove
.setToolTipText("Remove");
70 // button_remove.addSelectionListener(removeListener);
73 createControls(this, style
);
79 * Init gets executed before any other setup of the section takes place
81 * Implement this if you want to configure the section
84 // default implementation is empty
89 * Setter for the field <code>entity</code>.
95 public abstract void setEntity(ENTITY entity
);
99 * Getter for the field <code>entity</code>.
102 * @return a ENTITY object.
105 public ENTITY
getEntity() {
115 * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
120 public abstract void createControls(ICdmFormElement element
, int style
);
123 * Mark <code>this</code> element as selected.
126 public void setSelected(boolean selected
) {
128 for (ICdmFormElement element
: getElements()) {
129 if (element
instanceof ISelectable
) {
130 ((ISelectable
) element
).setSelected(selected
);
133 setBackground(selected ? SELECTED
: getPersistentBackground());
140 * eu.etaxonomy.taxeditor.forms.AbstractCdmFormElement#propertyChange(org
141 * .eclipse.jface.util.PropertyChangeEvent)
145 public void propertyChange(PropertyChangeEvent event
) {
149 Object eventSource
= event
.getSource();
150 if (getElements().contains(eventSource
)) {
151 handleEvent(eventSource
);
161 * a {@link java.lang.Object} object.
163 public abstract void handleEvent(Object eventSource
);
167 public void setBackground(Color color
) {
168 backgroundColor
= color
;
169 super.setBackground(backgroundColor
);
170 box
.setBackground(backgroundColor
);
171 container
.setBackground(backgroundColor
);
177 * React when selection occurs
180 public void widgetSelected(SelectionEvent e
) {
186 public void widgetDefaultSelected(SelectionEvent e
) {
191 public Composite
getLayoutComposite() {
197 * Getter for the field <code>backgroundColor</code>.
200 * @return the backgroundColor
202 public Color
getBackgroundColor() {
203 return backgroundColor
;
208 * getConversationHolder
211 * @return a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder}
215 public ConversationHolder
getConversationHolder() {
216 if (getParentElement() instanceof IConversationEnabled
) {
217 return ((IConversationEnabled
) getParentElement())
218 .getConversationHolder();
220 throw new IllegalArgumentException(
221 "Parent element should be IConversationEnabled");
226 public void update(CdmDataChangeMap changeEvents
) {