Project

General

Profile

Download (2.27 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 java.util.Iterator;
12

    
13
import javax.inject.Named;
14

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

    
22
import eu.etaxonomy.cdm.model.common.CdmBase;
23
import eu.etaxonomy.taxeditor.bulkeditor.e4.BulkEditorE4;
24

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

    
33

    
34
    @Execute
35
    public void execute(@Named(IServiceConstants.ACTIVE_PART)MPart activePart) {
36
        BulkEditorE4 editor = (BulkEditorE4) activePart.getObject();
37
        IStructuredSelection selection = editor.getSelection();
38
        Iterator iterator = selection.iterator();
39
        for(selection.iterator();iterator.hasNext();){
40
            CdmBase cdmBase = (CdmBase) iterator.next();
41
            editor.getEditorInput().removeMergeCandidate(cdmBase);
42
        }
43
        editor.refresh();
44
    }
45

    
46
    @CanExecute
47
    public boolean canExecute(@Named(IServiceConstants.ACTIVE_PART)MPart activePart,
48
            MHandledMenuItem menuItem) {
49
        boolean canExecute = false;
50
        BulkEditorE4 editor = (BulkEditorE4) activePart.getObject();
51
        IStructuredSelection selection = ((BulkEditorE4)activePart.getObject()).getSelection();
52
        boolean selectedMergeCandidate = false;
53
        Iterator iterator = selection.iterator();
54
        for(selection.iterator();iterator.hasNext();){
55
            Object object = iterator.next();
56
            if (object instanceof CdmBase){
57
                editor.getEditorInput().getMergeCandidates().contains(object);
58
                selectedMergeCandidate = true;
59
            }
60
        }
61
        canExecute = editor.getEditorInput().isMergingEnabled() && selectedMergeCandidate;
62
        menuItem.setVisible(canExecute);
63
        return canExecute;
64
    }
65
}
(7-7/10)