Fixes #2681
[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 * <p>FilteredTaxonBaseSelectionDialog class.</p>
29 *
30 * @author n.hoffmann
31 * @created Sep 21, 2009
32 * @version 1.0
33 */
34 public class TaxonBaseSelectionDialog extends
35 AbstractFilteredCdmResourceSelectionDialog<TaxonBase> {
36
37
38 /**
39 * <p>select</p>
40 *
41 * @param shell a {@link org.eclipse.swt.widgets.Shell} object.
42 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
43 * @return a {@link eu.etaxonomy.cdm.model.taxon.TaxonBase} object.
44 */
45 public static TaxonBase selectTaxonBase(Shell shell, ConversationHolder conversation) {
46 AbstractFilteredCdmResourceSelectionDialog<TaxonBase> dialog = new TaxonBaseSelectionDialog(TaxonBase.class, shell, conversation,
47 "Choose a taxon", false, null, null);
48 return getSelectionFromDialog(dialog);
49 }
50
51 /**
52 * <p>select</p>
53 *
54 * @param shell a {@link org.eclipse.swt.widgets.Shell} object.
55 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
56 * @return a {@link eu.etaxonomy.cdm.model.taxon.TaxonBase} object.
57 */
58 public static Taxon selectTaxon(Shell shell, ConversationHolder conversation, Taxon taxonToBeFiltered) {
59
60
61 AbstractFilteredCdmResourceSelectionDialog<TaxonBase> dialog = new TaxonBaseSelectionDialog(Taxon.class, shell, conversation,
62 "Choose a taxon", false, null, taxonToBeFiltered);
63 return (Taxon) getSelectionFromDialog(dialog);
64 }
65
66 /**
67 * <p>select</p>
68 *
69 * @param shell a {@link org.eclipse.swt.widgets.Shell} object.
70 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
71 * @return a {@link eu.etaxonomy.cdm.model.taxon.TaxonBase} object.
72 */
73 public static Synonym selectSynonym(Shell shell, ConversationHolder conversation) {
74 AbstractFilteredCdmResourceSelectionDialog<TaxonBase> dialog = new TaxonBaseSelectionDialog(Synonym.class, shell, conversation,
75 "Choose a taxon", false, null, null);
76 return (Synonym) getSelectionFromDialog(dialog);
77 }
78
79 private final Class<? extends TaxonBase> clazz;
80
81 /**
82 * <p>Constructor for FilteredTaxonBaseSelectionDialog.</p>
83 *
84 * @param shell a {@link org.eclipse.swt.widgets.Shell} object.
85 * @param title a {@link java.lang.String} object.
86 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
87 * @param multi a boolean.
88 * @param taxon a {@link eu.etaxonomy.cdm.model.taxon.TaxonBase} object.
89 */
90 protected TaxonBaseSelectionDialog(Class<? extends TaxonBase> clazz, Shell shell, ConversationHolder conversation, String title, boolean multi, TaxonBase taxon, TaxonBase taxonToBeFiltered) {
91 super(shell, conversation, title, multi, ReferenceSelectionDialog.class.getCanonicalName(), taxon);
92 this.cdmBaseToBeFiltered = taxonToBeFiltered;
93
94
95
96 this.clazz = clazz;
97 }
98
99 /* (non-Javadoc)
100 * @see org.eclipse.ui.dialogs.FilteredItemsSelectionDialog#createExtendedContentArea(org.eclipse.swt.widgets.Composite)
101 */
102 /** {@inheritDoc} */
103 @Override
104 protected Control createExtendedContentArea(Composite parent) {
105 return null;
106 }
107
108 /* (non-Javadoc)
109 * @see eu.etaxonomy.taxeditor.dialogs.AbstractFilteredCdmResourceSelectionDialog#getPersistentObject(java.util.UUID)
110 */
111 /** {@inheritDoc} */
112 @Override
113 protected TaxonBase getPersistentObject(UUID uuid) {
114 return CdmStore.getService(ITaxonService.class).load(uuid);
115 }
116
117 /* (non-Javadoc)
118 * @see eu.etaxonomy.taxeditor.dialogs.AbstractFilteredCdmResourceSelectionDialog#initModel()
119 */
120 /** {@inheritDoc} */
121 @Override
122 protected void initModel() {
123 if(clazz == TaxonBase.class){
124 model = CdmStore.getService(ITaxonService.class).getUuidAndTitleCache();
125 }
126 else if(clazz == Taxon.class){
127
128 model = CdmStore.getService(ITaxonService.class).getUuidAndTitleCacheTaxon();
129
130 }
131 else if(clazz == Synonym.class){
132 model = CdmStore.getService(ITaxonService.class).getUuidAndTitleCacheSynonym();
133 }
134 }
135
136 /** {@inheritDoc} */
137 @Override
138 protected AbstractNewEntityWizard getNewEntityWizard(String parameter) {
139 return null;
140 }
141
142 /** {@inheritDoc} */
143 @Override
144 protected String getNewWizardLinkText() {
145 return null;
146 }
147 }