Merge branch 'release/4.0.0'
[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.Shell;
16
17 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
18 import eu.etaxonomy.cdm.api.service.ITaxonService;
19 import eu.etaxonomy.cdm.model.taxon.Synonym;
20 import eu.etaxonomy.cdm.model.taxon.Taxon;
21 import eu.etaxonomy.cdm.model.taxon.TaxonBase;
22 import eu.etaxonomy.taxeditor.newWizard.AbstractNewEntityWizard;
23 import eu.etaxonomy.taxeditor.newWizard.NewTaxonWizard;
24 import eu.etaxonomy.taxeditor.store.CdmStore;
25
26 /**
27 * @author n.hoffmann
28 * @created Sep 21, 2009
29 * @version 1.0
30 */
31 public class TaxonBaseSelectionDialog extends AbstractFilteredCdmResourceSelectionDialog<TaxonBase> {
32
33
34 public static TaxonBase selectTaxonBase(Shell shell, ConversationHolder conversation) {
35 AbstractFilteredCdmResourceSelectionDialog<TaxonBase> dialog = new TaxonBaseSelectionDialog(TaxonBase.class, shell, conversation,
36 "Choose a taxon/synonym", false, null, null);
37 return getSelectionFromDialog(dialog);
38 }
39
40 public static Taxon selectTaxon(Shell shell, ConversationHolder conversation, Taxon taxonToBeFiltered) {
41
42
43 AbstractFilteredCdmResourceSelectionDialog<TaxonBase> dialog = new TaxonBaseSelectionDialog(Taxon.class, shell, conversation,
44 "Choose a taxon", false, null, taxonToBeFiltered);
45 return (Taxon) getSelectionFromDialog(dialog);
46 }
47
48 public static Synonym selectSynonym(Shell shell, ConversationHolder conversation) {
49 AbstractFilteredCdmResourceSelectionDialog<TaxonBase> dialog = new TaxonBaseSelectionDialog(Synonym.class, shell, conversation,
50 "Choose a synonym", false, null, null);
51 return (Synonym) getSelectionFromDialog(dialog);
52 }
53
54 private final Class<? extends TaxonBase> clazz;
55
56 protected TaxonBaseSelectionDialog(Class<? extends TaxonBase> clazz, Shell shell, ConversationHolder conversation, String title, boolean multi, TaxonBase taxon, TaxonBase taxonToBeFiltered) {
57 super(shell, conversation, title, multi, TaxonBaseSelectionDialog.class.getCanonicalName(), taxon);
58 this.cdmBaseToBeFiltered = taxonToBeFiltered;
59 this.clazz = clazz;
60 initModel();
61 }
62
63 /** {@inheritDoc} */
64 @Override
65 protected TaxonBase getPersistentObject(UUID uuid) {
66 return CdmStore.getService(ITaxonService.class).load(uuid);
67 }
68
69 /** {@inheritDoc} */
70 @Override
71 protected void initModel() {
72 if(clazz == TaxonBase.class){
73 model = CdmStore.getService(ITaxonService.class).getUuidAndTitleCache();
74 }
75 else if(clazz == Taxon.class){
76 model = CdmStore.getService(ITaxonService.class).getUuidAndTitleCacheTaxon();
77 }
78 else if(clazz == Synonym.class){
79 model = CdmStore.getService(ITaxonService.class).getUuidAndTitleCacheSynonym();
80 }
81 }
82
83 /** {@inheritDoc} */
84 @Override
85 protected AbstractNewEntityWizard getNewEntityWizard(String parameter) {
86 return new NewTaxonWizard();
87 }
88
89 /** {@inheritDoc} */
90 @Override
91 protected String getNewWizardLinkText() {
92 return String.format("Create a new <a>%1s</a>", "Taxon ");
93 }
94 }