import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
import eu.etaxonomy.taxeditor.editor.Messages;
+import eu.etaxonomy.taxeditor.editor.view.derivate.searchFilter.DerivateSearchCompositeController;
import eu.etaxonomy.taxeditor.model.IDirtyMarkable;
import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
import eu.etaxonomy.taxeditor.model.IPartContentHasFactualData;
import eu.etaxonomy.taxeditor.model.IPartContentHasSupplementalData;
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
import eu.etaxonomy.taxeditor.store.CdmStore;
+import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
import eu.etaxonomy.taxeditor.view.derivateSearch.DerivateContentProvider;
import eu.etaxonomy.taxeditor.view.derivateSearch.DerivateLabelProvider;
private DerivateContentProvider contentProvider;
+ private DerivateSearchCompositeController derivateSearchCompositeController;
+
/**
* Default constructor
*/
@Override
public void createPartControl(Composite parent) {
+
+ parent.setLayout(LayoutConstants.LAYOUT());
+ parent.setLayoutData(LayoutConstants.FILL());
+
+ //---search and filter---
+ derivateSearchCompositeController = new DerivateSearchCompositeController(parent, this);
+ derivateSearchCompositeController.setEnabled(CdmStore.isActive());
+ derivateSearchCompositeController.setLayoutData(LayoutConstants.FILL_HORIZONTALLY());
+
+ //---tree viewer---
viewer = new TreeViewer(new Tree(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION));
+ viewer.getTree().setLayoutData(LayoutConstants.FILL());
contentProvider = new DerivateContentProvider();
viewer.setContentProvider(contentProvider);
labelProvider = new DerivateLabelProvider();
--- /dev/null
+package eu.etaxonomy.taxeditor.editor.view.derivate.searchFilter;
+
+import java.util.ArrayList;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.TreeNode;
+import org.eclipse.jface.viewers.Viewer;
+
+import eu.etaxonomy.cdm.model.molecular.DnaSample;
+import eu.etaxonomy.cdm.model.molecular.Sequence;
+import eu.etaxonomy.cdm.model.molecular.SingleRead;
+import eu.etaxonomy.cdm.model.occurrence.DerivationEvent;
+import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
+import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
+import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType;
+
+public class DerivateContentProvider implements ITreeContentProvider {
+
+ List<TreeNode> rootNodes;
+
+ @Override
+ public void dispose() {
+ // TODO Auto-generated method stub
+
+ }
+
+ public List<SpecimenOrObservationBase> getRootElements() {
+ List<SpecimenOrObservationBase> elements = new ArrayList<SpecimenOrObservationBase>();
+
+ if(rootNodes != null) {
+ for(TreeNode node : rootNodes) {
+ elements.add((SpecimenOrObservationBase)node.getValue());
+ }
+ }
+ return elements;
+ }
+
+ @Override
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ }
+
+ @Override
+ public Object[] getElements(Object inputElement) {
+ rootNodes = new ArrayList<TreeNode>();
+ if(inputElement instanceof Set){
+ for (Object o: (Set)inputElement) {
+ if(o instanceof SpecimenOrObservationBase){
+ SpecimenOrObservationBase<?> rootElement = (SpecimenOrObservationBase<?>)o;
+ if(rootElement!=null){
+ rootNodes.add(new TreeNode(rootElement));
+ }
+ }
+ }
+ }
+ return rootNodes.toArray();
+ }
+
+ @Override
+ public Object[] getChildren(Object element) {
+ TreeNode currentnode = null;
+ Object value = null;
+ if(element instanceof TreeNode){
+ currentnode = (TreeNode) element;
+ value = ((TreeNode) element).getValue();
+ }
+ Set<Object> children = new LinkedHashSet<Object>();
+ if(value instanceof DnaSample && ((DnaSample) value).getRecordBasis()==SpecimenOrObservationType.DnaSample){
+ DnaSample dnaSample = (DnaSample)value;
+ Set<Sequence> sequences = dnaSample.getSequences();
+ for (Sequence sequence : sequences) {
+ TreeNode node = new TreeNode(sequence);
+ node.setParent(currentnode);
+ children.add(node);
+ }
+ }
+ else if(value instanceof Sequence){
+ Set<SingleRead> singleReads = ((Sequence) value).getSingleReads();
+ for(SingleRead singleRead:singleReads){
+ TreeNode node = new TreeNode(singleRead);
+ node.setParent(currentnode);
+ children.add(node);
+ }
+ return children.toArray();
+ }
+
+ if(value instanceof SpecimenOrObservationBase){
+ List<DerivedUnit> derivates = getDerivates((SpecimenOrObservationBase<?>) value);
+ for (DerivedUnit derivedUnit:derivates) {
+ TreeNode node = new TreeNode(derivedUnit);
+ node.setParent(currentnode);
+ children.add(node);
+ }
+ return children.toArray();
+ }
+ return null;
+ }
+
+ @Override
+ public Object getParent(Object element) {
+ if(element instanceof TreeNode){
+ return ((TreeNode) element).getParent();
+ }
+ return null;
+ }
+
+ @Override
+ public boolean hasChildren(Object element) {
+ if(element instanceof TreeNode){
+ element = ((TreeNode) element).getValue();
+ }
+
+ if(element instanceof DnaSample && ((DnaSample) element).getRecordBasis()==SpecimenOrObservationType.DnaSample){
+ DnaSample dnaSample = (DnaSample)element;
+ if(!dnaSample.getSequences().isEmpty()){// || !dnaSample.getAmplifications().isEmpty()){
+ return true;
+ }
+ }
+ else if(element instanceof Sequence){
+ return !((Sequence)element).getSingleReads().isEmpty();
+ }
+
+ if(element instanceof SpecimenOrObservationBase){
+ SpecimenOrObservationBase<?> specimenOrObservation = (SpecimenOrObservationBase<?>)element;
+ for(DerivationEvent event:specimenOrObservation.getDerivationEvents()){
+ if(!event.getDerivatives().isEmpty()){
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ private List<DerivedUnit> getDerivates(SpecimenOrObservationBase<?> specimenOrObservation){
+ List<DerivedUnit> derivates = new ArrayList<DerivedUnit>();
+ for(DerivationEvent derivationEvent:specimenOrObservation.getDerivationEvents()){
+ derivates.addAll(derivationEvent.getDerivatives());
+ }
+ return derivates;
+ }
+
+}
--- /dev/null
+// $Id$
+/**
+* Copyright (C) 2013 EDIT
+* European Distributed Institute of Taxonomy
+* http://www.e-taxonomy.eu
+*
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+package eu.etaxonomy.taxeditor.editor.view.derivate.searchFilter;
+
+import java.util.List;
+import java.util.Set;
+import java.util.UUID;
+
+import org.eclipse.jface.viewers.ColumnLabelProvider;
+import org.eclipse.jface.viewers.TreeNode;
+import org.eclipse.swt.graphics.Image;
+import org.hibernate.LazyInitializationException;
+
+import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
+import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
+import eu.etaxonomy.cdm.model.common.CdmBase;
+import eu.etaxonomy.cdm.model.common.DefinedTerm;
+import eu.etaxonomy.cdm.model.common.Identifier;
+import eu.etaxonomy.cdm.model.molecular.DnaSample;
+import eu.etaxonomy.cdm.model.molecular.Sequence;
+import eu.etaxonomy.cdm.model.molecular.SingleRead;
+import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
+import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
+import eu.etaxonomy.cdm.model.occurrence.GatheringEvent;
+import eu.etaxonomy.cdm.model.occurrence.MediaSpecimen;
+import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
+import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType;
+import eu.etaxonomy.taxeditor.model.ImageResources;
+import eu.etaxonomy.taxeditor.store.CdmStore;
+
+/**
+ * Label provider for the views to show {@link SpecimenOrObservationBase}s.<br>
+ * <br>
+ * <b>Note:</b> If you use this label provider you need to assure that you
+ * created a {@link ConversationHolder} resp. have an open session because
+ * the labels are generated from various fields of the derivate hierarchy which
+ * are lazy loaded and could therefore throw a {@link LazyInitializationException}.<br>
+ * Use <b>{@link #setConversation(ConversationHolder)}</b> to assign the session to this provider.
+ */
+public class DerivateLabelProvider extends ColumnLabelProvider {
+
+ private static final String NO_SAMPLE_DESIGNATION = "[no sample designation]";
+
+ private Set<SingleRead> multiLinkSingleReads;
+
+ private ConversationHolder conversation;
+
+ private static DefinedTerm photoTerm = null;
+ private static DefinedTerm drawingTerm = null;
+ private static DefinedTerm specimenScanTerm = null;
+ private static DefinedTerm detailImageTerm = null;
+ private static DefinedTerm sampleDesignationTerm = null;
+
+ //FIXME: move static term getters to new singleton utility class
+ private static void initializeTerms() {
+ List<DefinedTerm> preferredTerms = CdmStore.getTermManager().getPreferredTerms(DefinedTerm.class);
+ for (DefinedTerm definedTerm : preferredTerms) {
+ if(definedTerm.getUuid().equals(UUID.fromString("c5c59c42-f254-471e-96c6-09f459f7c903"))){
+ photoTerm = definedTerm;
+ }
+ else if(definedTerm.getUuid().equals(UUID.fromString("669b0409-4aa4-4695-aae4-a95ed27bad4c"))){
+ drawingTerm = definedTerm;
+ }
+ else if(definedTerm.getUuid().equals(UUID.fromString("acda15be-c0e2-4ea8-8783-b9b0c4ad7f03"))){
+ specimenScanTerm = definedTerm;
+ }
+ else if(definedTerm.getUuid().equals(UUID.fromString("31eb8d02-bf5d-437c-bcc6-87a626445f34"))){
+ detailImageTerm = definedTerm;
+ }
+ else if(definedTerm.getUuid().equals(UUID.fromString("fadeba12-1be3-4bc7-9ff5-361b088d86fc"))){
+ sampleDesignationTerm = definedTerm;
+ }
+ }
+ }
+
+ public static DefinedTerm getLivingPlantPhotoTerm(){
+ if(photoTerm==null){
+ initializeTerms();
+ }
+ return photoTerm;
+ }
+
+ public static DefinedTerm getArtworkTerm(){
+ if(drawingTerm==null){
+ initializeTerms();
+ }
+ return drawingTerm;
+ }
+
+ public static DefinedTerm getSpecimenScanTerm(){
+ if(specimenScanTerm==null){
+ initializeTerms();
+ }
+ return specimenScanTerm;
+ }
+
+ public static DefinedTerm getDetailImageTerm(){
+ if(detailImageTerm==null){
+ initializeTerms();
+ }
+ return detailImageTerm;
+ }
+
+ public static DefinedTerm getSampleDesignationTerm(){
+ if(sampleDesignationTerm==null){
+ initializeTerms();
+ }
+ return sampleDesignationTerm;
+ }
+
+
+ /** {@inheritDoc} */
+ @Override
+ public String getText(Object element) {
+ return getDerivateText(element);
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public String getToolTipText(Object element) {
+ return getDerivateText(element);
+ }
+
+ /**
+ * @param conversation the conversation to set
+ */
+ public void setConversation(ConversationHolder conversation) {
+ this.conversation = conversation;
+ }
+
+ public String getDerivateText(Object element){
+ return getDerivateText(element, conversation);
+ }
+
+ public static String getDerivateText(Object element, ConversationHolder conversation){
+ //TODO: use list of strings to assemble labels to avoid adding the separator every time and to allow null values
+ TreeNode parentNode = null;
+ TreeNode node = null;
+ Object derivate = element;
+ if(element instanceof TreeNode){
+ node = (TreeNode) element;
+ parentNode = node.getParent();
+ //unwrap specimen from TreeNode
+ derivate = node.getValue();
+ }
+
+ conversation.bind();
+
+ final String emptyString = "";
+ final String separator = " ";
+
+ String label = emptyString;
+
+ //Field Unit
+ if(derivate instanceof FieldUnit){
+ FieldUnit fieldUnit = (FieldUnit)derivate;
+ if(fieldUnit.getGatheringEvent()!=null){
+ GatheringEvent gatheringEvent = fieldUnit.getGatheringEvent();
+ label += gatheringEvent.getCountry()!=null?gatheringEvent.getCountry().getLabel()+separator:emptyString;
+ label += gatheringEvent.getLocality()!=null?gatheringEvent.getLocality().getText()+separator:emptyString;
+ label += gatheringEvent.getGatheringDate()!=null?gatheringEvent.getGatheringDate()+separator:emptyString;
+ label += gatheringEvent.getCollector()!=null?gatheringEvent.getCollector()+separator:emptyString;
+ }
+ label += fieldUnit.getFieldNumber()!=null?fieldUnit.getFieldNumber():emptyString;
+ }
+ //MediaSpecimen
+ else if(derivate instanceof MediaSpecimen){
+ MediaSpecimen mediaSpecimen = (MediaSpecimen)derivate;
+ if(mediaSpecimen.getMediaSpecimen()!=null){
+ label += mediaSpecimen.getMediaSpecimen().getTitle()!=null?mediaSpecimen.getMediaSpecimen().getTitle().getText()+separator:"[no motif]";
+ label += mediaSpecimen.getMediaSpecimen().getArtist()!=null?mediaSpecimen.getMediaSpecimen().getArtist()+separator:emptyString;
+ }
+ eu.etaxonomy.cdm.model.occurrence.Collection collection = mediaSpecimen.getCollection();
+ if(collection!=null){
+ label += collection.getName()!=null?collection.getName()+" ":emptyString;
+ label += collection.getCode()!=null?"("+collection.getCode()+")"+separator:emptyString;
+ }
+ label += mediaSpecimen.getAccessionNumber()!=null?mediaSpecimen.getAccessionNumber()+separator:emptyString;
+ label += mediaSpecimen.getBarcode()!=null?mediaSpecimen.getBarcode()+separator:emptyString;
+ }
+ //TissueSample + DnaSample
+ else if(derivate instanceof DnaSample){
+ DnaSample dnaSample = (DnaSample)derivate;
+ if(((DnaSample) derivate).getRecordBasis()==SpecimenOrObservationType.DnaSample){
+ Identifier<DnaSample> currentSampleDesignation = getCurrentSampleDesignation(dnaSample);
+ if(currentSampleDesignation!=null && currentSampleDesignation.getIdentifier()!=null){
+ label += currentSampleDesignation.getIdentifier()+separator;
+ }
+ else{
+ label += NO_SAMPLE_DESIGNATION+separator;
+ }
+ }
+ else if(((DnaSample) derivate).getRecordBasis()==SpecimenOrObservationType.TissueSample){
+ if(dnaSample.getKindOfUnit()!=null){
+ label += dnaSample.getKindOfUnit()+separator;
+ }
+ Identifier<DnaSample> currentSampleDesignation = getCurrentSampleDesignation(dnaSample);
+ if(currentSampleDesignation!=null && currentSampleDesignation.getIdentifier()!=null){
+ label += currentSampleDesignation.getIdentifier()+separator;
+ }
+ else{
+ label += NO_SAMPLE_DESIGNATION+separator;
+ }
+ }
+
+ }
+ //DerivedUnit + TissueSample
+ else if(derivate instanceof DerivedUnit){
+ DerivedUnit derivedUnit = (DerivedUnit)derivate;
+ if(derivedUnit.getRecordBasis()==SpecimenOrObservationType.PreservedSpecimen){
+ //java.util.Collection<FieldUnit> fieldUnits = CdmStore.getService(IOccurrenceService.class).getFieldUnits(derivedUnit.getUuid());
+ //TODO : This is not generic anymore for performance reasons
+ Set<SpecimenOrObservationBase> originals = derivedUnit.getOriginals();
+ if(originals!=null && originals.size() ==1) {
+ SpecimenOrObservationBase specimen = originals.iterator().next();
+ if(specimen instanceof FieldUnit) {
+ FieldUnit fieldUnit = (FieldUnit)specimen;
+ GatheringEvent gatheringEvent = fieldUnit.getGatheringEvent();
+ if(gatheringEvent!=null){
+ label += gatheringEvent.getCollector()!=null?gatheringEvent.getCollector()+separator:emptyString;
+ }
+ label += fieldUnit.getFieldNumber()!=null?fieldUnit.getFieldNumber()+separator:emptyString;
+ }
+ }
+
+ eu.etaxonomy.cdm.model.occurrence.Collection collection = derivedUnit.getCollection();
+ if(collection!=null){
+ label += collection.getCode()!=null?"("+collection.getCode()+")"+separator:emptyString;
+ }
+ String mostSignificantIdentifier = derivedUnit.getMostSignificantIdentifier();
+ label += mostSignificantIdentifier!=null?mostSignificantIdentifier+separator:emptyString;
+ }
+ else if(derivedUnit.getRecordBasis()==SpecimenOrObservationType.TissueSample){
+ //TissueSample should only be created by using it's own class
+ //in future using only one class with different SpecimenOrObservationTypes is desired
+// label += derivedUnit.getKindOfUnit() + NO_SAMPLE_DESIGNATION;
+ }
+ }
+ //Sequence
+ else if(derivate instanceof Sequence){
+ Sequence sequence = (Sequence)derivate;
+ Identifier<DnaSample> currentSampleDesignation = getCurrentSampleDesignation(sequence);
+ if(currentSampleDesignation!=null && currentSampleDesignation.getIdentifier()!=null){
+ label += currentSampleDesignation.getIdentifier()+separator;
+ }
+ else{
+ label += NO_SAMPLE_DESIGNATION+separator;
+ }
+ label += sequence.getDnaMarker()!=null?sequence.getDnaMarker():emptyString;
+ }
+ //SingleRead
+ else if(derivate instanceof SingleRead){
+ SingleRead singleRead = (SingleRead)derivate;
+ if(parentNode!=null && parentNode.getValue() instanceof Sequence){
+ Sequence sequence = (Sequence) parentNode.getValue();
+ Identifier<DnaSample> currentSampleDesignation = getCurrentSampleDesignation(sequence);
+ if(currentSampleDesignation!=null && currentSampleDesignation.getIdentifier()!=null){
+ label = currentSampleDesignation.getIdentifier()+separator;
+ }
+ else{
+ label += NO_SAMPLE_DESIGNATION+separator;
+ }
+ label += singleRead.getPrimer()!=null?singleRead.getPrimer().getLabel()+separator:emptyString;
+ if(sequence!=null && sequence.getDnaMarker()!=null){
+ label += sequence.getDnaMarker()+separator;
+ }
+ if(singleRead.getAmplificationResult()!=null && singleRead.getAmplificationResult().getAmplification()!=null){
+ label += singleRead.getAmplificationResult().getAmplification().getLabelCache()+separator;
+ }
+ }
+ }
+ //SOOB
+ else if(derivate instanceof SpecimenOrObservationBase){
+ SpecimenOrObservationBase<?> specimen = (SpecimenOrObservationBase<?>) derivate;
+ SpecimenOrObservationType type = specimen.getRecordBasis();
+ return specimen.getTitleCache() + (type!=null?" ["+type.toString()+"]":emptyString);
+ }
+ if(label.isEmpty()){
+ label = derivate.toString();
+ }
+ //remove last comma
+ else if(label.endsWith(separator)){
+ label = label.substring(0, label.length()-separator.length());
+ }
+ return label;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.ColumnLabelProvider#getImage(java.lang.Object)
+ */
+ @Override
+ public Image getImage(Object element) {
+ if(element instanceof TreeNode){
+ element = ((TreeNode) element).getValue();
+ }
+ if(element instanceof CdmBase){
+ CdmBase cdmBase = (CdmBase)element;
+ boolean hasCharacterData = false;
+ if(cdmBase.isInstanceOf(SpecimenOrObservationBase.class)){
+ SpecimenOrObservationBase<?> specimen = HibernateProxyHelper.deproxy(cdmBase, SpecimenOrObservationBase.class);
+ if(specimen.hasCharacterData()){
+ hasCharacterData = true;
+ }
+ }
+ if(cdmBase.isInstanceOf(FieldUnit.class)){
+ return hasCharacterData?ImageResources.getImage(ImageResources.FIELD_UNIT_CHARACTER_DATA):ImageResources.getImage(ImageResources.FIELD_UNIT);
+ }
+ else if(cdmBase.isInstanceOf(DerivedUnit.class)){
+ DerivedUnit derivedUnit = HibernateProxyHelper.deproxy(element, DerivedUnit.class);
+ if(derivedUnit.getRecordBasis()==SpecimenOrObservationType.FieldUnit){
+ return hasCharacterData?ImageResources.getImage(ImageResources.FIELD_UNIT_CHARACTER_DATA):ImageResources.getImage(ImageResources.FIELD_UNIT);
+ }
+ else if(derivedUnit.getRecordBasis()==SpecimenOrObservationType.DnaSample){
+ return hasCharacterData?ImageResources.getImage(ImageResources.DNA_SAMPLE_DERIVATE_CHARACTER_DATA):ImageResources.getImage(ImageResources.DNA_SAMPLE_DERIVATE);
+ }
+ else if(derivedUnit.getRecordBasis()==SpecimenOrObservationType.TissueSample){
+ return hasCharacterData?ImageResources.getImage(ImageResources.TISSUE_SAMPLE_DERIVATE_CHARACTER_DATA):ImageResources.getImage(ImageResources.TISSUE_SAMPLE_DERIVATE);
+ }
+ else if(derivedUnit.getRecordBasis()==SpecimenOrObservationType.PreservedSpecimen){
+ return hasCharacterData?ImageResources.getImage(ImageResources.SPECIMEN_DERIVATE_CHARACTER_DATA):ImageResources.getImage(ImageResources.SPECIMEN_DERIVATE);
+ }
+ else if(derivedUnit.getRecordBasis()==SpecimenOrObservationType.Media){
+ if(derivedUnit.getKindOfUnit()!=null){
+ if(derivedUnit.getKindOfUnit().equals(getArtworkTerm())){
+ return hasCharacterData?ImageResources.getImage(ImageResources.ARTWORK_DERIVATE_CHARACTER_DATA):ImageResources.getImage(ImageResources.ARTWORK_DERIVATE);
+ }
+ else if(derivedUnit.getKindOfUnit().equals(getLivingPlantPhotoTerm())){
+ return hasCharacterData?ImageResources.getImage(ImageResources.LIVING_PLANT_PHOTO_DERIVATE_CHARACTER_DATA):ImageResources.getImage(ImageResources.LIVING_PLANT_PHOTO_DERIVATE);
+ }
+ else if(derivedUnit.getKindOfUnit().equals(getSpecimenScanTerm())){
+ return hasCharacterData?ImageResources.getImage(ImageResources.SPECIMEN_SCAN_DERIVATE_CHARACTER_DATA):ImageResources.getImage(ImageResources.SPECIMEN_SCAN_DERIVATE);
+ }
+ else if(derivedUnit.getKindOfUnit().equals(getDetailImageTerm())){
+ return hasCharacterData?ImageResources.getImage(ImageResources.DETAIL_IMAGE_DERIVATE_CHARACTER_DATA):ImageResources.getImage(ImageResources.DETAIL_IMAGE_DERIVATE);
+ }
+ }
+ }
+ }
+ else if(cdmBase.isInstanceOf(Sequence.class)){
+ return ImageResources.getImage(ImageResources.SEQUENCE_DERIVATE);
+ }
+
+ else if(cdmBase.isInstanceOf(SingleRead.class)){
+ if(multiLinkSingleReads.contains(element)){
+ return ImageResources.getImage(ImageResources.SINGLE_READ_DERIVATE_MULTILINK);
+ }
+ else{
+ return ImageResources.getImage(ImageResources.SINGLE_READ_DERIVATE);
+ }
+ }
+ }
+ return super.getImage(element);
+ }
+
+ public static Identifier<DnaSample> getCurrentSampleDesignation(CdmBase entity) {
+ if(entity.isInstanceOf(DnaSample.class)){
+ DnaSample dnaSample = HibernateProxyHelper.deproxy(entity, DnaSample.class);
+ for (Identifier<DnaSample> identifier : dnaSample.getIdentifiers()) {
+ if(identifier.getType()!=null && identifier.getType().equals(DerivateLabelProvider.getSampleDesignationTerm())){
+ //first sample designation is the current
+ return identifier;
+ }
+ }
+ }
+ else if(entity.isInstanceOf(Sequence.class)){
+ Sequence sequence = HibernateProxyHelper.deproxy(entity, Sequence.class);
+ if(sequence.getDnaSample()!=null){
+ return getCurrentSampleDesignation(sequence.getDnaSample());
+ }
+ }
+ return null;
+ }
+
+ /**
+ * @param multiLinkSingleReads2
+ */
+ public void setMultiLinkSingleReads(Set<SingleRead> multiLinkSingleReads) {
+ this.multiLinkSingleReads = multiLinkSingleReads;
+ }
+
+}
--- /dev/null
+// $Id$
+/**
+ * Copyright (C) 2013 EDIT
+ * European Distributed Institute of Taxonomy
+ * http://www.e-taxonomy.eu
+ *
+ * The contents of this file are subject to the Mozilla Public License Version 1.1
+ * See LICENSE.TXT at the top of this package for the full license terms.
+ */
+package eu.etaxonomy.taxeditor.editor.view.derivate.searchFilter;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.forms.widgets.FormToolkit;
+import org.eclipse.wb.swt.ResourceManager;
+
+/**
+ * The widgets of the {@link DerivateSearchView}<br>
+ *
+ */
+public class DerivateSearchComposite extends Composite {
+ private final FormToolkit formToolkit = new FormToolkit(Display.getDefault());
+ private final Text searchField;
+ private final Combo comboDerivateType;
+ private final Button buttonSearch;
+ private final Button btnFilterUndeterminedSpecimen;
+ private final Text textTaxonName;
+ private final Button btnBrowseTaxa;
+ private final Label lblTaxon;
+ private final Label lblDerivateType;
+ private final Button btnClearTaxon;
+
+ /**
+ * Create the composite.
+ * @param parent
+ * @param style
+ */
+ public DerivateSearchComposite(Composite parent, int style) {
+ super(parent, style);
+ setLayout(new GridLayout(4, false));
+
+ lblTaxon = new Label(this, SWT.NONE);
+ lblTaxon.setText("Taxon");
+
+ textTaxonName = formToolkit.createText(this, "New Text", SWT.NONE);
+ textTaxonName.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
+ textTaxonName.setEnabled(false);
+ textTaxonName.setText("");
+
+ btnBrowseTaxa = formToolkit.createButton(this, "", SWT.NONE);
+ btnBrowseTaxa.setImage(ResourceManager.getPluginImage("eu.etaxonomy.taxeditor.store", "icons/open.gif"));
+
+ btnClearTaxon = formToolkit.createButton(this, "", SWT.NONE);
+ btnClearTaxon.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false, 1, 1));
+ btnClearTaxon.setImage(ResourceManager.getPluginImage("eu.etaxonomy.taxeditor.store", "icons/trash.gif"));
+
+ lblDerivateType = new Label(this, SWT.NULL);
+ lblDerivateType.setText("Derivative Type");
+
+ comboDerivateType = new Combo(this, SWT.READ_ONLY);
+ comboDerivateType.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
+ formToolkit.paintBordersFor(comboDerivateType);
+
+ btnFilterUndeterminedSpecimen = new Button(this, SWT.CHECK);
+ btnFilterUndeterminedSpecimen.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1));
+ btnFilterUndeterminedSpecimen.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ }
+ });
+ btnFilterUndeterminedSpecimen.setText("Determined");
+
+ buttonSearch = new Button(this, SWT.NONE);
+ formToolkit.adapt(buttonSearch, true, true);
+ buttonSearch.setText("Search");
+
+ searchField = formToolkit.createText(this, "New Text", SWT.NONE);
+ searchField.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
+ searchField.setText("");
+ new Label(this, SWT.NONE);
+ new Label(this, SWT.NONE);
+
+ }
+
+ @Override
+ protected void checkSubclass() {
+ // Disable the check that prevents subclassing of SWT components
+ }
+ public Text getSearchField() {
+ return searchField;
+ }
+ public Combo getComboDerivateType() {
+ return comboDerivateType;
+ }
+ public Button getButtonSearch() {
+ return buttonSearch;
+ }
+
+ @Override
+ public void setEnabled(boolean enabled){
+ super.setEnabled(enabled);
+ searchField.setEnabled(enabled);
+ comboDerivateType.setEnabled(enabled);
+ buttonSearch.setEnabled(enabled);
+ btnFilterUndeterminedSpecimen.setEnabled(enabled);
+ btnBrowseTaxa.setEnabled(enabled);
+ lblTaxon.setEnabled(enabled);
+ lblDerivateType.setEnabled(enabled);
+ }
+ public Button getBtnFilterUndeterminedSpecimen() {
+ return btnFilterUndeterminedSpecimen;
+ }
+ public Button getBtnBrowseTaxa() {
+ return btnBrowseTaxa;
+ }
+ public Text getTextTaxonName() {
+ return textTaxonName;
+ }
+ public Button getBtnClearTaxon() {
+ return btnClearTaxon;
+ }
+}
--- /dev/null
+// $Id$
+/**
+* Copyright (C) 2013 EDIT
+* European Distributed Institute of Taxonomy
+* http://www.e-taxonomy.eu
+*
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+package eu.etaxonomy.taxeditor.editor.view.derivate.searchFilter;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Widget;
+import org.eclipse.ui.forms.widgets.TableWrapData;
+
+import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
+import eu.etaxonomy.cdm.api.service.IOccurrenceService;
+import eu.etaxonomy.cdm.api.service.config.FindOccurrencesConfigurator;
+import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
+import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType;
+import eu.etaxonomy.cdm.model.taxon.Taxon;
+import eu.etaxonomy.taxeditor.editor.view.derivate.DerivateView;
+import eu.etaxonomy.taxeditor.store.CdmStore;
+import eu.etaxonomy.taxeditor.store.SearchManager;
+import eu.etaxonomy.taxeditor.ui.dialog.selection.SelectionDialogFactory;
+import eu.etaxonomy.taxeditor.ui.mvc.combo.EnumTermComboController;
+
+/**
+ * Controller class for the {@link DerivateSearchComposite}.<br>
+ * This controller contains the logic to search the data base for {@link SpecimenOrObservationBase}s
+ * and handles GUI events.
+ *
+ */
+public class DerivateSearchCompositeController implements Listener{
+
+ private final DerivateSearchComposite derivateSearchComposite;
+ private EnumTermComboController<SpecimenOrObservationType> comboSpecimenTypeController;
+ private DerivateLabelProvider labelProvider;
+ private Taxon selectedTaxon;
+ private DerivateView derivativeEditor;
+
+ public DerivateSearchCompositeController(Composite parent, DerivateView derivativeEditor) {
+ this.derivateSearchComposite = new DerivateSearchComposite(parent, SWT.NONE);
+ this.derivativeEditor = derivativeEditor;
+ init();
+ }
+
+ private void init(){
+ //derivate type combo
+ comboSpecimenTypeController = new EnumTermComboController<SpecimenOrObservationType>(derivateSearchComposite.getComboDerivateType(), null, null, SpecimenOrObservationType.class, 0);
+ comboSpecimenTypeController.setSelection(SpecimenOrObservationType.Unknown);
+
+ //add listeners
+ derivateSearchComposite.getSearchField().addListener(SWT.KeyDown, this);
+ derivateSearchComposite.getButtonSearch().addListener(SWT.Selection, this);
+ derivateSearchComposite.getBtnBrowseTaxa().addListener(SWT.Selection, this);
+ derivateSearchComposite.getBtnClearTaxon().addListener(SWT.Selection, this);
+
+ }
+
+ private void searchDerivates(){
+// if(!conversation.isBound()){
+// conversation.bind();
+// }
+
+ String queryString = derivateSearchComposite.getSearchField().getText();
+ SpecimenOrObservationType specimenType = comboSpecimenTypeController.getSelection();
+
+ FindOccurrencesConfigurator config = new FindOccurrencesConfigurator();
+ config.setAssociatedTaxonUuid(selectedTaxon!=null?selectedTaxon.getUuid():null);
+ config.setSpecimenType(specimenType.equals(SpecimenOrObservationType.Unknown)?null:specimenType);//unknown := all types
+ config.setTitleSearchString(queryString);
+ if(selectedTaxon!=null){
+ config.setRetrieveIndirectlyAssociatedSpecimens(true);
+ config.setSpecimenType(null);
+ }
+
+ SearchManager searchManager = new SearchManager();
+ List<SpecimenOrObservationBase> occurrences = searchManager.findOccurrences(config, true);
+
+ //filter out specimens of wrong type (only if an associated taxon was selected)
+ if(selectedTaxon!=null && !specimenType.equals(SpecimenOrObservationType.Unknown)){
+ List<SpecimenOrObservationBase> specimensOfCorrectType = new ArrayList<SpecimenOrObservationBase>();
+ for(SpecimenOrObservationBase<?> occurrence:occurrences){
+ if(occurrence.getRecordBasis().equals(specimenType)
+ || occurrence.getRecordBasis().isKindOf(specimenType)){
+ specimensOfCorrectType.add(occurrence);
+ }
+ }
+ occurrences = specimensOfCorrectType;
+ }
+
+ //filter out assigned specimens
+ if(derivateSearchComposite.getBtnFilterUndeterminedSpecimen().getSelection()){
+ List<SpecimenOrObservationBase> specimensWithNoDetermination = new ArrayList<SpecimenOrObservationBase>();
+ for(SpecimenOrObservationBase<?> result:occurrences){
+ if(CdmStore.getService(IOccurrenceService.class).countDeterminations(result, null)==0){
+ specimensWithNoDetermination.add(result);
+ }
+ }
+ occurrences = specimensWithNoDetermination;
+ }
+ //TODO add to DerivateViewEditorInput
+// derivateSearchComposite.getResultViewer().setInput(occurrences);
+ }
+
+ @Override
+ public void handleEvent(Event event) {
+ Widget eventSource = event.widget;
+ if(eventSource == derivateSearchComposite.getButtonSearch()
+ || (eventSource == derivateSearchComposite.getSearchField() && event.keyCode == SWT.CR)){
+ searchDerivates();
+ }
+ else if(eventSource==derivateSearchComposite.getBtnBrowseTaxa()){
+ selectedTaxon = SelectionDialogFactory.getSelectionFromDialog(Taxon.class, this.derivateSearchComposite.getShell(), derivativeEditor.getConversationHolder(), null);
+ if(selectedTaxon!=null){
+ derivateSearchComposite.getTextTaxonName().setText(selectedTaxon.getTitleCache());
+ }
+ }
+ else if(eventSource==derivateSearchComposite.getBtnClearTaxon()){
+ selectedTaxon = null;
+ derivateSearchComposite.getTextTaxonName().setText("");
+ }
+ }
+
+ /**
+ * Sets enable status of all input fields
+ * @param enabled
+ */
+ public void setEnabled(boolean enabled) {
+ if(!derivateSearchComposite.isDisposed()){
+ derivateSearchComposite.setEnabled(enabled);
+ }
+ }
+
+ public void setLayoutData(TableWrapData layoutData){
+ derivateSearchComposite.setLayoutData(layoutData);
+ }
+
+ /**
+ * Resets all input fields
+ */
+ public void reset(){
+ if(!derivateSearchComposite.isDisposed()){
+ derivateSearchComposite.getSearchField().setText("");
+ derivateSearchComposite.getComboDerivateType().deselectAll();
+ comboSpecimenTypeController.setSelection(SpecimenOrObservationType.Unknown);
+ }
+ selectedTaxon = null;
+ }
+
+ public void setConversation(ConversationHolder conversationHolder) {
+ labelProvider.setConversation(conversationHolder);
+ }
+
+}
eu.etaxonomy.taxeditor.ui.dialog.selection,
eu.etaxonomy.taxeditor.ui.element,
eu.etaxonomy.taxeditor.ui.group.grantedauthority,
+ eu.etaxonomy.taxeditor.ui.mvc.combo,
eu.etaxonomy.taxeditor.ui.section,
eu.etaxonomy.taxeditor.ui.section.agent,
eu.etaxonomy.taxeditor.ui.section.classification,
eu.etaxonomy.taxeditor.view.derivateSearch,
eu.etaxonomy.taxeditor.view.detail,
eu.etaxonomy.taxeditor.view.specimenSearch,
- eu.etaxonomy.taxeditor.view.supplementaldata
+ eu.etaxonomy.taxeditor.view.supplementaldata,
+ org.eclipse.wb.swt
Require-Bundle: org.eclipse.osgi,
org.eclipse.ui,
org.eclipse.jface.text,