Merge branch 'release/4.12.0'
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / dialog / selection / FeatureSelectionDialog.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.dialog.selection;
11
12 import java.util.ArrayList;
13 import java.util.List;
14 import java.util.UUID;
15
16 import org.eclipse.swt.widgets.Shell;
17
18 import eu.etaxonomy.cdm.api.service.ITermService;
19 import eu.etaxonomy.cdm.model.common.DefinedTermBase;
20 import eu.etaxonomy.cdm.model.description.Feature;
21 import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
22 import eu.etaxonomy.taxeditor.newWizard.AbstractNewEntityWizard;
23 import eu.etaxonomy.taxeditor.store.CdmStore;
24
25 /**
26 * @author n.hoffmann
27 * @created Dec 6, 2010
28 * @version 1.0
29 */
30 public class FeatureSelectionDialog extends
31 AbstractFilteredCdmResourceSelectionDialog<Feature> {
32
33 public static Feature select(Shell shell, //ConversationHolder conversation,
34 Feature feature){
35 FeatureSelectionDialog dialog = new FeatureSelectionDialog(shell, //conversation,
36 "Choose Feature", false, FeatureSelectionDialog.class.getCanonicalName(), feature);
37 return getSelectionFromDialog(dialog);
38 }
39
40 /**
41 * @param shell
42 * @param conversation
43 * @param title
44 * @param multi
45 * @param settings
46 * @param cdmObject
47 */
48 protected FeatureSelectionDialog(Shell shell,//ConversationHolder conversation,
49 String title, boolean multi,
50 String settings, Feature cdmObject) {
51 super(shell,//conversation,
52 title, multi, settings, cdmObject);
53 }
54
55 @Override
56 protected Feature getPersistentObject(UUID uuid) {
57
58 DefinedTermBase<?> term = CdmStore.getService(ITermService.class).load(uuid);
59
60 if(term instanceof Feature){
61 return (Feature) term;
62 }
63
64 return null;
65 }
66
67 @Override
68 protected void callService(String pattern) {
69 List<Feature> features = CdmStore.getService(ITermService.class).list(Feature.class, null, null, null, null);
70
71 List<UuidAndTitleCache<Feature>> featureUuidAndTitleCache = new ArrayList<UuidAndTitleCache<Feature>>();
72
73 for(Feature feature : features){
74 UuidAndTitleCache<Feature> uuidAndTitleCache = new UuidAndTitleCache<Feature>(Feature.class, feature.getUuid(), feature.getId(), feature.getTitleCache());
75 if (uuidAndTitleCache.getTitleCache().matches(pattern)) {
76 featureUuidAndTitleCache.add(uuidAndTitleCache);
77 }
78 }
79
80 model = featureUuidAndTitleCache;
81
82 }
83
84 /* (non-Javadoc)
85 * @see eu.etaxonomy.taxeditor.dialogs.filteredSelection.AbstractFilteredCdmResourceSelectionDialog#getNewWizardLinkText()
86 */
87 @Override
88 protected String[] getNewWizardText() {
89 return null;
90 }
91
92 /* (non-Javadoc)
93 * @see eu.etaxonomy.taxeditor.dialogs.filteredSelection.AbstractFilteredCdmResourceSelectionDialog#getNewEntityWizard()
94 */
95 @Override
96 protected AbstractNewEntityWizard getNewEntityWizard(String parameter) {
97 return null;
98 }
99
100 }