import java.util.ArrayList;
import java.util.Collection;
+import java.util.Set;
+import java.util.UUID;
import org.eclipse.core.commands.Command;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.jface.viewers.DoubleClickEvent;
import org.eclipse.jface.viewers.IDoubleClickListener;
import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Label;
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
import eu.etaxonomy.cdm.api.service.IOccurrenceService;
+import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation;
+import eu.etaxonomy.cdm.model.name.TaxonNameBase;
+import eu.etaxonomy.cdm.model.occurrence.DeterminationEvent;
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
import eu.etaxonomy.taxeditor.model.MessagingUtils;
import eu.etaxonomy.taxeditor.store.CdmStore;
*/
public class TaxonAssociationDetailElement extends AbstractCdmDetailElement<DerivedUnitFacade> implements IDoubleClickListener{
- private TableViewer associationsViewer;
-
public TaxonAssociationDetailElement(CdmFormFactory formFactory, ICdmFormElement formElement) {
super(formFactory, formElement);
}
//TODO add context menu for deleting associations
- Collection<TaxonBase<?>> associatedTaxa = CdmStore.getService(IOccurrenceService.class).listAssociatedTaxa(entity.innerDerivedUnit(), null, null, null, null);
+ Collection<TaxonBase<?>> associatedTaxa = CdmStore.getService(IOccurrenceService.class).listIndividualsAssociationTaxa(entity.innerDerivedUnit(), null, null, null, null);
+ Collection<SpecimenTypeDesignation> typeDesignations = CdmStore.getService(IOccurrenceService.class).listTypeDesignations(entity.innerDerivedUnit(), null, null, null, null);
+ Collection<DeterminationEvent> determinationEvents = CdmStore.getService(IOccurrenceService.class).listDeterminationEvents(entity.innerDerivedUnit(), null, null, null, null);
- if(!associatedTaxa.isEmpty()){
- associationsViewer = new TableViewer(getLayoutComposite(), SWT.FULL_SELECTION);
- associationsViewer.getTable().setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
- associationsViewer.setContentProvider(new ArrayContentProvider());
- associationsViewer.setInput(associatedTaxa);
- associationsViewer.addDoubleClickListener(this);
- }
- else{
+ if(associatedTaxa.isEmpty() && typeDesignations.isEmpty() && determinationEvents.isEmpty()){
Label label = formFactory.createLabel(getLayoutComposite(), "No associations");
label.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
+ return;
+ }
+ if(!associatedTaxa.isEmpty()){
+ TableViewer viewer = new TableViewer(getLayoutComposite(), SWT.FULL_SELECTION);
+ viewer.getTable().setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
+ viewer.setContentProvider(new ArrayContentProvider());
+ viewer.setLabelProvider(new LabelProvider(){
+ @Override
+ public String getText(Object element) {
+ return "Associated with "+element.toString();
+ }
+ });
+ viewer.setInput(associatedTaxa);
+ viewer.addDoubleClickListener(this);
+ }
+ if(!typeDesignations.isEmpty()){
+ TableViewer viewer = new TableViewer(getLayoutComposite(), SWT.FULL_SELECTION);
+ viewer.getTable().setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
+ viewer.setContentProvider(new ArrayContentProvider());
+ viewer.setLabelProvider(new LabelProvider(){
+ @Override
+ public String getText(Object element) {
+ SpecimenTypeDesignation typeDesignation = (SpecimenTypeDesignation)element;
+ String label = typeDesignation.getTypeStatus().getLabel()+" of ";
+ Set<TaxonNameBase> typifiedNames = typeDesignation.getTypifiedNames();
+ for (TaxonNameBase taxonNameBase : typifiedNames) {
+ label += taxonNameBase+", ";
+ }
+ if(label.endsWith(", ")){
+ label = label.substring(0, label.length()-2);
+ }
+ return label;
+ }
+ });
+ viewer.setInput(typeDesignations);
+ viewer.addDoubleClickListener(this);
+ }
+ if(!determinationEvents.isEmpty()){
+ TableViewer viewer = new TableViewer(getLayoutComposite(), SWT.FULL_SELECTION);
+ viewer.getTable().setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
+ viewer.setContentProvider(new ArrayContentProvider());
+ viewer.setLabelProvider(new LabelProvider(){
+ @Override
+ public String getText(Object element) {
+ DeterminationEvent determinationEvent = (DeterminationEvent)element;
+ if(determinationEvent.getTaxon()!=null){
+ return "Determined as taxon "+determinationEvent.getTaxon();
+ }
+ if(determinationEvent.getTaxonName()!=null){
+ return "Determined as name "+determinationEvent.getTaxonName();
+ }
+ return element.toString();
+ }
+ });
+ viewer.setInput(determinationEvents);
+ viewer.addDoubleClickListener(this);
}
-
}
/** {@inheritDoc} */
public void doubleClick(DoubleClickEvent event) {
if(event.getSelection() instanceof IStructuredSelection){
Object firstElement = ((IStructuredSelection) event.getSelection()).getFirstElement();
+ UUID taxonToOpenUuid = null;
if(firstElement instanceof TaxonBase<?>){
- TaxonBase<?> taxonBase = (TaxonBase<?>)firstElement;
+ taxonToOpenUuid = ((TaxonBase<?>)firstElement).getUuid();
+ }
+ else if(firstElement instanceof SpecimenTypeDesignation){
+ //TODO how to open an editor for all typed names?
+ }
+ else if(firstElement instanceof DeterminationEvent){
+ if(((DeterminationEvent) firstElement).getTaxon()!=null){
+ taxonToOpenUuid = ((DeterminationEvent) firstElement).getTaxon().getUuid();
+ }
+ else if(((DeterminationEvent) firstElement).getTaxonName()!=null){
+ //TODO how to open editor for taxon name
+ }
+ }
+ if(taxonToOpenUuid!=null){
String commandId = "eu.etaxonomy.taxeditor.editor.openTaxonEditor";
} catch (NotDefinedException e1) {
MessagingUtils.error(this.getClass(), "Command not defined", e1);
}
- Parameterization params = new Parameterization(iparam, (taxonBase).getUuid().toString());
+ Parameterization params = new Parameterization(iparam, taxonToOpenUuid.toString());
parameters.add(params);
//build the parameterized command
}
}
}
-
}