fix #6330 Add default sorting for all entity collections
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / section / description / DescribedSpecimenSection.java
1 /**
2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
8 */
9
10 package eu.etaxonomy.taxeditor.ui.section.description;
11
12 import java.util.ArrayList;
13 import java.util.Collection;
14 import java.util.Comparator;
15 import java.util.List;
16
17 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
18 import eu.etaxonomy.cdm.model.description.TaxonDescription;
19 import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
20 import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
21 import eu.etaxonomy.taxeditor.ui.dialog.selection.DerivedUnitSelectionDialog;
22 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
23 import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
24 import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionSection;
25 import eu.etaxonomy.taxeditor.ui.section.DefaultCdmBaseComparator;
26
27 /**
28 * <p>DescribedSpecimenSection class.</p>
29 *
30 * @author n.hoffmann
31 * @created Sep 16, 2010
32 * @version 1.0
33 */
34 public class DescribedSpecimenSection extends AbstractEntityCollectionSection<TaxonDescription, SpecimenOrObservationBase> {
35
36 /**
37 * <p>Constructor for DescribedSpecimenSection.</p>
38 *
39 * @param formFactory a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} object.
40 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
41 * @param parentElement a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement} object.
42 * @param style a int.
43 */
44 public DescribedSpecimenSection(CdmFormFactory formFactory,
45 ConversationHolder conversation, ICdmFormElement parentElement,
46 int style) {
47 super(formFactory, conversation, parentElement, "Described Specimen", style);
48 }
49
50 /** {@inheritDoc} */
51 @Override
52 public Collection<SpecimenOrObservationBase> getCollection(
53 TaxonDescription entity) {
54 //FIXME:This class is not really an entity collection section, and should be moved
55 // to a single entity section, but one with the possibility of launching a wizard
56 List<SpecimenOrObservationBase> collection = new ArrayList<SpecimenOrObservationBase>();
57 if(entity.getDescribedSpecimenOrObservation() != null) {
58 collection.add(entity.getDescribedSpecimenOrObservation());
59 }
60 return collection;
61 }
62
63 @Override
64 public Comparator<SpecimenOrObservationBase> getComparator() {
65 return new DefaultCdmBaseComparator<>();
66 }
67
68 /** {@inheritDoc} */
69 @Override
70 public SpecimenOrObservationBase createNewElement() {
71 DerivedUnit selection = DerivedUnitSelectionDialog.select(getShell(), //getConversationHolder(),
72 null);
73 return selection;
74 }
75
76 /** {@inheritDoc} */
77 @Override
78 public void addElement(SpecimenOrObservationBase element) {
79 getEntity().setDescribedSpecimenOrObservation(element);
80 }
81
82 /** {@inheritDoc} */
83 @Override
84 public void removeElement(SpecimenOrObservationBase element) {
85 getEntity().setDescribedSpecimenOrObservation(null);
86 }
87
88 /** {@inheritDoc} */
89 @Override
90 public String getEmptyString() {
91 return "No described specimen yet.";
92 }
93
94 /** {@inheritDoc} */
95 @Override
96 protected String getTooltipString() {
97 return "Add a described specimen.";
98 }
99
100 /**
101 * {@inheritDoc}
102 */
103 @Override
104 public SpecimenOrObservationBase addExisting() {
105 return null;
106 }
107
108 /**
109 * {@inheritDoc}
110 */
111 @Override
112 public boolean allowAddExisting() {
113 return false;
114 }
115 }