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.List;
|
13
|
import java.util.UUID;
|
14
|
|
15
|
import org.eclipse.swt.SWT;
|
16
|
import org.eclipse.swt.events.SelectionAdapter;
|
17
|
import org.eclipse.swt.events.SelectionEvent;
|
18
|
import org.eclipse.swt.widgets.Button;
|
19
|
import org.eclipse.swt.widgets.Composite;
|
20
|
import org.eclipse.swt.widgets.Shell;
|
21
|
|
22
|
import eu.etaxonomy.cdm.api.service.IReferenceService;
|
23
|
import eu.etaxonomy.cdm.api.service.dto.IdentifiedEntityDTO;
|
24
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
25
|
import eu.etaxonomy.cdm.persistence.query.MatchMode;
|
26
|
import eu.etaxonomy.taxeditor.newWizard.AbstractNewEntityWizard;
|
27
|
import eu.etaxonomy.taxeditor.newWizard.NewReferenceWizard;
|
28
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
29
|
|
30
|
/**
|
31
|
* <p>FilteredReferenceSelectionDialog class.</p>
|
32
|
*
|
33
|
* @author n.hoffmann
|
34
|
* @created 04.06.2009
|
35
|
* @version 1.0
|
36
|
*/
|
37
|
public class ReferenceSelectionDialog extends AbstractFilteredCdmResourceSelectionDialog<Reference> {
|
38
|
|
39
|
protected static boolean isInReference = false;
|
40
|
private Reference currentReference;
|
41
|
|
42
|
/**
|
43
|
* <p>select</p>
|
44
|
*
|
45
|
* @param reference a {@link eu.etaxonomy.cdm.model.reference.ReferenceBase} object.
|
46
|
* @param shell a {@link org.eclipse.swt.widgets.Shell} object.
|
47
|
* @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
|
48
|
* @return a {@link eu.etaxonomy.cdm.model.reference.ReferenceBase} object.
|
49
|
*/
|
50
|
public static Reference select(Shell shell, //ConversationHolder conversation,
|
51
|
Reference reference, boolean isInReference) {
|
52
|
ReferenceSelectionDialog dialog = new ReferenceSelectionDialog(shell, //conversation,
|
53
|
"Choose a reference", false, reference, isInReference);
|
54
|
return getSelectionFromDialog(dialog);
|
55
|
}
|
56
|
|
57
|
/**
|
58
|
* <p>select</p>
|
59
|
*
|
60
|
* @param reference a {@link eu.etaxonomy.cdm.model.reference.ReferenceBase} object.
|
61
|
* @param shell a {@link org.eclipse.swt.widgets.Shell} object.
|
62
|
* @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
|
63
|
* @return a {@link eu.etaxonomy.cdm.model.reference.ReferenceBase} object.
|
64
|
*/
|
65
|
public static Reference select(Shell shell, //ConversationHolder conversation,
|
66
|
Reference reference) {
|
67
|
ReferenceSelectionDialog dialog = new ReferenceSelectionDialog(shell, //conversation,
|
68
|
"Choose a reference", false, reference);
|
69
|
return getSelectionFromDialog(dialog);
|
70
|
}
|
71
|
|
72
|
|
73
|
|
74
|
/**
|
75
|
* <p>Constructor for FilteredReferenceSelectionDialog.</p>
|
76
|
*
|
77
|
* @param shell a {@link org.eclipse.swt.widgets.Shell} object.
|
78
|
* @param title a {@link java.lang.String} object.
|
79
|
* @param reference a {@link eu.etaxonomy.cdm.model.reference.ReferenceBase} object.
|
80
|
* @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
|
81
|
* @param multi a boolean.
|
82
|
*/
|
83
|
protected ReferenceSelectionDialog(Shell shell, //ConversationHolder conversation,
|
84
|
String title, boolean multi, Reference reference) {
|
85
|
super(shell, //conversation,
|
86
|
title, multi, ReferenceSelectionDialog.class.getCanonicalName(), null);
|
87
|
this.currentReference = reference;
|
88
|
|
89
|
|
90
|
}
|
91
|
|
92
|
|
93
|
|
94
|
|
95
|
/**
|
96
|
* <p>Constructor for FilteredReferenceSelectionDialog.</p>
|
97
|
*
|
98
|
* @param shell a {@link org.eclipse.swt.widgets.Shell} object.
|
99
|
* @param title a {@link java.lang.String} object.
|
100
|
* @param reference a {@link eu.etaxonomy.cdm.model.reference.ReferenceBase} object.
|
101
|
* @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
|
102
|
* @param multi a boolean.
|
103
|
*/
|
104
|
protected ReferenceSelectionDialog(Shell shell, //ConversationHolder conversation,
|
105
|
String title, boolean multi, Reference reference, boolean isInReference) {
|
106
|
super(shell, //conversation,
|
107
|
title, multi, ReferenceSelectionDialog.class.getCanonicalName(), null);
|
108
|
this.isInReference = isInReference;
|
109
|
this.currentReference = reference;
|
110
|
|
111
|
}
|
112
|
|
113
|
|
114
|
/* (non-Javadoc)
|
115
|
* @see eu.etaxonomy.taxeditor.dialogs.AbstractFilteredCdmResourceSelectionDialog#getPersistentObject(java.util.UUID)
|
116
|
*/
|
117
|
/** {@inheritDoc} */
|
118
|
@Override
|
119
|
protected Reference getPersistentObject(UUID cdmUuid) {
|
120
|
return CdmStore.getService(IReferenceService.class).load(cdmUuid);
|
121
|
}
|
122
|
|
123
|
/* (non-Javadoc)
|
124
|
* @see eu.etaxonomy.taxeditor.dialogs.AbstractFilteredCdmResourceSelectionDialog#search
|
125
|
*/
|
126
|
/** {@inheritDoc} */
|
127
|
@Override
|
128
|
protected void callService(String pattern) {
|
129
|
|
130
|
if (isInReference && currentReference != null){
|
131
|
|
132
|
if (isUseIdentifier()){
|
133
|
List<IdentifiedEntityDTO<Reference>> list = CdmStore.getService(IReferenceService.class).listByIdentifierAbbrev(pattern, null, MatchMode.BEGINNING, limitOfInitialElements);
|
134
|
if (model!= null){
|
135
|
model.clear();
|
136
|
}
|
137
|
for (IdentifiedEntityDTO dto: list){
|
138
|
|
139
|
model.add(dto.getCdmEntity());
|
140
|
}
|
141
|
}else{
|
142
|
model = CdmStore.getService(IReferenceService.class).getUuidAndTitleCache(limitOfInitialElements,pattern, currentReference.getType());
|
143
|
}
|
144
|
|
145
|
}else{
|
146
|
if (isUseIdentifier()){
|
147
|
List<IdentifiedEntityDTO<Reference>> list = CdmStore.getService(IReferenceService.class).listByIdentifierAbbrev(pattern, null, MatchMode.BEGINNING, limitOfInitialElements);
|
148
|
if (model!= null){
|
149
|
model.clear();
|
150
|
}
|
151
|
for (IdentifiedEntityDTO dto: list){
|
152
|
|
153
|
model.add(dto.getCdmEntity());
|
154
|
}
|
155
|
}else{
|
156
|
model = CdmStore.getService(IReferenceService.class).getUuidAndTitleCache(limitOfInitialElements,pattern);
|
157
|
}
|
158
|
|
159
|
}
|
160
|
|
161
|
}
|
162
|
|
163
|
@Override
|
164
|
protected void addIdentifierCheckButton(Composite searchAndFilter) {
|
165
|
Button btnCheckButton = new Button(searchAndFilter, SWT.CHECK);
|
166
|
btnCheckButton.setText("Use Identifier");
|
167
|
btnCheckButton.addSelectionListener(new SelectionAdapter() {
|
168
|
@Override
|
169
|
public void widgetSelected(SelectionEvent e) {
|
170
|
useIdentifier = btnCheckButton.getSelection();
|
171
|
}
|
172
|
});
|
173
|
}
|
174
|
/** {@inheritDoc} */
|
175
|
@Override
|
176
|
protected String getTitle(Reference cdmObject) {
|
177
|
if(cdmObject == null){
|
178
|
return "";
|
179
|
}else{
|
180
|
return super.getTitle(cdmObject);
|
181
|
}
|
182
|
// }else{
|
183
|
// return DefaultReferenceCacheStrategy.putAuthorToEndOfString(cdmObject.getTitleCache(), cdmObject.getAuthorship().getTitleCache());
|
184
|
// }
|
185
|
}
|
186
|
|
187
|
/** {@inheritDoc} */
|
188
|
@Override
|
189
|
protected AbstractNewEntityWizard getNewEntityWizard(String parameter) {
|
190
|
return new NewReferenceWizard();
|
191
|
}
|
192
|
|
193
|
/** {@inheritDoc} */
|
194
|
@Override
|
195
|
protected String[] getNewWizardText() {
|
196
|
return new String[]{"New Reference"};
|
197
|
}
|
198
|
|
199
|
}
|