Project

General

Profile

Download (2.55 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

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

    
31

    
32
    @Execute
33
    public void execute(@Named(IServiceConstants.ACTIVE_SELECTION)Object selection,
34
            @Named(IServiceConstants.ACTIVE_PART)MPart activePart) {
35
        BulkEditorE4 editor = (BulkEditorE4) activePart.getObject();
36
        if (selection instanceof Object[]){
37
            for(Object object: (Object[])selection){
38
                 if (object instanceof CdmBase){
39
                	 editor.getEditorInput().removeMergeCandidate((CdmBase)object);
40
                     editor.refresh();
41
                 }
42
             }
43
         }else if (selection instanceof CdmBase){
44
        	 editor.getEditorInput().removeMergeCandidate((CdmBase)selection);
45
             editor.refresh();
46
         }
47

    
48

    
49
    }
50

    
51
    @CanExecute
52
    public boolean canExecute(@Named(IServiceConstants.ACTIVE_PART)MPart activePart,
53
            MHandledMenuItem menuItem) {
54
        boolean canExecute = false;
55
        BulkEditorE4 editor = (BulkEditorE4) activePart.getObject();
56
        StructuredSelection selection = (StructuredSelection)((BulkEditorE4)activePart.getObject()).getViewer().getSelection();
57
        boolean selectedMergeCandidate = false;
58
        if (selection instanceof StructuredSelection){
59
            for(Object object: selection.toArray()){
60
                 if (object instanceof CdmBase){
61
                	 editor.getEditorInput().getMergeCandidates().contains(object);
62
                	 selectedMergeCandidate = true;
63
                 }
64
             }
65
         }
66

    
67
        canExecute = editor.getEditorInput().isMergingEnabled() && selectedMergeCandidate;
68
//                && editor.getEditorInput().getMergeCandidates().contains(selection);
69
        menuItem.setVisible(canExecute);
70
        return canExecute;
71
    }
72
}
(6-6/9)