Project

General

Profile

Download (23.2 KB) Statistics
| Branch: | Tag: | Revision:
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.ITaxonTreeNode;
39
import eu.etaxonomy.cdm.model.taxon.Synonym;
40
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
41
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
42
import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto;
43
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
44
import eu.etaxonomy.taxeditor.bulkeditor.e4.BulkEditor;
45
import eu.etaxonomy.taxeditor.bulkeditor.input.TaxonBulkEditorInput;
46
import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.DescriptiveDataSetEditor;
47
import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.CharacterMatrixPart;
48
import eu.etaxonomy.taxeditor.editor.e4.TaxonEditorInput;
49
import eu.etaxonomy.taxeditor.editor.group.authority.CdmAuthorityEditorInput;
50
import eu.etaxonomy.taxeditor.editor.group.authority.e4.CdmAuthorityEditorE4;
51
import eu.etaxonomy.taxeditor.editor.internal.TaxeditorEditorPlugin;
52
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
53
import eu.etaxonomy.taxeditor.editor.name.e4.TaxonEditor;
54
import eu.etaxonomy.taxeditor.editor.view.checklist.e4.DistributionEditorPart;
55
import eu.etaxonomy.taxeditor.editor.view.derivate.DerivateView;
56
import eu.etaxonomy.taxeditor.editor.view.derivate.DerivateViewEditorInput;
57
import eu.etaxonomy.taxeditor.model.AbstractUtility;
58
import eu.etaxonomy.taxeditor.model.MessagingUtils;
59
import eu.etaxonomy.taxeditor.security.RequiredPermissions;
60
import eu.etaxonomy.taxeditor.store.CdmStore;
61
import eu.etaxonomy.taxeditor.workbench.WorkbenchUtility;
62
import eu.etaxonomy.taxeditor.workbench.part.IE4SavablePart;
63

    
64
/**
65
 * Utility for the editor package
66
 *
67
 * @author n.hoffmann
68
 * @created 20.01.2009
69
 */
