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/DerivateView.java
1 1
package eu.etaxonomy.taxeditor.editor.view.derivate;
2 2

  
3
import java.util.Arrays;
3 4
import java.util.Collection;
5
import java.util.HashMap;
4 6
import java.util.HashSet;
7
import java.util.List;
8
import java.util.Map;
5 9
import java.util.Map.Entry;
6 10
import java.util.Set;
7 11
import java.util.UUID;
......
34 38

  
35 39
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
36 40
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
41
import eu.etaxonomy.cdm.api.service.IOccurrenceService;
37 42
import eu.etaxonomy.cdm.api.service.molecular.ISequenceService;
38 43
import eu.etaxonomy.cdm.model.common.CdmBase;
39 44
import eu.etaxonomy.cdm.model.molecular.Sequence;
40 45
import eu.etaxonomy.cdm.model.molecular.SingleRead;
46
import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
41 47
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
42 48
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
49
import eu.etaxonomy.taxeditor.editor.EditorUtil;
43 50
import eu.etaxonomy.taxeditor.editor.Messages;
44 51
import eu.etaxonomy.taxeditor.editor.view.derivate.searchFilter.DerivateSearchCompositeController;
45 52
import eu.etaxonomy.taxeditor.model.IDirtyMarkable;
......
58 65
 */
59 66
public class DerivateView extends EditorPart implements IPartContentHasFactualData, IDirtyMarkable,
60 67
        IConversationEnabled, IPartContentHasDetails, IPartContentHasSupplementalData, IPartContentHasMedia,
