Project

General

Profile

Revision 2e385b93

ID2e385b930a93f39d748b47cdf1061c12b3f5dd1d
Parent 530e4fec
Child 0747234f

Added by Katja Luther about 2 years ago

ref #7854: session handling in distribution editor

View differences:

eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/checklist/e4/DistributionCellSelectionListener.java
68 68
                }
69 69
            }
70 70
        }
71
        part.getSelectionService().setSelection(new StructuredSelection());
71
      //  part.getSelectionService().setSelection(new StructuredSelection());
72 72
    }
73 73
}
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/checklist/e4/DistributionColumnAccessor.java
8 8
*/
9 9
package eu.etaxonomy.taxeditor.editor.view.checklist.e4;
10 10

  
11
import java.util.HashMap;
11 12
import java.util.HashSet;
13
import java.util.Map;
12 14
import java.util.Set;
13 15

  
14 16
import org.eclipse.nebula.widgets.nattable.data.IColumnPropertyAccessor;
......
55 57
        NamedArea area = editor.getAreaToColumnIndexMap().get(columnIndex);
56 58

  
57 59
        //TODO: do not get the distribution objcts, but the label of the status.
58
        Set<DescriptionElementBase> distributionsForArea = rowObject.getDistributionMap().get(area);
60
        Set<DescriptionElementBase> distributionsForArea = editor.taxonDistributionMap.get(rowObject.getTaxonUuid()).get(area);
59 61
        if (distributionsForArea == null){
60 62
            return null;
61 63
        }
......
102 104
    public void setDataValue(TaxonDistributionDTO taxonWrapper, int columnIndex, Object newValue) {
103 105
            if (newValue instanceof PresenceAbsenceTerm){
104 106
                NamedArea area =editor.getAreaToColumnIndexMap().get(columnIndex);
105
                Set<DescriptionElementBase> distributions = taxonWrapper.getDistributionMap().get(area);
107
                Map<NamedArea, Set<DescriptionElementBase>> distributionMap = editor.taxonDistributionMap.get(taxonWrapper.getTaxonUuid());
108
                if (distributionMap == null){
109
                    distributionMap = new HashMap();
110
                    editor.taxonDistributionMap.put(taxonWrapper.getTaxonUuid(),distributionMap);
111
                }
112
                Set<DescriptionElementBase> distributions = distributionMap.get(area);
106 113
                if (distributions != null && !distributions.isEmpty()){
107 114
                    DescriptionElementBase desc = distributions.iterator().next();
108 115
                    if (desc instanceof Distribution){
......
116 123
                }else{
117 124
                    if (distributions == null){
118 125
                        distributions = new HashSet();
126
                        distributionMap.put(area, distributions);
119 127
                    }
120 128
                    Distribution dist = Distribution.NewInstance(area, (PresenceAbsenceTerm)newValue);
121 129
                    Set<TaxonDescription> descs = taxonWrapper.getDescriptionsWrapper().getDescriptions();
......
123 131
                    if (descs.size() >= 1){
124 132
                        desc = descs.iterator().next();
125 133
                    }else {
126
                        desc = TaxonDescription.NewInstance();
134
                        desc = TaxonDescription.NewInstance(taxonWrapper.getTaxon());
135
                        taxonWrapper.getDescriptionsWrapper().getDescriptions().add(desc);
127 136
                    }
128 137
                    desc.addElement(dist);
129 138
                    distributions.add(dist);
139

  
130 140
                }
131 141

  
132 142
            }
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/checklist/e4/DistributionEditor.java
12 12
import java.util.Arrays;
13 13
import java.util.HashMap;
14 14
import java.util.HashSet;
15
import java.util.Iterator;
15 16
import java.util.List;
16 17
import java.util.Map;
17 18
import java.util.Set;
......
71 72
import ca.odell.glazedlists.BasicEventList;
72 73
import ca.odell.glazedlists.EventList;
73 74
import eu.etaxonomy.cdm.api.service.IVocabularyService;
75
import eu.etaxonomy.cdm.api.service.dto.TaxonDescriptionDTO;
74 76
import eu.etaxonomy.cdm.api.service.dto.TaxonDistributionDTO;
75 77
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
76 78
import eu.etaxonomy.cdm.model.common.Language;
......
82 84
import eu.etaxonomy.cdm.model.description.DescriptionBase;
83 85
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
84 86
import eu.etaxonomy.cdm.model.description.Distribution;
87
import eu.etaxonomy.cdm.model.description.TaxonDescription;
85 88
import eu.etaxonomy.cdm.model.location.NamedArea;
86 89
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
87 90
import eu.etaxonomy.cdm.model.reference.Reference;
......
131 134
    private Text searchText;
132 135

  
133 136
    EventList<TaxonDistributionDTO> taxonList;
137
    Map<UUID,Map<NamedArea,Set<DescriptionElementBase>>> taxonDistributionMap = new HashMap();
138

  
139
    Set<TaxonDescription> descriptionsToSave;
140

  
134 141

  
135 142
    SortedSet<DefinedTermBase> areas;
136 143
    DistributionEditorPart part;
......
206 213
    }
207 214

  
208 215

  
216
    public Set<TaxonDescription> getDescriptionsToSave() {
217
        return descriptionsToSave;
218
    }
219

  
220
    public void setDescriptionsToSave(Set<TaxonDescription> descriptionsToSave) {
221
        this.descriptionsToSave = descriptionsToSave;
222
    }
223

  
224

  
209 225

  
210 226
    private void createStatusBar(Composite composite) {
211 227
        GridData gridData = new GridData();
......
471 487
        }
472 488
       taxonList.stream().forEach(wrapper->DistributionEditor.this.taxonList.add(wrapper));
473 489
       statusLabel.setText(ELEMENT_COUNT + (taxonList != null ? taxonList.size() : UNKNOWN));
490
       Iterator<TaxonDistributionDTO> iterator = this.taxonList.iterator();
491
       while (iterator.hasNext()){
492
           TaxonDistributionDTO dto = iterator.next();
493
           TaxonDescriptionDTO descriptionDto = dto.getDescriptionsWrapper();
494
           for (TaxonDescription desc: descriptionDto.getDescriptions()){
495
               for (DescriptionElementBase descElement: desc.getElements()){
496
                   if (descElement instanceof Distribution){
497
                       Map<NamedArea, Set<DescriptionElementBase>> distributionsMap = taxonDistributionMap.get(dto.getTaxonUuid());
498

  
499
                       if (distributionsMap == null){
500
                           distributionsMap = new HashMap();
501
                           taxonDistributionMap.put(dto.getTaxonUuid(), distributionsMap);
502
                       }
503
                       Set<DescriptionElementBase> distributions = distributionsMap.get(((Distribution) descElement).getArea());
504
                       if (distributions == null){
505
                           distributions = new HashSet();
506
                           distributionsMap.put(((Distribution)descElement).getArea(), distributions);
507
                       }
508
                       distributions.add(descElement);
509

  
510
                   }
511
               }
512
           }
513
       }
474 514
    }
