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