3 * Copyright (C) 2007 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.
11 package eu
.etaxonomy
.taxeditor
.ui
.section
;
13 import org
.eclipse
.jface
.util
.PropertyChangeEvent
;
14 import org
.eclipse
.swt
.SWT
;
15 import org
.eclipse
.swt
.events
.SelectionEvent
;
16 import org
.eclipse
.swt
.events
.SelectionListener
;
17 import org
.eclipse
.swt
.graphics
.Color
;
18 import org
.eclipse
.swt
.widgets
.Button
;
19 import org
.eclipse
.swt
.widgets
.Composite
;
20 import org
.eclipse
.swt
.widgets
.Layout
;
21 import org
.eclipse
.ui
.forms
.widgets
.TableWrapLayout
;
23 import eu
.etaxonomy
.cdm
.api
.conversation
.ConversationHolder
;
24 import eu
.etaxonomy
.cdm
.api
.conversation
.IConversationEnabled
;
25 import eu
.etaxonomy
.cdm
.persistence
.hibernate
.CdmDataChangeMap
;
26 import eu
.etaxonomy
.taxeditor
.model
.ImageResources
;
27 import eu
.etaxonomy
.taxeditor
.ui
.element
.AbstractCdmFormElement
;
28 import eu
.etaxonomy
.taxeditor
.ui
.element
.AbstractFormSection
;
29 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmFormFactory
;
30 import eu
.etaxonomy
.taxeditor
.ui
.element
.IEntityElement
;
31 import eu
.etaxonomy
.taxeditor
.ui
.element
.ISelectable
;
32 import eu
.etaxonomy
.taxeditor
.ui
.element
.LayoutConstants
;
33 import eu
.etaxonomy
.taxeditor
.ui
.section
.campanula
.compatibility
.ICdmFormElement
;
37 * Abstract AbstractEntityCollectionElement class.
41 * @created Nov 16, 2009
44 public abstract class AbstractEntityCollectionElement
<ENTITY
> extends
45 AbstractCdmFormElement
implements IEntityElement
<ENTITY
>,
46 SelectionListener
, IConversationEnabled
, ISelectable
{
48 protected ENTITY entity
;
50 private final Composite container
;
52 private final Composite box
;
54 private Button button_remove
;
56 private Color backgroundColor
;
60 * Constructor for AbstractEntityCollectionElement.
66 * a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
69 * a {@link eu.etaxonomy.taxeditor.ui.element.AbstractFormSection}
73 * @param removeListener
74 * a {@link org.eclipse.swt.events.SelectionListener} object.
78 public AbstractEntityCollectionElement(CdmFormFactory formFactory
,
79 AbstractFormSection section
, ENTITY entity
,
80 SelectionListener removeListener
, Color backgroundColor
, int style
) {
81 super(formFactory
, (ICdmFormElement
) section
);
85 formFactory
.addPropertyChangeListener(this);
87 // section.getLayoutComposite().setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_CYAN));
89 box
= formFactory
.createComposite(section
.getLayoutComposite());
90 box
.setBackgroundMode(SWT
.INHERIT_DEFAULT
);
93 TableWrapLayout boxLayout
= LayoutConstants
.LAYOUT(2, false);
94 boxLayout
.topMargin
= 4;
95 boxLayout
.bottomMargin
= 4;
96 box
.setLayout(boxLayout
);
98 box
.setLayoutData(LayoutConstants
.FILL_HORIZONTALLY());
100 // box.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_BLUE));
102 container
= formFactory
.createComposite(box
);
103 container
.setBackgroundMode(SWT
.INHERIT_DEFAULT
);
105 // container.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_RED));
106 setLayoutComposite(container
);
108 addControl(container
);
109 Layout containerLayout
= LayoutConstants
.LAYOUT(2, false);
111 container
.setLayout(containerLayout
);
112 container
.setLayoutData(LayoutConstants
.FILL_HORIZONTALLY());
114 if (removeListener
!= null) {
115 button_remove
= formFactory
.createButton(box
, null, SWT
.PUSH
);
116 addControl(button_remove
);
117 button_remove
.setLayoutData(LayoutConstants
.RIGHT());
118 button_remove
.setImage(ImageResources
119 .getImage(ImageResources
.TRASH_ICON
));
120 button_remove
.setToolTipText("Remove");
122 button_remove
.addSelectionListener(removeListener
);
125 createControls(this, style
);
131 * Init gets executed before any other setup of the section takes place
133 * Implement this if you want to configure the section
136 // default implementation is empty
141 * Setter for the field <code>entity</code>.
147 public abstract void setEntity(ENTITY entity
);
151 * Getter for the field <code>entity</code>.
154 * @return a ENTITY object.
157 public ENTITY
getEntity() {
167 * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
172 public abstract void createControls(ICdmFormElement element
, int style
);
175 * Mark <code>this</code> element as selected.
178 public void setSelected(boolean selected
) {
180 for (ICdmFormElement element
: getElements()) {
181 if (element
instanceof ISelectable
) {
182 ((ISelectable
) element
).setSelected(selected
);
185 setBackground(selected ? SELECTED
: getPersistentBackground());
192 * eu.etaxonomy.taxeditor.forms.AbstractCdmFormElement#propertyChange(org
193 * .eclipse.jface.util.PropertyChangeEvent)
197 public void propertyChange(PropertyChangeEvent event
) {
201 Object eventSource
= event
.getSource();
202 if (getElements().contains(eventSource
)) {
203 handleEvent(eventSource
);
213 * a {@link java.lang.Object} object.
215 public abstract void handleEvent(Object eventSource
);
219 public void setBackground(Color color
) {
220 backgroundColor
= color
;
221 super.setBackground(color
);
222 box
.setBackground(color
);
223 container
.setBackground(color
);
229 * React when selection occurs
232 public void widgetSelected(SelectionEvent e
) {
238 public void widgetDefaultSelected(SelectionEvent e
) {
243 public Composite
getLayoutComposite() {
249 * Getter for the field <code>backgroundColor</code>.
252 * @return the backgroundColor
254 public Color
getBackgroundColor() {
255 return backgroundColor
;
260 * getConversationHolder
263 * @return a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder}
267 public ConversationHolder
getConversationHolder() {
268 if (getParentElement() instanceof IConversationEnabled
) {
269 return ((IConversationEnabled
) getParentElement())
270 .getConversationHolder();
272 throw new IllegalArgumentException(
273 "Parent element should be IConversationEnabled");
278 public void update(CdmDataChangeMap changeEvents
) {