Project

General

Profile

Revision 8ccf2acc

ID8ccf2acc7373ac1a892b97de5dc7d4bdb8397737
Parent 0a7b1887
Child 2c04b7fb

Added by Katja Luther over 2 years ago

improve deduplication handling and saving in bulkeditor

View differences:

eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/command/BulkEditorMenuPropertyTester.java
24 24

  
25 25
	private static final String IS_TEAM = "isTeam";
26 26
	private static final String IS_PERSON = "isPerson";
27
	
27
	private static final String IS_TEAM_OR_PERSON = "isTeamOrPerson";
28

  
28 29
	public BulkEditorMenuPropertyTester(){
29 30
	}
30 31
	/**
......
36 37
		if(receiver instanceof IStructuredSelection){
37 38
			IStructuredSelection selection = (IStructuredSelection) receiver;
38 39
			Object selectedElement = selection.getFirstElement();
40
			if (property.equals(IS_TEAM_OR_PERSON) && (selectedElement instanceof Team || selectedElement instanceof Person)){
41
                return true;
42
            }
39 43
			if (property.equals(IS_PERSON) && selectedElement instanceof Person){
40 44
				return true;
41
			} 
45
			}
42 46
			if (property.equals(IS_TEAM) && selectedElement instanceof Team){
43 47
				return true;
44 48
			}
45 49
			return false;
46
		
50

  
47 51
		}
48 52
		return false;
49 53
	}
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/BulkEditorE4.java
61 61
import eu.etaxonomy.taxeditor.model.IPartContentHasMedia;
62 62
import eu.etaxonomy.taxeditor.model.IPartContentHasSupplementalData;
63 63
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
64
import eu.etaxonomy.taxeditor.store.CdmStore;
65 64
import eu.etaxonomy.taxeditor.workbench.part.IE4SavablePart;
66 65

  
67 66
/**
......
249 248
	    Object object = viewer.getInput();
250 249
	    List<CdmBase> saveCandidates = getEditorInput().getSaveCandidates();
251 250

  
252
	    if (!saveCandidates.isEmpty()){
253
	        CdmStore.getService(saveCandidates.get(0)).merge(saveCandidates, true);
254
	    }
251

  
255 252
        dirty.setDirty(false);
256 253
        getEditorInput().resetSaveCandidates();
257 254

  
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/handler/MergeGroupHandlerE4.java
8 8
 */
9 9
package eu.etaxonomy.taxeditor.bulkeditor.e4.handler;
10 10

  
11
import java.util.HashSet;
11 12
import java.util.Set;
12 13

  
13 14
import javax.inject.Named;
......
48 49

  
49 50
        BulkEditorE4 editor = (BulkEditorE4) activePart.getObject();
50 51
        AbstractBulkEditorInput input = editor.getEditorInput();
52
        Set<CdmBase> mergedCandidates = new HashSet<>();
51 53

  
52 54
        if(editor.isDirty()){
53 55
            boolean proceed = MessageDialog.openQuestion(null,
......
63 65
        }
64 66

  
65 67
        // Check whether there are any group annotations
66
        Set<CdmBase> mergeCandidates = input.getMergeCandidates();
67
        if (mergeCandidates.size() == 0) {
68
        Set<CdmBase> candidatesToMerge = input.getMergeCandidates();
69
        if (candidatesToMerge.size() == 0) {
68 70
            MessageDialog.openWarning(shell,
69 71
                    "No merge candidates", "No objects have been chosen for merging.");
70 72
            return;
......
85 87
        } else if(mergeTarget instanceof Reference){
86 88
            ref = HibernateProxyHelper.deproxy(mergeTarget, Reference.class);
87 89
        }
88
        for (CdmBase item : mergeCandidates) {
90
        for (CdmBase item : candidatesToMerge) {
89 91
            //first check whether entities are mergeable
90 92
            try{
91 93
                if (ref != null){
......
97 99
                        return;
98 100
                    }
99 101
                    input.getModel().remove(item);
102
                    mergedCandidates.add(item);
103

  
100 104
                }
101 105
                if (teamOrPerson != null){
102 106
                    TeamOrPersonBase<?> teamOrPerson2 = HibernateProxyHelper.deproxy(item, TeamOrPersonBase.class);
......
107 111
                        return;
108 112
                    }
109 113
                    input.getModel().remove(item);
114
                    mergedCandidates.add(item);
110 115
                }
111 116
            }catch(MergeException e){
112

  
117
                candidatesToMerge.clear();
118
                MessageDialog.openWarning(shell,
119
                        "No merge possible", "A merge is not possible." + e.getLocalizedMessage());
120
                return;
113 121
            }
114 122
        }
115

  
123
        if (!candidatesToMerge.isEmpty()){
124
            input.getMergedEntities().put(mergeTarget, mergedCandidates);
125
//            mergeCandidates.clear();
126
            input.getMergeCandidates().clear();
127
            input.setMergeTarget(null);
128
        }
116 129
        editor.setDirty();
117 130
        editor.refresh();
118 131
    }
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/AbstractBulkEditorInput.java
57 57
	private List<T> saveCandidates = new ArrayList<>();
