1 package eu
.etaxonomy
.taxeditor
.ui
.dialog
.selection
;
3 import java
.text
.Collator
;
4 import java
.util
.Comparator
;
6 import org
.eclipse
.jface
.viewers
.ILabelProvider
;
7 import org
.eclipse
.jface
.viewers
.LabelProvider
;
8 import org
.eclipse
.swt
.widgets
.Control
;
9 import org
.eclipse
.swt
.widgets
.Shell
;
10 import org
.eclipse
.swt
.widgets
.Text
;
12 import eu
.etaxonomy
.cdm
.api
.conversation
.ConversationHolder
;
13 import eu
.etaxonomy
.cdm
.api
.service
.IReferenceService
;
14 import eu
.etaxonomy
.cdm
.model
.agent
.TeamOrPersonBase
;
15 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
16 import eu
.etaxonomy
.cdm
.persistence
.dto
.UuidAndTitleCache
;
17 import eu
.etaxonomy
.taxeditor
.preference
.IPreferenceKeys
;
18 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
19 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
21 public class NomenclaturalReferenceSelectionDialog
extends
22 ReferenceSelectionDialog
{
24 private TeamOrPersonBase author
;
25 private boolean firstCall
= true;
27 protected NomenclaturalReferenceSelectionDialog(Shell shell
,
28 ConversationHolder conversation
, String title
, boolean multi
,
29 Reference reference
, boolean inReference
, TeamOrPersonBase author
) {
30 super(shell
, conversation
, title
, multi
, reference
);
37 * @see eu.etaxonomy.taxeditor.dialogs.AbstractFilteredCdmResourceSelectionDialog#initModel()
41 protected void initModel() {
42 Control control
= getPatternControl();
43 String pattern
= null;
45 pattern
= ((Text
)control
).getText();
48 if (firstCall
&& author
!= null){
49 pattern
= author
.getNomenclaturalTitle();
52 ((Text
)control
).setText(pattern
);
57 if (pattern
== null || pattern
.equals("?")){
58 model
= CdmStore
.getService(IReferenceService
.class).getUuidAndAbbrevTitleCache(null, null);
60 model
= CdmStore
.getService(IReferenceService
.class).getUuidAndAbbrevTitleCache(limitOfInitialElements
, pattern
);
69 protected ILabelProvider
createListLabelProvider() {
70 return new FilteredCdmResourceAbbrevLabelProvider();
76 * @param reference a {@link eu.etaxonomy.cdm.model.reference.ReferenceBase} object.
77 * @param shell a {@link org.eclipse.swt.widgets.Shell} object.
78 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
79 * @return a {@link eu.etaxonomy.cdm.model.reference.ReferenceBase} object.
82 public static Reference
select(Shell shell
, ConversationHolder conversation
, Reference reference
, TeamOrPersonBase author
) {
83 NomenclaturalReferenceSelectionDialog dialog
= new NomenclaturalReferenceSelectionDialog(shell
, conversation
,
84 "Choose a reference", isInReference
, reference
, false, author
);
85 return getSelectionFromDialog(dialog
);
89 * @see org.eclipse.ui.dialogs.FilteredItemsSelectionDialog#createFilter()
93 protected ItemsFilter
createFilter() {
94 return new ItemsFilter() {
97 * Always returns false to enforce refiltering even if the pattern is equal
100 public boolean equalsFilter(ItemsFilter filter
) {
105 public boolean isConsistentItem(Object item
) {
110 public boolean matchItem(Object item
) {
112 // String text = null;
113 // if(item instanceof UuidAndTitleCache){
114 // if (((UuidAndTitleCache) item).getAbbrevTitleCache() != null){
115 // text = ((UuidAndTitleCache) item).getAbbrevTitleCache();
117 // text = ((UuidAndTitleCache) item).getTitleCache();
119 // }else if(item instanceof String){
120 // text = (String) item;
122 // return text != null ? matches(text) : false;
130 public class FilteredCdmResourceAbbrevLabelProvider
extends LabelProvider
{
132 public String
getText(Object element
) {
133 if (element
== null) {
136 UuidAndTitleCache uuidAndTitleCache
= (UuidAndTitleCache
) element
;
137 String titleCache
= uuidAndTitleCache
.getTitleCache();
138 String abbrevTitleCache
= uuidAndTitleCache
.getAbbrevTitleCache();
139 if (!abbrevTitleCache
.equals(titleCache
)){
140 abbrevTitleCache
+= " - " + titleCache
;
142 if(PreferencesUtil
.getPreferenceStore().getBoolean(IPreferenceKeys
.SHOW_ID_IN_ENTITY_SELECTION_DIAOLOG
)){
143 abbrevTitleCache
+= " ["+uuidAndTitleCache
.getId()+"]";
145 return abbrevTitleCache
;
150 protected Comparator
getItemsComparator() {
151 return new Comparator
<UuidAndTitleCache
>() {
153 public int compare(UuidAndTitleCache entity1
,
154 UuidAndTitleCache entity2
) {
156 if (entity1
.getUuid().equals(entity2
.getUuid())){
159 Collator collator
= Collator
.getInstance();
160 String compareString1
= "";
161 if (entity1
.getAbbrevTitleCache() != null){
162 compareString1
= entity1
.getAbbrevTitleCache();
164 if (entity1
.getTitleCache() != null){
165 compareString1
+= entity1
.getTitleCache();
169 String compareString2
= "";
170 if (entity2
.getAbbrevTitleCache() != null){
171 compareString2
= entity2
.getAbbrevTitleCache();
173 if (entity2
.getTitleCache() != null){
174 compareString2
+= entity2
.getTitleCache();
178 int result
=collator
.compare(compareString1
, compareString2
);
180 result
= entity1
.getUuid().compareTo(entity2
.getUuid());
187 protected String
getTitle(Reference cdmObject
) {
188 if(cdmObject
== null){
191 if (cdmObject
.getAbbrevTitle() != null){
192 return cdmObject
.getAbbrevTitleCache();
194 return cdmObject
.getTitleCache();