Project

General

Profile

Download (3.19 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2016 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.handler.defaultHandler.e4;
10

    
11
import java.util.Collection;
12

    
13
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
14
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
15
import org.eclipse.e4.ui.workbench.modeling.EPartService;
16
import org.eclipse.jface.dialogs.MessageDialog;
17
import org.eclipse.jface.viewers.IStructuredSelection;
18
import org.eclipse.jface.wizard.WizardDialog;
19
import org.eclipse.swt.widgets.Shell;
20

    
21
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
22
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
23
import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto;
24
import eu.etaxonomy.taxeditor.editor.ITaxonEditor;
25
import eu.etaxonomy.taxeditor.event.EventUtility;
26
import eu.etaxonomy.taxeditor.event.WorkbenchEventConstants;
27
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
28
import eu.etaxonomy.taxeditor.store.CdmStore;
29
import eu.etaxonomy.taxeditor.ui.section.classification.EditTaxonNodeWizard;
30

    
31
/**
32
 * @author k.luther
33
 * @date 22.03.2016
34
 *
35
 */
36
public class DefaultOpenTaxonNodeWizardHandlerE4 extends DefaultOpenHandlerBaseE4<TaxonNodeDto> {
37

    
38
//    @Override
39
//    protected TaxonNode getEntity(UUID uuid) {
40
//        return CdmStore.getService(ITaxonNodeService.class).load(uuid);
41
//    }
42

    
43
    @Override
44
    protected void open(TaxonNodeDto entity, Shell shell, EPartService partService) {
45
        Collection<MPart> dirtyParts = partService.getDirtyParts();
46
        if (!dirtyParts.isEmpty()){
47

    
48
            for (MPart dirtyPart: dirtyParts){
49
                if (dirtyPart.getElementId().equals("eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4")  && ((ITaxonEditor)dirtyPart.getObject()).getTaxonNode().getUuid().equals(entity.getUuid())){
50
                    boolean doSave = MessageDialog
51
                            .openConfirm(shell, "The taxonnode is in an unsaved mode",
52
                                    "Do you want to save?");
53

    
54
                    if (!doSave) {
55
                        return ;
56
                    }
57

    
58
                    partService.savePart(dirtyPart, false);
59
                }
60

    
61
            }
62
        }
63
        EditTaxonNodeWizard taxonNodeWizard = ContextInjectionFactory.make(EditTaxonNodeWizard.class, context);
64
        taxonNodeWizard.init(null, null);
65
        taxonNodeWizard.setEntity(CdmStore.getService(ITaxonNodeService.class).load(entity.getUuid()));
66
        WizardDialog dialog = new WizardDialog(shell, taxonNodeWizard);
67
        dialog.open();
68
        EventUtility.postEvent(WorkbenchEventConstants.REFRESH_NAVIGATOR, entity);
69

    
70
    }
71

    
72
    @Override
73
    public boolean canExecute(Object selection) {
74
        if (((IStructuredSelection)selection).getFirstElement() instanceof TaxonNodeDto && ((IStructuredSelection)selection).size() == 1){
75
            return ((TaxonNodeDto)((IStructuredSelection)selection).getFirstElement()).getTaxonUuid()!=null && PreferencesUtil.getBooleanValue(PreferencePredicate.ShowTaxonNodeWizard.getKey());
76
        }
77
        return false;
78
    }
79

    
80

    
81

    
82
}
(4-4/4)