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
|
package eu.etaxonomy.taxeditor.editor;
|
10
|
|
11
|
import java.util.Collection;
|
12
|
import java.util.HashSet;
|
13
|
import java.util.List;
|
14
|
import java.util.UUID;
|
15
|
|
16
|
import org.eclipse.core.commands.ExecutionEvent;
|
17
|
import org.eclipse.core.commands.operations.IOperationHistory;
|
18
|
import org.eclipse.core.commands.operations.IUndoContext;
|
19
|
import org.eclipse.e4.ui.model.application.MApplication;
|
20
|
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
|
21
|
import org.eclipse.e4.ui.model.application.ui.basic.MPartStack;
|
22
|
import org.eclipse.e4.ui.workbench.modeling.EModelService;
|
23
|
import org.eclipse.e4.ui.workbench.modeling.EPartService;
|
24
|
import org.eclipse.e4.ui.workbench.modeling.EPartService.PartState;
|
25
|
import org.eclipse.jface.dialogs.MessageDialog;
|
26
|
import org.eclipse.jface.viewers.ISelection;
|
27
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
28
|
import org.eclipse.jface.viewers.TreeNode;
|
29
|
import org.eclipse.swt.widgets.Shell;
|
30
|
import org.eclipse.ui.IEditorPart;
|
31
|
import org.eclipse.ui.handlers.HandlerUtil;
|
32
|
|
33
|
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
|
34
|
import eu.etaxonomy.cdm.model.description.DescriptiveDataSet;
|
35
|
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
|
36
|
import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
|
37
|
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
|
38
|
import eu.etaxonomy.cdm.model.taxon.Synonym;
|
39
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
40
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
41
|
import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto;
|
42
|
import eu.etaxonomy.taxeditor.bulkeditor.e4.BulkEditorE4;
|
43
|
import eu.etaxonomy.taxeditor.bulkeditor.input.TaxonEditorInput;
|
44
|
import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.DescriptiveDataSetEditor;
|
45
|
import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.CharacterMatrixPart;
|
46
|
import eu.etaxonomy.taxeditor.editor.e4.TaxonEditorInputE4;
|
47
|
import eu.etaxonomy.taxeditor.editor.group.authority.CdmAuthorityEditorInput;
|
48
|
import eu.etaxonomy.taxeditor.editor.group.authority.e4.CdmAuthorityEditorE4;
|
49
|
import eu.etaxonomy.taxeditor.editor.internal.TaxeditorEditorPlugin;
|
50
|
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
|
51
|
import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4;
|
52
|
import eu.etaxonomy.taxeditor.editor.view.checklist.e4.DistributionEditorPart;
|
53
|
import eu.etaxonomy.taxeditor.editor.view.derivate.DerivateView;
|
54
|
import eu.etaxonomy.taxeditor.editor.view.derivate.DerivateViewEditorInput;
|
55
|
import eu.etaxonomy.taxeditor.model.AbstractUtility;
|
56
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
57
|
import eu.etaxonomy.taxeditor.security.RequiredPermissions;
|
58
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
59
|
import eu.etaxonomy.taxeditor.workbench.WorkbenchUtility;
|
60
|
import eu.etaxonomy.taxeditor.workbench.part.IE4SavablePart;
|
61
|
|
62
|
/**
|
63
|
* Utility for the editor package
|
64
|
*
|
65
|
* @author n.hoffmann
|
66
|
* @created 20.01.2009
|
67
|
*/
|
68
|
public class EditorUtil extends AbstractUtility {
|
69
|
|
70
|
private static final String NAME_EDITOR_ID = "eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4";
|
71
|
|
72
|
private static boolean factsVisible = true;
|
73
|
|
74
|
private static boolean mediaVisible = true;
|
75
|
|
76
|
public static void openDescriptiveDataSetEditor(UUID descriptiveDataSetUuid, EModelService modelService, EPartService partService, MApplication application){
|
77
|
Collection<MPart> parts = partService.getParts();
|
78
|
for (MPart part : parts) {
|
79
|
if(part.getObject() instanceof DescriptiveDataSetEditor
|
80
|
&& ((DescriptiveDataSetEditor) part.getObject()).getDescriptiveDataSet().getUuid().equals(descriptiveDataSetUuid)){
|
81
|
partService.showPart(part, PartState.ACTIVATE);
|
82
|
return;
|
83
|
}
|
84
|
}
|
85
|
String partId = AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_VIEW_DESCRIPTIVEDATASET_DESCRIPTIVEDATASETEDITOR;
|
86
|
MPart part = showPart(partId, modelService, partService, application);
|
87
|
DescriptiveDataSetEditor editor = (DescriptiveDataSetEditor) part.getObject();
|
88
|
editor.init(descriptiveDataSetUuid);
|
89
|
}
|
90
|
|
91
|
public static void openCharacterMatrix(UUID descriptiveDataSetUuid, EModelService modelService, EPartService partService, MApplication application){
|
92
|
Collection<MPart> parts = partService.getParts();
|
93
|
for (MPart part : parts) {
|
94
|
if(part.getObject() instanceof CharacterMatrixPart
|
95
|
&& ((CharacterMatrixPart) part.getObject()).getDescriptiveDataSet().getUuid().equals(descriptiveDataSetUuid)){
|
96
|
partService.showPart(part, PartState.ACTIVATE);
|
97
|
return;
|
98
|
}
|
99
|
}
|
100
|
String partId = AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_DESCRIPTIVEDATASET_MATRIX_CHARACTERMATRIXPART;
|
101
|
MPart part = showPart(partId, modelService, partService, application);
|
102
|
CharacterMatrixPart editor = (CharacterMatrixPart) part.getObject();
|
103
|
editor.init(descriptiveDataSetUuid, true);
|
104
|
}
|
105
|
|
106
|
public static void openDistributionEditor(List<TaxonNodeDto> parentTaxonUuidList, EModelService modelService, EPartService partService, MApplication application){
|
107
|
String partId = AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_VIEW_CHECKLIST_E4_DISTRIBUTIONEDITORPART;
|
108
|
checkAndCloseFactsAndMediaParts(partService);
|
109
|
MPart part = showPart(partId, modelService, partService, application);
|
110
|
DistributionEditorPart editor = (DistributionEditorPart) part.getObject();
|
111
|
editor.init(parentTaxonUuidList);
|
112
|
}
|
113
|
|
114
|
public static void checkAndCloseFactsAndMediaParts(EPartService partService) {
|
115
|
String partIdFactualData = AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_VIEW_DESCRIPTIVE_E4_FACTUALDATAPARTE4;
|
116
|
String partIdMedia = AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_VIEW_MEDIA_E4_MEDIAVIEWPARTE4;
|
117
|
MPart part1 = partService.findPart(AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_VIEW_DESCRIPTIVE_E4_FACTUALDATAPARTE4);
|
118
|
if (factsVisible || (part1!=null && part1.getWidget() != null && partService.isPartVisible(part1))){
|
119
|
factsVisible = true;
|
120
|
}else{
|
121
|
factsVisible = false;
|
122
|
}
|
123
|
part1 = partService.findPart(AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_VIEW_MEDIA_E4_MEDIAVIEWPARTE4);
|
124
|
if (mediaVisible || (part1!=null && part1.getWidget() != null && partService.isPartVisible(part1))){
|
125
|
mediaVisible = true;
|
126
|
}else{
|
127
|
mediaVisible = false;
|
128
|
}
|
129
|
closePart(partIdMedia, partService);
|
130
|
closePart(partIdFactualData, partService);
|
131
|
}
|
132
|
|
133
|
|
134
|
public static void openSpecimenEditor(DerivateViewEditorInput input, EModelService modelService, EPartService partService, MApplication application){
|
135
|
String partId = AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_VIEW_DERIVATE_DERIVATEVIEW;
|
136
|
MPart part = showPart(partId, modelService, partService, application);
|
137
|
DerivateView derivateView = (DerivateView) part.getObject();
|
138
|
derivateView.init(input);
|
139
|
}
|
140
|
|
141
|
public static void openRightsEditor(CdmAuthorityEditorInput input, EModelService modelService, EPartService partService, MApplication application){
|
142
|
Collection<MPart> parts = partService.getParts();
|
143
|
for (MPart part : parts) {
|
144
|
if(part.getObject() instanceof CdmAuthorityEditorE4
|
145
|
&& ((CdmAuthorityEditorE4) part.getObject()).getInput().getGroup().equals(input.getGroup())){
|
146
|
partService.showPart(part, PartState.ACTIVATE);
|
147
|
return;
|
148
|
}
|
149
|
}
|
150
|
String partId = AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_GROUP_AUTHORITY_E4_CDMAUTHORITYEDITORE4;
|
151
|
MPart part = showPart(partId, modelService, partService, application);
|
152
|
CdmAuthorityEditorE4 authorityView = (CdmAuthorityEditorE4) part.getObject();
|
153
|
authorityView.init(input);
|
154
|
}
|
155
|
|
156
|
public static MPart showPart(String partId, EModelService modelService, EPartService partService, MApplication application){
|
157
|
MPart part = partService.findPart(partId);
|
158
|
if(part==null || modelService.getPartDescriptor(partId).isAllowMultiple()){
|
159
|
part = partService.createPart(partId);
|
160
|
}
|
161
|
MPartStack editorAreaPartStack = WorkbenchUtility.getEditorAreaPartStack(application, modelService);
|
162
|
if(editorAreaPartStack!=null){
|
163
|
editorAreaPartStack.getChildren().add(part);
|
164
|
}
|
165
|
|
166
|
return partService.showPart(part, PartState.ACTIVATE);
|
167
|
|
168
|
}
|
169
|
|
170
|
public static MPart showPart(String partId, EModelService modelService, EPartService partService){
|
171
|
MPart part = partService.findPart(partId);
|
172
|
if(part==null || modelService.getPartDescriptor(partId).isAllowMultiple()){
|
173
|
part = partService.createPart(partId);
|
174
|
partService.activate(part);
|
175
|
}else{
|
176
|
partService.activate(part);
|
177
|
}
|
178
|
|
179
|
return part;
|
180
|
}
|
181
|
|
182
|
public static void openTaxonNodeE4(UUID taxonNodeUuid, EModelService modelService, EPartService partService, MApplication application) {
|
183
|
TaxonEditorInputE4 input = TaxonEditorInputE4.NewInstance(taxonNodeUuid);
|
184
|
openNameEditor_internal(input, modelService, partService, application);
|
185
|
}
|
186
|
|
187
|
public static void openTaxonBaseE4(UUID taxonBaseUuid, EModelService modelService, EPartService partService, MApplication application) {
|
188
|
TaxonEditorInputE4 input = TaxonEditorInputE4.NewInstanceFromTaxonBase(taxonBaseUuid);
|
189
|
openNameEditor_internal(input, modelService, partService, application);
|
190
|
}
|
191
|
|
192
|
public static void openTaxonBaseE4(UUID taxonBaseUuid) {
|
193
|
//FIXME E4 this can probably be removed when fully migrated
|
194
|
TaxonEditorInputE4 input = TaxonEditorInputE4.NewInstanceFromTaxonBase(taxonBaseUuid);
|
195
|
|
196
|
EPartService partService = TaxeditorEditorPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getService(EPartService.class);
|
197
|
EModelService modelService = TaxeditorEditorPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getService(EModelService.class);
|
198
|
openNameEditor_internal(input, modelService, partService, null);
|
199
|
}
|
200
|
|
201
|
private static void openNameEditor_internal(TaxonEditorInputE4 input, EModelService modelService, EPartService partService, MApplication application) {
|
202
|
TaxonBase<?> taxonBase = input.getTaxon();
|
203
|
TaxonNode node = input.getTaxonNode();
|
204
|
if(taxonBase==null){
|
205
|
return;
|
206
|
}
|
207
|
boolean hasPermission = false;
|
208
|
// if (node != null){
|
209
|
hasPermission = CdmStore.currentAuthentiationHasPermission(node, RequiredPermissions.TAXON_EDIT);
|
210
|
// }
|
211
|
// if (!hasPermission){
|
212
|
// MessagingUtils.warningDialog(Messages.EditorUtil_MISSING_PERMISSION, TaxonEditorInputE4.class, Messages.EditorUtil_MISSING_PERMISSION_MESSAGE);
|
213
|
// return;
|
214
|
// }
|
215
|
if (taxonBase.isOrphaned()) {
|
216
|
if(taxonBase.isInstanceOf(Synonym.class)){
|
217
|
MessagingUtils.warningDialog(Messages.EditorUtil_ORPHAN_ACCEPTED_TAXON, TaxonEditorInputE4.class, Messages.EditorUtil_ORPHAN_ACCEPTED_TAXON_MESSAGE);
|
218
|
return;
|
219
|
}
|
220
|
else{
|
221
|
MessagingUtils.warningDialog(Messages.EditorUtil_ORPHAN_TAXON, TaxonEditorInputE4.class, Messages.EditorUtil_ORPHAN_TAXON_MESSAGE);
|
222
|
return;
|
223
|
}
|
224
|
}
|
225
|
|
226
|
Collection<MPart> parts = partService.getParts();
|
227
|
//check if part is already opened
|
228
|
for (MPart part : parts) {
|
229
|
if(part.getObject() instanceof TaxonNameEditorE4
|
230
|
&& ((TaxonNameEditorE4) part.getObject()).getTaxon()!=null
|
231
|
&& ((TaxonNameEditorE4) part.getObject()).getTaxon().getUuid().equals(input.getTaxon().getUuid())){
|
232
|
if (part.isDirty()){
|
233
|
forceUserSaveE4Editor(((TaxonNameEditorE4) part.getObject()), getShell());
|
234
|
}
|
235
|
partService.hidePart(part);
|
236
|
break;
|
237
|
}
|
238
|
}
|
239
|
MPart part = showPart(NAME_EDITOR_ID, modelService, partService, application);
|
240
|
|
241
|
TaxonNameEditorE4 editor = (TaxonNameEditorE4) part.getObject();
|
242
|
// editor.setDisabled();
|
243
|
editor.init(input);
|
244
|
// editor.setEnabled();
|
245
|
editor.setFocus();
|
246
|
if (factsVisible){
|
247
|
showFacts(modelService, partService);
|
248
|
factsVisible = false;
|
249
|
}
|
250
|
|
251
|
if (mediaVisible){
|
252
|
showMedia(modelService, partService);
|
253
|
mediaVisible = false;
|
254
|
}
|
255
|
}
|
256
|
|
257
|
public static void showMedia(EModelService modelService, EPartService partService) {
|
258
|
String partIdFactualData = AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_VIEW_MEDIA_E4_MEDIAVIEWPARTE4;
|
259
|
showPart(partIdFactualData, modelService, partService);
|
260
|
|
261
|
}
|
262
|
|
263
|
public static void showFacts(EModelService modelService, EPartService partService) {
|
264
|
String partIdFactualData = AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_VIEW_DESCRIPTIVE_E4_FACTUALDATAPARTE4;
|
265
|
showPart(partIdFactualData, modelService, partService);
|
266
|
|
267
|
}
|
268
|
|
269
|
public static Collection<MPart> checkForChanges(UUID taxonUUID, EPartService partService ){
|
270
|
Collection<MPart> parts = partService.getParts();
|
271
|
Collection<MPart> dirtyParts = new HashSet();
|
272
|
//check if part is already opened
|
273
|
boolean isDirty = false;
|
274
|
for (MPart part : parts) {
|
275
|
if(part.getObject() instanceof TaxonNameEditorE4
|
276
|
&& ((TaxonNameEditorE4) part.getObject()).getTaxon()!=null
|
277
|
&& ((TaxonNameEditorE4) part.getObject()).getTaxon().getUuid().equals(taxonUUID)){
|
278
|
if (part.isDirty()){
|
279
|
dirtyParts.add(part);
|
280
|
}
|
281
|
|
282
|
break;
|
283
|
}else if (taxonUUID == null){
|
284
|
if (part.isDirty()){
|
285
|
dirtyParts.add(part);
|
286
|
}
|
287
|
}
|
288
|
}
|
289
|
return dirtyParts;
|
290
|
}
|
291
|
|
292
|
public static Collection<IE4SavablePart> checkForTaxonChanges(UUID taxonUUID, EPartService partService ){
|
293
|
Collection<MPart> parts = partService.getParts();
|
294
|
Collection<IE4SavablePart> dirtyParts = new HashSet<>();
|
295
|
//check if part is already opened
|
296
|
for (MPart part : parts) {
|
297
|
if(part.getObject() instanceof TaxonNameEditorE4
|
298
|
&& ((TaxonNameEditorE4) part.getObject()).getTaxon()!=null
|
299
|
&& ((TaxonNameEditorE4) part.getObject()).getTaxon().getUuid().equals(taxonUUID)){
|
300
|
if (part.isDirty()){
|
301
|
dirtyParts.add((IE4SavablePart) part);
|
302
|
}
|
303
|
|
304
|
break;
|
305
|
}else if (taxonUUID == null){
|
306
|
if (part.isDirty() && (part.getObject() instanceof TaxonNameEditorE4 || (part.getObject() instanceof BulkEditorE4 && ((BulkEditorE4)part.getObject()).getEditorInput() instanceof TaxonEditorInput))){
|
307
|
dirtyParts.add((IE4SavablePart) part.getObject());
|
308
|
}
|
309
|
}
|
310
|
}
|
311
|
return dirtyParts;
|
312
|
}
|
313
|
|
314
|
/**
|
315
|
* An uninitialized taxon is one that hasn't been saved yet. As such, it
|
316
|
* should appear in neither the list of recent names nor in the taxonomic
|
317
|
* tree when opened.
|
318
|
*
|
319
|
* @param parentNodeUuid
|
320
|
* a {@link java.util.UUID} object.
|
321
|
*/
|
322
|
public static void openEmptyE4(UUID parentNodeUuid) {
|
323
|
TaxonEditorInputE4 input = TaxonEditorInputE4
|
324
|
.NewEmptyInstance(parentNodeUuid);
|
325
|
EPartService partService = TaxeditorEditorPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getService(EPartService.class);
|
326
|
MPart part = partService.createPart(NAME_EDITOR_ID);
|
327
|
part = partService.showPart(part, PartState.ACTIVATE);
|
328
|
TaxonNameEditorE4 editor = (TaxonNameEditorE4) part.getObject();
|
329
|
editor.init(input);
|
330
|
}
|
331
|
|
332
|
/**
|
333
|
* <p>
|
334
|
* getUndoContext
|
335
|
* </p>
|
336
|
*
|
337
|
* @return a {@link org.eclipse.core.commands.operations.IUndoContext}
|
338
|
* object.
|
339
|
*/
|
340
|
public static IUndoContext getUndoContext() {
|
341
|
return IOperationHistory.GLOBAL_UNDO_CONTEXT;
|
342
|
}
|
343
|
|
344
|
public static boolean isFactsVisible() {
|
345
|
return factsVisible;
|
346
|
}
|
347
|
|
348
|
public static void setFactsVisible(boolean factsVisible) {
|
349
|
EditorUtil.factsVisible = factsVisible;
|
350
|
}
|
351
|
|
352
|
public static boolean isMediaVisible() {
|
353
|
return mediaVisible;
|
354
|
}
|
355
|
|
356
|
public static void setMediaVisible(boolean mediaVisible) {
|
357
|
EditorUtil.mediaVisible = mediaVisible;
|
358
|
}
|
359
|
|
360
|
/**
|
361
|
* <p>
|
362
|
* forceUserSave
|
363
|
* </p>
|
364
|
*
|
365
|
* @param editor
|
366
|
* a {@link org.eclipse.ui.IEditorPart} object.
|
367
|
* @param shell
|
368
|
* a {@link org.eclipse.swt.widgets.Shell} object.
|
369
|
* @return a boolean.
|
370
|
*/
|
371
|
public static boolean forceUserSave(IEditorPart editor, Shell shell) {
|
372
|
if (editor.isDirty()) {
|
373
|
|
374
|
boolean doSave = MessageDialog
|
375
|
.openConfirm(shell, Messages.EditorUtil_COMFIRM_SAVE,
|
376
|
Messages.EditorUtil_CONFIRM_SAVE_MESSAGE);
|
377
|
|
378
|
if (!doSave) {
|
379
|
return false;
|
380
|
}
|
381
|
|
382
|
editor.doSave(AbstractUtility.getMonitor());
|
383
|
}
|
384
|
return true;
|
385
|
}
|
386
|
|
387
|
public static boolean forceUserSaveE4Editor(IE4SavablePart editor, Shell shell) {
|
388
|
if (editor.isDirty()) {
|
389
|
|
390
|
boolean doSave = MessageDialog
|
391
|
.openConfirm(shell, Messages.EditorUtil_COMFIRM_SAVE,
|
392
|
Messages.EditorUtil_CONFIRM_SAVE_MESSAGE);
|
393
|
|
394
|
if (!doSave) {
|
395
|
return false;
|
396
|
}
|
397
|
|
398
|
editor.save(AbstractUtility.getMonitor());
|
399
|
}
|
400
|
return true;
|
401
|
}
|
402
|
|
403
|
/**
|
404
|
* <p>
|
405
|
* getSelection
|
406
|
* </p>
|
407
|
*
|
408
|
* @param event
|
409
|
* a {@link org.eclipse.core.commands.ExecutionEvent} object.
|
410
|
* @return a {@link org.eclipse.jface.viewers.IStructuredSelection} object.
|
411
|
*/
|
412
|
public static IStructuredSelection getSelection(ExecutionEvent event) {
|
413
|
IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
|
414
|
|
415
|
return (IStructuredSelection) activeEditor.getSite()
|
416
|
.getSelectionProvider().getSelection();
|
417
|
}
|
418
|
|
419
|
/**
|
420
|
* <p>
|
421
|
* getPluginId
|
422
|
* </p>
|
423
|
*
|
424
|
* @return a {@link java.lang.String} object.
|
425
|
*/
|
426
|
public static String getPluginId() {
|
427
|
return TaxeditorEditorPlugin.PLUGIN_ID;
|
428
|
}
|
429
|
|
430
|
/**
|
431
|
* Iterates recursively over all originals having the given specimen as a derivate.
|
432
|
* The first {@link DerivedUnit} with no more originals or the first {@link FieldUnit} is returned
|
433
|
* @param specimen the start element for which the originals are iterated recursively
|
434
|
* @return either a FieldUnit or a the topmost DerivedUnit (which can be itself)
|
435
|
*/
|
436
|
public static SpecimenOrObservationBase<?> getTopMostDerivate(SpecimenOrObservationBase<?> specimen){
|
437
|
if(specimen==null){
|
438
|
return null;
|
439
|
}
|
440
|
if(specimen.isInstanceOf(FieldUnit.class)){
|
441
|
return specimen;
|
442
|
}
|
443
|
else if(specimen.isInstanceOf(DerivedUnit.class)){
|
444
|
DerivedUnit derivedUnit = HibernateProxyHelper.deproxy(specimen, DerivedUnit.class);
|
445
|
if(derivedUnit.getOriginals()!=null
|
446
|
&& !(derivedUnit.getOriginals().isEmpty())){
|
447
|
for(SpecimenOrObservationBase<?> original:((DerivedUnit) specimen).getOriginals()){
|
448
|
return getTopMostDerivate(original);
|
449
|
}
|
450
|
}
|
451
|
}
|
452
|
return specimen;
|
453
|
}
|
454
|
|
455
|
/**
|
456
|
* If the current selection is a single {@link TreeNode} it will be returned.
|
457
|
* @param selection the selection to check
|
458
|
* @return the selected TreeNode or <code>null</code> if no TreeNode selected
|
459
|
*/
|
460
|
public static TreeNode getTreeNodeOfSelection(ISelection selection){
|
461
|
if(selection instanceof IStructuredSelection
|
462
|
&& ((IStructuredSelection) selection).size()==1
|
463
|
&& ((IStructuredSelection) selection).getFirstElement() instanceof TreeNode){
|
464
|
return (TreeNode) ((IStructuredSelection) selection).getFirstElement();
|
465
|
|
466
|
}
|
467
|
return null;
|
468
|
}
|
469
|
|
470
|
public static void closeObsoleteEditor(TaxonNodeDto taxonNode, EPartService partService){
|
471
|
String treeIndex = taxonNode.getTreeIndex();
|
472
|
Collection<MPart> parts = partService.getParts();
|
473
|
for (MPart part : parts) {
|
474
|
Object object = part.getObject();
|
475
|
if(object instanceof TaxonNameEditorE4){
|
476
|
TaxonNameEditorE4 taxonEditor = (TaxonNameEditorE4)object;
|
477
|
TaxonNode node = taxonEditor.getEditorInput().getTaxonNode();
|
478
|
if (node.treeIndex()!= null){
|
479
|
if(node.treeIndex().startsWith(treeIndex)){
|
480
|
if (part.isDirty()){
|
481
|
forceUserSaveE4Editor(taxonEditor, getShell());
|
482
|
}
|
483
|
partService.hidePart(part);
|
484
|
}
|
485
|
}else{
|
486
|
logger.debug("The taxonnode of taxon " + node.getTaxon().getTitleCache() + " uuid: " + node.getUuid() + " has no treeindex");;
|
487
|
}
|
488
|
}
|
489
|
}
|
490
|
}
|
491
|
|
492
|
public static void closeObsoleteEditorWithChildren(TaxonNodeDto taxonNode, EPartService partService){
|
493
|
String treeIndex = taxonNode.getTreeIndex();
|
494
|
Collection<MPart> parts = partService.getParts();
|
495
|
for (MPart part : parts) {
|
496
|
Object object = part.getObject();
|
497
|
if(object instanceof TaxonNameEditorE4){
|
498
|
TaxonNameEditorE4 taxonEditor = (TaxonNameEditorE4)object;
|
499
|
TaxonNode node = taxonEditor.getEditorInput().getTaxonNode();
|
500
|
if (node.treeIndex()!= null){
|
501
|
if(node.treeIndex().startsWith(treeIndex)){
|
502
|
if (part.isDirty()){
|
503
|
forceUserSaveE4Editor(taxonEditor, getShell());
|
504
|
}
|
505
|
partService.hidePart(part);
|
506
|
}
|
507
|
}else{
|
508
|
logger.debug("The taxonnode of taxon " + node.getTaxon().getTitleCache() + " uuid: " + node.getUuid() + " has no treeindex");;
|
509
|
}
|
510
|
}
|
511
|
}
|
512
|
}
|
513
|
|
514
|
public static void closeObsoleteDescriptiveDatasetEditor(UUID datasetUuid, EPartService partService){
|
515
|
|
516
|
Collection<MPart> parts = partService.getParts();
|
517
|
for (MPart part : parts) {
|
518
|
Object object = part.getObject();
|
519
|
if(object instanceof DescriptiveDataSetEditor){
|
520
|
DescriptiveDataSetEditor editor = (DescriptiveDataSetEditor)object;
|
521
|
DescriptiveDataSet descDataSet = editor.getDescriptiveDataSet();
|
522
|
if(descDataSet.getUuid().equals(datasetUuid)){
|
523
|
if (part.isDirty()){
|
524
|
forceUserSaveE4Editor(editor, getShell());
|
525
|
}
|
526
|
partService.hidePart(part);
|
527
|
}
|
528
|
|
529
|
}
|
530
|
}
|
531
|
}
|
532
|
|
533
|
public static void closePart(String partID, EPartService partService){
|
534
|
|
535
|
Collection<MPart> parts = partService.getParts();
|
536
|
for (MPart part : parts) {
|
537
|
String elementId = part.getElementId();
|
538
|
if (elementId.equals(partID)){
|
539
|
partService.hidePart(part);
|
540
|
}
|
541
|
}
|
542
|
}
|
543
|
|
544
|
public static void updateEditor(TaxonNode taxonNode, TaxonNameEditorE4 editor){
|
545
|
String treeIndex = taxonNode.treeIndex();
|
546
|
TaxonNode node = editor.getEditorInput().getTaxonNode();
|
547
|
if(node.treeIndex().equals(treeIndex)){
|
548
|
TaxonEditorInputE4 input = TaxonEditorInputE4.NewInstance(node.getUuid());
|
549
|
editor.init(input);
|
550
|
}
|
551
|
}
|
552
|
}
|