Project

General

Profile

Download (22.6 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

    
10
package eu.etaxonomy.taxeditor.editor;
11

    
12
import java.util.Collection;
13
import java.util.HashSet;
14
import java.util.List;
15
import java.util.UUID;
16

    
17
import org.eclipse.core.commands.ExecutionEvent;
18
import org.eclipse.core.commands.operations.IOperationHistory;
19
import org.eclipse.core.commands.operations.IUndoContext;
20
import org.eclipse.e4.ui.model.application.MApplication;
21
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
22
import org.eclipse.e4.ui.model.application.ui.basic.MPartStack;
23
import org.eclipse.e4.ui.workbench.modeling.EModelService;
24
import org.eclipse.e4.ui.workbench.modeling.EPartService;
25
import org.eclipse.e4.ui.workbench.modeling.EPartService.PartState;
26
import org.eclipse.jface.dialogs.MessageDialog;
27
import org.eclipse.jface.viewers.ISelection;
28
import org.eclipse.jface.viewers.IStructuredSelection;
29
import org.eclipse.jface.viewers.TreeNode;
30
import org.eclipse.swt.widgets.Shell;
31
import org.eclipse.ui.IEditorPart;
32
import org.eclipse.ui.handlers.HandlerUtil;
33

    
34
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
35
import eu.etaxonomy.cdm.model.description.DescriptiveDataSet;
36
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
37
import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
38
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
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.BulkEditorE4;
45
import eu.etaxonomy.taxeditor.bulkeditor.input.TaxonEditorInput;
46
import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.DescriptiveDataSetEditor;
47
import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.CharacterMatrixPart;
48
import eu.etaxonomy.taxeditor.editor.e4.TaxonEditorInputE4;
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.TaxonNameEditorE4;
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.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
 * @version 1.0
68
 */
69
public class EditorUtil extends AbstractUtility {
70

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

    
73
    private static boolean factsVisible = true;
74

    
75
    private static boolean mediaVisible = true;
76

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

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

    
107
    public static void openDistributionEditor(UuidAndTitleCache parentUuidAndTitleCache, EModelService modelService, EPartService partService, MApplication application){
108
        Collection<MPart> parts = partService.getParts();
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(parentUuidAndTitleCache);
114
    }
115

    
116
    public static void openDistributionEditor(List<UuidAndTitleCache> parentTaxonUuidList, EModelService modelService, EPartService partService, MApplication application){
117
        Collection<MPart> parts = partService.getParts();
118
        String partId = AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_VIEW_CHECKLIST_E4_DISTRIBUTIONEDITORPART;
119
        checkAndCloseFactsAndMediaParts(partService);
120
        MPart part = showPart(partId, modelService, partService, application);
121
        DistributionEditorPart editor = (DistributionEditorPart) part.getObject();
122
        editor.init(parentTaxonUuidList);
123
    }
124

    
125
    public static void checkAndCloseFactsAndMediaParts(EPartService partService) {
126
        String partIdFactualData = AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_VIEW_DESCRIPTIVE_E4_FACTUALDATAPARTE4;
127
        String partIdMedia = AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_VIEW_MEDIA_E4_MEDIAVIEWPARTE4;
128
        MPart part1 = partService.findPart(AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_VIEW_DESCRIPTIVE_E4_FACTUALDATAPARTE4);
129
        if (factsVisible || (part1!=null && part1.getWidget() != null && partService.isPartVisible(part1))){
130
            factsVisible = true;
131
        }else{
132
            factsVisible = false;
133
        }
134
        part1 = partService.findPart(AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_VIEW_MEDIA_E4_MEDIAVIEWPARTE4);
135
        if (mediaVisible || (part1!=null && part1.getWidget() != null && partService.isPartVisible(part1))){
136
            mediaVisible = true;
137
        }else{
138
            mediaVisible = false;
139
        }
140
        closePart(partIdMedia, partService);
141
        closePart(partIdFactualData, partService);
142
    }
143

    
144

    
145
    public static void openSpecimenEditor(DerivateViewEditorInput input, EModelService modelService, EPartService partService, MApplication application){
146
        String partId = AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_VIEW_DERIVATE_DERIVATEVIEW;
147
        MPart part = showPart(partId, modelService, partService, application);
148
        DerivateView derivateView = (DerivateView) part.getObject();
149
        derivateView.init(input);
150
    }
151

    
152
    public static void openRightsEditor(CdmAuthorityEditorInput input, EModelService modelService, EPartService partService, MApplication application){
153
        Collection<MPart> parts = partService.getParts();
154
        for (MPart part : parts) {
155
            if(part.getObject() instanceof CdmAuthorityEditorE4
156
                && ((CdmAuthorityEditorE4) part.getObject()).getInput().getGroup().equals(input.getGroup())){
157
                partService.showPart(part, PartState.ACTIVATE);
158
                return;
159
            }
160
        }
161
        String partId = AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_GROUP_AUTHORITY_E4_CDMAUTHORITYEDITORE4;
162
        MPart part = showPart(partId, modelService, partService, application);
163
        CdmAuthorityEditorE4 authorityView = (CdmAuthorityEditorE4) part.getObject();
164
        authorityView.init(input);
165
    }
166

    
167
    public static MPart showPart(String partId, EModelService modelService, EPartService partService, MApplication application){
168
        MPart part = partService.findPart(partId);
169
        if(part==null || modelService.getPartDescriptor(partId).isAllowMultiple()){
170
            part = partService.createPart(partId);
171
        }
172
        MPartStack editorAreaPartStack = WorkbenchUtility.getEditorAreaPartStack(application, modelService);
173
        if(editorAreaPartStack!=null){
174
            editorAreaPartStack.getChildren().add(part);
175
        }
176

    
177
        return partService.showPart(part, PartState.ACTIVATE);
178

    
179
    }
180

    
181
    public static MPart showPart(String partId, EModelService modelService, EPartService partService){
182
        MPart part = partService.findPart(partId);
183
        if(part==null || modelService.getPartDescriptor(partId).isAllowMultiple()){
184
            part = partService.createPart(partId);
185
            partService.activate(part);
186
        }else{
187
            partService.activate(part);
188
        }
189

    
190
       return part;
191
    }
192

    
193
	public static void openTaxonNodeE4(UUID taxonNodeUuid, EModelService modelService, EPartService partService, MApplication application) {
194
	    TaxonEditorInputE4 input = TaxonEditorInputE4.NewInstance(taxonNodeUuid);
195
	    openNameEditor_internal(input, modelService, partService, application);
196
	}
197

    
198
	public static void openTaxonBaseE4(UUID taxonBaseUuid, EModelService modelService, EPartService partService, MApplication application) {
199
	    TaxonEditorInputE4 input = TaxonEditorInputE4.NewInstanceFromTaxonBase(taxonBaseUuid);
200
	    openNameEditor_internal(input, modelService, partService, application);
201
	}
202

    
203
    public static void openTaxonBaseE4(UUID taxonBaseUuid) {
204
        //FIXME E4 this can probably be removed when fully migrated
205
        TaxonEditorInputE4 input = TaxonEditorInputE4.NewInstanceFromTaxonBase(taxonBaseUuid);
206

    
207
        EPartService partService = TaxeditorEditorPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getService(EPartService.class);
208
        EModelService modelService = TaxeditorEditorPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getService(EModelService.class);
209
        openNameEditor_internal(input, modelService, partService, null);
210
    }
211

    
212
    private static void openNameEditor_internal(TaxonEditorInputE4 input, EModelService modelService, EPartService partService, MApplication application) {
213
        TaxonBase taxonBase = input.getTaxon();
214
        TaxonNode node = input.getTaxonNode();
215
        if(taxonBase==null){
216
            return;
217
        }
218
        boolean hasPermission = false;
219
//        if (node != null){
220
//            hasPermission = CdmStore.currentAuthentiationHasPermission(node, RequiredPermissions.TAXON_EDIT);
221
//        }
222
//        if (!hasPermission){
223
//            MessagingUtils.warningDialog(Messages.EditorUtil_MISSING_PERMISSION, TaxonEditorInputE4.class, Messages.EditorUtil_MISSING_PERMISSION_MESSAGE);
224
//            return;
225
//        }
226
        if (taxonBase.isOrphaned()) {
227
            if(taxonBase.isInstanceOf(Synonym.class)){
228
                MessagingUtils.warningDialog(Messages.EditorUtil_ORPHAN_ACCEPTED_TAXON, TaxonEditorInputE4.class, Messages.EditorUtil_ORPHAN_ACCEPTED_TAXON_MESSAGE);
229
                return;
230
            }
231
            else{
232
                MessagingUtils.warningDialog(Messages.EditorUtil_ORPHAN_TAXON, TaxonEditorInputE4.class, Messages.EditorUtil_ORPHAN_TAXON_MESSAGE);
233
                return;
234
            }
235
        }
236

    
237

    
238
        Collection<MPart> parts = partService.getParts();
239
        //check if part is already opened
240
        for (MPart part : parts) {
241
        	if(part.getObject() instanceof TaxonNameEditorE4
242
                    && ((TaxonNameEditorE4) part.getObject()).getTaxon()!=null
243
                    && ((TaxonNameEditorE4) part.getObject()).getTaxon().getUuid().equals(input.getTaxon().getUuid())){
244
        	    if (part.isDirty()){
245
        	        forceUserSaveE4Editor(((TaxonNameEditorE4) part.getObject()), getShell());
246
        	    }
247
                partService.hidePart(part);
248
                break;
249
            }
250
        }
251
        MPart part = showPart(NAME_EDITOR_ID, modelService, partService, application);
252

    
253
        TaxonNameEditorE4 editor = (TaxonNameEditorE4) part.getObject();
254
        editor.init(input);
255

    
256
        if (factsVisible){
257
            showFacts(modelService, partService);
258
            factsVisible = false;
259
        }
260

    
261
        if (mediaVisible){
262
            showMedia(modelService, partService);
263
            mediaVisible = false;
264
        }
265

    
266
        editor.setFocus();
267
    }
268

    
269
    public static void showMedia(EModelService modelService, EPartService partService) {
270
        String partIdFactualData = AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_VIEW_MEDIA_E4_MEDIAVIEWPARTE4;
271
        showPart(partIdFactualData, modelService, partService);
272

    
273
    }
274

    
275
    public static void showFacts(EModelService modelService, EPartService partService) {
276
        String partIdFactualData = AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_VIEW_DESCRIPTIVE_E4_FACTUALDATAPARTE4;
277
        showPart(partIdFactualData, modelService, partService);
278

    
279
    }
280

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

    
294
                break;
295
            }else if (taxonUUID == null){
296
                if (part.isDirty()){
297
                    dirtyParts.add(part);
298
                }
299
            }
300
        }
