Project

General

Profile

Download (22.9 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
    public static MPart showPart(String partId, EModelService modelService, EPartService partService){
172
        MPart part = partService.findPart(partId);
173
        if(part==null || modelService.getPartDescriptor(partId).isAllowMultiple()){
174
            part = partService.createPart(partId);
175
            partService.activate(part);
176
        }else{
177
            partService.activate(part);
178
        }
179

    
180
       return part;
181
    }
182

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
366
	public static boolean forceUserSave(IEditorPart editor, Shell shell) {
367
		if (editor.isDirty()) {
368

    
369
			boolean doSave = MessageDialog
370
					.openConfirm(shell, Messages.EditorUtil_COMFIRM_SAVE,
371
							Messages.EditorUtil_CONFIRM_SAVE_MESSAGE);
372

    
373
			if (!doSave) {
374
				return false;
375
			}
376

    
377
			editor.doSave(AbstractUtility.getMonitor());
378
		}
379
		return true;
380
	}
381

    
382
	public static boolean forceUserSaveE4Editor(IE4SavablePart editor, Shell shell) {
383
	    if (editor.isDirty()) {
384

    
385
	        boolean doSave = MessageDialog
386
	                .openConfirm(shell, Messages.EditorUtil_COMFIRM_SAVE,
387
	                        Messages.EditorUtil_CONFIRM_SAVE_MESSAGE);
388

    
389
	        if (!doSave) {
390
	            return false;
391
	        }
392

    
393
	        editor.save(AbstractUtility.getMonitor());
394
	    }
395
	    return true;
396
	}
397

    
398
	/**
399
	 * <p>
400
	 * getSelection
401
	 * </p>
402
	 *
403
	 * @param event
404
	 *            a {@link org.eclipse.core.commands.ExecutionEvent} object.
405
	 * @return a {@link org.eclipse.jface.viewers.IStructuredSelection} object.
406
	 */
407
	public static IStructuredSelection getSelection(ExecutionEvent event) {
408
		IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
409

    
410
		return (IStructuredSelection) activeEditor.getSite()
411
				.getSelectionProvider().getSelection();
412
	}
413

    
414
	/**
415
	 * <p>
416
	 * getPluginId
417
	 * </p>
418
	 *
419
	 * @return a {@link java.lang.String} object.
420
	 */
421
	public static String getPluginId() {
422
		return TaxeditorEditorPlugin.PLUGIN_ID;
423
	}
424

    
425
	/**
426
	 * Iterates recursively over all originals having the given specimen as a derivate.
427
	 * The first {@link DerivedUnit} with no more originals or the first {@link FieldUnit} is returned
428
	 * @param specimen the start element for which the originals are iterated recursively
429
	 * @return either a FieldUnit or a the topmost DerivedUnit (which can be itself)
430
	 */
431
	public static SpecimenOrObservationBase<?> getTopMostDerivate(SpecimenOrObservationBase<?> specimen){
432
	    if(specimen==null){
433
	        return null;
434
	    }
435
	    if(specimen.isInstanceOf(FieldUnit.class)){
436
	        return specimen;
437
	    }
438
	    else if(specimen.isInstanceOf(DerivedUnit.class)){
439
	        DerivedUnit derivedUnit = HibernateProxyHelper.deproxy(specimen, DerivedUnit.class);
440
	        if(derivedUnit.getOriginals()!=null
441
	                && !(derivedUnit.getOriginals().isEmpty())){
442
	            for(SpecimenOrObservationBase<?> original:((DerivedUnit) specimen).getOriginals()){
443
	                return getTopMostDerivate(original);
444
	            }
445
	        }
446
	    }
447
	    return specimen;
448
	}
449

    
450
    /**
451
     * If the current selection is a single {@link TreeNode} it will be returned.
452
     * @param selection the selection to check
453
     * @return the selected TreeNode or <code>null</code> if no TreeNode selected
454
     */
455
    public static TreeNode getTreeNodeOfSelection(ISelection selection){
456
        if(selection instanceof IStructuredSelection
457
                && ((IStructuredSelection) selection).size()==1
458
                && ((IStructuredSelection) selection).getFirstElement() instanceof TreeNode){
459
            return (TreeNode) ((IStructuredSelection) selection).getFirstElement();
460

    
461
        }
462
        return null;
463
    }
464

    
465
    public static void closeObsoleteEditor(TaxonNodeDto taxonNode, EPartService partService){
466
        String treeIndex = taxonNode.getTreeIndex();
467
        Collection<MPart> parts = partService.getParts();
468
        for (MPart part : parts) {
469
            Object object = part.getObject();
470
            if(object instanceof TaxonEditor){
471
                TaxonEditor taxonEditor = (TaxonEditor)object;
472
                TaxonNode node = taxonEditor.getEditorInput().getTaxonNode();
473
                if (node.treeIndex()!= null){
474
	                if(node.treeIndex().startsWith(treeIndex)){
475
	                    if (part.isDirty()){
476
	                        forceUserSaveE4Editor(taxonEditor, getShell());
477
	                    }
478
	                    partService.hidePart(part);
479
	                }
480
                }else{
481
                	logger.debug("The taxonnode of taxon " + node.getTaxon().getTitleCache() + " uuid: " + node.getUuid() + " has no treeindex");;
482
                }
483
            }
484
        }
485
    }
486

    
487
    public static void closeObsoleteEditorWithChildren(TaxonNodeDto taxonNode, EPartService partService){
488
        String treeIndex = taxonNode.getTreeIndex();
489
        Collection<MPart> parts = partService.getParts();
490
        for (MPart part : parts) {
491
            Object object = part.getObject();
492
            if(object instanceof TaxonEditor){
493
                TaxonEditor taxonEditor = (TaxonEditor)object;
494
                TaxonNode node = taxonEditor.getEditorInput().getTaxonNode();
495
                if (node.treeIndex()!= null){
496
                    if(node.treeIndex().startsWith(treeIndex)){
497
                        if (part.isDirty()){
498
                            forceUserSaveE4Editor(taxonEditor, getShell());
499
                        }
500
                        partService.hidePart(part);
501
                    }
502
                }else{
503
                    logger.debug("The taxonnode of taxon " + node.getTaxon().getTitleCache() + " uuid: " + node.getUuid() + " has no treeindex");;
504
                }
505
            }
506
        }
507
    }
508

    
509
    public static void closeObsoleteDescriptiveDatasetEditor(UUID datasetUuid, EPartService partService){
510

    
511
        Collection<MPart> parts = partService.getParts();
512
        for (MPart part : parts) {
513
            Object object = part.getObject();
514
            if(object instanceof DescriptiveDataSetEditor){
515
                DescriptiveDataSetEditor editor = (DescriptiveDataSetEditor)object;
516
                DescriptiveDataSet descDataSet = editor.getDescriptiveDataSet();
517
                if(descDataSet.getUuid().equals(datasetUuid)){
518
                    if (part.isDirty()){
519
                        forceUserSaveE4Editor(editor, getShell());
520
                    }
521
                    partService.hidePart(part);
522
                }
523

    
524
            }
525
        }
526
    }
527

    
528
    public static void closePart(String partID, EPartService partService){
529

    
530
        Collection<MPart> parts = partService.getParts();
531
        for (MPart part : parts) {
532
            String elementId = part.getElementId();
533
            if (elementId.equals(partID)){
534
                partService.hidePart(part);
535
            }
536
        }
537
    }
538

    
539
    public static void updateEditor(TaxonNode taxonNode, TaxonEditor editor){
540
        String treeIndex = taxonNode.treeIndex();
541
        TaxonNode node = editor.getEditorInput().getTaxonNode();
542
        if(node.treeIndex().equals(treeIndex)){
543
        	TaxonEditorInput input = TaxonEditorInput.NewInstance(node.getUuid());
544
        	editor.init(input);
545
        }
546
    }
547
}
(5-5/9)