Project

General

Profile

« Previous | Next » 

Revision 103f7f4a

Added by Patrick Plitzner over 5 years ago

ref #7887 Use term DTOs for distribution wizards

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/wizard/AbstractTermSelectionWizardPage.java
14 14
import java.util.UUID;
15 15

  
16 16
import org.apache.commons.lang.StringUtils;
17
import org.eclipse.jface.viewers.ColumnViewer;
17
import org.eclipse.jface.layout.GridLayoutFactory;
18
import org.eclipse.jface.viewers.CheckboxTreeViewer;
18 19
import org.eclipse.jface.wizard.WizardPage;
20
import org.eclipse.swt.SWT;
21
import org.eclipse.swt.layout.GridLayout;
19 22
import org.eclipse.swt.widgets.Composite;
20 23

  
21 24
import eu.etaxonomy.cdm.api.service.ITermService;
22 25
import eu.etaxonomy.cdm.api.service.IVocabularyService;
23 26
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
24
import eu.etaxonomy.cdm.model.common.TermBase;
25 27
import eu.etaxonomy.cdm.model.common.TermType;
26 28
import eu.etaxonomy.cdm.model.common.TermVocabulary;
29
import eu.etaxonomy.cdm.persistence.dto.AbstractTermDto;
30
import eu.etaxonomy.cdm.persistence.dto.TermDto;
31
import eu.etaxonomy.cdm.persistence.dto.TermVocabularyDto;
32
import eu.etaxonomy.taxeditor.editor.definedterm.DefinedTermSorter;
33
import eu.etaxonomy.taxeditor.editor.definedterm.TermDtoContentProvider;
34
import eu.etaxonomy.taxeditor.editor.definedterm.TermDtoLabelProvider;
27 35
import eu.etaxonomy.taxeditor.store.CdmStore;
28 36

  
29 37
/**
......
33 41
 */
