Merge branch 'release/4.4.0'
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / dialog / selection / ReferenceSelectionDialog.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.Control;
16 import org.eclipse.swt.widgets.Shell;
17 import org.eclipse.swt.widgets.Text;
18
19 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
20 import eu.etaxonomy.cdm.api.service.IReferenceService;
21 import eu.etaxonomy.cdm.model.reference.Reference;
22 import eu.etaxonomy.cdm.strategy.cache.reference.DefaultReferenceCacheStrategy;
23 import eu.etaxonomy.taxeditor.newWizard.AbstractNewEntityWizard;
24 import eu.etaxonomy.taxeditor.newWizard.NewReferenceWizard;
25 import eu.etaxonomy.taxeditor.store.CdmStore;
26
27 /**
28 * <p>FilteredReferenceSelectionDialog class.</p>
29 *
30 * @author n.hoffmann
31 * @created 04.06.2009
32 * @version 1.0
33 */
34 public class ReferenceSelectionDialog extends AbstractFilteredCdmResourceSelectionDialog<Reference> {
35
36 /**
37 * <p>select</p>
38 *
39 * @param reference a {@link eu.etaxonomy.cdm.model.reference.ReferenceBase} object.
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.reference.ReferenceBase} object.
43 */
44 public static Reference select(Shell shell, ConversationHolder conversation, Reference reference) {
45 ReferenceSelectionDialog dialog = new ReferenceSelectionDialog(shell, conversation,
46 "Choose a reference", false, reference);
47 return getSelectionFromDialog(dialog);
48 }
49
50
51 /**
52 * <p>Constructor for FilteredReferenceSelectionDialog.</p>
53 *
54 * @param shell a {@link org.eclipse.swt.widgets.Shell} object.
55 * @param title a {@link java.lang.String} object.
56 * @param reference a {@link eu.etaxonomy.cdm.model.reference.ReferenceBase} object.
57 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
58 * @param multi a boolean.
59 */
60 protected ReferenceSelectionDialog(Shell shell, ConversationHolder conversation, String title, boolean multi, Reference reference) {
61 super(shell, conversation, title, multi, ReferenceSelectionDialog.class.getCanonicalName(), null);
62 }
63
64
65 /* (non-Javadoc)
66 * @see eu.etaxonomy.taxeditor.dialogs.AbstractFilteredCdmResourceSelectionDialog#getPersistentObject(java.util.UUID)
67 */
68 /** {@inheritDoc} */
69 @Override
70 protected Reference getPersistentObject(UUID cdmUuid) {
71 return CdmStore.getService(IReferenceService.class).load(cdmUuid);
72 }
73
74 /* (non-Javadoc)
75 * @see eu.etaxonomy.taxeditor.dialogs.AbstractFilteredCdmResourceSelectionDialog#initModel()
76 */
77 /** {@inheritDoc} */
78 @Override
79 protected void initModel() {
80 Control control = getPatternControl();
81 String pattern = null;
82 if (control != null){
83 pattern = ((Text)control).getText();
84 }
85
86
87 model = CdmStore.getService(IReferenceService.class).getUuidAndTitleCache(limitOfInitialElements,pattern);
88 }
89
90
91 /** {@inheritDoc} */
92 @Override
93 protected String getTitle(Reference cdmObject) {
94 if(cdmObject == null){
95 return "";
96 }else{
97 return super.getTitle(cdmObject);
98 }
99 // }else{
100 // return DefaultReferenceCacheStrategy.putAuthorToEndOfString(cdmObject.getTitleCache(), cdmObject.getAuthorship().getTitleCache());
101 // }
102 }
103
104 /** {@inheritDoc} */
105 @Override
106 protected AbstractNewEntityWizard getNewEntityWizard(String parameter) {
107 return new NewReferenceWizard();
108 }
109
110 /** {@inheritDoc} */
111 @Override
112 protected String getNewWizardLinkText() {
113 return String.format("Create a new <a>%1s</a>", "Reference ");
114 }
115
116 }