1 |
a4b31985
|
Patrick Plitzner
|
/**
|
2 |
5cfc8708
|
Patrick Plitzner
|
* 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 |
a4b31985
|
Patrick Plitzner
|
package eu.etaxonomy.taxeditor.bulkeditor.e4.handler;
|
10 |
|
|
|
11 |
5cfc8708
|
Patrick Plitzner
|
import java.util.List;
|
12 |
|
|
|
13 |
a380926d
|
Patrick Plitzner
|
import javax.inject.Named;
|
14 |
a4b31985
|
Patrick Plitzner
|
|
15 |
|
|
import org.apache.log4j.Logger;
|
16 |
a380926d
|
Patrick Plitzner
|
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.services.IServiceConstants;
|
19 |
5cfc8708
|
Patrick Plitzner
|
import org.eclipse.jface.dialogs.MessageDialog;
|
20 |
a380926d
|
Patrick Plitzner
|
import org.eclipse.swt.widgets.Shell;
|
21 |
a4b31985
|
Patrick Plitzner
|
|
22 |
5cfc8708
|
Patrick Plitzner
|
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
|
23 |
|
|
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
|
24 |
|
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
25 |
|
|
import eu.etaxonomy.cdm.strategy.merge.MergeException;
|
26 |
|
|
import eu.etaxonomy.taxeditor.bulkeditor.e4.AnnotatedTableItem;
|
27 |
|
|
import eu.etaxonomy.taxeditor.bulkeditor.e4.BulkEditorE4;
|
28 |
|
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
29 |
|
|
|
30 |
a4b31985
|
Patrick Plitzner
|
/**
|
31 |
|
|
*
|
32 |
a380926d
|
Patrick Plitzner
|
* @author pplitzner
|
33 |
|
|
* @date 11.09.2017
|
34 |
|
|
*
|
35 |
a4b31985
|
Patrick Plitzner
|
*/
|
36 |
a380926d
|
Patrick Plitzner
|
public class MergeGroupHandlerE4 {
|
37 |
5cfc8708
|
Patrick Plitzner
|
private static final Logger logger = Logger
|
38 |
|
|
.getLogger(MergeGroupHandlerE4.class);
|
39 |
a4b31985
|
Patrick Plitzner
|
|
40 |
a380926d
|
Patrick Plitzner
|
@Execute
|
41 |
|
|
public void execute(@Named(IServiceConstants.ACTIVE_SELECTION)Object object,
|
42 |
|
|
@Named(IServiceConstants.ACTIVE_PART)MPart activePart,
|
43 |
|
|
@Named(IServiceConstants.ACTIVE_SHELL)Shell shell) {
|
44 |
a4b31985
|
Patrick Plitzner
|
|
45 |
5cfc8708
|
Patrick Plitzner
|
BulkEditorE4 editor = (BulkEditorE4) activePart.getObject();
|
46 |
|
|
|
47 |
|
|
// Check whether there are any group annotations
|
48 |
|
|
List<AnnotatedTableItem> mergeCandidates = editor.getMergeCandidates();
|
49 |
|
|
if (mergeCandidates.size() == 0) {
|
50 |
|
|
MessageDialog.openWarning(shell,
|
51 |
|
|
"No merge candidates", "No objects have been chosen for merging.");
|
52 |
|
|
return;
|
53 |
|
|
}
|
54 |
|
|
|
55 |
|
|
// Check whether group merge target has been set
|
56 |
|
|
AnnotatedTableItem mergeTarget = editor.getMergeTarget();
|
57 |
|
|
if (mergeTarget == null) {
|
58 |
|
|
MessageDialog.openWarning(shell,
|
59 |
|
|
"No group merge target set", "No group merge target has been set.");
|
60 |
|
|
return;
|
61 |
|
|
}
|
62 |
|
|
Object targetEntity = mergeTarget.getElement();
|
63 |
|
|
|
64 |
|
|
TeamOrPersonBase teamOrPerson = null;
|
65 |
|
|
Reference ref = null;
|
66 |
|
|
if (targetEntity instanceof TeamOrPersonBase){
|
67 |
|
|
teamOrPerson = HibernateProxyHelper.deproxy(targetEntity, TeamOrPersonBase.class);
|
68 |
|
|
} else if(targetEntity instanceof Reference){
|
69 |
|
|
ref = HibernateProxyHelper.deproxy(targetEntity, Reference.class);
|
70 |
|
|
}
|
71 |
|
|
for (AnnotatedTableItem item : mergeCandidates) {
|
72 |
|
|
//first check whether entities are mergeable
|
73 |
|
|
try{
|
74 |
|
|
if (ref != null){
|
75 |
|
|
Reference ref2 = HibernateProxyHelper.deproxy(item.getElement(), Reference.class);
|
76 |
|
|
|
77 |
|
|
if (!CdmStore.getCommonService().isMergeable(ref, ref2, null)){
|
78 |
|
|
MessageDialog.openWarning(shell,
|
79 |
|
|
"No merge possible", "A merge of " + ref.getTitleCache() + " and " + ref2.getTitleCache() + " is not possible.");
|
80 |
|
|
return;
|
81 |
|
|
}
|
82 |
|
|
}
|
83 |
|
|
if (teamOrPerson != null){
|
84 |
|
|
TeamOrPersonBase teamOrPerson2 = HibernateProxyHelper.deproxy(item.getElement(), TeamOrPersonBase.class);
|
85 |
|
|
|
86 |
|
|
if (!CdmStore.getCommonService().isMergeable(teamOrPerson, teamOrPerson2, null)){
|
87 |
|
|
MessageDialog.openWarning(shell,
|
88 |
|
|
"No merge possible", "A merge of " + teamOrPerson.getTitleCache() + " and " + teamOrPerson2.getTitleCache() + " is not possible.");
|
89 |
|
|
return;
|
90 |
|
|
}
|
91 |
|
|
}
|
92 |
|
|
}catch(MergeException e){
|
93 |
|
|
|
94 |
|
|
}
|
95 |
|
|
editor.removeAllAnnotations();
|
96 |
|
|
editor.refresh();
|
97 |
|
|
// ((BulkEditor) editor).removeAnnotatedLine(item);
|
98 |
|
|
//
|
99 |
|
|
// // Mark entity container for merging with target entity
|
100 |
|
|
// ((IEntityContainer) item).markAsMerged(targetEntity);
|
101 |
|
|
// logger.info("Merging " + item + " with " + targetAnnotation);
|
102 |
|
|
//
|
103 |
|
|
// // Remove annotation from model
|
104 |
|
|
// model.removeAnnotation(item);
|
105 |
|
|
// }
|
106 |
|
|
//
|
107 |
|
|
// model.removeTypeFromAllAnnotations(IBulkEditorConstants.TYPE_MERGE_CANDIDATE);
|
108 |
|
|
// model.removeTypeFromAllAnnotations(IBulkEditorConstants.TYPE_MERGE_TARGET);
|
109 |
|
|
}
|
110 |
|
|
}
|
111 |
a4b31985
|
Patrick Plitzner
|
}
|