Revision a380926d
Added by Patrick Plitzner over 6 years ago
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/handler/MergeGroupHandlerE4.java | ||
---|---|---|
1 | 1 |
/** |
2 | 2 |
* Copyright (C) 2007 EDIT |
3 |
* European Distributed Institute of Taxonomy
|
|
3 |
* European Distributed Institute of Taxonomy |
|
4 | 4 |
* http://www.e-taxonomy.eu |
5 |
*
|
|
5 |
* |
|
6 | 6 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
7 | 7 |
* See LICENSE.TXT at the top of this package for the full license terms. |
8 | 8 |
*/ |
9 | 9 |
package eu.etaxonomy.taxeditor.bulkeditor.e4.handler; |
10 | 10 |
|
11 |
import java.util.Set;
|
|
11 |
import javax.inject.Named;
|
|
12 | 12 |
|
13 | 13 |
import org.apache.log4j.Logger; |
14 |
import org.eclipse.core.commands.AbstractHandler; |
|
15 |
import org.eclipse.core.commands.ExecutionEvent; |
|
16 |
import org.eclipse.core.commands.ExecutionException; |
|
17 |
import org.eclipse.jface.dialogs.MessageDialog; |
|
18 |
import org.eclipse.jface.text.source.Annotation; |
|
19 |
import org.eclipse.ui.IEditorInput; |
|
20 |
import org.eclipse.ui.IEditorPart; |
|
21 |
import org.eclipse.ui.handlers.HandlerUtil; |
|
22 |
import org.eclipse.ui.texteditor.IDocumentProvider; |
|
23 |
|
|
24 |
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper; |
|
25 |
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase; |
|
26 |
import eu.etaxonomy.cdm.model.reference.Reference; |
|
27 |
import eu.etaxonomy.cdm.strategy.merge.MergeException; |
|
28 |
import eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityContainer; |
|
29 |
import eu.etaxonomy.taxeditor.annotatedlineeditor.LineAnnotation; |
|
30 |
import eu.etaxonomy.taxeditor.annotatedlineeditor.LineAnnotationModel; |
|
31 |
import eu.etaxonomy.taxeditor.bulkeditor.BulkEditor; |
|
32 |
import eu.etaxonomy.taxeditor.bulkeditor.IBulkEditorConstants; |
|
33 |
import eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput; |
|
34 |
import eu.etaxonomy.taxeditor.store.CdmStore; |
|
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.services.IServiceConstants; |
|
17 |
import org.eclipse.swt.widgets.Shell; |
|
35 | 18 |
|
36 | 19 |
/** |
37 |
* <p>MergeGroupHandler class.</p> |
|
38 | 20 |
* |
39 |
* @author p.ciardelli
|
|
40 |
* @created 25.06.2009
|
|
41 |
* @version 1.0
|
|
21 |
* @author pplitzner
|
|
22 |
* @date 11.09.2017
|
|
23 |
* |
|
42 | 24 |
*/ |
43 |
public class MergeGroupHandlerE4 extends AbstractHandler {
|
|
25 |
public class MergeGroupHandlerE4 { |
|
44 | 26 |
private static final Logger logger = Logger |
45 | 27 |
.getLogger(MergeGroupHandlerE4.class); |
46 | 28 |
|
47 |
/* (non-Javadoc) |
|
48 |
* @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent) |
|
49 |
*/ |
|
50 |
/** {@inheritDoc} */ |
|
51 |
public Object execute(ExecutionEvent event) throws ExecutionException { |
|
52 |
|
|
53 |
IEditorPart editor = HandlerUtil.getActiveEditor(event); |
|
54 |
IEditorInput input = editor.getEditorInput(); |
|
55 |
if (editor instanceof BulkEditor && input instanceof AbstractBulkEditorInput) { |
|
29 |
@Execute |
|
30 |
public void execute(@Named(IServiceConstants.ACTIVE_SELECTION)Object object, |
|
31 |
@Named(IServiceConstants.ACTIVE_PART)MPart activePart, |
|
32 |
@Named(IServiceConstants.ACTIVE_SHELL)Shell shell) { |
|
56 | 33 |
|
57 |
IDocumentProvider provider = ((BulkEditor) editor).getDocumentProvider();
|
|
58 |
LineAnnotationModel model =
|
|
59 |
(LineAnnotationModel) provider.getAnnotationModel(input);
|
|
60 |
|
|
61 |
// Check whether there are any group annotations
|
|
62 |
Set<LineAnnotation> candidateAnnotations = model.getAllAnnotationsOfType(IBulkEditorConstants.TYPE_MERGE_CANDIDATE);
|
|
63 |
if (candidateAnnotations.size() == 0) {
|
|
64 |
MessageDialog.openWarning(HandlerUtil.getActiveShell(event),
|
|
65 |
"No merge candidates", "No objects have been chosen for merging.");
|
|
66 |
return null;
|
|
67 |
}
|
|
68 |
|
|
69 |
// Check whether group merge target has been set
|
|
70 |
Annotation targetAnnotation = model.getFirstAnnotationOfType(IBulkEditorConstants.TYPE_MERGE_TARGET);
|
|
71 |
if (targetAnnotation == null) {
|
|
72 |
MessageDialog.openWarning(HandlerUtil.getActiveShell(event),
|
|
73 |
"No group merge target set", "No group merge target has been set.");
|
|
74 |
return null;
|
|
75 |
}
|
|
76 |
Object targetEntity = ((IEntityContainer<?>) targetAnnotation).getEntity();
|
|
77 |
|
|
78 |
TeamOrPersonBase teamOrPerson = null;
|
|
79 |
Reference ref = null;
|
|
80 |
if (targetEntity instanceof TeamOrPersonBase){
|
|
81 |
teamOrPerson = HibernateProxyHelper.deproxy(targetEntity, TeamOrPersonBase.class);
|
|
82 |
} else if(targetEntity instanceof Reference){
|
|
83 |
ref = HibernateProxyHelper.deproxy(targetEntity, Reference.class);
|
|
84 |
}
|
|
85 |
logger.info("Merging group");
|
|
86 |
// model.printAnnotations();
|
|
87 |
for (LineAnnotation annotation : candidateAnnotations) {
|
|
88 |
//first check whether entities are mergeable
|
|
89 |
|
|
90 |
|
|
91 |
try{
|
|
92 |
if (ref != null){
|
|
93 |
Reference ref2 = HibernateProxyHelper.deproxy(annotation.getEntity(), Reference.class);
|
|
94 |
|
|
95 |
if (!CdmStore.getCommonService().isMergeable(ref, ref2, null)){
|
|
96 |
MessageDialog.openWarning(HandlerUtil.getActiveShell(event),
|
|
97 |
"No merge possible", "A merge of " + ref.getTitleCache() + " and " + ref2.getTitleCache() + " is not possible.");
|
|
98 |
return null;
|
|
99 |
}
|
|
100 |
}
|
|
101 |
if (teamOrPerson != null){
|
|
102 |
TeamOrPersonBase teamOrPerson2 = HibernateProxyHelper.deproxy(annotation.getEntity(), TeamOrPersonBase.class);
|
|
103 |
|
|
104 |
if (!CdmStore.getCommonService().isMergeable(teamOrPerson, teamOrPerson2, null)){
|
|
105 |
MessageDialog.openWarning(HandlerUtil.getActiveShell(event),
|
|
106 |
"No merge possible", "A merge of " + teamOrPerson.getTitleCache() + " and " + teamOrPerson2.getTitleCache() + " is not possible.");
|
|
107 |
return null;
|
|
108 |
}
|
|
109 |
}
|
|
110 |
}catch(MergeException e){
|
|
111 |
|
|
112 |
} |
|
113 |
((BulkEditor) editor).removeAnnotatedLine(annotation);
|
|
114 |
|
|
115 |
// Mark entity container for merging with target entity
|
|
116 |
((IEntityContainer) annotation).markAsMerged(targetEntity);
|
|
117 |
logger.info("Merging " + annotation + " with " + targetAnnotation);
|
|
118 |
|
|
119 |
// Remove annotation from model
|
|
120 |
model.removeAnnotation(annotation);
|
|
121 |
}
|
|
122 |
// model.printAnnotations();
|
|
123 |
|
|
124 |
model.removeTypeFromAllAnnotations(IBulkEditorConstants.TYPE_MERGE_CANDIDATE);
|
|
125 |
model.removeTypeFromAllAnnotations(IBulkEditorConstants.TYPE_MERGE_TARGET);
|
|
126 |
}
|
|
127 |
return null;
|
|
34 |
//FIXME E4 migrate merge handler
|
|
35 |
// BulkEditorE4 editor = (BulkEditorE4) activePart.getObject();
|
|
36 |
//
|
|
37 |
// IDocumentProvider provider = ((BulkEditor) editor).getDocumentProvider(); |
|
38 |
// LineAnnotationModel model =
|
|
39 |
// (LineAnnotationModel) provider.getAnnotationModel(input);
|
|
40 |
//
|
|
41 |
// // Check whether there are any group annotations
|
|
42 |
// Set<LineAnnotation> candidateAnnotations = model.getAllAnnotationsOfType(IBulkEditorConstants.TYPE_MERGE_CANDIDATE);
|
|
43 |
// if (candidateAnnotations.size() == 0) {
|
|
44 |
// MessageDialog.openWarning(HandlerUtil.getActiveShell(event),
|
|
45 |
// "No merge candidates", "No objects have been chosen for merging."); |
|
46 |
// return null;
|
|
47 |
// }
|
|
48 |
//
|
|
49 |
// // Check whether group merge target has been set
|
|
50 |
// Annotation targetAnnotation = model.getFirstAnnotationOfType(IBulkEditorConstants.TYPE_MERGE_TARGET);
|
|
51 |
// if (targetAnnotation == null) {
|
|
52 |
// MessageDialog.openWarning(HandlerUtil.getActiveShell(event),
|
|
53 |
// "No group merge target set", "No group merge target has been set.");
|
|
54 |
// return null; |
|
55 |
// }
|
|
56 |
// Object targetEntity = ((IEntityContainer<?>) targetAnnotation).getEntity();
|
|
57 |
//
|
|
58 |
// TeamOrPersonBase teamOrPerson = null;
|
|
59 |
// Reference ref = null;
|
|
60 |
// if (targetEntity instanceof TeamOrPersonBase){
|
|
61 |
// teamOrPerson = HibernateProxyHelper.deproxy(targetEntity, TeamOrPersonBase.class);
|
|
62 |
// } else if(targetEntity instanceof Reference){
|
|
63 |
// ref = HibernateProxyHelper.deproxy(targetEntity, Reference.class);
|
|
64 |
// }
|
|
65 |
// logger.info("Merging group");
|
|
66 |
//// model.printAnnotations(); |
|
67 |
// for (LineAnnotation annotation : candidateAnnotations) { |
|
68 |
// //first check whether entities are mergeable
|
|
69 |
//
|
|
70 |
//
|
|
71 |
// try{ |
|
72 |
// if (ref != null){
|
|
73 |
// Reference ref2 = HibernateProxyHelper.deproxy(annotation.getEntity(), Reference.class);
|
|
74 |
//
|
|
75 |
// if (!CdmStore.getCommonService().isMergeable(ref, ref2, null)){
|
|
76 |
// MessageDialog.openWarning(HandlerUtil.getActiveShell(event),
|
|
77 |
// "No merge possible", "A merge of " + ref.getTitleCache() + " and " + ref2.getTitleCache() + " is not possible.");
|
|
78 |
// return null;
|
|
79 |
// }
|
|
80 |
// } |
|
81 |
// if (teamOrPerson != null){
|
|
82 |
// TeamOrPersonBase teamOrPerson2 = HibernateProxyHelper.deproxy(annotation.getEntity(), TeamOrPersonBase.class);
|
|
83 |
//
|
|
84 |
// if (!CdmStore.getCommonService().isMergeable(teamOrPerson, teamOrPerson2, null)){
|
|
85 |
// MessageDialog.openWarning(HandlerUtil.getActiveShell(event),
|
|
86 |
// "No merge possible", "A merge of " + teamOrPerson.getTitleCache() + " and " + teamOrPerson2.getTitleCache() + " is not possible.");
|
|
87 |
// return null;
|
|
88 |
// } |
|
89 |
// }
|
|
90 |
// }catch(MergeException e){
|
|
91 |
// |
|
92 |
// }
|
|
93 |
// ((BulkEditor) editor).removeAnnotatedLine(annotation);
|
|
94 |
//
|
|
95 |
// // Mark entity container for merging with target entity |
|
96 |
// ((IEntityContainer) annotation).markAsMerged(targetEntity);
|
|
97 |
// logger.info("Merging " + annotation + " with " + targetAnnotation);
|
|
98 |
//
|
|
99 |
// // Remove annotation from model
|
|
100 |
// model.removeAnnotation(annotation); |
|
101 |
// }
|
|
102 |
//
|
|
103 |
// model.removeTypeFromAllAnnotations(IBulkEditorConstants.TYPE_MERGE_CANDIDATE);
|
|
104 |
// model.removeTypeFromAllAnnotations(IBulkEditorConstants.TYPE_MERGE_TARGET);
|
|
128 | 105 |
} |
129 | 106 |
} |
Also available in: Unified diff
ref #6932 Migrate bulk editor handlers (part I)