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
.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
.forms
.AbstractCdmFormElement
;
27 import eu
.etaxonomy
.taxeditor
.forms
.AbstractFormSection
;
28 import eu
.etaxonomy
.taxeditor
.forms
.CdmFormFactory
;
29 import eu
.etaxonomy
.taxeditor
.forms
.ICdmFormElement
;
30 import eu
.etaxonomy
.taxeditor
.forms
.IEntityElement
;
31 import eu
.etaxonomy
.taxeditor
.forms
.ISelectable
;
32 import eu
.etaxonomy
.taxeditor
.model
.ImageResources
;
35 * <p>Abstract AbstractEntityCollectionElement class.</p>
38 * @created Nov 16, 2009
41 public abstract class AbstractEntityCollectionElement
<ENTITY
> extends AbstractCdmFormElement
implements IEntityElement
<ENTITY
>, SelectionListener
, IConversationEnabled
{
43 protected ENTITY entity
;
45 private Composite container
;
47 private Composite box
;
49 private Button button_remove
;
51 private Color backgroundColor
;
54 * <p>Constructor for AbstractEntityCollectionElement.</p>
56 * @param backgroundColor TODO
58 * @param formFactory a {@link eu.etaxonomy.taxeditor.forms.CdmFormFactory} object.
59 * @param section a {@link eu.etaxonomy.taxeditor.forms.AbstractFormSection} object.
60 * @param entity a ENTITY object.
61 * @param removeListener a {@link org.eclipse.swt.events.SelectionListener} object.
62 * @param <ENTITY> a ENTITY object.
64 public AbstractEntityCollectionElement(CdmFormFactory formFactory
, AbstractFormSection section
, ENTITY entity
, SelectionListener removeListener
,
65 Color backgroundColor
, int style
) {
66 super(formFactory
, (ICdmFormElement
) section
);
70 formFactory
.addPropertyChangeListener(this);
72 // section.getLayoutComposite().setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_CYAN));
74 box
= formFactory
.createComposite(section
.getLayoutComposite());
75 box
.setBackgroundMode(SWT
.INHERIT_DEFAULT
);
79 TableWrapLayout boxLayout
= CdmFormFactory
.LAYOUT(2, false);
80 boxLayout
.topMargin
= 4;
81 boxLayout
.bottomMargin
= 4;
82 box
.setLayout(boxLayout
);
84 box
.setLayoutData(CdmFormFactory
.FILL_HORIZONTALLY());
86 // box.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_BLUE));
88 container
= formFactory
.createComposite(box
);
89 container
.setBackgroundMode(SWT
.INHERIT_DEFAULT
);
91 // container.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_RED));
92 setLayoutComposite(container
);
94 addControl(container
);
95 Layout containerLayout
= CdmFormFactory
.LAYOUT(2, false);
97 container
.setLayout(containerLayout
);
98 container
.setLayoutData(CdmFormFactory
.FILL_HORIZONTALLY());
100 if(removeListener
!= null){
101 button_remove
= formFactory
.createButton(box
, null, SWT
.PUSH
);
102 addControl(button_remove
);
103 button_remove
.setLayoutData(CdmFormFactory
.RIGHT());
104 button_remove
.setImage(ImageResources
.getImage(ImageResources
.TRASH_ICON
));
105 button_remove
.setToolTipText("Remove");
107 button_remove
.addSelectionListener(removeListener
);
111 createControls(this, style
);
117 * Init gets executed before any other setup of the section takes place
119 * Implement this if you want to configure the section
122 // default implementation is empty
126 * <p>Setter for the field <code>entity</code>.</p>
128 * @param entity a ENTITY object.
130 public abstract void setEntity(ENTITY entity
);
133 * <p>Getter for the field <code>entity</code>.</p>
135 * @return a ENTITY object.
137 public ENTITY
getEntity(){
142 * <p>createControls</p>
144 * @param element a {@link eu.etaxonomy.taxeditor.forms.ICdmFormElement} object.
145 * @param style a int.
147 public abstract void createControls(ICdmFormElement element
, int style
);
150 public void setSelected(boolean selected
) {
151 for(ICdmFormElement element
: getElements()){
152 if(element
instanceof ISelectable
){
153 ((ISelectable
)element
).setSelected(selected
);
156 this.setBackground(getColor(selected
));
161 * @see eu.etaxonomy.taxeditor.forms.AbstractCdmFormElement#propertyChange(org.eclipse.jface.util.PropertyChangeEvent)
165 public void propertyChange(PropertyChangeEvent event
) {
169 Object eventSource
= event
.getSource();
170 if(getElements().contains(eventSource
)){
171 handleEvent(eventSource
);
178 * @param eventSource a {@link java.lang.Object} object.
180 public abstract void handleEvent(Object eventSource
);
184 * @see eu.etaxonomy.taxeditor.forms.AbstractCdmFormElement#getColor(boolean)
188 public Color
getColor(boolean selected
) {
189 return selected ? SELECTED
: backgroundColor
;
193 public void setBackground(Color color
){
194 container
.setBackground(color
);
195 box
.setBackground(color
);
196 for(ICdmFormElement element
: getElements()){
197 element
.setBackground(color
);
204 * React when selection occurs
206 public void widgetSelected(SelectionEvent e
) {
211 public void widgetDefaultSelected(SelectionEvent e
) {}
215 public Composite
getLayoutComposite() {
220 * <p>Setter for the field <code>backgroundColor</code>.</p>
222 * @param backgroundColor the backgroundColor to set
224 public void setBackgroundColor(Color backgroundColor
) {
225 this.backgroundColor
= backgroundColor
;
226 getLayoutComposite().setBackground(backgroundColor
);
227 setBackground(backgroundColor
);
231 * <p>Getter for the field <code>backgroundColor</code>.</p>
233 * @return the backgroundColor
235 public Color
getBackgroundColor() {
236 return backgroundColor
;
240 * <p>getConversationHolder</p>
242 * @return a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
244 public ConversationHolder
getConversationHolder() {
245 if(getParentElement() instanceof IConversationEnabled
){
246 return ((IConversationEnabled
) getParentElement()).getConversationHolder();
248 throw new IllegalArgumentException("Parent element should be IConversationEnabled");
252 public void update(CdmDataChangeMap changeEvents
) {}