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
|
import eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput;
|
25
|
|
26
|
/**
|
27
|
*
|
28
|
* @author pplitzner
|
29
|
* @date 12.09.2017
|
30
|
*
|
31
|
*/
|
32
|
public class SetMergeCandidateHandlerE4 {
|
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
|
Object object = iterator.next();
|
41
|
|
42
|
AbstractBulkEditorInput input = editor.getEditorInput();
|
43
|
if(input.getMergeTarget()!=null
|
44
|
&& input.getMergeTarget().equals(object)){
|
45
|
input.setMergeTarget(null);
|
46
|
}
|
47
|
if (object instanceof CdmBase){
|
48
|
input.addMergeCandidate((CdmBase)object);
|
49
|
}
|
50
|
}
|
51
|
|
52
|
editor.refresh();
|
53
|
}
|
54
|
|
55
|
@CanExecute
|
56
|
public boolean canExecute(@Named(IServiceConstants.ACTIVE_PART)MPart activePart,
|
57
|
MHandledMenuItem menuItem) {
|
58
|
boolean canExecute = false;
|
59
|
BulkEditorE4 editor = (BulkEditorE4) activePart.getObject();
|
60
|
IStructuredSelection selection = ((BulkEditorE4)activePart.getObject()).getSelection();
|
61
|
canExecute = !selection.isEmpty()
|
62
|
&& editor.getEditorInput().isMergingEnabled();
|
63
|
Iterator iterator = selection.iterator();
|
64
|
for(selection.iterator();iterator.hasNext();){
|
65
|
Object object = iterator.next();
|
66
|
if (editor.getEditorInput().getMergeCandidates().contains(object)){
|
67
|
canExecute = false;
|
68
|
break;
|
69
|
}
|
70
|
}
|
71
|
menuItem.setVisible(canExecute);
|
72
|
return canExecute;
|
73
|
}
|
74
|
}
|