475 515

  
476 516

  
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/checklist/e4/DistributionEditorPart.java
37 37
import eu.etaxonomy.cdm.api.service.dto.TaxonDistributionDTO;
38 38
import eu.etaxonomy.cdm.model.description.DescriptionBase;
39 39
import eu.etaxonomy.cdm.model.taxon.Taxon;
40
import eu.etaxonomy.cdm.persistence.dto.MergeResult;
40 41
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
41 42
import eu.etaxonomy.taxeditor.editor.IDistributionEditor;
42 43
import eu.etaxonomy.taxeditor.model.IDirtyMarkable;
......
164 165
     */
165 166
    @Override
166 167
    public ICdmEntitySession getCdmEntitySession() {
167
        // TODO Auto-generated method stub
168
        return null;
168

  
169
        return cdmEntitySession;
169 170
    }
170 171

  
171 172

  
......
215 216
    @Persist
216 217
    @Override
217 218
    public void save(IProgressMonitor monitor) {
218
      CdmStore.getService(IDescriptionService.class).merge(editor.getDistributions(), true);
219

  
219
      List<MergeResult<DescriptionBase>> result =CdmStore.getService(IDescriptionService.class).merge(editor.getDistributions(), true);
220
//      for (MergeResult mergeRes: result){
221
//          mergeRes.getNewEntities()
222
//      }
220 223
      conversation.commit();
224
      //editor.getDescriptionsToSave().clear();
221 225

  
222 226
      dirty.setDirty(false);
223 227
    }
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/checklist/e4/StatusDataCellEditor.java
8 8
*/
9 9
package eu.etaxonomy.taxeditor.editor.view.checklist.e4;
10 10

  
11
import java.util.HashMap;
11 12
import java.util.HashSet;
12 13
import java.util.Iterator;
14
import java.util.Map;
13 15
import java.util.Set;
14 16

  
15 17
import org.eclipse.nebula.widgets.nattable.edit.editor.ComboBoxCellEditor;
......
51 53
            Object rowWrapper = editor.getBodyDataProvider().getRowObject(this.getRowIndex());
