Project

General

Profile

Download (2.09 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.bulkeditor.e4.handler;
10

    
11
import javax.inject.Named;
12

    
13
import org.eclipse.e4.core.di.annotations.CanExecute;
14
import org.eclipse.e4.core.di.annotations.Execute;
15
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
16
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
17
import org.eclipse.e4.ui.services.IServiceConstants;
18
import org.eclipse.jface.viewers.StructuredSelection;
19

    
20
import eu.etaxonomy.cdm.model.common.CdmBase;
21
import eu.etaxonomy.taxeditor.bulkeditor.e4.BulkEditorE4;
22
import eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput;
23

    
24
/**
25
 *
26
 * @author pplitzner
27
 * @date 12.09.2017
28
 *
29
 */
30
public class SetMergeTargetHandlerE4 {
31

    
32
    @Execute
33
    public void execute(@Named(IServiceConstants.ACTIVE_SELECTION)CdmBase selection,
34
            @Named(IServiceConstants.ACTIVE_PART)MPart activePart) {
35
        BulkEditorE4 editor = (BulkEditorE4) activePart.getObject();
36
        AbstractBulkEditorInput input = editor.getEditorInput();
37
        if(input.getMergeCandidates().contains(selection)){
38
            input.removeMergeCandidate(selection);
39
        }
40
        input.setMergeTarget(selection);
41
        editor.refresh();
42
	}
43

    
44
    @CanExecute
45
    public boolean canExecute(@Named(IServiceConstants.ACTIVE_PART)MPart activePart,
46
            MHandledMenuItem menuItem) {
47
        boolean canExecute = false;
48
        BulkEditorE4 editor = (BulkEditorE4) activePart.getObject();
49
        StructuredSelection selection = (StructuredSelection)((BulkEditorE4)activePart.getObject()).getSelection();
50
        canExecute = !selection.isEmpty()
51
                && editor.getEditorInput().isMergingEnabled()
52
                && (editor.getEditorInput().getMergeTarget()==null
53
                || !editor.getEditorInput().getMergeTarget().equals(selection));
54
        menuItem.setVisible(canExecute);
55
        return canExecute;
56
    }
57
}
(10-10/10)