Merge branch 'develop' into LibrAlign
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / dialog / selection / PrimerSelectionDialog.java
1 /**
2 * Copyright (C) 2014 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 package eu.etaxonomy.taxeditor.ui.dialog.selection;
10
11 import java.util.UUID;
12
13 import org.eclipse.swt.widgets.Shell;
14
15 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
16 import eu.etaxonomy.cdm.api.service.molecular.IPrimerService;
17 import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
18 import eu.etaxonomy.cdm.model.molecular.Primer;
19 import eu.etaxonomy.taxeditor.model.MessagingUtils;
20 import eu.etaxonomy.taxeditor.newWizard.AbstractNewEntityWizard;
21 import eu.etaxonomy.taxeditor.newWizard.NewPrimerWizard;
22 import eu.etaxonomy.taxeditor.store.CdmStore;
23
24 /**
25 * @author pplitzner
26 * @date 11.03.2014
27 *
28 */
29 public class PrimerSelectionDialog extends
30 AbstractFilteredCdmResourceSelectionDialog<Primer> {
31
32 public static Primer select(Shell shell, ConversationHolder conversation, Primer primer){
33 PrimerSelectionDialog dialog = new PrimerSelectionDialog(shell, conversation,
34 "Choose Primer", false, PrimerSelectionDialog.class.getCanonicalName(), primer);
35 return getSelectionFromDialog(dialog);
36 }
37
38 /**
39 * <p>Constructor for FilteredDerivedUnitSelectionDialog.</p>
40 */
41 protected PrimerSelectionDialog(Shell shell, ConversationHolder conversation, String title,
42 boolean multi, String settings, Primer cdmObject) {
43 super(shell, conversation, title, multi, settings, cdmObject);
44 }
45
46 /** {@inheritDoc} */
47 @Override
48 protected Primer getPersistentObject(UUID uuid) {
49 Object object = CdmStore.getService(IPrimerService.class).load(uuid);
50
51 Primer primer = (Primer) HibernateProxyHelper.deproxy(object);
52
53 if(primer != null){
54 return primer;
55 }
56 MessagingUtils.error(this.getClass(), "Selected element is not a primer", null);
57 return null;
58 }
59
60 /** {@inheritDoc} */
61 @Override
62 protected void initModel() {
63 model = CdmStore.getService(IPrimerService.class).getPrimerUuidAndTitleCache();
64 }
65
66 /* (non-Javadoc)
67 * @see eu.etaxonomy.taxeditor.ui.dialog.selection.AbstractFilteredCdmResourceSelectionDialog#getTitle(eu.etaxonomy.cdm.model.common.ICdmBase)
68 */
69 @Override
70 protected String getTitle(Primer cdmObject) {
71 if(cdmObject!=null){
72 return cdmObject.getLabel();
73 }
74 return super.getTitle(cdmObject);
75 }
76
77 /** {@inheritDoc} */
78 @Override
79 protected AbstractNewEntityWizard getNewEntityWizard(String parameter) {
80 return new NewPrimerWizard();
81 }
82
83 /** {@inheritDoc} */
84 @Override
85 protected String getNewWizardLinkText() {
86 return String.format("Create a new <a>%1s</a>", "Primer ");
87 }
88 }