52 54
            if(rowWrapper instanceof TaxonDistributionDTO){
53 55
                NamedArea area = editor.getAreaToColumnIndexMap().get(getColumnIndex());
54
                Set<DescriptionElementBase> elements =  ((TaxonDistributionDTO) rowWrapper).getDistributionMap().get(area);
56
                Map<NamedArea, Set<DescriptionElementBase>> distributionMap = editor.taxonDistributionMap.get(((TaxonDistributionDTO) rowWrapper).getTaxonUuid());
57
                if (distributionMap == null){
58
                    distributionMap = new HashMap();
59
                    editor.taxonDistributionMap.put(((TaxonDistributionDTO) rowWrapper).getTaxonUuid(),distributionMap);
60
                }
61
                Set<DescriptionElementBase> elements = distributionMap.get(area);
55 62
                if (elements == null){
56 63

  
57 64
                }else if (elements.size() == 1){
......
78 85
            if (editor.getDefaultSource() != null){
79 86
                newDistribution.addSource(DescriptionElementSource.NewPrimarySourceInstance(editor.getDefaultSource(), null));
80 87
            }
81
            Set<DescriptionElementBase> elements =  ((TaxonDistributionDTO) rowWrapper).getDistributionMap().get(area);
88
            Map<NamedArea, Set<DescriptionElementBase>> distributionMap = editor.taxonDistributionMap.get(((TaxonDistributionDTO) rowWrapper).getTaxonUuid());
89
            if (distributionMap == null){
90
                distributionMap = new HashMap();
91
                editor.taxonDistributionMap.put(((TaxonDistributionDTO) rowWrapper).getTaxonUuid(),distributionMap);
92
            }
93
            Set<DescriptionElementBase> elements = distributionMap.get(area);
82 94
            if (elements == null){
83 95
                elements = new HashSet<DescriptionElementBase>();
96
                distributionMap.put(area, elements);
84 97
            }
85 98
            elements.add(newDistribution);
86
            ((TaxonDistributionDTO) rowWrapper).getDistributionMap().put(area, elements);
99
          //  ((TaxonDistributionDTO) rowWrapper).getDistributionMap().put(area, elements);
87 100
            Set<TaxonDescription> descriptionSet = ((TaxonDistributionDTO) rowWrapper).getDescriptionsWrapper().getDescriptions();
88 101
            Iterator<TaxonDescription> iterator = descriptionSet.iterator();
89 102
            if (iterator.hasNext()){
90 103
                iterator.next().addElement(newDistribution);
91 104
            }else{
92
                Taxon taxon = ((TaxonDistributionDTO) rowWrapper).getDescriptionsWrapper().getTaxon();
105
                Taxon taxon = ((TaxonDistributionDTO) rowWrapper).getTaxon();
93 106
                TaxonDescription desc = TaxonDescription.NewInstance(taxon);
94 107
                desc.addElement(newDistribution);
95 108
                ((TaxonDistributionDTO) rowWrapper).getDescriptionsWrapper().getDescriptions().add(desc);
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/checklist/e4/TaxonDistributionDtoComparator.java
11 11
import java.util.Comparator;
12 12

  
13 13
import eu.etaxonomy.cdm.api.service.dto.TaxonDistributionDTO;
14
import eu.etaxonomy.cdm.model.name.Rank;
15 14

  
16 15
/**
17 16
 * @author k.luther
......
35 34

  
36 35
        String name1 = arg0.getNameCache();
37 36
        String name2 = arg1.getNameCache();
38
        Rank rankTax1 = arg0.getRank();
39
        Rank rankTax2 = arg1.getRank();
37
        Integer rankTax1 = arg0.getRankOrderIndex();
38
        Integer rankTax2 = arg1.getRankOrderIndex();
40 39

  
41 40
        if (rankTax1 == null && rankTax2 != null){
42 41
            return 1;
43 42
        }else if(rankTax2 == null && rankTax1 != null){
44 43
            return -1;
45
        }else if (rankTax1 != null && rankTax1.isHigher(rankTax2)){
46
            return -1;
47 44
        }else if (rankTax1 == null && rankTax2 == null || rankTax1.equals(rankTax2)) {
48 45
            //same rank, order by name
49 46
            return name1.compareTo(name2);
47
         }else if (rankTax1 != null && rankTax1<rankTax2){
48
             return -1;
50 49
         }
51 50

  
52 51
        return 0;
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/wizard/AbstractTermSelectionWizardPage.java
51 51
    protected AbstractTermSelectionWizardPage(String pageName, TermType type) {
52 52
        super(pageName);
53 53
        // TODO check if configuration exists
54
        CdmStore.getCurrentSessionManager().bindNullSession();
54
       // CdmStore.getCurrentSessionManager().bindNullSession();
55 55
        this.type = type;
56 56
    }
57 57

  
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/wizard/AvailableDistributionPage.java
10 10

  
11 11
import java.util.ArrayList;
12 12
import java.util.Arrays;
13
import java.util.Collection;
14 13
import java.util.HashMap;
15 14
import java.util.HashSet;
16 15
import java.util.List;
......
22 21
import org.eclipse.swt.widgets.Composite;
23 22

  
24 23
import eu.etaxonomy.cdm.api.service.IVocabularyService;
25
import eu.etaxonomy.cdm.model.common.CdmBase;
26 24
import eu.etaxonomy.cdm.model.common.TermType;
27 25
import eu.etaxonomy.cdm.model.common.TermVocabulary;
28 26
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
29 27
import eu.etaxonomy.cdm.persistence.dto.TermVocabularyDto;
30 28
import eu.etaxonomy.taxeditor.l10n.Messages;
31 29
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
32
import eu.etaxonomy.taxeditor.session.ICdmEntitySession;
33
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
34 30
import eu.etaxonomy.taxeditor.store.CdmStore;
35 31

  
36 32
/**
......
38 34
 * @date 21.07.2014
39 35
 *
40 36
 */
41
public class AvailableDistributionPage extends AbstractTermSelectionWizardPage implements ICdmEntitySessionEnabled {
37
public class AvailableDistributionPage extends AbstractTermSelectionWizardPage {
42 38

  
43 39
    protected AvailableDistributionPage(String pageName) {
44 40
        super(pageName, TermType.NamedArea);
......
63 59

  
64 60
    @Override
65 61
    public void dispose() {
66
        CdmStore.getCurrentSessionManager().dispose(this);
62
       // CdmStore.getCurrentSessionManager().dispose(this);
67 63
        super.dispose();
68 64
    }
69 65

  
70
    @Override
71
    public ICdmEntitySession getCdmEntitySession() {
72
        return CdmStore.getCurrentSessionManager().getNullSession();
73
    }
74

  
75
    @Override
76
    public <T extends CdmBase> Collection<T> getRootEntities() {
77
        return null;
78
    }
79

  
80
    @Override
66
//    @Override
67
//    public ICdmEntitySession getCdmEntitySession() {
68
//        return CdmStore.getCurrentSessionManager().getNullSession();
69
//    }
70
//
71
//    @Override
72
//    public <T extends CdmBase> Collection<T> getRootEntities() {
73
//        return null;
74
//    }
75
//
76
//    @Override
81 77
    public Map<Object, List<String>> getPropertyPathsMap() {
82 78
        Map<Object, List<String>> propertyPathsMap = new HashMap<Object, List<String>>();
83 79
        List<String> termsPropertyPaths = Arrays.asList(new String[] {
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/wizard/AvailableDistributionWizard.java
16 16
import org.apache.commons.lang.StringUtils;
17 17
import org.eclipse.jface.wizard.Wizard;
18 18

  
19
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
20
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
21 19
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
22 20
import eu.etaxonomy.cdm.persistence.dto.TermDto;
23 21
import eu.etaxonomy.cdm.persistence.dto.TermVocabularyDto;
24
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
25 22
import eu.etaxonomy.taxeditor.l10n.Messages;
26 23
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
27
import eu.etaxonomy.taxeditor.store.CdmStore;
28 24

  
29 25
/**
30 26
 * @author alex
31 27
 * @date 21.07.2014
32 28
 *
33 29
 */
34
public class AvailableDistributionWizard extends Wizard implements IConversationEnabled {
30
public class AvailableDistributionWizard extends Wizard {
35 31

  
36
    private ConversationHolder conversation;
32
   // private ConversationHolder conversation;
37 33
    private final AvailableDistributionPage aPage;
38 34

  
39 35
    public AvailableDistributionWizard() {
......
99 95
            return false;
100 96
        }
101 97
    }
102

  
103
    @Override
104
    public ConversationHolder getConversationHolder() {
105
        if (conversation == null) {
106
            conversation = CdmStore.createConversation();
107
        }
108
        return conversation;
109
    }
110

  
111
    @Override
112
    public void update(CdmDataChangeMap changeEvents) {
113
    }
98
//
99
//    @Override
100
//    public ConversationHolder getConversationHolder() {
101
//        if (conversation == null) {
102
//            conversation = CdmStore.createConversation();
103
//        }
104
//        return conversation;
105
//    }
106
//
107
//    @Override
108
//    public void update(CdmDataChangeMap changeEvents) {
109
//    }
114 110
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/e4/details/DetailsPartE4.java
67 67
        }
68 68

  
69 69
        Object partObject = createPartObject(activePart);
70
        if (partObject instanceof SupplementalDataPartE4) {
70
        if (partObject instanceof SupplementalDataPartE4 ) {
71 71
            // do not show empty page
72 72
            return;
73 73
        }
......
75 75
        if(partObject instanceof IPartContentHasDetails){
76 76
            IStructuredSelection structuredSelection = createSelection(selection);
77 77
            if(structuredSelection==null || structuredSelection.isEmpty()){
78
               // showEmptyPage();
78
                showEmptyPage();
79 79
                return;
80 80
            }
81 81
            if(!(partObject instanceof ISelectionElementEditingPart) &&

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)