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
.campanula
.compatibility
.ICdmFormElement
;
28 import eu
.etaxonomy
.taxeditor
.ui
.element
.AbstractCdmFormElement
;
29 import eu
.etaxonomy
.taxeditor
.ui
.element
.AbstractFormSection
;
30 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmFormFactory
;
31 import eu
.etaxonomy
.taxeditor
.ui
.element
.IEntityElement
;
32 import eu
.etaxonomy
.taxeditor
.ui
.element
.ISelectable
;
33 import eu
.etaxonomy
.taxeditor
.ui
.element
.LayoutConstants
;
36 * Visualizes an element of type ENTITY in an {@link AbstractEntityCollectionSection}
37 * and links listener functionalities to it.
39 * @param ENTITY the type of the element which is visualized by this class
42 * @created Nov 16, 2009
45 public abstract class AbstractEntityCollectionElement
<ENTITY
> extends
46 AbstractCdmFormElement
implements IEntityElement
<ENTITY
>,
47 SelectionListener
, IConversationEnabled
{
49 protected ENTITY entity
;
51 private final Composite container
;
53 private final Composite box
;
55 private Button button_remove
;
57 private Color backgroundColor
;
61 * Constructor for AbstractEntityCollectionElement.
67 * a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
70 * a {@link eu.etaxonomy.taxeditor.ui.element.AbstractFormSection}
74 * @param removeListener
75 * a {@link org.eclipse.swt.events.SelectionListener} object.
79 public AbstractEntityCollectionElement(CdmFormFactory formFactory
,
80 AbstractFormSection section
, ENTITY entity
,
81 SelectionListener removeListener
, Color backgroundColor
, int style
) {
82 super(formFactory
, (ICdmFormElement
) section
);
86 formFactory
.addPropertyChangeListener(this);
88 // section.getLayoutComposite().setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_CYAN));
90 box
= formFactory
.createComposite(section
.getLayoutComposite());
91 box
.setBackgroundMode(SWT
.INHERIT_DEFAULT
);
94 TableWrapLayout boxLayout
= LayoutConstants
.LAYOUT(2, false);
95 boxLayout
.topMargin
= 4;
96 boxLayout
.bottomMargin
= 4;
97 box
.setLayout(boxLayout
);
99 box
.setLayoutData(LayoutConstants
.FILL_HORIZONTALLY());
101 // box.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_BLUE));
103 container
= formFactory
.createComposite(box
);
104 container
.setBackgroundMode(SWT
.INHERIT_DEFAULT
);
106 // container.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_RED));
107 setLayoutComposite(container
);
109 addControl(container
);
110 Layout containerLayout
= LayoutConstants
.LAYOUT(2, false);
112 container
.setLayout(containerLayout
);
113 container
.setLayoutData(LayoutConstants
.FILL_HORIZONTALLY());
115 if (removeListener
!= null) {
116 button_remove
= formFactory
.createButton(box
, null, SWT
.PUSH
);
117 addControl(button_remove
);
118 button_remove
.setLayoutData(LayoutConstants
.RIGHT());
119 button_remove
.setImage(ImageResources
120 .getImage(ImageResources
.TRASH_ICON
));
121 button_remove
.setToolTipText("Remove");
123 button_remove
.addSelectionListener(removeListener
);
126 createControls(this, style
);
132 * Init gets executed before any other setup of the section takes place
134 * Implement this if you want to configure the section
137 // default implementation is empty
142 * Setter for the field <code>entity</code>.
148 public abstract void setEntity(ENTITY entity
);
152 * Getter for the field <code>entity</code>.
155 * @return a ENTITY object.
158 public ENTITY
getEntity() {
168 * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
173 public abstract void createControls(ICdmFormElement element
, int style
);
176 * Mark <code>this</code> element as selected.
179 public void setSelected(boolean selected
) {
181 for (ICdmFormElement element
: getElements()) {
182 if (element
instanceof ISelectable
) {
183 ((ISelectable
) element
).setSelected(selected
);
186 setBackground(selected ? SELECTED
: getPersistentBackground());
193 * eu.etaxonomy.taxeditor.forms.AbstractCdmFormElement#propertyChange(org
194 * .eclipse.jface.util.PropertyChangeEvent)
198 public void propertyChange(PropertyChangeEvent event
) {
202 Object eventSource
= event
.getSource();
203 if (getElements().contains(eventSource
)) {
204 handleEvent(eventSource
);
214 * a {@link java.lang.Object} object.
216 public abstract void handleEvent(Object eventSource
);
220 public void setBackground(Color color
) {
221 backgroundColor
= color
;
222 super.setBackground(color
);
223 box
.setBackground(color
);
224 container
.setBackground(color
);
230 * React when selection occurs
233 public void widgetSelected(SelectionEvent e
) {
239 public void widgetDefaultSelected(SelectionEvent e
) {
244 public Composite
getLayoutComposite() {
250 * Getter for the field <code>backgroundColor</code>.
253 * @return the backgroundColor
255 public Color
getBackgroundColor() {
256 return backgroundColor
;
261 * getConversationHolder
264 * @return a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder}
268 public ConversationHolder
getConversationHolder() {
269 if (getParentElement() instanceof IConversationEnabled
) {
270 return ((IConversationEnabled
) getParentElement())
271 .getConversationHolder();
273 throw new IllegalArgumentException(
274 "Parent element should be IConversationEnabled");
279 public void update(CdmDataChangeMap changeEvents
) {