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