34 42
public abstract class AbstractTermSelectionWizardPage extends WizardPage {
35 43

  
36
    private ColumnViewer viewer;
37
    private List<TermVocabulary<DefinedTermBase>> vocabularies = new ArrayList<>();
44
    protected CheckBoxTreeComposite treeComposite;
45
    private List<TermVocabularyDto> vocabularies = new ArrayList<>();
38 46
    boolean localPref;
39
    List<TermBase> listCheckedTerms = new ArrayList<>();
40
    List<TermBase> listGrayedTerms = new ArrayList<>();
47
    List<AbstractTermDto> listCheckedTerms = new ArrayList<>();
48
    List<AbstractTermDto> listGrayedTerms = new ArrayList<>();
41 49

  
42 50
    TermType type;
43 51

  
......
55 63
     * {@inheritDoc}
56 64
     */
57 65
    @Override
58
    public abstract void createControl(Composite parent) ;
66
    public void createControl(Composite parent){
67
        parent.setLayout(new GridLayout());
68
        treeComposite = new CheckBoxTreeComposite(parent, new TermDtoContentProvider(), new TermDtoLabelProvider(), SWT.NONE);
69
        treeComposite.getViewer().setComparator(new DefinedTermSorter());
70
        GridLayoutFactory.fillDefaults().applyTo(treeComposite);
59 71

  
60
    public ColumnViewer getViewer() {
61
        return viewer;
72

  
73
        rememberCheckedValues(getCheckedValuesFromPreferences(), getGrayedValuesFromPreferences());
74
        treeComposite.setCheckedElements(listCheckedTerms.toArray());
75
        setControl(treeComposite);
62 76
    }
63 77

  
64
    public void setViewer(ColumnViewer viewer) {
65
        this.viewer = viewer;
78
    protected abstract String getCheckedValuesFromPreferences();
79

  
80
    protected abstract String getGrayedValuesFromPreferences();
81

  
82
    protected CheckboxTreeViewer getViewer(){
83
        return treeComposite.getViewer();
66 84
    }
67 85

  
68
    public List<TermVocabulary<DefinedTermBase>> getVocabularies() {
86
    public List<TermVocabularyDto> getVocabularies() {
69 87
        return vocabularies;
70 88
    }
71 89

  
72
    public void addVocabularies(TermVocabulary<DefinedTermBase> vocabulary) {
90
    public void addVocabularies(TermVocabularyDto vocabulary) {
73 91
        this.vocabularies.add(vocabulary);
74 92
    }
75 93

  
......
77 95
    /**
78 96
     * @param vocs
79 97
     */
80
    protected void setVocabularies(List<TermVocabulary<DefinedTermBase>> vocs) {
81
        for (TermVocabulary voc:vocs){
82
            vocabularies.add(voc);
83
        }
98
    protected void setVocabularies(List<TermVocabularyDto> vocs) {
99
        vocabularies = vocs;
84 100
    }
85 101

  
86
    public List<TermBase> getListCheckedTerms() {
102
    public List<AbstractTermDto> getListCheckedTerms() {
87 103
        return listCheckedTerms;
88 104
    }
89 105

  
90
    public List<TermBase> getListGrayedTerms() {
106
    public List<AbstractTermDto> getListGrayedTerms() {
91 107
        return listGrayedTerms;
92 108
    }
93 109

  
94 110
    protected void rememberCheckedValues(String checkedValues, String grayedValues) {
95 111
        initialiseVocabularies();
96
        getViewer().setInput(getVocabularies());
112
        treeComposite.getViewer().setInput(getVocabularies());
97 113

  
98 114
        if (grayedValues != null && grayedValues != "") { //$NON-NLS-1$
99 115
            String[] arrayGrayed = grayedValues.split(";"); //$NON-NLS-1$
100 116
            List<String> listGrayed = Arrays.asList(arrayGrayed);
101
            if (listGrayedTerms == null){
102
                listGrayedTerms = new ArrayList();
103
            }
104
            getTermsFromStringValues(listGrayed, this.listGrayedTerms);
117
            listGrayedTerms = getTermsFromStringValues(listGrayed);
105 118

  
106 119
        }
107 120
        if (checkedValues != null && checkedValues != "") { //$NON-NLS-1$
......
114 127
            if (listCheckedComma != null && checkedValues.contains(",")){ //$NON-NLS-1$
115 128
                checked = Arrays.asList(listCheckedComma);
116 129
            }
117
            if (listCheckedTerms == null){
118
                listCheckedTerms = new ArrayList();
119
            }
120
            getTermsFromStringValues(checked, listCheckedTerms);
130
            listCheckedTerms = getTermsFromStringValues(checked);
121 131

  
122 132
        }
123 133
    }
......
126 136
     * @param split
127 137
     * @param termlist
128 138
     */
129
    private void getTermsFromStringValues(List<String> listValue, List<TermBase> termlist) {
130

  
139
    private List<AbstractTermDto> getTermsFromStringValues(List<String> listValue) {
140
        List<AbstractTermDto> termlist = new ArrayList<>();
131 141
        for (String s : listValue) {
132 142
            if (!StringUtils.isBlank(s)){
133 143
                UUID uuid = UUID.fromString(s);
134 144
                ITermService termService = CdmStore.getService(ITermService.class);
135 145
                DefinedTermBase definedTermBase = termService.load(uuid);
136 146
                if(definedTermBase != null){
137
                    termlist.add(definedTermBase);
147
                    termlist.add(new TermDto(uuid, definedTermBase.getRepresentations(), null));
138 148
                }else{
139 149
                    IVocabularyService vocabularyService = CdmStore.getService(IVocabularyService.class);
140 150
                    TermVocabulary termVocabulary = vocabularyService.load(uuid);
141
                    termlist.add(termVocabulary);
151
                    termlist.add(new TermVocabularyDto(uuid, termVocabulary.getRepresentations()));
142 152
                }
143 153
            }
144 154
        }
155
        return termlist;
145 156
    }
146 157

  
147 158

  
......
149 160
        if (getVocabularies() != null) {
150 161
            getVocabularies().clear();
151 162
        }
152
        List<TermVocabulary<DefinedTermBase>> vocs = new ArrayList<>();
163
        List<TermVocabularyDto> vocs = new ArrayList<>();
153 164
        if (localPref){
154 165
            vocs = getVocabulariesFromPreference();
155 166

  
156 167
        }else{
157
            vocs = CdmStore.getService(IVocabularyService.class).findByTermType(
158
                    type, null);
168
            vocs = CdmStore.getService(IVocabularyService.class).findVocabularyDtoByTermType(type);
159 169
        }
160 170
        setVocabularies(vocs);
161 171
    }
162 172

  
163
    protected abstract List<TermVocabulary<DefinedTermBase>> getVocabulariesFromPreference();
173
    protected abstract List<TermVocabularyDto> getVocabulariesFromPreference();
164 174

  
165 175

  
166 176
}

Also available in: Unified diff