3 * Copyright (C) 2013 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.
10 package eu
.etaxonomy
.taxeditor
.ui
.section
;
12 import org
.eclipse
.jface
.util
.PropertyChangeEvent
;
13 import org
.eclipse
.swt
.SWT
;
14 import org
.eclipse
.swt
.events
.SelectionEvent
;
15 import org
.eclipse
.swt
.events
.SelectionListener
;
16 import org
.eclipse
.swt
.graphics
.Color
;
17 import org
.eclipse
.swt
.widgets
.Button
;
18 import org
.eclipse
.swt
.widgets
.Composite
;
19 import org
.eclipse
.swt
.widgets
.Layout
;
20 import org
.eclipse
.ui
.forms
.widgets
.FormToolkit
;
21 import org
.eclipse
.ui
.forms
.widgets
.TableWrapLayout
;
22 import org
.eclipse
.wb
.swt
.ResourceManager
;
23 import org
.eclipse
.wb
.swt
.SWTResourceManager
;
25 import eu
.etaxonomy
.cdm
.api
.conversation
.ConversationHolder
;
26 import eu
.etaxonomy
.cdm
.api
.conversation
.IConversationEnabled
;
27 import eu
.etaxonomy
.cdm
.persistence
.hibernate
.CdmDataChangeMap
;
28 import eu
.etaxonomy
.taxeditor
.ui
.element
.AbstractCdmFormElementComposite
;
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
;
40 public abstract class AbstractEntityCollectionElementComposite
<ENTITY
> extends AbstractCdmFormElementComposite
implements IEntityElement
<ENTITY
>, SelectionListener
, IConversationEnabled
{
42 protected ENTITY entity
;
44 private final Composite container
;
46 // private final Composite box;
48 private final Button btnRstre
;
50 private Color backgroundColor
;
54 * Constructor for AbstractEntityCollectionElement.
60 * a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
64 * {@link eu.etaxonomy.taxeditor.ui.element.AbstractFormSection}
68 * @param removeListener
69 * a {@link org.eclipse.swt.events.SelectionListener} object.
73 public AbstractEntityCollectionElementComposite(Composite parent
, FormToolkit formFactory
, ICdmFormElement parentFormElement
, ENTITY entity
, SelectionListener removeListener
, Color backgroundColor
, int style
) {
74 super(parent
, formFactory
, parentFormElement
, style
);
75 setBackground(SWTResourceManager
.getColor(SWT
.COLOR_WHITE
));
79 if(formFactory
instanceof CdmFormFactory
){
80 ((CdmFormFactory
) formFactory
).addPropertyChangeListener(this);
83 // section.getLayoutComposite().setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_CYAN));
85 // box = formFactory.createComposite(this);
86 this.setBackgroundMode(SWT
.INHERIT_DEFAULT
);
89 TableWrapLayout boxLayout
= LayoutConstants
.LAYOUT(2, false);
90 boxLayout
.topMargin
= 4;
91 boxLayout
.bottomMargin
= 4;
92 this.setLayout(boxLayout
);
94 this.setLayoutData(LayoutConstants
.FILL_HORIZONTALLY());
96 // box.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_BLUE));
98 container
= formFactory
.createComposite(this);
99 container
.setBackgroundMode(SWT
.INHERIT_DEFAULT
);
101 // container.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_RED));
102 setLayoutComposite(container
);
104 addControl(container
);
105 Layout containerLayout
= LayoutConstants
.LAYOUT(2, false);
107 container
.setLayout(containerLayout
);
108 container
.setLayoutData(LayoutConstants
.FILL_HORIZONTALLY());
110 btnRstre
= formFactory
.createButton(this, null, SWT
.PUSH
);
111 addControl(btnRstre
);
112 btnRstre
.setLayoutData(LayoutConstants
.RIGHT());
113 btnRstre
.setImage(ResourceManager
.getPluginImage("eu.etaxonomy.taxeditor.store", "icons/trash.gif"));
114 btnRstre
.setToolTipText("Remove");
116 if (removeListener
!= null) {
117 btnRstre
.addSelectionListener(removeListener
);
120 createControls(this, style
);
126 * Init gets executed before any other setup of the section takes place
128 * Implement this if you want to configure the section
131 // default implementation is empty
136 * Setter for the field <code>entity</code>.
142 public abstract void setEntity(ENTITY entity
);
146 * Getter for the field <code>entity</code>.
149 * @return a ENTITY object.
152 public ENTITY
getEntity() {
162 * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
167 public abstract void createControls(ICdmFormElement element
, int style
);
170 * Mark <code>this</code> element as selected.
173 public void setSelected(boolean selected
) {
175 for (ICdmFormElement element
: getElements()) {
176 if (element
instanceof ISelectable
) {
177 ((ISelectable
) element
).setSelected(selected
);
180 setBackground(selected ? SELECTED
: getPersistentBackground());
187 * eu.etaxonomy.taxeditor.forms.AbstractCdmFormElement#propertyChange(org
188 * .eclipse.jface.util.PropertyChangeEvent)
192 public void propertyChange(PropertyChangeEvent event
) {
196 Object eventSource
= event
.getSource();
197 if (getElements().contains(eventSource
)) {
198 handleEvent(eventSource
);
208 * a {@link java.lang.Object} object.
210 public abstract void handleEvent(Object eventSource
);
214 public void setBackground(Color color
) {
216 backgroundColor
= color
;
217 super.setBackground(color
);
218 // box.setBackground(color);
219 // container.setBackground(color);
226 * React when selection occurs
229 public void widgetSelected(SelectionEvent e
) {
235 public void widgetDefaultSelected(SelectionEvent e
) {
240 public Composite
getLayoutComposite() {
246 * Getter for the field <code>backgroundColor</code>.
249 * @return the backgroundColor
251 public Color
getBackgroundColor() {
252 return backgroundColor
;
257 * getConversationHolder
260 * @return a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder}
264 public ConversationHolder
getConversationHolder() {
265 if (getParentElement() instanceof IConversationEnabled
) {
266 return ((IConversationEnabled
) getParentElement()).getConversationHolder();
268 throw new IllegalArgumentException("Parent element should be IConversationEnabled");
273 public void update(CdmDataChangeMap changeEvents
) {