58 58

  
59 59

  
60
	private Set<T> mergeCandidates = new HashSet<>();
61
	private T mergeTarget = null;
60
	private Set<T> markedMergeCandidates = new HashSet<>();
61
	private T markedMergeTarget = null;
62

  
63
	private HashMap<T, Set<T>> mergedEntities = new HashMap<>();
62 64

  
63 65
	private IEntityCreator<T> entityCreator;
64 66
	private final ConversationHolder conversation;
......
91 93
	protected abstract T loadEntity(UUID entityUuid);
92 94

  
93 95
	public void setMergeTarget(T t){
94
	    mergeTarget = t;
96
	    markedMergeTarget = t;
95 97
	}
96 98

  
97 99
    public Set<T> getMergeCandidates() {
98
        return mergeCandidates;
100
        return markedMergeCandidates;
99 101
    }
100 102

  
101 103
    public T getMergeTarget() {
102
        return mergeTarget;
104
        return markedMergeTarget;
103 105
    }
104 106

  
105 107
	public void removeMergeTarget(){
106
	    mergeTarget = null;
108
	    markedMergeTarget = null;
107 109
	}
108 110

  
109 111
	public void addMergeCandidate(T t){
110
	    mergeCandidates.add(t);
112
	    markedMergeCandidates.add(t);
111 113
	}
112 114

  
113 115
	public void removeMergeCandidate(T t){
114
		mergeCandidates.remove(t);
116
		markedMergeCandidates.remove(t);
115 117
	}
116 118

  
117 119
    public void addToDelete(T t, DeleteConfiguratorBase config) {
......
198 200
            }
199 201
	    }
200 202
	    toDelete.clear();
203
	    if (!saveCandidates.isEmpty()){
204
            CdmStore.getService(saveCandidates.get(0)).merge(saveCandidates, true);
205
        }
201 206
	    if(resetMerge){
202 207
	        //merge entities
203
	        for(T mergeCandidate:mergeCandidates){
204
	            merge(mergeCandidate, mergeTarget);
208
	        for(T mergeTarget:mergedEntities.keySet()){
209
	            for (T mergeCandidate: mergedEntities.get(mergeTarget)){
210
	                merge(mergeCandidate, mergeTarget);
211
	            }
205 212
	        }
206
	        mergeCandidates.clear();
207
	        mergeTarget = null;
213
	        mergedEntities.clear();
214

  
208 215
	    }
209 216
	}
210 217

  
......
299 306
       this.saveCandidates.clear();
300 307

  
301 308
    }
309

  
310
    public HashMap<T, Set<T>> getMergedEntities() {
311
        return mergedEntities;
312
    }
313

  
314
    public void setMergedEntities(HashMap<T, Set<T>> mergedEntities) {
315
        this.mergedEntities = mergedEntities;
316
    }
302 317
}
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/AgentEditorInput.java
105 105
	/** {@inheritDoc} */
106 106
	@Override
107 107
	public List<TeamOrPersonBase> listEntities(IIdentifiableEntityServiceConfigurator configurator) {
108

  
108 109
		return CdmStore.getSearchManager().findTeamOrPersons(configurator);
109 110
	}
110 111

  

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)