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 SetMergeCandidateHandlerE4 {
|
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
|
AbstractBulkEditorInput input = editor.getEditorInput();
|
37
|
if(input.getMergeTarget()!=null
|
38
|
&& input.getMergeTarget().equals(selection)){
|
39
|
input.setMergeTarget(null);
|
40
|
}
|
41
|
if (selection instanceof Object[]){
|
42
|
for(Object object: (Object[])selection){
|
43
|
if (object instanceof CdmBase){
|
44
|
input.addMergeCandidate((CdmBase)object);
|
45
|
}
|
46
|
}
|
47
|
}else if (selection instanceof CdmBase){
|
48
|
input.addMergeCandidate((CdmBase)selection);
|
49
|
}
|
50
|
editor.refresh();
|
51
|
}
|
52
|
|
53
|
@CanExecute
|
54
|
public boolean canExecute(@Named(IServiceConstants.ACTIVE_PART)MPart activePart,
|
55
|
MHandledMenuItem menuItem) {
|
56
|
boolean canExecute = false;
|
57
|
BulkEditorE4 editor = (BulkEditorE4) activePart.getObject();
|
58
|
|
59
|
StructuredSelection selection = (StructuredSelection)((BulkEditorE4)activePart.getObject()).getSelection();
|
60
|
canExecute = !selection.isEmpty()
|
61
|
&& editor.getEditorInput().isMergingEnabled()
|
62
|
&& !editor.getEditorInput().getMergeCandidates().contains(selection.getFirstElement());
|
63
|
menuItem.setVisible(canExecute);
|
64
|
return canExecute;
|
65
|
}
|
66
|
}
|