61
        ISelectionChangedListener, IPostOperationEnabled{
62 68

  
69
        ISelectionChangedListener, IPostOperationEnabled/*, ICdmEntitySessionEnabled*/{
63 70
    public static final String ID = "eu.etaxonomy.taxeditor.editor.view.derivate.DerivateView"; //$NON-NLS-1$
64 71

  
65 72
    public static final String YOU_NEED_TO_SAVE_BEFORE_PERFORMING_THIS_ACTION = Messages.DerivateView_YOU_NEED_TO_SAVE;
66 73
    public static final String VIEW_HAS_UNSAVED_CHANGES = Messages.DerivateView_UNSAVED_CHANGES;
67 74

  
75
    private static final List<String> SPECIMEN_INIT_STRATEGY = Arrays.asList(new String[] {
76
            "descriptions",
77
            "annotations",
78
            "markers",
79
            "credits",
80
            "extensions",
81
            "rights",
82
            "sources",
83
            "derivationEvents.derivatives.annotations",
84
            "derivationEvents.derivatives.markers",
85
            "derivationEvents.derivatives.credits",
86
            "derivationEvents.derivatives.extensions",
87
            "derivationEvents.derivatives.rights",
88
            "derivationEvents.derivatives.sources"
89
    });
90

  
68 91
	private ConversationHolder conversation;
69 92

  
70 93
	private TreeViewer viewer;
......
84 107

  
85 108
    private DerivateSearchCompositeController derivateSearchCompositeController;
86 109

  
110
    /**
111
     * A map with keys being the derivative entities belonging to the {@link UUID}s passed to the constructor
112
     * and values being the root elements of the hierarchy (may be the same objects as the derivative entities)
113
     */
114
    private Map<SpecimenOrObservationBase<?>, SpecimenOrObservationBase<?>> derivateToRootEntityMap;
115

  
116
    /**
117
     * The set of root elements
118
     */
119
    private Set<SpecimenOrObservationBase<?>> rootElements;
120

  
87 121
    /**
88 122
     * Default constructor
89 123
     */
90 124
    public DerivateView() {
125
        conversation = CdmStore.createConversation();
91 126
    }
92 127

  
93 128
    @Override
......
129 164
        Menu menu = menuManager.createContextMenu(control);
130 165
        control.setMenu(menu);
131 166

  
167
        //single read multi links
132 168
        generateMultiLinkSingleReads();
133 169
        labelProvider.setMultiLinkSingleReads(multiLinkSingleReads);
134
        IEditorInput editorInput = getEditorInput();
135
        viewer.setInput(((DerivateViewEditorInput) editorInput).getRootEntities());
136
        //set selection to selected derivate if only one was selected
137
        if(editorInput instanceof DerivateViewEditorInput){
138
            Set<SpecimenOrObservationBase<?>> derivateEntities = ((DerivateViewEditorInput) editorInput).getDerivateEntities();
139
            if(derivateEntities.size()==1){
140
                SpecimenOrObservationBase<?> specimen = derivateEntities.iterator().next();
141
                if(specimen != null){
142
                    viewer.setSelection(new StructuredSelection(new TreeNode(specimen)));
143
                }
144
            }
170

  
171
        //init tree
172
        DerivateViewEditorInput editorInput = (DerivateViewEditorInput) getEditorInput();
173
        if(editorInput.getDerivativeUUIDs()!=null){
174
            updateRootEntities(editorInput.getDerivativeUUIDs());
175
        }
176
        else{
177
            updateRootEntities();
145 178
        }
146 179

  
147 180
        //add drag'n'drop support
......
150 183
        viewer.addDropSupport(dndOperations, transfers, new DerivateDropListener(this));
151 184
    }
152 185

  
186
    public void updateRootEntities() {
187
        updateRootEntities(null);
188
    }
189

  
190
    public void updateRootEntities(Collection<UUID> derivativeUuids) {
191
        if(derivativeUuids!=null){
192
            this.derivateToRootEntityMap = new HashMap<SpecimenOrObservationBase<?>, SpecimenOrObservationBase<?>>();
193
            this.rootElements = new HashSet<SpecimenOrObservationBase<?>>();
194
            for (UUID uuid : derivativeUuids) {
195
                SpecimenOrObservationBase<?> derivate = CdmStore.getService(IOccurrenceService.class).load(uuid, SPECIMEN_INIT_STRATEGY);
196
                if(derivate instanceof FieldUnit){
197
                    derivateToRootEntityMap.put(derivate, derivate);
198
                }
199
                else {
200
                    SpecimenOrObservationBase<?> topMostDerivate = EditorUtil.getTopMostDerivate(derivate);
201
                    if(topMostDerivate!=null){
202
                        derivateToRootEntityMap.put(derivate, topMostDerivate);
203
                    }
204
                    else{
205
                        derivateToRootEntityMap.put(derivate, derivate);
206
                    }
207
                }
208
            }
209
            for (SpecimenOrObservationBase<?> specimen : derivateToRootEntityMap.values()) {
210
                rootElements.add(specimen);
211
            }
212
        }
213
        viewer.setInput(rootElements);
214
        refreshTree();
215
    }
216

  
153 217
    @Override
154 218
    public void doSave(IProgressMonitor monitor) {
155 219
        String taskName = Messages.DerivateView_SAVING_HIERARCHY;
......
165 229

  
166 230
        // commit the conversation and start a new transaction immediately
167 231
        conversation.commit(true);
168
        ((DerivateViewEditorInput) getEditorInput()).merge();
232
//      TODO: what does this do?  merge();
169 233
        monitor.worked(1);
170 234

  
171 235
        this.setDirty(false);
......
179 243
    public void doSaveAs() {
180 244
    }
181 245

  
246
    public Set<SpecimenOrObservationBase<?>> getRootElements() {
247
        return rootElements;
248
    }
249

  
182 250
    @Override
183 251
    public String getTitleToolTip() {
184 252
        if(getEditorInput() instanceof DerivateViewEditorInput){
......
192 260
    public void init(IEditorSite site, IEditorInput input) throws PartInitException {
193 261
        setSite(site);
194 262
        setInput(input);
195
        if(input instanceof DerivateViewEditorInput){
196
            DerivateViewEditorInput derivateViewEditorInput = (DerivateViewEditorInput) input;
197
            conversation = derivateViewEditorInput.getConversationHolder();
198
            setPartName(derivateViewEditorInput.getName());
199
        }
263
        this.derivateToRootEntityMap = new HashMap<SpecimenOrObservationBase<?>, SpecimenOrObservationBase<?>>();
264
        this.rootElements = new HashSet<SpecimenOrObservationBase<?>>();
200 265
    }
201 266

  
202 267
    @Override
......
223 288
        if(!conversation.isBound()){
224 289
            conversation.bind();
225 290
        }
226
        ((DerivateViewEditorInput) getEditorInput()).bind();
227 291
    }
228 292

  
229 293
    @Override
......
254 318
        changed(null);
255 319
    }
256 320

  
257
    protected void setRootEntities(Collection<UUID> rootEntityUuids){
258
        ((DerivateViewEditorInput)getEditorInput()).updateRootEntities(rootEntityUuids);
259
    }
321
//    @Override
322
//    public Set<SpecimenOrObservationBase<?>> getRootEntities() {
323
//        return rootElements;
324
//    }
325
//
326
//    @Override
327
//    public void merge() {
328
//        if(CdmStore.getCurrentSessionManager().isRemoting()) {
329
//            CdmApplicationState.getCurrentAppConfig().getOccurrenceService().merge(new ArrayList(getRootEntities()), true);
330
//        }
331
//    }
332
//
333
//    @Override
334
//    public Map<Object, List<String>> getPropertyPathsMap() {
335
//        List<String> specimenPropertyPaths = Arrays.asList(new String[] {
336
//                "descriptions",
337
//                "derivationEvents.derivates",
338
//                "annotations",
339
//                "markers",
340
//                "credits",
341
//                "extensions",
342
//                "rights",
343
//                "sources"
344
//        });
345
//        Map<Object, List<String>> specimenPropertyPathMap =
346
//                new HashMap<Object, List<String>>();
347
//        specimenPropertyPathMap.put(SpecimenOrObservationBase.class,specimenPropertyPaths);
348
//        return specimenPropertyPathMap;
349
//    }
260 350

  
261 351
    /**
262 352
     * Refreshes the derivate hierarchy tree and expands the tree
......
283 373
    //FIXME:Remoting hack to make this work for remoting
284 374
    //This should actually be resolved using remoting post operations
285 375
    public void remove(Object obj) {
286
        Set<SpecimenOrObservationBase<?>> rootEntities = ((DerivateViewEditorInput) getEditorInput()).getRootEntities();
287
        rootEntities.remove(obj);
288
        viewer.setInput(rootEntities);
376
        rootElements.remove(obj);
377
        viewer.setInput(rootElements);
289 378
    }
290 379

  
291 380
    private void generateMultiLinkSingleReads() {
......
332 421
        return true;
333 422
    }
334 423

  
335
    @Override
336
    public void dispose() {
337
        ((DerivateViewEditorInput) getEditorInput()).dispose();
338
        super.dispose();
339
    }
340

  
341 424

  
342 425
    @Override
343 426
    public boolean canAttachMedia() {
344 427
        return true;
345 428
    }
429

  
430
    public void removeHierarchy(SpecimenOrObservationBase<?> specimenOrObservationBase) {
431
        SpecimenOrObservationBase<?> rootElement = derivateToRootEntityMap.remove(specimenOrObservationBase);
432
        rootElements.remove(rootElement);
433
    }
434

  
435
    public void addHierarchy(FieldUnit fieldUnit) {
436
        rootElements.add(fieldUnit);
437
        derivateToRootEntityMap.put(fieldUnit, fieldUnit);
438
    }
439

  
440
//    @Override
441
//    public ICdmEntitySession getCdmEntitySession() {
442
//        return conversation;
443
//    }
346 444
}

Also available in: Unified diff