Project

General

Profile

« Previous | Next » 

Revision bce766a1

Added by Patrick Plitzner over 6 years ago

ref #6932 Refactor merge annotating

View differences:

eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/handler/MergeGroupHandlerE4.java
12 12

  
13 13
import javax.inject.Named;
14 14

  
15
import org.apache.log4j.Logger;
16 15
import org.eclipse.e4.core.di.annotations.Execute;
17 16
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
18 17
import org.eclipse.e4.ui.services.IServiceConstants;
......
21 20

  
22 21
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
23 22
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
23
import eu.etaxonomy.cdm.model.common.CdmBase;
24 24
import eu.etaxonomy.cdm.model.reference.Reference;
25 25
import eu.etaxonomy.cdm.strategy.merge.MergeException;
26
import eu.etaxonomy.taxeditor.bulkeditor.e4.AnnotatedTableItem;
27 26
import eu.etaxonomy.taxeditor.bulkeditor.e4.BulkEditorE4;
27
import eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput;
28 28
import eu.etaxonomy.taxeditor.store.CdmStore;
29 29

  
30 30
/**
......
34 34
 *
35 35
 */
36 36
public class MergeGroupHandlerE4 {
37
    private static final Logger logger = Logger
38
            .getLogger(MergeGroupHandlerE4.class);
39 37

  
40 38
    @Execute
41
    public void execute(@Named(IServiceConstants.ACTIVE_SELECTION)Object object,
39
    public void execute(
42 40
            @Named(IServiceConstants.ACTIVE_PART)MPart activePart,
43 41
            @Named(IServiceConstants.ACTIVE_SHELL)Shell shell) {
44 42

  
45 43
        BulkEditorE4 editor = (BulkEditorE4) activePart.getObject();
44
        AbstractBulkEditorInput input = editor.getEditorInput();
46 45

  
47 46
        // Check whether there are any group annotations
48
        List<AnnotatedTableItem> mergeCandidates = editor.getMergeCandidates();
47
        List<CdmBase> mergeCandidates = input.getMergeCandidates();
49 48
        if (mergeCandidates.size() == 0) {
50 49
            MessageDialog.openWarning(shell,
51 50
                    "No merge candidates", "No objects have been chosen for merging.");
......
53 52
        }
54 53

  
55 54
        // Check whether group merge target has been set
56
        AnnotatedTableItem mergeTarget = editor.getMergeTarget();
55
        CdmBase mergeTarget = input.getMergeTarget();
57 56
        if (mergeTarget == null) {
58 57
            MessageDialog.openWarning(shell,
59 58
                    "No group merge target set", "No group merge target has been set.");
60 59
            return;
61 60
        }
62
        Object targetEntity = mergeTarget.getElement();
63 61

  
64 62
        TeamOrPersonBase teamOrPerson = null;
65 63
        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);
64
        if (mergeTarget instanceof TeamOrPersonBase){
65
            teamOrPerson = HibernateProxyHelper.deproxy(mergeTarget, TeamOrPersonBase.class);
66
        } else if(mergeTarget instanceof Reference){
67
            ref = HibernateProxyHelper.deproxy(mergeTarget, Reference.class);
70 68
        }
71
        for (AnnotatedTableItem item : mergeCandidates) {
69
        for (CdmBase item : mergeCandidates) {
72 70
            //first check whether entities are mergeable
73 71
            try{
74 72
                if (ref != null){
75
                    Reference ref2 = HibernateProxyHelper.deproxy(item.getElement(), Reference.class);
73
                    Reference ref2 = HibernateProxyHelper.deproxy(item, Reference.class);
76 74

  
77 75
                    if (!CdmStore.getCommonService().isMergeable(ref, ref2, null)){
78 76
                        MessageDialog.openWarning(shell,
79 77
                                "No merge possible", "A merge of " + ref.getTitleCache() + " and " + ref2.getTitleCache() + " is not possible.");
80 78
                        return;
81 79
                    }
80
                    input.getModel().remove(item);
82 81
                }
83 82
                if (teamOrPerson != null){
84
                    TeamOrPersonBase teamOrPerson2 = HibernateProxyHelper.deproxy(item.getElement(), TeamOrPersonBase.class);
83
                    TeamOrPersonBase teamOrPerson2 = HibernateProxyHelper.deproxy(item, TeamOrPersonBase.class);
85 84

  
86 85
                    if (!CdmStore.getCommonService().isMergeable(teamOrPerson, teamOrPerson2, null)){
87 86
                        MessageDialog.openWarning(shell,
88 87
                                "No merge possible", "A merge of " + teamOrPerson.getTitleCache() + " and " + teamOrPerson2.getTitleCache() + " is not possible.");
89 88
                        return;
90 89
                    }
90
                    input.getModel().remove(item);
91 91
                }
92 92
            }catch(MergeException e){
93 93

  
94 94
            }
95
            editor.removeAllAnnotations();
96
            editor.refresh();
97 95
            //				((BulkEditor) editor).removeAnnotatedLine(item);
98 96
            //
99 97
            //				// Mark entity container for merging with target entity
......
107 105
            //			model.removeTypeFromAllAnnotations(IBulkEditorConstants.TYPE_MERGE_CANDIDATE);
108 106
            //			model.removeTypeFromAllAnnotations(IBulkEditorConstants.TYPE_MERGE_TARGET);
109 107
        }
108
        editor.setDirty();
109
        editor.refresh();
110 110
    }
111 111
}

Also available in: Unified diff