301
        return dirtyParts;
302
    }
303

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

    
316
                break;
317
            }else if (taxonUUID == null){
318
                if (part.isDirty() && (part.getObject() instanceof TaxonNameEditorE4 || (part.getObject() instanceof BulkEditorE4 && ((BulkEditorE4)part.getObject()).getEditorInput() instanceof TaxonEditorInput))){
319
                    dirtyParts.add((IE4SavablePart) part.getObject());
320
                }
321
            }
322
        }
323
        return dirtyParts;
324
    }
325

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

    
344
	/**
345
	 * <p>
346
	 * getUndoContext
347
	 * </p>
348
	 *
349
	 * @return a {@link org.eclipse.core.commands.operations.IUndoContext}
350
	 *         object.
351
	 */
352
	public static IUndoContext getUndoContext() {
353
		return IOperationHistory.GLOBAL_UNDO_CONTEXT;
354
	}
355

    
356
	public static boolean isFactsVisible() {
357
        return factsVisible;
358
    }
359

    
360
    public static void setFactsVisible(boolean factsVisible) {
361
        EditorUtil.factsVisible = factsVisible;
362
    }
363

    
364
    public static boolean isMediaVisible() {
365
        return mediaVisible;
366
    }
367

    
368
    public static void setMediaVisible(boolean mediaVisible) {
369
        EditorUtil.mediaVisible = mediaVisible;
370
    }
