Project

General

Profile

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

    
11
import javax.inject.Named;
12

    
13
import org.eclipse.e4.core.di.annotations.Execute;
14
import org.eclipse.e4.ui.di.UISynchronize;
15
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
16
import org.eclipse.e4.ui.model.application.ui.menu.MMenuItem;
17
import org.eclipse.e4.ui.services.IServiceConstants;
18
import org.eclipse.swt.widgets.Shell;
19

    
20
import eu.etaxonomy.cdm.model.common.IdentifiableSource;
21
import eu.etaxonomy.cdm.model.common.OriginalSourceType;
22
import eu.etaxonomy.cdm.model.name.TaxonName;
23
import eu.etaxonomy.cdm.model.reference.Reference;
24
import eu.etaxonomy.cdm.model.taxon.Taxon;
25
import eu.etaxonomy.taxeditor.editor.EditorUtil;
26
import eu.etaxonomy.taxeditor.editor.view.descriptive.operation.CreateTaxonNameDescriptionOperation;
27
import eu.etaxonomy.taxeditor.editor.view.descriptive.operation.CreateTaxonDescriptionOperation;
28
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
29
import eu.etaxonomy.taxeditor.ui.dialog.selection.ReferenceSelectionDialog;
30

    
31
/**
32
 * @author pplitzner
33
 * @since Sep 20, 2018
34
 *
35
 */
36
public class CreateDescriptionWithSourceHandler extends CreateDescriptionHandlerE4 {
37

    
38
    private Shell shell;
39

    
40
    @Execute
41
    public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart activePart, MMenuItem menuItem,
42
            UISynchronize sync, @Named(IServiceConstants.ACTIVE_SHELL) Shell shell) {
43
        this.shell = shell;
44
        super.execute(activePart, menuItem, sync);
45
    }
46

    
47
    @Override
48
    protected CreateTaxonDescriptionOperation createTaxonOperation(String eventLabel, Taxon taxon, IPostOperationEnabled postOperationEnabled) {
49
        Reference reference = ReferenceSelectionDialog.select(shell, null);
50
        if(reference==null){
51
            return null;
52
        }
53
        IdentifiableSource source = IdentifiableSource.NewInstance(OriginalSourceType.Unknown, null, null, reference, null);
54
        return new CreateTaxonDescriptionOperation(eventLabel, EditorUtil.getUndoContext(), taxon, source, postOperationEnabled);
55
    }
56

    
57
    @Override
58
    protected CreateTaxonNameDescriptionOperation createTaxonNameOperation(String eventLabel, TaxonName taxonName, IPostOperationEnabled postOperationEnabled) {
59
        Reference reference = ReferenceSelectionDialog.select(shell, null);
60
        if(reference==null){
61
            return null;
62
        }
63
        IdentifiableSource source = IdentifiableSource.NewInstance(OriginalSourceType.Unknown, null, null, reference, null);
64
        return new CreateTaxonNameDescriptionOperation(eventLabel, EditorUtil.getUndoContext(), taxonName, source, postOperationEnabled);
65
    }
66
}
(3-3/9)