-// $Id$
/**
* Copyright (C) 2007 EDIT
* European Distributed Institute of Taxonomy
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Layout;
import org.eclipse.ui.forms.widgets.TableWrapLayout;
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
import eu.etaxonomy.taxeditor.model.ImageResources;
-import eu.etaxonomy.taxeditor.ui.campanula.compatibility.ICdmFormElement;
import eu.etaxonomy.taxeditor.ui.element.AbstractCdmFormElement;
import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection;
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
+import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
import eu.etaxonomy.taxeditor.ui.element.IEntityElement;
import eu.etaxonomy.taxeditor.ui.element.ISelectable;
import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
/**
- * <p>
- * Abstract AbstractEntityCollectionElement class.
- * </p>
+ * Visualizes an element of type ENTITY in an {@link AbstractEntityCollectionSection}
+ * and links listener functionalities to it.
+ *
+ * @param ENTITY the type of the element which is visualized by this class
*
* @author n.hoffmann
* @created Nov 16, 2009
- * @version 1.0
*/
public abstract class AbstractEntityCollectionElement<ENTITY> extends
AbstractCdmFormElement implements IEntityElement<ENTITY>,
- SelectionListener, IConversationEnabled, ISelectable {
+ SelectionListener, IConversationEnabled {
protected ENTITY entity;
private final Composite container;
+ /**
+ * Composite "around" the actual content. Is used for control action like e.g. remove button
+ */
private final Composite box;
- private Button button_remove;
+ private Button btnRemove;
+ protected Button btnChooseEntity;
private Color backgroundColor;
- /**
- * <p>
- * Constructor for AbstractEntityCollectionElement.
- * </p>
- *
- * @param style
- * a int.
- * @param formFactory
- * a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
- * object.
- * @param section
- * a {@link eu.etaxonomy.taxeditor.ui.element.AbstractFormSection}
- * object.
- * @param entity
- * a ENTITY object.
- * @param removeListener
- * a {@link org.eclipse.swt.events.SelectionListener} object.
- * @param <ENTITY>
- * a ENTITY object.
- */
public AbstractEntityCollectionElement(CdmFormFactory formFactory,
- AbstractFormSection section, ENTITY entity,
- SelectionListener removeListener, Color backgroundColor, int style) {
+ AbstractFormSection section, ENTITY entity, SelectionListener removeListener,
+ Color backgroundColor, int style) {
super(formFactory, (ICdmFormElement) section);
+ this.entity = entity;
init();
formFactory.addPropertyChangeListener(this);
- // section.getLayoutComposite().setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_CYAN));
-
box = formFactory.createComposite(section.getLayoutComposite());
box.setBackgroundMode(SWT.INHERIT_DEFAULT);
addControl(box);
- TableWrapLayout boxLayout = LayoutConstants.LAYOUT(2, false);
+ TableWrapLayout boxLayout = LayoutConstants.LAYOUT(4, false);
boxLayout.topMargin = 4;
boxLayout.bottomMargin = 4;
box.setLayout(boxLayout);
box.setLayoutData(LayoutConstants.FILL_HORIZONTALLY());
- // box.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_BLUE));
-
container = formFactory.createComposite(box);
container.setBackgroundMode(SWT.INHERIT_DEFAULT);
- // container.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_RED));
setLayoutComposite(container);
addControl(container);
- Layout containerLayout = LayoutConstants.LAYOUT(2, false);
+ TableWrapLayout containerLayout = LayoutConstants.LAYOUT(2, false);
+ containerLayout.horizontalSpacing = 5;
container.setLayout(containerLayout);
container.setLayoutData(LayoutConstants.FILL_HORIZONTALLY());
if (removeListener != null) {
- button_remove = formFactory.createButton(box, null, SWT.PUSH);
- addControl(button_remove);
- button_remove.setLayoutData(LayoutConstants.RIGHT());
- button_remove.setImage(ImageResources
+ btnRemove = formFactory.createButton(box, null, SWT.PUSH);
+ addControl(btnRemove);
+ btnRemove.setLayoutData(LayoutConstants.RIGHT());
+ btnRemove.setImage(ImageResources
.getImage(ImageResources.TRASH_ICON));
- button_remove.setToolTipText("Remove");
+ btnRemove.setToolTipText("Remove");
- button_remove.addSelectionListener(removeListener);
+ btnRemove.addSelectionListener(removeListener);
}
createControls(this, style);
// default implementation is empty
}
- /**
- * <p>
- * Setter for the field <code>entity</code>.
- * </p>
- *
- * @param entity
- * a ENTITY object.
- */
public abstract void setEntity(ENTITY entity);
- /**
- * <p>
- * Getter for the field <code>entity</code>.
- * </p>
- *
- * @return a ENTITY object.
- */
@Override
public ENTITY getEntity() {
return entity;
}
/**
- * <p>
- * createControls
- * </p>
- *
- * @param element
- * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
- * object.
- * @param style
- * a int.
+ * Sub classes should override to provide the functionality to choose the
+ * entity from existing ones from the data source.<br>
+ * <b>Note:</b> to enable this functionality sub classes have to set
+ * the corresponding flag in the super constructor
+ * @return an existing entity from the data source
*/
+ protected ENTITY selectFromDialog(){
+ return null;
+ }
+
public abstract void createControls(ICdmFormElement element, int style);
/**
setBackground(selected ? SELECTED : getPersistentBackground());
}
- /*
- * (non-Javadoc)
- *
- * @see
- * eu.etaxonomy.taxeditor.forms.AbstractCdmFormElement#propertyChange(org
- * .eclipse.jface.util.PropertyChangeEvent)
- */
/** {@inheritDoc} */
@Override
public void propertyChange(PropertyChangeEvent event) {
return;
}
Object eventSource = event.getSource();
- if (getElements().contains(eventSource)) {
+ if (getElements().contains(eventSource) || getControls().contains(eventSource)) {
handleEvent(eventSource);
}
}
- /**
- * <p>
- * handleEvent
- * </p>
- *
- * @param eventSource
- * a {@link java.lang.Object} object.
- */
public abstract void handleEvent(Object eventSource);
/** {@inheritDoc} */
@Override
public void setBackground(Color color) {
+ if(box.isDisposed() || container.isDisposed()){
+ return;
+ }
backgroundColor = color;
super.setBackground(color);
box.setBackground(color);
return container;
}
- /**
- * <p>
- * Getter for the field <code>backgroundColor</code>.
- * </p>
- *
- * @return the backgroundColor
- */
public Color getBackgroundColor() {
return backgroundColor;
}
- /**
- * <p>
- * getConversationHolder
- * </p>
- *
- * @return a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder}
- * object.
- */
+ public Composite getBox() {
+ return box;
+ }
+
@Override
public ConversationHolder getConversationHolder() {
if (getParentElement() instanceof IConversationEnabled) {