Project

General

Profile

« Previous | Next » 

Revision dd35c5fd

Added by Patrick Plitzner over 8 years ago

Implement taxon assignment filter and refactor DerivativeEditor

  • Input no longer needs session
  • editor itself keeps track of its root elements
  • taxon assignment filter allows filtering specimens with/without taxon assignment or both

View differences:

eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/DerivateViewEditorInput.java
9 9
*/
10 10
package eu.etaxonomy.taxeditor.editor.view.derivate;
11 11

  
12
import java.util.ArrayList;
13
import java.util.Arrays;
14
import java.util.Collection;
15
import java.util.HashMap;
16
import java.util.HashSet;
17
import java.util.List;
18
import java.util.Map;
19 12
import java.util.Set;
20 13
import java.util.UUID;
21 14

  
......
23 16
import org.eclipse.ui.IEditorInput;
24 17
import org.eclipse.ui.IPersistableElement;
25 18

  
26
import eu.etaxonomy.cdm.api.application.CdmApplicationState;
27
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
28
import eu.etaxonomy.cdm.api.service.IOccurrenceService;
29
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
30 19
import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
31 20
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
32
import eu.etaxonomy.taxeditor.editor.CdmEntitySessionInput;
33
import eu.etaxonomy.taxeditor.editor.EditorUtil;
34
import eu.etaxonomy.taxeditor.store.CdmStore;
35
import eu.etaxonomy.taxeditor.view.derivateSearch.DerivateLabelProvider;
36 21

  
37 22
/**
38 23
 * Editor input for the {@link DerivateView} which holds the currently selected derivate for which
......
42 27
 * @date 25.11.2013
43 28
 *
44 29
 */
