82bbf3482620c2429b4b18f59c6a066648fd14dd
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / dialog / selection / NomenclaturalReferenceSelectionDialog.java
1 package eu.etaxonomy.taxeditor.ui.dialog.selection;
2
3 import org.eclipse.swt.widgets.Control;
4 import org.eclipse.swt.widgets.Shell;
5 import org.eclipse.swt.widgets.Text;
6
7 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
8 import eu.etaxonomy.cdm.api.service.IReferenceService;
9 import eu.etaxonomy.cdm.model.reference.Reference;
10 import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
11 import eu.etaxonomy.taxeditor.store.CdmStore;
12 import eu.etaxonomy.taxeditor.ui.dialog.selection.CdmFilteredItemsSelectionDialog.ItemsFilter;
13
14 public class NomenclaturalReferenceSelectionDialog extends
15 ReferenceSelectionDialog {
16
17 protected NomenclaturalReferenceSelectionDialog(Shell shell,
18 ConversationHolder conversation, String title, boolean multi,
19 Reference reference) {
20 super(shell, conversation, title, multi, reference);
21 // TODO Auto-generated constructor stub
22 }
23
24 /* (non-Javadoc)
25 * @see eu.etaxonomy.taxeditor.dialogs.AbstractFilteredCdmResourceSelectionDialog#initModel()
26 */
27 /** {@inheritDoc} */
28 @Override
29 protected void initModel() {
30 Control control = getPatternControl();
31 String pattern = null;
32 if (control != null){
33 pattern = ((Text)control).getText();
34 }
35
36
37 model = CdmStore.getService(IReferenceService.class).getUuidAndAbbrevTitleCache(limitOfInitialElements, pattern);
38 }
39
40 /**
41 * <p>select</p>
42 *
43 * @param reference a {@link eu.etaxonomy.cdm.model.reference.ReferenceBase} object.
44 * @param shell a {@link org.eclipse.swt.widgets.Shell} object.
45 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
46 * @return a {@link eu.etaxonomy.cdm.model.reference.ReferenceBase} object.
47 */
48
49 public static Reference select(Shell shell, ConversationHolder conversation, Reference reference) {
50 NomenclaturalReferenceSelectionDialog dialog = new NomenclaturalReferenceSelectionDialog(shell, conversation,
51 "Choose a reference", false, reference);
52 return getSelectionFromDialog(dialog);
53 }
54
55 /* (non-Javadoc)
56 * @see org.eclipse.ui.dialogs.FilteredItemsSelectionDialog#createFilter()
57 */
58 /** {@inheritDoc} */
59 @Override
60 protected ItemsFilter createFilter() {
61 return new ItemsFilter() {
62
63 /**
64 * Always returns false to enforce refiltering even if the pattern is equal
65 */
66 @Override
67 public boolean equalsFilter(ItemsFilter filter) {
68 return false;
69 }
70
71 @Override
72 public boolean isConsistentItem(Object item) {
73 return false;
74 }
75
76 @Override
77 public boolean matchItem(Object item) {
78 String text = null;
79 if(item instanceof UuidAndTitleCache){
80 text = ((UuidAndTitleCache) item).getAbbrevTitleCache();
81 }else if(item instanceof String){
82 text = (String) item;
83 }
84 return text != null ? matches(text) : false;
85 }
86
87 };
88 }
89
90
91 }