1
|
/**
|
2
|
* Copyright (C) 2017 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.application.ICdmRepository;
|
16
|
import eu.etaxonomy.cdm.api.service.IReferenceService;
|
17
|
import eu.etaxonomy.cdm.model.agent.Person;
|
18
|
import eu.etaxonomy.cdm.model.agent.Team;
|
19
|
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
|
20
|
import eu.etaxonomy.cdm.model.reference.OriginalSourceType;
|
21
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
22
|
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
|
23
|
import eu.etaxonomy.taxeditor.newWizard.AbstractNewEntityWizard;
|
24
|
import eu.etaxonomy.taxeditor.newWizard.NewReferenceWizard;
|
25
|
import eu.etaxonomy.taxeditor.remoting.source.CdmServerInfo;
|
26
|
import eu.etaxonomy.taxeditor.remoting.source.ICdmRemoteSource;
|
27
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
28
|
|
29
|
|
30
|
/**
|
31
|
* @author k.luther
|
32
|
* @date 02.05.2017
|
33
|
*/
|
34
|
public class ExtReferenceSelectionDialog extends
|
35
|
AbstractFilteredCdmResourceSelectionDialog<Reference> {
|
36
|
|
37
|
protected static boolean isInReference = false;
|
38
|
private Reference currentReference;
|
39
|
ICdmRepository controller;
|
40
|
ICdmRemoteSource remoteSource ;
|
41
|
Reference remoteSourceRef;
|
42
|
IReferenceService service = null;
|
43
|
|
44
|
|
45
|
/**
|
46
|
* <p>select</p>
|
47
|
*
|
48
|
* @param reference a {@link eu.etaxonomy.cdm.model.reference.ReferenceBase} object.
|
49
|
* @param shell a {@link org.eclipse.swt.widgets.Shell} object.
|
50
|
* @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
|
51
|
* @return a {@link eu.etaxonomy.cdm.model.reference.ReferenceBase} object.
|
52
|
*/
|
53
|
public static Reference select(Shell shell, //ConversationHolder conversation,
|
54
|
Reference reference, boolean isInReference) {
|
55
|
ExtReferenceSelectionDialog dialog = new ExtReferenceSelectionDialog(shell, //conversation,
|
56
|
"Choose a reference", false, reference, isInReference);
|
57
|
return getSelectionFromDialog(dialog);
|
58
|
}
|
59
|
|
60
|
/**
|
61
|
* <p>select</p>
|
62
|
*
|
63
|
* @param reference a {@link eu.etaxonomy.cdm.model.reference.ReferenceBase} object.
|
64
|
* @param shell a {@link org.eclipse.swt.widgets.Shell} object.
|
65
|
* @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
|
66
|
* @return a {@link eu.etaxonomy.cdm.model.reference.ReferenceBase} object.
|
67
|
*/
|
68
|
public static Reference select(Shell shell, //ConversationHolder conversation,
|
69
|
Reference reference) {
|
70
|
ExtReferenceSelectionDialog dialog = new ExtReferenceSelectionDialog(shell, //conversation,
|
71
|
"Choose a reference", false, reference);
|
72
|
return getSelectionFromDialog(dialog);
|
73
|
}
|
74
|
|
75
|
|
76
|
|
77
|
|
78
|
|
79
|
|
80
|
/**
|
81
|
* <p>Constructor for FilteredReferenceSelectionDialog.</p>
|
82
|
*
|
83
|
* @param shell a {@link org.eclipse.swt.widgets.Shell} object.
|
84
|
* @param title a {@link java.lang.String} object.
|
85
|
* @param reference a {@link eu.etaxonomy.cdm.model.reference.ReferenceBase} object.
|
86
|
* @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
|
87
|
* @param multi a boolean.
|
88
|
*/
|
89
|
protected ExtReferenceSelectionDialog(Shell shell, //ConversationHolder conversation,
|
90
|
String title, boolean multi, Reference reference) {
|
91
|
super(shell, //conversation,
|
92
|
title, multi, ExtReferenceSelectionDialog.class.getCanonicalName());
|
93
|
this.currentReference = reference;
|
94
|
// controller = CdmStore.getCurrentApplicationConfiguration();
|
95
|
remoteSource = CdmServerInfo.getDevServerRemoteSource();
|
96
|
remoteSourceRef = ReferenceFactory.newDatabase();
|
97
|
remoteSourceRef.setTitle(remoteSource.getName());
|
98
|
}
|
99
|
|
100
|
|
101
|
|
102
|
|
103
|
/**
|
104
|
* <p>Constructor for FilteredReferenceSelectionDialog.</p>
|
105
|
*
|
106
|
* @param shell a {@link org.eclipse.swt.widgets.Shell} object.
|
107
|
* @param title a {@link java.lang.String} object.
|
108
|
* @param reference a {@link eu.etaxonomy.cdm.model.reference.ReferenceBase} object.
|
109
|
* @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
|
110
|
* @param multi a boolean.
|
111
|
*/
|
112
|
protected ExtReferenceSelectionDialog(Shell shell, //ConversationHolder conversation,
|
113
|
String title, boolean multi, Reference reference, boolean isInReference) {
|
114
|
super(shell, //conversation,
|
115
|
title, multi, ExtReferenceSelectionDialog.class.getCanonicalName());
|
116
|
this.isInReference = isInReference;
|
117
|
this.currentReference = reference;
|
118
|
|
119
|
// controller = CdmStore.getCurrentApplicationConfiguration();
|
120
|
// CdmServerInfoConfig parameterObject = new CdmServerInfoConfig("localhost", "localhost", 8080, "cdmserver/", true);
|
121
|
// CdmServerInfo selectedCsii = new CdmServerInfo(parameterObject);
|
122
|
// CdmInstanceInfo selectedCdmInstance = selectedCsii.getInstanceFromName("local-cuba") ;
|
123
|
// Integer port;
|
124
|
// remoteSource = selectedCsii.getCdmRemoteSource(selectedCdmInstance, 80);
|
125
|
|
126
|
|
127
|
}
|
128
|
|
129
|
|
130
|
/* (non-Javadoc)
|
131
|
* @see eu.etaxonomy.taxeditor.dialogs.AbstractFilteredCdmResourceSelectionDialog#getPersistentObject(java.util.UUID)
|
132
|
*/
|
133
|
/** {@inheritDoc} */
|
134
|
@Override
|
135
|
protected Reference getPersistentObject(UUID cdmUuid) {
|
136
|
Reference extRef = service.load(cdmUuid);
|
137
|
|
138
|
Reference newRef = ReferenceFactory.newReference( extRef.getType());
|
139
|
if (extRef.getTitle() != null){
|
140
|
newRef.setTitle(extRef.getTitle());
|
141
|
}else{
|
142
|
newRef.setTitleCache(extRef.getTitleCache(), true);
|
143
|
}
|
144
|
if (extRef.getAbbrevTitle() != null){
|
145
|
newRef.setAbbrevTitle(extRef.getAbbrevTitle());
|
146
|
}else{
|
147
|
newRef.setAbbrevTitleCache(extRef.getAbbrevTitleCache(), true);
|
148
|
}
|
149
|
|
150
|
if (extRef.getInReference() != null){
|
151
|
Reference inRef = extRef.getInReference();
|
152
|
Reference newRefInRef = ReferenceFactory.newReference( extRef.getInBook().getType());
|
153
|
if (inRef.getTitle() != null){
|
154
|
newRefInRef.setTitle(inRef.getTitle());
|
155
|
}else{
|
156
|
newRefInRef.setTitleCache(inRef.getTitleCache(), true);
|
157
|
}
|
158
|
if (inRef.getAbbrevTitle() != null){
|
159
|
newRefInRef.setAbbrevTitle(inRef.getAbbrevTitle());
|
160
|
}else{
|
161
|
newRefInRef.setAbbrevTitleCache(inRef.getAbbrevTitleCache(), true);
|
162
|
}
|
163
|
newRefInRef.addSource(OriginalSourceType.Other, String.valueOf(newRefInRef.getId()), "Reference", remoteSourceRef, null);
|
164
|
newRef.setInReference(newRefInRef);
|
165
|
newRef.setProtectedTitleCache(false);
|
166
|
newRef.setProtectedAbbrevTitleCache(false);
|
167
|
newRef.addSource(OriginalSourceType.Other, String.valueOf(newRef.getId()), "Reference", remoteSourceRef, null);
|
168
|
}
|
169
|
TeamOrPersonBase author;
|
170
|
if (extRef.getAuthorship() != null){
|
171
|
if (extRef.getAuthorship() instanceof Person){
|
172
|
author = Person.NewTitledInstance(extRef.getAuthorship().getTitleCache());
|
173
|
author.setProtectedTitleCache(true);
|
174
|
}else{
|
175
|
author = Team.NewInstance();
|
176
|
Person newMember;
|
177
|
|
178
|
for (Person member:((Team)extRef.getAuthorship()).getTeamMembers()){
|
179
|
newMember = Person.NewTitledInstance(member.getTitleCache());
|
180
|
((Team)author).addTeamMember(newMember);
|
181
|
}
|
182
|
|
183
|
}
|
184
|
newRef.setAuthorship(author);
|
185
|
}
|
186
|
|
187
|
newRef = CdmStore.getService(IReferenceService.class).save(newRef);
|
188
|
|
189
|
return newRef;
|
190
|
}
|
191
|
|
192
|
/** {@inheritDoc} */
|
193
|
@Override
|
194
|
protected void callService(String pattern) {
|
195
|
|
196
|
|
197
|
if (remoteSource != null){
|
198
|
// if (service == null){
|
199
|
// service = CdmApplicationRemoteConfiguration.getExtReferenceService(remoteSource);
|
200
|
// }
|
201
|
if (pattern.equals("?")){ //$NON-NLS-1$
|
202
|
if (isInReference && currentReference != null){
|
203
|
model = service.getUuidAndTitleCache(null, null, currentReference.getType());
|
204
|
}else{
|
205
|
model = service.getUuidAndTitleCache(null, null);
|
206
|
}
|
207
|
}else{
|
208
|
if (isInReference && currentReference != null){
|
209
|
model = service.getUuidAndTitleCache(limitOfInitialElements, pattern, currentReference.getType());
|
210
|
}else{
|
211
|
model = service.getUuidAndTitleCache(limitOfInitialElements,pattern);
|
212
|
|
213
|
}
|
214
|
}
|
215
|
}
|
216
|
}
|
217
|
|
218
|
|
219
|
/** {@inheritDoc} */
|
220
|
@Override
|
221
|
protected String getTitle(Reference cdmObject) {
|
222
|
if(cdmObject == null){
|
223
|
return "";
|
224
|
}else{
|
225
|
return super.getTitle(cdmObject);
|
226
|
}
|
227
|
// }else{
|
228
|
// return DefaultReferenceCacheStrategy.putAuthorToEndOfString(cdmObject.getTitleCache(), cdmObject.getAuthorship().getTitleCache());
|
229
|
// }
|
230
|
}
|
231
|
|
232
|
/** {@inheritDoc} */
|
233
|
@Override
|
234
|
protected AbstractNewEntityWizard getNewEntityWizard(String parameter) {
|
235
|
return new NewReferenceWizard();
|
236
|
}
|
237
|
|
238
|
/** {@inheritDoc} */
|
239
|
@Override
|
240
|
protected String[] getNewWizardText() {
|
241
|
return new String[]{"Reference "};
|
242
|
}
|
243
|
|
244
|
}
|
245
|
|
246
|
|