45
public class DerivateViewEditorInput extends CdmEntitySessionInput implements IEditorInput {
30
public class DerivateViewEditorInput implements IEditorInput {
46 31

  
47 32
    /**
48
     * The selected derivate {@link UUID}s
33
     * The {@link UUID}s of the derivative entities
49 34
     */
50
    private Set<SpecimenOrObservationBase<?>> derivateEntities;
51
    /**
52
     * List of the {@link UUID}s of the root elements of the hierarchy (may be the same objects as the derivates)
53
     */
54
    private Set<SpecimenOrObservationBase<?>> rootEntities;
55
    private Set<UUID> rootUUIDs;
56

  
57
    private final ConversationHolder conversationHolder;
58

  
59
    private static final List<String> SPECIMEN_INIT_STRATEGY = Arrays.asList(new String[] {
60
            "descriptions",
61
            "annotations",
62
            "markers",
63
            "credits",
64
            "extensions",
65
            "rights",
66
            "sources",
67
            "derivationEvents.derivatives.annotations",
68
            "derivationEvents.derivatives.markers",
69
            "derivationEvents.derivatives.credits",
70
            "derivationEvents.derivatives.extensions",
71
            "derivationEvents.derivatives.rights",
72
            "derivationEvents.derivatives.sources"
73
    });
35
    private Set<UUID> derivativeUUIDs;
74 36

  
75 37
    /**
76 38
     * Creates an editor input for the {@link DerivateView} with the currently selected derivates and the
77 39
     * corresponding {@link FieldUnit}s (both may be the same object).
78 40
     * @param derivateUuids the {@link UUID}s of the derivates for which the derivate hierarchy should be shown
79
     * @param rootUUIDs the root of the hierarchy
41
     * @param derivativeUUIDs the root of the hierarchy
80 42
     */
81 43
    public DerivateViewEditorInput(Set<UUID> derivateUuids) {
82
        super(false);
83
        rootUUIDs = derivateUuids;
84
        //FIXME:Remoting temporary hack for making the sessions work
85
        //This should ideally be changed to initializing the
86
        //super class with a collection of (id) objects which can
87
        //then be used for the hashCode, equals methods
88
        initSession();
89
        this.conversationHolder = CdmStore.createConversation();
90
        updateRootEntities(derivateUuids);
91

  
44
        this.derivativeUUIDs = derivateUuids;
92 45
    }
93 46

  
94 47
    /* (non-Javadoc)
......
142 95
    }
143 96

  
144 97
    private String getEditorName() {
145
        String name = null;
146
        for( SpecimenOrObservationBase<?> specimen : rootEntities){
147
            if(specimen!=null){
148
                if(name==null){
149
                    name = DerivateLabelProvider.getDerivateText(specimen, conversationHolder);
150
                }
151
                else{
152
                    name += " + "+DerivateLabelProvider.getDerivateText(specimen, conversationHolder); //$NON-NLS-1$
153
                }
154
            }
155
        }
156
        if(name==null){
157
            name = "Derivative Editor";
158
        }
159
        return name;
98
            return "Derivative Editor";
160 99
    }
161 100

  
162
    @Override
163
    public Set<SpecimenOrObservationBase<?>> getRootEntities() {
164
        return rootEntities;
165
    }
166

  
167
    public Set<SpecimenOrObservationBase<?>> getDerivateEntities() {
168
        return derivateEntities;
169
    }
170

  
171
    public void addRootEntity(SpecimenOrObservationBase<?> root){
172
        rootEntities.add(root);
173
    }
174

  
175

  
176
    public ConversationHolder getConversationHolder() {
177
        return conversationHolder;
101
    /**
102
     * @return the derivativeUUIDs
103
     */
104
    public Set<UUID> getDerivativeUUIDs() {
105
        return derivativeUUIDs;
178 106
    }
179 107

  
180 108
    @Override
181 109
    public int hashCode() {
182 110
        final int prime = 31;
183 111
        int result = 1;
184
        result = prime * result + ((rootUUIDs == null) ? 0 : rootUUIDs.hashCode());
112
        result = prime * result + ((derivativeUUIDs == null) ? 0 : derivativeUUIDs.hashCode());
185 113
        return result;
186 114
    }
187 115

  
......
197 125
            return false;
198 126
        }
199 127
        DerivateViewEditorInput other = (DerivateViewEditorInput) obj;
200
        if (rootUUIDs == null) {
201
            if (other.rootUUIDs != null) {
128
        if (derivativeUUIDs == null) {
129
            if (other.derivativeUUIDs != null) {
202 130
                return false;
203 131
            }
204
        } else if (!rootUUIDs.equals(other.rootUUIDs)) {
132
        } else if (!derivativeUUIDs.equals(other.derivativeUUIDs)) {
205 133
            return false;
206 134
        }
207 135
        return true;
208 136
    }
209 137

  
210
    @Override
211
    public void merge() {
212
        if(CdmStore.getCurrentSessionManager().isRemoting()) {
213
            CdmApplicationState.getCurrentAppConfig().getOccurrenceService().merge(new ArrayList(getRootEntities()), true);
214
        }
215

  
216
    }
217

  
218
    @Override
219
    public Map<Object, List<String>> getPropertyPathsMap() {
220
        List<String> specimenPropertyPaths = Arrays.asList(new String[] {
221
                "descriptions",
222
                "derivationEvents.derivates",
223
                "annotations",
224
                "markers",
225
                "credits",
226
                "extensions",
227
                "rights",
228
                "sources"
229
        });
230
        Map<Object, List<String>> specimenPropertyPathMap =
231
                new HashMap<Object, List<String>>();
232
        specimenPropertyPathMap.put(SpecimenOrObservationBase.class,specimenPropertyPaths);
233
        return specimenPropertyPathMap;
234
    }
235

  
236
    public void updateRootEntities(Collection<UUID> derivateUuids) {
237
        this.derivateEntities = new HashSet<SpecimenOrObservationBase<?>>();
238
        this.rootEntities = new HashSet<SpecimenOrObservationBase<?>>();
239
        for (UUID uuid : derivateUuids) {
240
            SpecimenOrObservationBase<?> derivate = CdmStore.getService(IOccurrenceService.class).load(uuid, SPECIMEN_INIT_STRATEGY);
241
            derivateEntities.add(derivate);
242
            if(derivate instanceof FieldUnit){
243
                rootEntities.add(derivate);
244
            }
245
            else if(derivate instanceof DerivedUnit){
246
                SpecimenOrObservationBase<?> topMostDerivate = EditorUtil.getTopMostDerivate(derivate);
247
                if(topMostDerivate!=null){
248
                    rootEntities.add(topMostDerivate);
249
                }
250
            }
251
        }
252
        if(rootEntities.isEmpty()){
253
            rootEntities = derivateEntities;
254
        }
255
    }
256

  
257 138
}

Also available in: Unified diff