70
public class EditorUtil extends AbstractUtility {
71

    
72
    private static final String NAME_EDITOR_ID = "eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditor";
73

    
74
    private static boolean factsVisible = true;
75

    
76
    private static boolean mediaVisible = true;
77

    
78
    public static void openDescriptiveDataSetEditor(UUID descriptiveDataSetUuid, EModelService modelService, EPartService partService, MApplication application){
79
        Collection<MPart> parts = partService.getParts();
80
        for (MPart part : parts) {
81
            if(part.getObject() instanceof DescriptiveDataSetEditor
82
                && ((DescriptiveDataSetEditor) part.getObject()).getDescriptiveDataSet().getUuid().equals(descriptiveDataSetUuid)){
83
                partService.showPart(part, PartState.ACTIVATE);
84
                return;
85
            }
86
        }
87
        String partId = AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_VIEW_DESCRIPTIVEDATASET_DESCRIPTIVEDATASETEDITOR;
88
        MPart part = showPart(partId, modelService, partService, application);
89
        DescriptiveDataSetEditor editor = (DescriptiveDataSetEditor) part.getObject();
90
        editor.init(descriptiveDataSetUuid);
91
    }
92

    
93
    public static void openCharacterMatrix(UUID descriptiveDataSetUuid, EModelService modelService, EPartService partService, MApplication application){
94
        Collection<MPart> parts = partService.getParts();
95
        for (MPart part : parts) {
96
            if(part.getObject() instanceof CharacterMatrixPart
97
                && ((CharacterMatrixPart) part.getObject()).getDescriptiveDataSet().getUuid().equals(descriptiveDataSetUuid)){
98
                partService.showPart(part, PartState.ACTIVATE);
99
                return;
100
            }
101
        }
102
        String partId = AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_DESCRIPTIVEDATASET_MATRIX_CHARACTERMATRIXPART;
103
        MPart part = showPart(partId, modelService, partService, application);
104
        CharacterMatrixPart editor = (CharacterMatrixPart) part.getObject();
105
        editor.init(descriptiveDataSetUuid, true);
106
    }
107

    
108
    public static void openDistributionEditor(List<UuidAndTitleCache<ITaxonTreeNode>> parentTaxonUuidList, EModelService modelService, EPartService partService, MApplication application){
109
        String partId = AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_VIEW_CHECKLIST_E4_DISTRIBUTIONEDITORPART;
110
        checkAndCloseFactsAndMediaParts(partService);
111
        MPart part = showPart(partId, modelService, partService, application);
112
        DistributionEditorPart editor = (DistributionEditorPart) part.getObject();
113
        editor.init(parentTaxonUuidList);
114
    }
115

    
116
    public static void checkAndCloseFactsAndMediaParts(EPartService partService) {
117
        String partIdFactualData = AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_VIEW_DESCRIPTIVE_E4_FACTUALDATAPARTE4;
118
        String partIdMedia = AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_VIEW_MEDIA_E4_MEDIAVIEWPARTE4;
119
        MPart part1 = partService.findPart(AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_VIEW_DESCRIPTIVE_E4_FACTUALDATAPARTE4);
120
        if (factsVisible || (part1!=null && part1.getWidget() != null && partService.isPartVisible(part1))){
121
            factsVisible = true;
122
        }else{
123
            factsVisible = false;
124
        }
125
        part1 = partService.findPart(AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_VIEW_MEDIA_E4_MEDIAVIEWPARTE4);
126
        if (mediaVisible || (part1!=null && part1.getWidget() != null && partService.isPartVisible(part1))){
127
            mediaVisible = true;
128
        }else{
129
            mediaVisible = false;
130
        }
131
        closePart(partIdMedia, partService);
132
        closePart(partIdFactualData, partService);
133
    }
134

    
135

    
136
    public static void openSpecimenEditor(DerivateViewEditorInput input, EModelService modelService, EPartService partService, MApplication application){
137
        String partId = AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_VIEW_DERIVATE_DERIVATEVIEW;
138
        MPart part = showPart(partId, modelService, partService, application);
139
        DerivateView derivateView = (DerivateView) part.getObject();
140
        derivateView.init(input);
141
    }
142

    
143
    public static void openRightsEditor(CdmAuthorityEditorInput input, EModelService modelService, EPartService partService, MApplication application){
144
        Collection<MPart> parts = partService.getParts();
145
        for (MPart part : parts) {
146
            if(part.getObject() instanceof CdmAuthorityEditorE4
147
                && ((CdmAuthorityEditorE4) part.getObject()).getInput().getGroup().equals(input.getGroup())){
148
                partService.showPart(part, PartState.ACTIVATE);
149
                return;
150
            }
151
        }
152
        String partId = AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_GROUP_AUTHORITY_E4_CDMAUTHORITYEDITORE4;
153
        MPart part = showPart(partId, modelService, partService, application);
154
        CdmAuthorityEditorE4 authorityView = (CdmAuthorityEditorE4) part.getObject();
155
        authorityView.init(input);
156
    }
157

    
158
    public static MPart showPart(String partId, EModelService modelService, EPartService partService, MApplication application){
159
        MPart part = partService.findPart(partId);
160
        if(part==null || modelService.getPartDescriptor(partId).isAllowMultiple()){
161
            part = partService.createPart(partId);
162
        }
163
        MPartStack editorAreaPartStack = WorkbenchUtility.getEditorAreaPartStack(application, modelService);
164
        if(editorAreaPartStack!=null){
165
            editorAreaPartStack.getChildren().add(part);
166
        }
167

    
168
        return partService.showPart(part, PartState.ACTIVATE);
169

    
170
    }
171

    
172
    public static MPart showPart(String partId, EModelService modelService, EPartService partService){
173
        MPart part = partService.findPart(partId);
174
        if(part==null || modelService.getPartDescriptor(partId).isAllowMultiple()){
175
            part = partService.createPart(partId);
176
            partService.activate(part);
177
        }else{
178
            partService.activate(part);
179
        }
180

    
181
       return part;
182
    }
183

    
184
	public static void openTaxonNodeE4(UUID taxonNodeUuid, EModelService modelService, EPartService partService, MApplication application) {
185
	    TaxonEditorInput input = TaxonEditorInput.NewInstance(taxonNodeUuid);
186
	    openTaxonEditor_internal(input, modelService, partService, application);
187
	}
188

    
189
	public static void openTaxonBaseE4(UUID taxonBaseUuid, EModelService modelService, EPartService partService, MApplication application) {
190
	    TaxonEditorInput input = TaxonEditorInput.NewInstanceFromTaxonBase(taxonBaseUuid);
191
	    openTaxonEditor_internal(input, modelService, partService, application);
192
	}
193

    
194
    private static void openTaxonEditor_internal(TaxonEditorInput input, EModelService modelService, EPartService partService, MApplication application) {
195
        TaxonBase<?> taxonBase = input.getTaxon();
196
        TaxonNode node = input.getTaxonNode();
197
        if(taxonBase==null){
198
            return;
199
        }
200
        boolean hasPermission = false;
201
//        if (node != null){
202
            hasPermission = CdmStore.currentAuthentiationHasPermission(node, RequiredPermissions.TAXON_EDIT);
203
//        }
204
//        if (!hasPermission){
205
//            MessagingUtils.warningDialog(Messages.EditorUtil_MISSING_PERMISSION, TaxonEditorInputE4.class, Messages.EditorUtil_MISSING_PERMISSION_MESSAGE);
206
//            return;
207
//        }
208
        if (taxonBase.isOrphaned()) {
209
            if(taxonBase.isInstanceOf(Synonym.class)){
210
                MessagingUtils.warningDialog(Messages.EditorUtil_ORPHAN_ACCEPTED_TAXON, TaxonEditorInput.class, Messages.EditorUtil_ORPHAN_ACCEPTED_TAXON_MESSAGE);
211
                return;
212
            }
213
            else{
214
                MessagingUtils.warningDialog(Messages.EditorUtil_ORPHAN_TAXON, TaxonEditorInput.class, Messages.EditorUtil_ORPHAN_TAXON_MESSAGE);
215
                return;
216
            }
217
        }
218

    
219
        Collection<MPart> parts = partService.getParts();
220
        //check if part is already opened
221
        MPart alreadyOpenInOtherClassification = null;
222
        for (MPart part : parts) {
223
        	if(part.getObject() instanceof TaxonEditor
224
                    && ((TaxonEditor) part.getObject()).getTaxon()!=null
225
                    && ((TaxonEditor) part.getObject()).getTaxon().getUuid().equals(input.getTaxon().getUuid())){
226

    
227
        	    UUID inputNode = input.getTaxonNode().getUuid();
228
        	    UUID editorNode = ((TaxonEditor) part.getObject()).getTaxonNode().getUuid();
229
        	    if (!inputNode.equals(editorNode)){
230
        	        alreadyOpenInOtherClassification = part;
231
        	    }else{
232
        	    	((TaxonEditor) part.getObject()).init(input);
233
        	        partService.activate(part, true);
234
        	        return;
235
        	    }
236
            }
237
        }
238
        if (alreadyOpenInOtherClassification != null){
239
            boolean doSave = forceUserSaveE4Editor(((TaxonEditor) alreadyOpenInOtherClassification.getObject()), getShell());
240
            if (doSave){
241
                input = TaxonEditorInput.NewInstance(input.getTaxonNode().getUuid());
242
                partService.hidePart(alreadyOpenInOtherClassification);
243
            }else {
244
                return;
245
            }
246
        }
247

    
248
        MPart part = showPart(NAME_EDITOR_ID, modelService, partService, application);
249

    
250
        TaxonEditor editor = (TaxonEditor) part.getObject();
251
//        editor.setDisabled();
252
        editor.init(input);
253
//        editor.setEnabled();
254
        editor.setFocus();
255
//        if (factsVisible){
256
//            showFacts(modelService, partService);
257
//            factsVisible = false;
258
//        }
259
//
260
//        if (mediaVisible){
261
//            showMedia(modelService, partService);
262
//            mediaVisible = false;
263
//        }
264
    }
265

    
266
    public static void showMedia(EModelService modelService, EPartService partService) {
267
        String partIdFactualData = AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_VIEW_MEDIA_E4_MEDIAVIEWPARTE4;
268
        showPart(partIdFactualData, modelService, partService);
269
    }
270

    
271
    public static void showFacts(EModelService modelService, EPartService partService) {
272
        String partIdFactualData = AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_VIEW_DESCRIPTIVE_E4_FACTUALDATAPARTE4;
273
        showPart(partIdFactualData, modelService, partService);
274
    }
275

    
276
    public static Collection<MPart> checkForChanges(UUID taxonUUID, EPartService partService ){
277
        Collection<MPart> parts = partService.getParts();
278
        Collection<MPart> dirtyParts = new HashSet();
279
        //check if part is already opened
280
        boolean isDirty = false;
281
        for (MPart part : parts) {
282
            if(part.getObject() instanceof TaxonEditor
283
                    && ((TaxonEditor) part.getObject()).getTaxon()!=null
284
                    && ((TaxonEditor) part.getObject()).getTaxon().getUuid().equals(taxonUUID)){
285
                if (part.isDirty()){
286
                    dirtyParts.add(part);
287
                }
288

    
289
                break;
290
            }else if (taxonUUID == null){
291
                if (part.isDirty()){
292
                    dirtyParts.add(part);
293
                }
294
            }
295
        }
296
        return dirtyParts;
297
    }
298

    
299
    public static Collection<IE4SavablePart> checkForTaxonChanges(UUID taxonUUID, EPartService partService ){
300
        Collection<MPart> parts = partService.getParts();
301
        Collection<IE4SavablePart> dirtyParts = new HashSet<>();
302
        //check if part is already opened
303
        for (MPart part : parts) {
304
            if(part.getObject() instanceof TaxonEditor
305
                    && ((TaxonEditor) part.getObject()).getTaxon()!=null
306
                    && ((TaxonEditor) part.getObject()).getTaxon().getUuid().equals(taxonUUID)){
307
                if (part.isDirty()){
308
                    dirtyParts.add((IE4SavablePart) part);
309
                }
310

    
311
                break;
312
            }else if (taxonUUID == null){
313
                if (part.isDirty() && (part.getObject() instanceof TaxonEditor || (part.getObject() instanceof BulkEditor && ((BulkEditor)part.getObject()).getEditorInput() instanceof TaxonBulkEditorInput))){
314
                    dirtyParts.add((IE4SavablePart) part.getObject());
315
                }
316
            }
317
        }
318
        return dirtyParts;
319
    }
320

    
321
	/**
322
	 * An uninitialized taxon is one that hasn't been saved yet. As such, it
323
	 * should appear in neither the list of recent names nor in the taxonomic
324
	 * tree when opened.
325
	 *
326
	 * @param parentNodeUuid
327
	 *            a {@link java.util.UUID} object.
328
	 */
329
	public static void openEmptyE4(UUID parentNodeUuid) {
330
		TaxonEditorInput input = TaxonEditorInput
331
				.NewEmptyInstance(parentNodeUuid);
332
        EPartService partService = TaxeditorEditorPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getService(EPartService.class);
333
        MPart part = partService.createPart(NAME_EDITOR_ID);
334
        part = partService.showPart(part, PartState.ACTIVATE);
335
        TaxonEditor editor = (TaxonEditor) part.getObject();
336
        editor.init(input);
337
	}
338

    
339
	/**
340
	 * <p>
341
	 * getUndoContext
342
	 * </p>
343
	 *
344
	 * @return a {@link org.eclipse.core.commands.operations.IUndoContext}
345
	 *         object.
346
	 */
347
	public static IUndoContext getUndoContext() {
348
		return IOperationHistory.GLOBAL_UNDO_CONTEXT;
349
	}
350

    
351
	public static boolean isFactsVisible() {
352
        return factsVisible;
353
    }
354

    
355
    public static void setFactsVisible(boolean factsVisible) {
356
        EditorUtil.factsVisible = factsVisible;
357
    }
358

    
359
    public static boolean isMediaVisible() {
360
        return mediaVisible;
361
    }
362

    
363
    public static void setMediaVisible(boolean mediaVisible) {
364
        EditorUtil.mediaVisible = mediaVisible;
365
    }
366

    
367
    /**
368
	 * <p>
369
	 * forceUserSave
370
	 * </p>
371
	 *
372
	 * @param editor
373
	 *            a {@link org.eclipse.ui.IEditorPart} object.
374
	 * @param shell
375
	 *            a {@link org.eclipse.swt.widgets.Shell} object.
376
	 * @return a boolean.
377
	 */
378
	public static boolean forceUserSave(IEditorPart editor, Shell shell) {
379
		if (editor.isDirty()) {
380

    
381
			boolean doSave = MessageDialog
382
					.openConfirm(shell, Messages.EditorUtil_COMFIRM_SAVE,
383
							Messages.EditorUtil_CONFIRM_SAVE_MESSAGE);
384

    
385
			if (!doSave) {
386
				return false;
387
			}
388

    
389
			editor.doSave(AbstractUtility.getMonitor());
390
		}
391
		return true;
392
	}
393

    
394
	public static boolean forceUserSaveE4Editor(IE4SavablePart editor, Shell shell) {
395
	    if (editor.isDirty()) {
396

    
397
	        boolean doSave = MessageDialog
398
	                .openConfirm(shell, Messages.EditorUtil_COMFIRM_SAVE,
399
	                        Messages.EditorUtil_CONFIRM_SAVE_MESSAGE);
400

    
401
	        if (!doSave) {
402
	            return false;
403
	        }
404

    
405
	        editor.save(AbstractUtility.getMonitor());
406
	    }
407
	    return true;
408
	}
409

    
410
	/**
411
	 * <p>
412
	 * getSelection
413
	 * </p>
414
	 *
415
	 * @param event
416
	 *            a {@link org.eclipse.core.commands.ExecutionEvent} object.
417
	 * @return a {@link org.eclipse.jface.viewers.IStructuredSelection} object.
418
	 */
419
	public static IStructuredSelection getSelection(ExecutionEvent event) {
420
		IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
421

    
422
		return (IStructuredSelection) activeEditor.getSite()
423
				.getSelectionProvider().getSelection();
424
	}
425

    
426
	/**
427
	 * <p>
428
	 * getPluginId
429
	 * </p>
430
	 *
431
	 * @return a {@link java.lang.String} object.
432
	 */
433
	public static String getPluginId() {
434
		return TaxeditorEditorPlugin.PLUGIN_ID;
435
	}
436

    
437
	/**
438
	 * Iterates recursively over all originals having the given specimen as a derivate.
439
	 * The first {@link DerivedUnit} with no more originals or the first {@link FieldUnit} is returned
440
	 * @param specimen the start element for which the originals are iterated recursively
441
	 * @return either a FieldUnit or a the topmost DerivedUnit (which can be itself)
442
	 */
443
	public static SpecimenOrObservationBase<?> getTopMostDerivate(SpecimenOrObservationBase<?> specimen){
444
	    if(specimen==null){
445
	        return null;
446
	    }
447
	    if(specimen.isInstanceOf(FieldUnit.class)){
448
	        return specimen;
449
	    }
450
	    else if(specimen.isInstanceOf(DerivedUnit.class)){
451
	        DerivedUnit derivedUnit = HibernateProxyHelper.deproxy(specimen, DerivedUnit.class);
452
	        if(derivedUnit.getOriginals()!=null
453
	                && !(derivedUnit.getOriginals().isEmpty())){
454
	            for(SpecimenOrObservationBase<?> original:((DerivedUnit) specimen).getOriginals()){
455
	                return getTopMostDerivate(original);
456
	            }
457
	        }
458
	    }
459
	    return specimen;
460
	}
461

    
462
    /**
463
     * If the current selection is a single {@link TreeNode} it will be returned.
464
     * @param selection the selection to check
465
     * @return the selected TreeNode or <code>null</code> if no TreeNode selected
466
     */
467
    public static TreeNode getTreeNodeOfSelection(ISelection selection){
468
        if(selection instanceof IStructuredSelection
469
                && ((IStructuredSelection) selection).size()==1
470
                && ((IStructuredSelection) selection).getFirstElement() instanceof TreeNode){
471
            return (TreeNode) ((IStructuredSelection) selection).getFirstElement();
472

    
473
        }
474
        return null;
475
    }
476

    
477
    public static void closeObsoleteEditor(TaxonNodeDto taxonNode, EPartService partService){
478
        String treeIndex = taxonNode.getTreeIndex();
479
        Collection<MPart> parts = partService.getParts();
480
        for (MPart part : parts) {
481
            Object object = part.getObject();
482
            if(object instanceof TaxonEditor){
483
                TaxonEditor taxonEditor = (TaxonEditor)object;
484
                TaxonNode node = taxonEditor.getEditorInput().getTaxonNode();
485
                if (node.treeIndex()!= null){
486
	                if(node.treeIndex().startsWith(treeIndex)){
487
	                    if (part.isDirty()){
488
	                        forceUserSaveE4Editor(taxonEditor, getShell());
489
	                    }
490
	                    partService.hidePart(part);
491
	                }
492
                }else{
493
                	logger.debug("The taxonnode of taxon " + node.getTaxon().getTitleCache() + " uuid: " + node.getUuid() + " has no treeindex");;
494
                }
495
            }
496
        }
497
    }
498

    
499
    public static void closeObsoleteEditorWithChildren(TaxonNodeDto taxonNode, EPartService partService){
500
        String treeIndex = taxonNode.getTreeIndex();
501
        Collection<MPart> parts = partService.getParts();
502
        for (MPart part : parts) {
503
            Object object = part.getObject();
504
            if(object instanceof TaxonEditor){
505
                TaxonEditor taxonEditor = (TaxonEditor)object;
506
                TaxonNode node = taxonEditor.getEditorInput().getTaxonNode();
507
                if (node.treeIndex()!= null){
508
                    if(node.treeIndex().startsWith(treeIndex)){
509
                        if (part.isDirty()){
510
                            forceUserSaveE4Editor(taxonEditor, getShell());
511
                        }
512
                        partService.hidePart(part);
513
                    }
514
                }else{
515
                    logger.debug("The taxonnode of taxon " + node.getTaxon().getTitleCache() + " uuid: " + node.getUuid() + " has no treeindex");;
516
                }
517
            }
518
        }
519
    }
520

    
521
    public static void closeObsoleteDescriptiveDatasetEditor(UUID datasetUuid, EPartService partService){
522

    
523
        Collection<MPart> parts = partService.getParts();
524
        for (MPart part : parts) {
525
            Object object = part.getObject();
526
            if(object instanceof DescriptiveDataSetEditor){
527
                DescriptiveDataSetEditor editor = (DescriptiveDataSetEditor)object;
528
                DescriptiveDataSet descDataSet = editor.getDescriptiveDataSet();
529
                if(descDataSet.getUuid().equals(datasetUuid)){
530
                    if (part.isDirty()){
531
                        forceUserSaveE4Editor(editor, getShell());
532
                    }
533
                    partService.hidePart(part);
534
                }
535

    
536
            }
537
        }
538
    }
539

    
540
    public static void closePart(String partID, EPartService partService){
541

    
542
        Collection<MPart> parts = partService.getParts();
543
        for (MPart part : parts) {
544
            String elementId = part.getElementId();
545
            if (elementId.equals(partID)){
546
                partService.hidePart(part);
547
            }
548
        }
549
    }
550

    
551
    public static void updateEditor(TaxonNode taxonNode, TaxonEditor editor){
552
        String treeIndex = taxonNode.treeIndex();
553
        TaxonNode node = editor.getEditorInput().getTaxonNode();
554
        if(node.treeIndex().equals(treeIndex)){
555
        	TaxonEditorInput input = TaxonEditorInput.NewInstance(node.getUuid());
556
        	editor.init(input);
557
        }
558
    }
559
}
(5-5/9)