Project

General

Profile

Download (3.75 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.view.descriptive.e4.handler;
11

    
12
import java.util.UUID;
13

    
14
import javax.inject.Named;
15

    
16
import org.eclipse.e4.core.di.annotations.Execute;
17
import org.eclipse.e4.core.di.annotations.Optional;
18
import org.eclipse.e4.ui.di.UISynchronize;
19
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
20
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
21
import org.eclipse.e4.ui.services.IServiceConstants;
22

    
23
import eu.etaxonomy.cdm.api.service.ITermService;
24
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
25
import eu.etaxonomy.cdm.model.description.DescriptionBase;
26
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
27
import eu.etaxonomy.cdm.model.description.Feature;
28
import eu.etaxonomy.taxeditor.editor.EditorUtil;
29
import eu.etaxonomy.taxeditor.editor.view.descriptive.e4.FactualDataPartE4;
30
import eu.etaxonomy.taxeditor.editor.view.descriptive.operation.CreateDescriptionElementOperation;
31
import eu.etaxonomy.taxeditor.model.AbstractUtility;
32
import eu.etaxonomy.taxeditor.model.FeatureNodeContainer;
33
import eu.etaxonomy.taxeditor.model.MessagingUtils;
34
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
35
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
36
import eu.etaxonomy.taxeditor.store.CdmStore;
37

    
38
/**
39
 *
40
 * @author pplitzner
41
 * @date 15.08.2017
42
 *
43
 */
44
public class CreateDescriptionElementHandlerE4 {
45

    
46
    @Execute
47
    public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart activePart,
48
            @Optional@Named(IServiceConstants.ACTIVE_SELECTION) Object object, MHandledMenuItem menuItem,
49
            UISynchronize sync) {
50

    
51
        String commandId = menuItem.getCommand().getElementId();
52
        UUID uuid = (UUID) menuItem.getTransientData().get(commandId+".feature.uuid");
53
        Feature feature = HibernateProxyHelper.deproxy(CdmStore.getService(ITermService.class).load(uuid), Feature.class);
54

    
55
        FactualDataPartE4 factualDataPart = (FactualDataPartE4) activePart.getObject();
56

    
57
        DescriptionBase description = null;
58
        if(object instanceof FeatureNodeContainer){
59
            description = ((FeatureNodeContainer) object).getDescription();
60
        }
61
        else if(object instanceof DescriptionElementBase){
62
            DescriptionElementBase elementBase = HibernateProxyHelper.deproxy(object, DescriptionElementBase.class);
63
            description = elementBase.getInDescription();
64
        }
65
        else if (object instanceof DescriptionBase) {
66
            description = HibernateProxyHelper.deproxy(object, DescriptionBase.class);
67
        } else {
68
            MessagingUtils.error(getClass(), new IllegalArgumentException("Could not determine the taxon description")); //$NON-NLS-1$
69
            return;
70
        }
71
        AbstractPostOperation operation = operationCreationInstance(menuItem.getLocalizedLabel(), feature, description,
72
                factualDataPart);
73
        // TODO use undo context specific to editor
74
        AbstractUtility.executeOperation(operation, sync);
75
    }
76

    
77
    /**
78
	 * Added to make the Class more generic and limit the amount of code changes required
79
	 * @param label
80
	 * @param event
81
	 * @param taxon
82
	 * @param description
83
	 * @param postOperationEnabled
84
	 * @return
85
	 */
86
    protected AbstractPostOperation operationCreationInstance(String label, Feature feature,
87
            DescriptionBase<?> description, IPostOperationEnabled postOperationEnabled) {
88
        return new CreateDescriptionElementOperation(label, EditorUtil.getUndoContext(), description, feature,
89
                postOperationEnabled);
90
    }
91

    
92
}
(1-1/8)