371

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

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

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

    
394
			editor.doSave(AbstractUtility.getMonitor());
395
		}
396
		return true;
397
	}
398

    
399
	public static boolean forceUserSaveE4Editor(IE4SavablePart editor, Shell shell) {
400
	    if (editor.isDirty()) {
401

    
402
	        boolean doSave = MessageDialog
403
	                .openConfirm(shell, Messages.EditorUtil_COMFIRM_SAVE,
404
	                        Messages.EditorUtil_CONFIRM_SAVE_MESSAGE);
405

    
406
	        if (!doSave) {
407
	            return false;
408
	        }
409

    
410
	        editor.save(AbstractUtility.getMonitor());
411
	    }
412
	    return true;
413
	}
414

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

    
427
		return (IStructuredSelection) activeEditor.getSite()
428
				.getSelectionProvider().getSelection();
429
	}
430

    
431
	/**
432
	 * <p>
433
	 * getPluginId
434
	 * </p>
435
	 *
436
	 * @return a {@link java.lang.String} object.
437
	 */
438
	public static String getPluginId() {
439
		return TaxeditorEditorPlugin.PLUGIN_ID;
440
	}
441

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

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

    
478
        }
479
        return null;
480
    }
481

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

    
504

    
505
    public static void closeObsoleteDescriptiveDatasetEditor(UUID datasetUuid, EPartService partService){
506

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

    
520
            }
521
        }
522
    }
523

    
524

    
525
    public static void closePart(String partID, EPartService partService){
526

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

    
536
    public static void updateEditor(TaxonNode taxonNode, TaxonNameEditorE4 editor){
537
        String treeIndex = taxonNode.treeIndex();
538
        TaxonNode node = editor.getEditorInput().getTaxonNode();
539
        if(node.treeIndex().equals(treeIndex)){
540
        	TaxonEditorInputE4 input = TaxonEditorInputE4.NewInstance(node.getUuid());
541
        	editor.init(input);
542

    
543

    
544
        }
545
    }
546

    
547
}
(5-5/9)