return section;
}
- /**
- * <p>
- * createEntityCollectionElement
- * </p>
- *
- * @param removeListener
- * a {@link org.eclipse.swt.events.SelectionListener} object.
- * @param style
- * a int.
- * @param parentElement
- * a
- * {@link eu.etaxonomy.taxeditor.ui.element.AbstractFormSection}
- * object.
- * @param versionableEntity
- * a {@link eu.etaxonomy.cdm.model.common.IVersionableEntity}
- * object.
- * @param backgroundColor
- * a {@link org.eclipse.swt.graphics.Color} object.
- * @return a
- * {@link eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionElement}
- * object.
- */
public AbstractEntityCollectionElement createEntityCollectionElement(AbstractFormSection parentElement,
Object versionableEntity, SelectionListener removeListener, Color backgroundColor, int style) {
AbstractEntityCollectionElement element = null;
} else if (entity instanceof Marker) {
element = new MarkerElement(this, parentElement, (Marker) entity, removeListener, style);
} else if (entity instanceof Media) {
- element = new MediaMetaElement(this, parentElement, (Media) entity, removeListener, style);
+ element = new MediaMetaElement(this, parentElement, (Media) entity, removeListener, true, style);
} else if (entity instanceof MediaRepresentation) {
element = new MediaRepresentationElement(this, parentElement, (MediaRepresentation) entity, removeListener,
style);
} else if (entity instanceof IdentifiableSource) {
element = new IdentifiableSourceElement(this, parentElement, (IdentifiableSource) entity, removeListener,
style);
- } else if (entity instanceof DefinedTerm) {
- switch(((DefinedTerm)entity).getTermType()) {
- case Scope:
- element = new ScopeElement(this,
- parentElement,
- (DefinedTerm) entity,
- removeListener,
- style);
- break;
- case Modifier:
- element = new ModifierElement(this,
- parentElement,
- (DefinedTerm) entity,
- removeListener,
- style);
- break;
- default:
- //FIXME : Actually we should through an exception here
- element = null;
- break;
-
- }
+ } else if (entity instanceof DefinedTerm) {
+ switch(((DefinedTerm)entity).getTermType()) {
+ case Scope:
+ element = new ScopeElement(this,
+ parentElement,
+ (DefinedTerm) entity,
+ removeListener,
+ style);
+ break;
+ case Modifier:
+ element = new ModifierElement(this,
+ parentElement,
+ (DefinedTerm) entity,
+ removeListener,
+ style);
+ break;
+ default:
+ //FIXME : Actually we should through an exception here
+ element = null;
+ break;
+
+ }
} else if (entity instanceof Reference) {
if(parentElement instanceof SequenceReferenceCollectionDetailSection){
element = new SequenceReferenceCollectionDetailElement(this, parentElement, (Reference) entity, removeListener, style);
element = new StatisticalMeasurementValueElement(this, parentElement, (StatisticalMeasurementValue) entity,
removeListener, style);
} else if (entity instanceof DerivedUnit) {
- switch(((DerivedUnit)entity).getRecordBasis()) {
- case LivingSpecimen:
- case PreservedSpecimen:
- case OtherSpecimen:
- element = new SpecimenCollectionDetailElement(this,
- parentElement,
- (DerivedUnit) entity,
- removeListener,
- style);
- break;
- default:
- element = new DerivedUnitElement(this,
- parentElement,
- (DerivedUnit) entity,
- removeListener,
- style);
- }
+ switch(((DerivedUnit)entity).getRecordBasis()) {
+ case LivingSpecimen:
+ case PreservedSpecimen:
+ case OtherSpecimen:
+ element = new SpecimenCollectionDetailElement(this,
+ parentElement,
+ (DerivedUnit) entity,
+ removeListener,
+ style);
+ break;
+ default:
+ element = new DerivedUnitElement(this,
+ parentElement,
+ (DerivedUnit) entity,
+ removeListener,
+ style);
+ }
} else if (entity instanceof NamedArea) {
element = new NamedAreaDetailElement(this, parentElement, (NamedArea) entity, removeListener, style);
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Layout;
+import org.eclipse.swt.widgets.Listener;
import org.eclipse.ui.forms.widgets.TableWrapLayout;
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
private final Composite box;
- private Button button_remove;
+ private Button btnRemove;
+ private Button btnChooseEntity;
private Color backgroundColor;
* 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) {
+ this(formFactory, section, entity, removeListener, false, backgroundColor, style);
+ }
+ public AbstractEntityCollectionElement(CdmFormFactory formFactory,
+ AbstractFormSection section, ENTITY entity, SelectionListener removeListener,
+ boolean isChoosableEntity, Color backgroundColor, int style) {
super(formFactory, (ICdmFormElement) section);
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(3, 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);
container.setLayout(containerLayout);
container.setLayoutData(LayoutConstants.FILL_HORIZONTALLY());
+ if(isChoosableEntity){
+ btnChooseEntity = formFactory.createButton(box, null, SWT.PUSH);
+ addControl(btnChooseEntity);
+ btnChooseEntity.setLayoutData(LayoutConstants.RIGHT());
+ btnChooseEntity.setImage(ImageResources.getImage(ImageResources.BROWSE_ICON));
+ btnChooseEntity.setToolTipText("Browse");
+ btnChooseEntity.addListener(SWT.Selection, new Listener() {
+
+ @Override
+ public void handleEvent(Event event) {
+ ENTITY entity = selectFromDialog();
+ if(entity!=null){
+ if(getParentElement() instanceof AbstractEntityCollectionSection){
+ ((AbstractEntityCollectionSection)getParentElement()).removeElement(getEntity());
+ setEntity(entity);
+ ((AbstractEntityCollectionSection)getParentElement()).addElement(entity);
+ ((AbstractEntityCollectionSection)getParentElement()).firePropertyChangeEvent(getParentElement());
+ }
+ }
+ }
+ });
+ }
+
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);
return entity;
}
+ /**
+ * 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;
+ }
+
/**
* <p>
* createControls
import eu.etaxonomy.cdm.model.agent.AgentBase;
import eu.etaxonomy.cdm.model.common.LanguageString;
import eu.etaxonomy.cdm.model.media.Media;
+import eu.etaxonomy.taxeditor.model.AbstractUtility;
import eu.etaxonomy.taxeditor.store.CdmStore;
+import eu.etaxonomy.taxeditor.ui.dialog.selection.MediaSelectionDialog;
import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection;
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
*/
public MediaMetaElement(CdmFormFactory cdmFormFactory,
AbstractFormSection<?> formElement, Media element,
- SelectionListener removeListener, int style) {
- super(cdmFormFactory, formElement, element, removeListener, null, style);
+ SelectionListener removeListener, boolean isChoosableEntity, int style) {
+ super(cdmFormFactory, formElement, element, removeListener, isChoosableEntity, null, style);
}
/*
/** {@inheritDoc} */
@Override
public void createControls(ICdmFormElement element, int style) {
+
text_title = formFactory.createLanguageStringWithLabelElement(element, "Title", null, style);
selection_artist = formFactory.createSelectionElement(AgentBase.class, getConversationHolder(), element, "Artist", null, EntitySelectionElement.ALL, style);
text_description = formFactory.createLanguageStringWithLabelElement(element, "Description", null, 100, true, style);
text_title.setLanguageString(title);
}
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionElement#selectFromDialog()
+ */
+ @Override
+ protected Media selectFromDialog() {
+ return MediaSelectionDialog.select(AbstractUtility.getShell(), null, null);
+ }
+
public void toggleAdvancedMediaView(){
mediaDetailElement.toggleAdvancedMediaView();
}