93860909685b64708e50f515cf973e8c700b7062
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / dialog / selection / TaxonBaseSelectionDialog.java
1 // $Id$
2 /**
3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
6 *
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
9 */
10
11 package eu.etaxonomy.taxeditor.ui.dialog.selection;
12
13 import java.util.UUID;
14
15 import org.eclipse.swt.widgets.Composite;
16 import org.eclipse.swt.widgets.Control;
17 import org.eclipse.swt.widgets.Shell;
18
19 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
20 import eu.etaxonomy.cdm.api.service.ITaxonService;
21 import eu.etaxonomy.cdm.model.taxon.Synonym;
22 import eu.etaxonomy.cdm.model.taxon.Taxon;
23 import eu.etaxonomy.cdm.model.taxon.TaxonBase;
24 import eu.etaxonomy.taxeditor.newWizard.AbstractNewEntityWizard;
25 import eu.etaxonomy.taxeditor.store.CdmStore;
26
27 /**
28 * @author n.hoffmann
29 * @created Sep 21, 2009
30 * @version 1.0
31 */
32 public class TaxonBaseSelectionDialog extends AbstractFilteredCdmResourceSelectionDialog<TaxonBase> {
33
34
35 public static TaxonBase selectTaxonBase(Shell shell, ConversationHolder conversation) {
36 AbstractFilteredCdmResourceSelectionDialog<TaxonBase> dialog = new TaxonBaseSelectionDialog(TaxonBase.class, shell, conversation,
37 "Choose a taxon", false, null, null);
38 return getSelectionFromDialog(dialog);
39 }
40
41 public static Taxon selectTaxon(Shell shell, ConversationHolder conversation, Taxon taxonToBeFiltered) {
42
43
44 AbstractFilteredCdmResourceSelectionDialog<TaxonBase> dialog = new TaxonBaseSelectionDialog(Taxon.class, shell, conversation,
45 "Choose a taxon", false, null, taxonToBeFiltered);
46 return (Taxon) getSelectionFromDialog(dialog);
47 }
48
49 public static Synonym selectSynonym(Shell shell, ConversationHolder conversation) {
50 AbstractFilteredCdmResourceSelectionDialog<TaxonBase> dialog = new TaxonBaseSelectionDialog(Synonym.class, shell, conversation,
51 "Choose a taxon", false, null, null);
52 return (Synonym) getSelectionFromDialog(dialog);
53 }
54
55 private final Class<? extends TaxonBase> clazz;
56
57 protected TaxonBaseSelectionDialog(Class<? extends TaxonBase> clazz, Shell shell, ConversationHolder conversation, String title, boolean multi, TaxonBase taxon, TaxonBase taxonToBeFiltered) {
58 super(shell, conversation, title, multi, ReferenceSelectionDialog.class.getCanonicalName(), taxon);
59 this.cdmBaseToBeFiltered = taxonToBeFiltered;
60 this.clazz = clazz;
61 initModel();
62 }
63
64 /** {@inheritDoc} */
65 @Override
66 protected Control createExtendedContentArea(Composite parent) {
67 return null;
68 }
69
70 /** {@inheritDoc} */
71 @Override
72 protected TaxonBase getPersistentObject(UUID uuid) {
73 return CdmStore.getService(ITaxonService.class).load(uuid);
74 }
75
76 /** {@inheritDoc} */
77 @Override
78 protected void initModel() {
79 if(clazz == TaxonBase.class){
80 model = CdmStore.getService(ITaxonService.class).getUuidAndTitleCache();
81 }
82 else if(clazz == Taxon.class){
83 model = CdmStore.getService(ITaxonService.class).getUuidAndTitleCacheTaxon();
84 }
85 else if(clazz == Synonym.class){
86 model = CdmStore.getService(ITaxonService.class).getUuidAndTitleCacheSynonym();
87 }
88 }
89
90 /** {@inheritDoc} */
91 @Override
92 protected AbstractNewEntityWizard getNewEntityWizard(String parameter) {
93 return null;
94 }
95
96 /** {@inheritDoc} */
97 @Override
98 protected String getNewWizardLinkText() {
99 return null;
100 }
101 }