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
.ICdmFormElement
;
31 import eu
.etaxonomy
.taxeditor
.ui
.element
.IEntityElement
;
32 import eu
.etaxonomy
.taxeditor
.ui
.element
.ISelectable
;
33 import eu
.etaxonomy
.taxeditor
.ui
.element
.LayoutConstants
;
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 Composite container
;
52 private 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.
156 public ENTITY
getEntity() {
166 * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
171 public abstract void createControls(ICdmFormElement element
, int style
);
174 * Mark <code>this</code> element as selected.
176 public void setSelected(boolean selected
) {
178 for (ICdmFormElement element
: getElements()) {
179 if (element
instanceof ISelectable
) {
180 ((ISelectable
) element
).setSelected(selected
);
183 setBackground(selected ? SELECTED
: getPersistentBackground());
190 * eu.etaxonomy.taxeditor.forms.AbstractCdmFormElement#propertyChange(org
191 * .eclipse.jface.util.PropertyChangeEvent)
195 public void propertyChange(PropertyChangeEvent event
) {
199 Object eventSource
= event
.getSource();
200 if (getElements().contains(eventSource
)) {
201 handleEvent(eventSource
);
211 * a {@link java.lang.Object} object.
213 public abstract void handleEvent(Object eventSource
);
216 public void setBackground(Color color
) {
217 backgroundColor
= color
;
218 super.setBackground(color
);
219 box
.setBackground(color
);
220 container
.setBackground(color
);
226 * React when selection occurs
228 public void widgetSelected(SelectionEvent e
) {
233 public void widgetDefaultSelected(SelectionEvent e
) {
238 public Composite
getLayoutComposite() {
244 * Getter for the field <code>backgroundColor</code>.
247 * @return the backgroundColor
249 public Color
getBackgroundColor() {
250 return backgroundColor
;
255 * getConversationHolder
258 * @return a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder}
261 public ConversationHolder
getConversationHolder() {
262 if (getParentElement() instanceof IConversationEnabled
) {
263 return ((IConversationEnabled
) getParentElement())
264 .getConversationHolder();
266 throw new IllegalArgumentException(
267 "Parent element should be IConversationEnabled");
271 public void update(CdmDataChangeMap changeEvents
) {