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.bulkeditor.referencingobjects.e4;
|
11
|
|
12
|
import java.util.ArrayList;
|
13
|
import java.util.Arrays;
|
14
|
import java.util.Collections;
|
15
|
import java.util.Comparator;
|
16
|
import java.util.HashMap;
|
17
|
import java.util.HashSet;
|
18
|
import java.util.List;
|
19
|
import java.util.Map;
|
20
|
import java.util.Set;
|
21
|
import java.util.UUID;
|
22
|
|
23
|
import javax.annotation.PostConstruct;
|
24
|
import javax.annotation.PreDestroy;
|
25
|
|
26
|
import org.apache.log4j.Logger;
|
27
|
import org.eclipse.core.runtime.IProgressMonitor;
|
28
|
import org.eclipse.core.runtime.IStatus;
|
29
|
import org.eclipse.core.runtime.Status;
|
30
|
import org.eclipse.core.runtime.jobs.Job;
|
31
|
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
|
32
|
import org.eclipse.e4.ui.services.EMenuService;
|
33
|
import org.eclipse.jface.viewers.CellEditor;
|
34
|
import org.eclipse.jface.viewers.ICellModifier;
|
35
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
36
|
import org.eclipse.jface.viewers.ITableLabelProvider;
|
37
|
import org.eclipse.jface.viewers.TableViewer;
|
38
|
import org.eclipse.jface.viewers.TableViewerColumn;
|
39
|
import org.eclipse.jface.viewers.TextCellEditor;
|
40
|
import org.eclipse.jface.viewers.TreeNode;
|
41
|
import org.eclipse.jface.viewers.Viewer;
|
42
|
import org.eclipse.swt.SWT;
|
43
|
import org.eclipse.swt.layout.GridData;
|
44
|
import org.eclipse.swt.layout.GridLayout;
|
45
|
import org.eclipse.swt.widgets.Composite;
|
46
|
import org.eclipse.swt.widgets.Display;
|
47
|
import org.eclipse.swt.widgets.Label;
|
48
|
import org.eclipse.swt.widgets.Table;
|
49
|
|
50
|
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
|
51
|
import eu.etaxonomy.cdm.api.service.IAgentService;
|
52
|
import eu.etaxonomy.cdm.api.service.IDescriptionService;
|
53
|
import eu.etaxonomy.cdm.api.service.IEventBaseService;
|
54
|
import eu.etaxonomy.cdm.api.service.IGroupService;
|
55
|
import eu.etaxonomy.cdm.api.service.IMediaService;
|
56
|
import eu.etaxonomy.cdm.api.service.INameService;
|
57
|
import eu.etaxonomy.cdm.api.service.IOccurrenceService;
|
58
|
import eu.etaxonomy.cdm.api.service.IPolytomousKeyNodeService;
|
59
|
import eu.etaxonomy.cdm.api.service.IPolytomousKeyService;
|
60
|
import eu.etaxonomy.cdm.api.service.IReferenceService;
|
61
|
import eu.etaxonomy.cdm.api.service.ITaxonService;
|
62
|
import eu.etaxonomy.cdm.api.service.ITermService;
|
63
|
import eu.etaxonomy.cdm.api.service.IUserService;
|
64
|
import eu.etaxonomy.cdm.api.service.molecular.ISequenceService;
|
65
|
import eu.etaxonomy.cdm.common.CdmUtils;
|
66
|
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
|
67
|
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
|
68
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
69
|
import eu.etaxonomy.cdm.model.common.EventBase;
|
70
|
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
|
71
|
import eu.etaxonomy.cdm.model.description.DescriptionBase;
|
72
|
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
|
73
|
import eu.etaxonomy.cdm.model.description.PolytomousKey;
|
74
|
import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
|
75
|
import eu.etaxonomy.cdm.model.media.Media;
|
76
|
import eu.etaxonomy.cdm.model.molecular.Sequence;
|
77
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
78
|
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
|
79
|
import eu.etaxonomy.cdm.model.permission.Group;
|
80
|
import eu.etaxonomy.cdm.model.permission.User;
|
81
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
82
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
83
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
84
|
import eu.etaxonomy.cdm.model.term.DefinedTermBase;
|
85
|
import eu.etaxonomy.cdm.model.term.TermBase;
|
86
|
import eu.etaxonomy.cdm.persistence.dto.ReferencingObjectDto;
|
87
|
import eu.etaxonomy.cdm.persistence.dto.TermDto;
|
88
|
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
|
89
|
import eu.etaxonomy.taxeditor.bulkeditor.referencingobjects.ReferencingObjectsContentProvider;
|
90
|
import eu.etaxonomy.taxeditor.bulkeditor.referencingobjects.ReferencingObjectsLabelProvider;
|
91
|
import eu.etaxonomy.taxeditor.editor.IReferencingObjectsView;
|
92
|
import eu.etaxonomy.taxeditor.model.AbstractUtility;
|
93
|
import eu.etaxonomy.taxeditor.model.DescriptionHelper;
|
94
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
95
|
import eu.etaxonomy.taxeditor.view.e4.AbstractCdmEditorPartE4;
|
96
|
|
97
|
/**
|
98
|
* @author pplitzner
|
99
|
* @since Aug 16, 2017
|
100
|
*/
|
101
|
public class ReferencingObjectsViewE4 extends AbstractCdmEditorPartE4 implements IReferencingObjectsView{
|
102
|
|
103
|
private static final Logger logger = Logger.getLogger(ReferencingObjectsViewE4.class);
|
104
|
|
105
|
public static final String IS_LOADING = "Loading ...";
|
106
|
// public static final String CANCELED = "Canceled ...";
|
107
|
|
108
|
private Label contentDescription;
|
109
|
private String description;
|
110
|
|
111
|
// private String referencedObjectTitleCache;
|
112
|
private ConversationHolder conversation;
|
113
|
private UUID actualUuid;
|
114
|
private List<ReferencingObjectDto> referencingObjects = null;
|
115
|
private Set<ReferencingObjectDto> referencingObjectsSet = null;
|
116
|
private IProgressMonitor actualMonitor = null;
|
117
|
private Job currentJob = null;
|
118
|
|
119
|
@PostConstruct
|
120
|
public void create(Composite parent, EMenuService menuService) {
|
121
|
if (CdmStore.isActive()){
|
122
|
if(conversation == null){
|
123
|
conversation = CdmStore.createConversation();
|
124
|
}
|
125
|
}
|
126
|
else{
|
127
|
return;
|
128
|
}
|
129
|
parent.setLayout(new GridLayout());
|
130
|
contentDescription = new Label(parent, SWT.NONE);
|
131
|
contentDescription.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
|
132
|
TableViewer tableViewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL
|
133
|
| SWT.V_SCROLL | SWT.FULL_SELECTION);
|
134
|
createColumns(tableViewer);
|
135
|
tableViewer.setContentProvider(new ReferencingObjectsContentProvider());
|
136
|
tableViewer.setLabelProvider(new ReferencingObjectsLabelProvider());
|
137
|
tableViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
|
138
|
|
139
|
tableViewer.setCellModifier(new ICellModifier() {
|
140
|
|
141
|
@Override
|
142
|
public void modify(Object element, String property, Object value) {}
|
143
|
|
144
|
@Override
|
145
|
public Object getValue(Object element, String property) {
|
146
|
ITableLabelProvider tableLabelProvider = null;
|
147
|
if(tableViewer.getLabelProvider() instanceof ITableLabelProvider){
|
148
|
tableLabelProvider = (ITableLabelProvider) tableViewer.getLabelProvider();
|
149
|
}
|
150
|
Object[] columnProperties = tableViewer.getColumnProperties();
|
151
|
for (int i=0;i<columnProperties.length;i++) {
|
152
|
if(columnProperties[i].equals(property) && tableLabelProvider!=null){
|
153
|
return tableLabelProvider.getColumnText(element, i);
|
154
|
}
|
155
|
}
|
156
|
return "";
|
157
|
}
|
158
|
|
159
|
@Override
|
160
|
public boolean canModify(Object element, String property) {
|
161
|
return true;
|
162
|
}
|
163
|
});
|
164
|
|
165
|
viewer = tableViewer;
|
166
|
|
167
|
// Propagate selection from viewer
|
168
|
selectionChangedListener = (event -> selService.setSelection(AbstractUtility.getElementsFromSelectionChangedEvent(event)));
|
169
|
viewer.addSelectionChangedListener(selectionChangedListener);
|
170
|
|
171
|
//create context menu
|
172
|
menuService.registerContextMenu(viewer.getControl(), "eu.etaxonomy.taxeditor.bulkeditor.popupmenu.referencingobjectsview");
|
173
|
|
174
|
}
|
175
|
|
176
|
/**
|
177
|
* Create the columns for the table
|
178
|
* @param viewer
|
179
|
*/
|
180
|
private void createColumns(TableViewer viewer) {
|
181
|
Table table = viewer.getTable();
|
182
|
String[] titles = {"Class", "Description", "UUID", "Object ID" };
|
183
|
int[] bounds = { 100, 200, 100, 70};
|
184
|
|
185
|
CellEditor[] editors = new CellEditor[titles.length];
|
186
|
|
187
|
for (int i = 0; i < titles.length; i++) {
|
188
|
TableViewerColumn column = new TableViewerColumn(viewer, SWT.NONE);
|
189
|
editors[i] = new TextCellEditor(table);
|
190
|
column.getColumn().setText(titles[i]);
|
191
|
column.getColumn().setWidth(bounds[i]);
|
192
|
column.getColumn().setResizable(true);
|
193
|
column.getColumn().setMoveable(true);
|
194
|
}
|
195
|
table.setHeaderVisible(true);
|
196
|
table.setLinesVisible(true);
|
197
|
|
198
|
viewer.setCellEditors(editors);
|
199
|
viewer.setColumnProperties(titles);
|
200
|
}
|
201
|
|
202
|
@Override
|
203
|
public void updateReferencingObjects(final UUID entityUUID, final Class objectClass) {
|
204
|
if (actualUuid == entityUUID){
|
205
|
return ;
|
206
|
}
|
207
|
|
208
|
if(actualMonitor!=null && !actualMonitor.isCanceled()){
|
209
|
while(!actualMonitor.isCanceled()){
|
210
|
actualMonitor.setCanceled(true);
|
211
|
}
|
212
|
}
|
213
|
|
214
|
currentJob = new Job("Update Referencing Objects for " + entityUUID) {
|
215
|
|
216
|
@Override
|
217
|
protected IStatus run(final IProgressMonitor monitor) {
|
218
|
monitor.beginTask("Calculating referencing objects", 100);
|
219
|
actualUuid = entityUUID;
|
220
|
|
221
|
monitor.worked(2);
|
222
|
ReferencingObjectDto loadDto = new ReferencingObjectDto();
|
223
|
loadDto.setTitleCache(IS_LOADING);
|
224
|
referencingObjects = Arrays.asList(loadDto);
|
225
|
updateView();
|
226
|
if(monitor.isCanceled()) {
|
227
|
// actualUuid = null;
|
228
|
return Status.CANCEL_STATUS;
|
229
|
}
|
230
|
if (actualMonitor != null){
|
231
|
actualMonitor.setCanceled(true);
|
232
|
|
233
|
}
|
234
|
actualMonitor = monitor;
|
235
|
if (entityUUID != null){
|
236
|
monitor.subTask("Load data from server");
|
237
|
monitor.worked(1);
|
238
|
Set<ReferencingObjectDto> refObjectsFromServer = loadReferencingObjects(entityUUID, objectClass);
|
239
|
monitor.worked(25);
|
240
|
if(monitor.isCanceled()) {
|
241
|
// actualUuid = null;
|
242
|
return Status.CANCEL_STATUS;
|
243
|
}
|
244
|
referencingObjectsSet = refObjectsFromServer;
|
245
|
|
246
|
monitor.subTask("Show without description");
|
247
|
monitor.worked(1);//maybe this helps to update the subtask label
|
248
|
|
249
|
//TODO have a status line instead
|
250
|
updateDescriptionLabel(description + "(n="+referencingObjectsSet.size()+")"); //
|
251
|
|
252
|
|
253
|
List<ReferencingObjectDto> localDtos = sortToList(referencingObjectsSet, monitor);
|
254
|
monitor.worked(10);
|
255
|
if(monitor.isCanceled()) {
|
256
|
// actualUuid = null;
|
257
|
return Status.CANCEL_STATUS;
|
258
|
}
|
259
|
referencingObjects = localDtos;
|
260
|
updateView();
|
261
|
|
262
|
monitor.subTask("Initialize");
|
263
|
monitor.worked(1);//maybe this helps to update the subtask label
|
264
|
initializeDtos(localDtos, monitor, 50);
|
265
|
if (monitor.isCanceled()){
|
266
|
// actualUuid = null;
|
267
|
//TODO use status line instead
|
268
|
// referencingObjects = Arrays.asList(CANCELED);
|
269
|
updateView();
|
270
|
// monitor.done();
|
271
|
return Status.CANCEL_STATUS;
|
272
|
}
|
273
|
|
274
|
//not necessary anymore, we sort by type and
|
275
|
//id as this can be done immediately
|
276
|
// monitor.subTask("Sort");
|
277
|
// referencingObjects = sortReferencing();
|
278
|
// monitor.worked(5);
|
279
|
// if (referencingObjects == null){
|
280
|
// if (monitor.isCanceled()){
|
281
|
//// actualUuid = null;
|
282
|
// return Status.CANCEL_STATUS;
|
283
|
// }
|
284
|
// }
|
285
|
|
286
|
if(monitor.isCanceled()) {
|
287
|
return Status.CANCEL_STATUS;
|
288
|
}
|
289
|
monitor.subTask("Update View");
|
290
|
|
291
|
updateView();
|
292
|
monitor.worked(5);
|
293
|
}
|
294
|
monitor.done();
|
295
|
actualMonitor = null;
|
296
|
|
297
|
return Status.OK_STATUS;
|
298
|
}
|
299
|
|
300
|
};
|
301
|
currentJob.setUser(true);
|
302
|
|
303
|
currentJob.schedule();
|
304
|
}
|
305
|
|
306
|
private List<ReferencingObjectDto> sortToList(Set<ReferencingObjectDto> referencingObjectsSet, IProgressMonitor monitor) {
|
307
|
List<ReferencingObjectDto> result = new ArrayList<>(referencingObjectsSet);
|
308
|
//TODO make singleton
|
309
|
Collections.sort(result, new RefObjectDtoComparator());
|
310
|
return result;
|
311
|
}
|
312
|
|
313
|
protected boolean initializeDtos(List<ReferencingObjectDto> localDtos, IProgressMonitor monitor, int work) {
|
314
|
IProgressMonitor subMonitor = AbstractUtility.getSubProgressMonitor(monitor, work);
|
315
|
subMonitor.beginTask("Initialize DTOs", localDtos.size());
|
316
|
|
317
|
int i = 100 - 20; //the first run should only include 20 records
|
318
|
|
319
|
Set<ReferencingObjectDto> toInitialize = new HashSet<>();
|
320
|
for (ReferencingObjectDto dto : localDtos){
|
321
|
toInitialize.add(dto);
|
322
|
|
323
|
// dto.setTitleCache(ReferencingObjectFormatter.format(dto.getReferencedEntity(), CdmStore.getDefaultLanguage() ));
|
324
|
if (monitor.isCanceled()){
|
325
|
return false;
|
326
|
}
|
327
|
subMonitor.worked(1);
|
328
|
if (++i == 100){
|
329
|
initBulk(toInitialize);
|
330
|
updateView();
|
331
|
toInitialize = new HashSet<>();
|
332
|
i = 0;
|
333
|
}
|
334
|
}
|
335
|
initBulk(toInitialize);
|
336
|
return true;
|
337
|
}
|
338
|
|
339
|
private void initBulk(Set<ReferencingObjectDto> toInitialize) {
|
340
|
Set<ReferencingObjectDto> initialized = CdmStore.getCommonService().initializeReferencingObjectDtos(toInitialize, true, true, true, CdmStore.getDefaultLanguage());
|
341
|
Map<UUID,ReferencingObjectDto> map = new HashMap<>();
|
342
|
initialized.forEach(i->map.put(i.getUuid(), i));
|
343
|
toInitialize.forEach(dto->merge(dto, map.get(dto.getUuid())));
|
344
|
updateView();
|
345
|
|
346
|
}
|
347
|
|
348
|
private void merge(ReferencingObjectDto to, ReferencingObjectDto from) {
|
349
|
to.setTitleCache(from.getTitleCache());
|
350
|
to.setOpenInTarget(from.getOpenInTarget());
|
351
|
to.setReferencedEntity(from.getReferencedEntity());
|
352
|
}
|
353
|
|
354
|
private Set<ReferencingObjectDto> loadReferencingObjects(UUID entity, Class objectClass) {
|
355
|
//TODO why do we need to load the referenced object here
|
356
|
CdmBase referencedObject = null;
|
357
|
try {
|
358
|
if (objectClass.getSuperclass().equals(TeamOrPersonBase.class) ){
|
359
|
referencedObject = CdmStore.getService(IAgentService.class).load(entity);
|
360
|
} else if (objectClass.getSuperclass().equals(TaxonName.class)){
|
361
|
referencedObject = CdmStore.getService(INameService.class).load(entity);
|
362
|
} else if (objectClass.getSuperclass().equals(TaxonBase.class)){
|
363
|
referencedObject = CdmStore.getService(ITaxonService.class).load(entity);
|
364
|
} else if (objectClass.equals(Reference.class)){
|
365
|
referencedObject = CdmStore.getService(IReferenceService.class).load(entity);
|
366
|
} else if (objectClass.getSuperclass().equals(SpecimenOrObservationBase.class)){
|
367
|
referencedObject = CdmStore.getService(IOccurrenceService.class).load(entity);
|
368
|
} else if (objectClass.isAssignableFrom(User.class)){
|
369
|
referencedObject = CdmStore.getService(IUserService.class).load(entity);
|
370
|
} else if (objectClass.isAssignableFrom(Group.class)){
|
371
|
referencedObject = CdmStore.getService(IGroupService.class).load(entity);
|
372
|
} else if (objectClass.isAssignableFrom(Media.class)){
|
373
|
referencedObject = CdmStore.getService(IMediaService.class).load(entity);
|
374
|
} else if (DescriptionBase.class.isAssignableFrom(objectClass)){
|
375
|
referencedObject = CdmStore.getService(IDescriptionService.class).load(entity);
|
376
|
} else if (DescriptionElementBase.class.isAssignableFrom(objectClass)){
|
377
|
referencedObject = CdmStore.getService(IDescriptionService.class).loadDescriptionElement(entity, null);
|
378
|
} else if (objectClass.equals(Sequence.class)){
|
379
|
referencedObject = CdmStore.getService(ISequenceService.class).load(entity, null);
|
380
|
} else if (PolytomousKey.class.isAssignableFrom(objectClass)){
|
381
|
referencedObject = CdmStore.getService(IPolytomousKeyService.class).load(entity, null);
|
382
|
} else if (PolytomousKeyNode.class.isAssignableFrom(objectClass)){
|
383
|
referencedObject = CdmStore.getService(IPolytomousKeyNodeService.class).load(entity, null);
|
384
|
} else if (DefinedTermBase.class.isAssignableFrom(objectClass)){
|
385
|
referencedObject = CdmStore.getService(ITermService.class).load(entity, null);
|
386
|
} else if (EventBase.class.isAssignableFrom(objectClass)){
|
387
|
referencedObject = CdmStore.getService(IEventBaseService.class).load(entity, null);
|
388
|
} else if (User.class.isAssignableFrom(objectClass)){
|
389
|
referencedObject = CdmStore.getService(IUserService.class).load(entity, null);
|
390
|
} else if (Group.class.isAssignableFrom(objectClass)){
|
391
|
referencedObject = CdmStore.getService(IGroupService.class).load(entity, null);
|
392
|
}
|
393
|
else if(CdmBase.class.isAssignableFrom(objectClass)){
|
394
|
referencedObject = CdmStore.getCommonService().find(objectClass, entity);
|
395
|
}
|
396
|
//referencedObject =(CdmBase) CdmStore.getService(IIdentifiableEntityService.class).load(referencedObject.getUuid());
|
397
|
Set<ReferencingObjectDto> setOfReferencingObjects = null;
|
398
|
|
399
|
if (referencedObject != null){
|
400
|
// if(referencedObject.isInstanceOf(IdentifiableEntity.class)){
|
401
|
// referencedObjectTitleCache = (HibernateProxyHelper.deproxy(referencedObject, IdentifiableEntity.class)).getTitleCache();
|
402
|
// }
|
403
|
// else if(referencedObject.isInstanceOf(DescriptionElementBase.class)){
|
404
|
// referencedObjectTitleCache = DescriptionHelper.getLabel(referencedObject);
|
405
|
// }
|
406
|
// else if (referencedObject.isInstanceOf(User.class)){
|
407
|
// referencedObjectTitleCache = ((User)referencedObject).getUsername();
|
408
|
// }else{
|
409
|
// referencedObjectTitleCache = DescriptionHelper.getLabel(referencedObject);
|
410
|
// }
|
411
|
setOfReferencingObjects = CdmStore.getCommonService().getReferencingObjectDtos(referencedObject);
|
412
|
return setOfReferencingObjects;
|
413
|
}
|
414
|
|
415
|
} catch (Exception e) {
|
416
|
logger.debug("Error retrieving referencing objects", e);
|
417
|
e.printStackTrace();
|
418
|
updateDescriptionLabel("The referencing objects view could not be loaded completely. Some problems occurred: " + e.getMessage());
|
419
|
}
|
420
|
return null;
|
421
|
}
|
422
|
|
423
|
class RefObjectDtoComparator implements Comparator<ReferencingObjectDto>{
|
424
|
|
425
|
@Override
|
426
|
public int compare(ReferencingObjectDto dto1, ReferencingObjectDto dto2) {
|
427
|
int result = dto1.getType().getSimpleName().compareToIgnoreCase(dto2.getType().getSimpleName());
|
428
|
if (result == 0) {
|
429
|
result = Integer.compare(dto1.getId(),dto2.getId());
|
430
|
}
|
431
|
return result;
|
432
|
}
|
433
|
}
|
434
|
|
435
|
private void updateView() {
|
436
|
Display.getDefault().asyncExec(()->{
|
437
|
if (viewer != null && !viewer.getControl().isDisposed()){
|
438
|
try{
|
439
|
viewer.setInput(referencingObjects);
|
440
|
viewer.refresh();
|
441
|
|
442
|
//enable/disable table
|
443
|
viewer.getControl().setEnabled(referencingObjects!=null);
|
444
|
}catch(Exception e){
|
445
|
e.printStackTrace();
|
446
|
logger.debug(e.getStackTrace());
|
447
|
updateDescriptionLabel("The referencing objects view could not be updated completely. Some Problems occurred: " + e.getMessage());
|
448
|
}
|
449
|
}
|
450
|
});
|
451
|
}
|
452
|
|
453
|
|
454
|
private void updateDescriptionLabel(final String description){
|
455
|
Display.getDefault().asyncExec(()->{
|
456
|
if(contentDescription!=null && !contentDescription.isDisposed()) {
|
457
|
contentDescription.setText(description.replace("&", "&&"));
|
458
|
}
|
459
|
}
|
460
|
);
|
461
|
}
|
462
|
|
463
|
@Override
|
464
|
public void selectionChanged_internal(Object selection, MPart activePart, MPart thisPart) {
|
465
|
if(activePart==thisPart){
|
466
|
return;
|
467
|
}
|
468
|
|
469
|
IStructuredSelection structuredSelection = createSelection(selection);
|
470
|
if(structuredSelection!=null){
|
471
|
//referencedObjectTitleCache = null;
|
472
|
showViewer(structuredSelection, activePart, viewer);
|
473
|
}
|
474
|
}
|
475
|
|
476
|
@Override
|
477
|
public void showViewer(IStructuredSelection selection, MPart activePart, Viewer viewer){
|
478
|
// this.part = part;
|
479
|
|
480
|
Object firstElement = selection.getFirstElement();
|
481
|
if (firstElement instanceof TermDto){
|
482
|
TermDto termDto = (TermDto) firstElement;
|
483
|
description = "'"+termDto.getRepresentation_L10n() + "' is referenced by:";
|
484
|
updateDescriptionLabel(description);
|
485
|
updateReferencingObjects(termDto.getUuid(), TermBase.class );
|
486
|
return;
|
487
|
}
|
488
|
if(firstElement instanceof TreeNode){
|
489
|
firstElement = ((TreeNode) firstElement).getValue();
|
490
|
}
|
491
|
if (firstElement instanceof TaxonNode && !((TaxonNode)firstElement).hasTaxon()){
|
492
|
firstElement = ((TaxonNode)firstElement).getClassification();
|
493
|
}
|
494
|
if(firstElement instanceof CdmBase){
|
495
|
CdmBase referencedCdmObject = (CdmBase) firstElement;
|
496
|
if (referencedCdmObject.getUuid() == actualUuid){
|
497
|
return;
|
498
|
}
|
499
|
String referencedObjectTitleCache = null;
|
500
|
if(referencedCdmObject.isInstanceOf(IdentifiableEntity.class)){
|
501
|
referencedObjectTitleCache = (HibernateProxyHelper.deproxy(referencedCdmObject, IdentifiableEntity.class)).getTitleCache();
|
502
|
}
|
503
|
else if(referencedCdmObject.isInstanceOf(DescriptionElementBase.class)){
|
504
|
referencedObjectTitleCache = DescriptionHelper.getLabel(referencedCdmObject);
|
505
|
}
|
506
|
else if (referencedCdmObject.isInstanceOf(User.class)){
|
507
|
referencedObjectTitleCache = ((User)referencedCdmObject).getUsername();
|
508
|
}else if (referencedCdmObject.isInstanceOf(TaxonNode.class)){
|
509
|
referencedObjectTitleCache = "TaxonNode of "+(HibernateProxyHelper.deproxy(referencedCdmObject, TaxonNode.class)).getTaxon().getTitleCache();
|
510
|
}
|
511
|
if (CdmUtils.isBlank(referencedObjectTitleCache)){
|
512
|
referencedObjectTitleCache = "#"+referencedCdmObject.getId();
|
513
|
}
|
514
|
description = referencedCdmObject.getUserFriendlyTypeName() + " '" + referencedObjectTitleCache + "' is referenced by:";
|
515
|
updateDescriptionLabel(description);
|
516
|
|
517
|
updateReferencingObjects(referencedCdmObject.getUuid(),firstElement.getClass() );
|
518
|
|
519
|
}else if (firstElement instanceof UuidAndTitleCache<?>){
|
520
|
UuidAndTitleCache<?> element = (UuidAndTitleCache<?>) firstElement;
|
521
|
description = element.getType().getSimpleName() + " '" + element.getTitleCache() + "' is referenced by:";
|
522
|
updateDescriptionLabel(description);
|
523
|
updateReferencingObjects(element.getUuid(),element.getType());
|
524
|
}
|
525
|
else if (firstElement != null){
|
526
|
updateView();
|
527
|
description = "undefined:";
|
528
|
updateDescriptionLabel(description);
|
529
|
}
|
530
|
}
|
531
|
|
532
|
@PreDestroy
|
533
|
public void dispose() {
|
534
|
if(conversation!=null){
|
535
|
conversation.close();
|
536
|
conversation = null;
|
537
|
}
|
538
|
}
|
539
|
|
540
|
@Override
|
541
|
public void changed(Object object) {
|
542
|
// no editing in this view
|
543
|
}
|
544
|
|
545
|
@Override
|
546
|
public boolean onComplete() {
|
547
|
return false;
|
548
|
}
|
549
|
|
550
|
@Override
|
551
|
protected String getViewName() {
|
552
|
return "Referencing Objects";
|
553
|
}
|
554
|
|
555
|
}
|