Merge branch 'release/4.7.0'
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / dialog / selection / ReferenceSelectionDialog.java
1 /**
2 * Copyright (C) 2007 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
10 package eu.etaxonomy.taxeditor.ui.dialog.selection;
11
12 import java.util.UUID;
13
14 import org.eclipse.swt.widgets.Control;
15 import org.eclipse.swt.widgets.Shell;
16 import org.eclipse.swt.widgets.Text;
17
18 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
19 import eu.etaxonomy.cdm.api.service.IReferenceService;
20 import eu.etaxonomy.cdm.model.reference.Reference;
21 import eu.etaxonomy.taxeditor.newWizard.AbstractNewEntityWizard;
22 import eu.etaxonomy.taxeditor.newWizard.NewReferenceWizard;
23 import eu.etaxonomy.taxeditor.store.CdmStore;
24
25 /**
26 * <p>FilteredReferenceSelectionDialog class.</p>
27 *
28 * @author n.hoffmann
29 * @created 04.06.2009
30 * @version 1.0
31 */
32 public class ReferenceSelectionDialog extends AbstractFilteredCdmResourceSelectionDialog<Reference> {
33
34 protected static boolean isInReference = false;
35 private Reference currentReference;
36
37 /**
38 * <p>select</p>
39 *
40 * @param reference a {@link eu.etaxonomy.cdm.model.reference.ReferenceBase} object.
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.reference.ReferenceBase} object.
44 */
45 public static Reference select(Shell shell, ConversationHolder conversation, Reference reference, boolean isInReference) {
46 ReferenceSelectionDialog dialog = new ReferenceSelectionDialog(shell, conversation,
47 "Choose a reference", false, reference, isInReference);
48 return getSelectionFromDialog(dialog);
49 }
50
51 /**
52 * <p>select</p>
53 *
54 * @param reference a {@link eu.etaxonomy.cdm.model.reference.ReferenceBase} object.
55 * @param shell a {@link org.eclipse.swt.widgets.Shell} object.
56 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
57 * @return a {@link eu.etaxonomy.cdm.model.reference.ReferenceBase} object.
58 */
59 public static Reference select(Shell shell, ConversationHolder conversation, Reference reference) {
60 ReferenceSelectionDialog dialog = new ReferenceSelectionDialog(shell, conversation,
61 "Choose a reference", false, reference);
62 return getSelectionFromDialog(dialog);
63 }
64
65
66
67 /**
68 * <p>Constructor for FilteredReferenceSelectionDialog.</p>
69 *
70 * @param shell a {@link org.eclipse.swt.widgets.Shell} object.
71 * @param title a {@link java.lang.String} object.
72 * @param reference a {@link eu.etaxonomy.cdm.model.reference.ReferenceBase} object.
73 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
74 * @param multi a boolean.
75 */
76 protected ReferenceSelectionDialog(Shell shell, ConversationHolder conversation, String title, boolean multi, Reference reference) {
77 super(shell, conversation, title, multi, ReferenceSelectionDialog.class.getCanonicalName(), null);
78 this.currentReference = reference;
79
80
81 }
82
83
84
85
86 /**
87 * <p>Constructor for FilteredReferenceSelectionDialog.</p>
88 *
89 * @param shell a {@link org.eclipse.swt.widgets.Shell} object.
90 * @param title a {@link java.lang.String} object.
91 * @param reference a {@link eu.etaxonomy.cdm.model.reference.ReferenceBase} object.
92 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
93 * @param multi a boolean.
94 */
95 protected ReferenceSelectionDialog(Shell shell, ConversationHolder conversation, String title, boolean multi, Reference reference, boolean isInReference) {
96 super(shell, conversation, title, multi, ReferenceSelectionDialog.class.getCanonicalName(), null);
97 this.isInReference = isInReference;
98 this.currentReference = reference;
99
100 }
101
102
103 /* (non-Javadoc)
104 * @see eu.etaxonomy.taxeditor.dialogs.AbstractFilteredCdmResourceSelectionDialog#getPersistentObject(java.util.UUID)
105 */
106 /** {@inheritDoc} */
107 @Override
108 protected Reference getPersistentObject(UUID cdmUuid) {
109 return CdmStore.getService(IReferenceService.class).load(cdmUuid);
110 }
111
112 /* (non-Javadoc)
113 * @see eu.etaxonomy.taxeditor.dialogs.AbstractFilteredCdmResourceSelectionDialog#initModel()
114 */
115 /** {@inheritDoc} */
116 @Override
117 protected void initModel() {
118 Control control = getPatternControl();
119 String pattern = null;
120 if (control != null){
121 pattern = ((Text)control).getText();
122 }
123
124 if (pattern == null || pattern.equals("?")){
125 if (isInReference && currentReference != null){
126 model = CdmStore.getService(IReferenceService.class).getUuidAndTitleCache(null,null,currentReference.getType());
127 }else{
128 model = CdmStore.getService(IReferenceService.class).getUuidAndTitleCache(null,null);
129 }
130 }else{
131 if (isInReference && currentReference != null){
132 model = CdmStore.getService(IReferenceService.class).getUuidAndTitleCache(limitOfInitialElements,pattern, currentReference.getType());
133 }else{
134 model = CdmStore.getService(IReferenceService.class).getUuidAndTitleCache(limitOfInitialElements,pattern);
135 }
136 }
137 }
138
139
140 /** {@inheritDoc} */
141 @Override
142 protected String getTitle(Reference cdmObject) {
143 if(cdmObject == null){
144 return "";
145 }else{
146 return super.getTitle(cdmObject);
147 }
148 // }else{
149 // return DefaultReferenceCacheStrategy.putAuthorToEndOfString(cdmObject.getTitleCache(), cdmObject.getAuthorship().getTitleCache());
150 // }
151 }
152
153 /** {@inheritDoc} */
154 @Override
155 protected AbstractNewEntityWizard getNewEntityWizard(String parameter) {
156 return new NewReferenceWizard();
157 }
158
159 /** {@inheritDoc} */
160 @Override
161 protected String getNewWizardLinkText() {
162 return String.format("Create a new <a>%1s</a>", "Reference ");
163 }
164
165 }