Project

General

Profile

Revision eb82a77d

IDeb82a77d14669f3310762fff3570f4894b51c06b
Parent 5642c43a
Child b5610bde

Added by Katja Luther about 2 years ago

ref #7063: add base element to named area tree in selection wizard to provide the posibility to check this and/or the elements of it

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/TermLabelProvider.java
104 104
        return label;
105 105
    }
106 106

  
107
    private Styler getVocabularyStyler() {
107
    protected Styler getVocabularyStyler() {
108 108
        if (vocStyler == null) {
109 109
            vocStyler = new Styler() {
110 110
                @Override
......
116 116
        return vocStyler;
117 117
    }
118 118

  
119
    private Styler getKindOfStyler() {
119
    protected Styler getKindOfStyler() {
120 120
        if (kindOfStyler == null) {
121 121
            kindOfStyler = new Styler() {
122 122
                @Override
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/wizard/AbstractAreaSelectionWizard.java
16 16
import java.util.UUID;
17 17

  
18 18
import org.apache.commons.lang.StringUtils;
19
import org.eclipse.jface.viewers.CheckboxTableViewer;
20
import org.eclipse.jface.viewers.CheckboxTreeViewer;
21 19
import org.eclipse.jface.viewers.ColumnViewer;
22 20
import org.eclipse.jface.wizard.WizardPage;
23 21
import org.eclipse.swt.widgets.Composite;
......
25 23
import eu.etaxonomy.cdm.api.service.ITermService;
26 24
import eu.etaxonomy.cdm.api.service.IVocabularyService;
27 25
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
26
import eu.etaxonomy.cdm.model.common.TermBase;
28 27
import eu.etaxonomy.cdm.model.common.TermType;
29 28
import eu.etaxonomy.cdm.model.common.TermVocabulary;
30 29
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
......
40 39
    private ColumnViewer viewer;
41 40
    private List<TermVocabulary<DefinedTermBase>> vocabularies = new ArrayList<>();
42 41
    boolean localPref;
43

  
42
    List<TermBase> listCheckedTerms;
43
    List<TermBase> listGrayedTerms;
44 44

  
45 45
    /**
46 46
     * @param pageName
......
81 81
        for (TermVocabulary voc:vocs){
82 82
            vocabularies.add(voc);
83 83
        }
84
    }
84 85

  
86
    public List<TermBase> getListCheckedTerms() {
87
        return listCheckedTerms;
88
    }
85 89

  
90
    public List<TermBase> getListGrayedTerms() {
91
        return listGrayedTerms;
86 92
    }
87 93

  
88 94
    protected void rememberCheckedValues(String checkedValues, String grayedValues) {
......
92 98
        if (grayedValues != null && grayedValues != "") {
93 99
            String[] arrayGrayed = grayedValues.split(";");
94 100
            List<String> listGrayed = Arrays.asList(arrayGrayed);
95
            ArrayList listGrayedTerms = new ArrayList();
96
            getTermsFromStringValues(listGrayed, listGrayedTerms);
97
            for(Object element : listGrayedTerms){
98
                if(element != null){
99
                    if (getViewer() instanceof CheckboxTreeViewer) {
100
                        ((CheckboxTreeViewer)getViewer()).setGrayChecked(element, true);
101
                    }
102
                }
101
            if (listGrayedTerms == null){
102
                listGrayedTerms = new ArrayList();
103 103
            }
104
            getTermsFromStringValues(listGrayed, this.listGrayedTerms);
105
            NamedAreaWrapper wrapper;
106
//            for(TermBase element : listGrayedTerms){
107
//                if(element != null){
108
//                    if (element instanceof DefinedTermBase){
109
//                        wrapper = new NamedAreaWrapper((DefinedTermBase)element, true, null);
110
//                        if (getViewer() instanceof CheckboxTreeViewer) {
111
//                            ((CheckboxTreeViewer)getViewer()).setGrayChecked(wrapper, true);
112
//                        }
113
//                    }else{
114
//                        if (getViewer() instanceof CheckboxTreeViewer) {
115
//                            ((CheckboxTreeViewer)getViewer()).setGrayChecked(element, true);
116
//                        }
117
//                    }
118
//                }
119
//
120
//            }
104 121
        }
105 122
        if (checkedValues != null && checkedValues != "") {
106 123
            String[] listChecked = checkedValues.split(";");
......
112 129
            if (listCheckedComma != null && checkedValues.contains(",")){
113 130
                checked = Arrays.asList(listCheckedComma);
114 131
            }
115
            ArrayList<DefinedTermBase<?>> listCheckedTerms = new ArrayList<DefinedTermBase<?>>();
116
            getTermsFromStringValues(checked, listCheckedTerms);
117
            for(Object element : listCheckedTerms){
118
                if(element != null){
119
                    if (getViewer() instanceof CheckboxTreeViewer) {
120
                        ((CheckboxTreeViewer)getViewer()).setChecked(element, true);
121
                    }else if (getViewer() instanceof CheckboxTableViewer){
122
                        ((CheckboxTableViewer)getViewer()).setChecked(element, true);
123
                    }
124
                }
132
            if (listCheckedTerms == null){
133
                listCheckedTerms = new ArrayList();
125 134
            }
135
            getTermsFromStringValues(checked, listCheckedTerms);
136

  
137
//            Object[] elements = ((CheckboxTreeViewer)getViewer()).getExpandedElements();
138
//            for (Object element: elements){
139
//                if (element instanceof NamedAreaWrapper){
140
//                    if (listCheckedTerms.contains(((NamedAreaWrapper)element).getNamedArea())){
141
//                        ((CheckboxTreeViewer)getViewer()).setChecked(element, true);
142
//                    }
143
//                    if (listGrayedTerms.contains(((NamedAreaWrapper)element).getNamedArea())){
144
//                        ((CheckboxTreeViewer)getViewer()).setGrayChecked(element, true);
145
//                    }
146
//                }
147
//            }
148
            NamedAreaWrapper wrapper;
149
//            for(Object element : listCheckedTerms){
150
//                if(element != null){
151
//                    if (element instanceof DefinedTermBase){
152
//                        wrapper = new NamedAreaWrapper((DefinedTermBase)element, true, null);
153
//                        if (getViewer() instanceof CheckboxTreeViewer) {
154
//                            ((CheckboxTreeViewer)getViewer()).setChecked(wrapper, true);
155
//                        }
156
//                    }else{
157
//                        if (getViewer() instanceof CheckboxTreeViewer) {
158
//                            ((CheckboxTreeViewer)getViewer()).setChecked(element, true);
159
//                        }
160
//                    }
161
//                }
162
//            }
126 163
        }
127 164
    }
128 165

  
......
130 167
     * @param split
131 168
     * @param termlist
132 169
     */
133
    private void getTermsFromStringValues(List<String> listValue, ArrayList termlist) {
170
    private void getTermsFromStringValues(List<String> listValue, List<TermBase> termlist) {
134 171

  
135 172
        for (String s : listValue) {
136 173
            if (!StringUtils.isBlank(s)){
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/wizard/AreaLabelProvider.java
1
/**
2
* Copyright (C) 2018 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.taxeditor.preference.wizard;
10

  
11
import org.eclipse.jface.viewers.ILabelProvider;
12
import org.eclipse.jface.viewers.StyledString;
13
import org.eclipse.jface.viewers.StyledString.Styler;
14
import org.eclipse.jface.viewers.ViewerCell;
15
import org.eclipse.swt.custom.StyleRange;
16
import org.eclipse.swt.graphics.Image;
17

  
18
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
19
import eu.etaxonomy.cdm.model.common.TermVocabulary;
20
import eu.etaxonomy.taxeditor.editor.definedterm.TermLabelProvider;
21

  
22
/**
23
 * @author k.luther
24
 * @since 04.10.2018
25
 *
26
 */
27
public class AreaLabelProvider extends TermLabelProvider implements ILabelProvider{
28

  
29
    public AreaLabelProvider(Styler vocStyler){
30
        super(vocStyler);
31
    }
32

  
33

  
34
    @Override
35
    public void update(ViewerCell cell) {
36
        Object element = cell.getElement();
37

  
38
        String text = getText(element);
39
        cell.setText(text);
40

  
41
        Styler styler = null;
42
        if (element instanceof TermVocabulary && text != null) {
43
            styler = getVocabularyStyler();
44
        }
45
        else if(element instanceof NamedAreaWrapper && ((NamedAreaWrapper) element).getNamedArea().getKindOf()!=null){
46
            styler = getKindOfStyler();
47
        }
48
        if(styler!=null){
49
            StyledString styledString = new StyledString(text, styler);
50
            StyleRange[] styleRanges;
51
            styleRanges = styledString.getStyleRanges();
52
            cell.setStyleRanges(styleRanges);
53
        }
54
        super.update(cell);
55
    }
56

  
57
    @Override
58
    public String getText(Object element) {
59
        String label = null;
60
        if(element instanceof NamedAreaWrapper){
61
            NamedAreaWrapper wrapper = (NamedAreaWrapper)element;
62
            DefinedTermBase termBase = wrapper.getNamedArea();
63
            label = super.getText(termBase);
64
            if (wrapper.isBaseElement){
65
                label = "Base - " + label;
66
            }
67
            return label;
68

  
69
        }
70
        return super.getText(element);
71
    }
72

  
73

  
74
    /**
75
     * {@inheritDoc}
76
     */
77
    @Override
78
    public Image getImage(Object element) {
79
        // TODO Auto-generated method stub
80
        return null;
81
    }
82

  
83

  
84

  
85

  
86
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/wizard/AreaViewerComparator.java
1
/**
2
* Copyright (C) 2018 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.taxeditor.preference.wizard;
10

  
11
import org.eclipse.jface.viewers.Viewer;
12
import org.eclipse.jface.viewers.ViewerComparator;
13

  
14
/**
15
 * @author k.luther
16
 * @since 04.10.2018
17
 *
18
 */
19
public class AreaViewerComparator extends ViewerComparator {
20

  
21
    /**
22
     * Returns a negative, zero, or positive number depending on whether
23
     * the first element is less than, equal to, or greater than
24
     * the second element.
25
     * <p>
26
     * The default implementation of this method is based on
27
     * comparing the elements' categories as computed by the <code>category</code>
28
     * framework method. Elements within the same category are further
29
     * subjected to a case insensitive compare of their label strings, either
30
     * as computed by the content viewer's label provider, or their
31
     * <code>toString</code> values in other cases. Subclasses may override.
32
     * </p>
33
     *
34
     * @param viewer the viewer
35
     * @param e1 the first element
36
     * @param e2 the second element
37
     * @return a negative number if the first element is less  than the
38
     *  second element; the value <code>0</code> if the first element is
39
     *  equal to the second element; and a positive number if the first
40
     *  element is greater than the second element
41
     */
42
    @Override
43
    public int compare(Viewer viewer, Object e1, Object e2) {
44
        int cat1 = category(e1);
45
        int cat2 = category(e2);
46

  
47
        if (cat1 != cat2) {
48
            return cat1 - cat2;
49
        }
50

  
51
        if (e1 instanceof NamedAreaWrapper && e2 instanceof NamedAreaWrapper){
52
            NamedAreaWrapper wrapper1 = (NamedAreaWrapper)e1;
53
            NamedAreaWrapper wrapper2 = (NamedAreaWrapper)e2;
54

  
55
            if (wrapper1.isBaseElement == wrapper2.isBaseElement){
56
               return super.compare(viewer, e1, e2);
57
            }else if (wrapper1.isBaseElement){
58
                return -1;
59
            }else{
60
                return 1;
61
            }
62
        }else{
63
            return super.compare(viewer, e1, e2);
64
        }
65

  
66
    }
67

  
68

  
69
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/wizard/AvailableDistributionPage.java
18 18
import org.eclipse.jface.viewers.CheckStateChangedEvent;
19 19
import org.eclipse.jface.viewers.CheckboxTreeViewer;
20 20
import org.eclipse.jface.viewers.ICheckStateListener;
21
import org.eclipse.jface.viewers.ITreeViewerListener;
21 22
import org.eclipse.jface.viewers.StyledString.Styler;
22
import org.eclipse.jface.viewers.TreePath;
23
import org.eclipse.jface.viewers.ViewerComparator;
23
import org.eclipse.jface.viewers.TreeExpansionEvent;
24 24
import org.eclipse.swt.SWT;
25 25
import org.eclipse.swt.graphics.TextStyle;
26 26
import org.eclipse.swt.layout.GridData;
......
29 29
import org.eclipse.swt.widgets.Display;
30 30

  
31 31
import eu.etaxonomy.cdm.model.common.CdmBase;
32
import eu.etaxonomy.taxeditor.editor.definedterm.TermContentProvider;
33
import eu.etaxonomy.taxeditor.editor.definedterm.TermLabelProvider;
34 32
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
35 33
import eu.etaxonomy.taxeditor.session.ICdmEntitySession;
36 34
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
......
73 71
        composite.setLayout(new GridLayout());
74 72
        setViewer(new CheckboxTreeViewer(composite, SWT.NULL));
75 73
        ((CheckboxTreeViewer)getViewer()).getTree().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
76
        getViewer().setContentProvider(new TermContentProvider());
74
        getViewer().setContentProvider(new DistributionContentProvider());
77 75
        Styler styler = new Styler() {
78 76
            @Override
79 77
            public void applyStyles(TextStyle textStyle) {
80 78
                textStyle.foreground = Display.getCurrent().getSystemColor(SWT.COLOR_BLACK);
81 79
            }
82 80
        };
83
        getViewer().setLabelProvider(new TermLabelProvider(styler));
84
        getViewer().setComparator(new ViewerComparator());
81
        getViewer().setLabelProvider(new AreaLabelProvider(styler));
82
        getViewer().setComparator(new AreaViewerComparator());
85 83
        ((CheckboxTreeViewer)getViewer()).addCheckStateListener(new ICheckStateListener() {
86 84

  
87 85
            private boolean ignoreCheckEvent = false;
88 86

  
89 87
            @Override
90 88
            public void checkStateChanged(CheckStateChangedEvent event) {
91

  
92

  
93 89
                if (ignoreCheckEvent ) {
94 90
                    return;
95 91
                }
96

  
97 92
                ignoreCheckEvent = true;
98

  
99 93
                try {
100

  
101 94
                    checkChildren(event.getElement(), event.getChecked());
102 95
                    grayParents(event.getElement(), event.getChecked());
103
                    ((CheckboxTreeViewer)getViewer()).refresh();
96
                   // ((CheckboxTreeViewer)getViewer()).refresh();
104 97
                }
105 98
                finally {
106 99
                    ignoreCheckEvent = false;
......
108 101
                checkNoneChecked();
109 102
            }
110 103
        });
104
        ((CheckboxTreeViewer)getViewer()).addTreeListener(new ITreeViewerListener() {
105
            @Override
106
            public void treeCollapsed(TreeExpansionEvent event) {
107
            }
108

  
109
            @Override
110
            public void treeExpanded(TreeExpansionEvent event) {
111
                final Object element = event.getElement();
112
                final Object[] children = ((DistributionContentProvider)getViewer().getContentProvider()).getChildren(element);
113
                for (Object child : children) {
114
                    if (child instanceof NamedAreaWrapper){
115
                        if (getListCheckedTerms().contains(((NamedAreaWrapper) child).getNamedArea()) ){
116
                            ((CheckboxTreeViewer)getViewer()).setChecked(child, true);
117
                        }
118
                        if (getListGrayedTerms().contains(((NamedAreaWrapper) child).getNamedArea())&& !((NamedAreaWrapper) child).isBaseElement){
119
                            ((CheckboxTreeViewer)getViewer()).setGrayChecked(child, true);
120
                        }
121
                    }
122

  
123
                }
124
            }
125
        });
126

  
111 127
        // TODO: write listener or toggle button to select all named areas
112 128

  
113 129
        rememberCheckedValues(checkedValues, grayedValues);
130
        ((CheckboxTreeViewer)getViewer()).expandToLevel(2);
114 131
        setControl(composite);
115 132
    }
116 133

  
......
131 148
    }
132 149

  
133 150

  
134
    /**
135
     *
136
     * @param path
137
     */
138
    private void checkParents(final TreePath path) {
139
        if (path == null) {
140
            return;
141
        }
142
        TermContentProvider tcp = new TermContentProvider();
143
        Object treeElement = path.getLastSegment();
144

  
145
        if (treeElement != null) {
146
            boolean allChecked = true;
147
            boolean allUnchecked = true;
148
            for (final Object fieldElement : tcp.getChildren(treeElement)) {
149
                allChecked = allChecked && ((CheckboxTreeViewer)getViewer()).getChecked(fieldElement);
150
                allUnchecked = allUnchecked && !((CheckboxTreeViewer)getViewer()).getChecked(fieldElement);
151
            }
152
            if (allUnchecked) {
153
                ((CheckboxTreeViewer)getViewer()).setChecked(treeElement, false);
154
                ((CheckboxTreeViewer)getViewer()).setGrayed(treeElement, false);
155
            } else if (allChecked) {
156
                ((CheckboxTreeViewer)getViewer()).setChecked(treeElement, true);
157
                ((CheckboxTreeViewer)getViewer()).setGrayed(treeElement, false);
158
            } else if (!allUnchecked && !allChecked) {
159
                ((CheckboxTreeViewer)getViewer()).setChecked(treeElement, true);
160
                ((CheckboxTreeViewer)getViewer()).setGrayed(treeElement, true);
161
            }
162
        }
163
        checkParents(path.getParentPath());
164
    }
151
//    /**
152
//     *
153
//     * @param path
154
//     */
155
//    private void checkParents(final TreePath path) {
156
//        if (path == null) {
157
//            return;
158
//        }
159
//        TermContentProvider tcp = new TermContentProvider();
160
//        Object treeElement = path.getLastSegment();
161
//
162
//        if (treeElement != null) {
163
//            boolean allChecked = true;
164
//            boolean allUnchecked = true;
165
//            for (final Object fieldElement : tcp.getChildren(treeElement)) {
166
//                allChecked = allChecked && ((CheckboxTreeViewer)getViewer()).getChecked(fieldElement);
167
//                allUnchecked = allUnchecked && !((CheckboxTreeViewer)getViewer()).getChecked(fieldElement);
168
//            }
169
//            if (allUnchecked) {
170
//                ((CheckboxTreeViewer)getViewer()).setChecked(treeElement, false);
171
//                ((CheckboxTreeViewer)getViewer()).setGrayed(treeElement, false);
172
//            } else if (allChecked) {
173
//                ((CheckboxTreeViewer)getViewer()).setChecked(treeElement, true);
174
//                ((CheckboxTreeViewer)getViewer()).setGrayed(treeElement, false);
175
//            } else if (!allUnchecked && !allChecked) {
176
//                ((CheckboxTreeViewer)getViewer()).setChecked(treeElement, true);
177
//                ((CheckboxTreeViewer)getViewer()).setGrayed(treeElement, true);
178
//            }
179
//        }
180
//        checkParents(path.getParentPath());
181
//    }
165 182

  
166 183

  
167 184
    /**
......
170 187
    * @param checked
171 188
    */
172 189
   private void checkChildren(final Object element, final boolean checked) {
173
       TermContentProvider tcp = new TermContentProvider();
174

  
175 190
       if (element == null) {
176 191
           return;
177 192
       }
178 193

  
179
       ((CheckboxTreeViewer)getViewer()).setChecked(element, checked);
180
       ((CheckboxTreeViewer)getViewer()).setGrayed(element, false);
181 194
       if (((CheckboxTreeViewer)getViewer()).isExpandable(element)){
182 195
           ((CheckboxTreeViewer)getViewer()).expandToLevel(element, CheckboxTreeViewer.ALL_LEVELS);
183 196
           ((CheckboxTreeViewer)getViewer()).setSubtreeChecked(element, checked);
197

  
198
           ((CheckboxTreeViewer)getViewer()).setChecked(element, checked);
199
           if (((CheckboxTreeViewer)getViewer()).getGrayed(element)){
200
               ((CheckboxTreeViewer)getViewer()).setGrayChecked(element, !checked);
201
           }
202
//           if (element instanceof NamedAreaWrapper){
203
//               NamedAreaWrapper baseElement = new NamedAreaWrapper(((NamedAreaWrapper)element).getNamedArea(), true, ((NamedAreaWrapper)element).parent);
204
//               ((CheckboxTreeViewer)getViewer()).setChecked(baseElement, !checked);
205
//               ((CheckboxTreeViewer)getViewer()).setGrayed(element, checked);
206
//           }
207

  
208
       }else{
209
           ((CheckboxTreeViewer)getViewer()).setChecked(element, checked);
210
           ((CheckboxTreeViewer)getViewer()).setGrayed(element, false);
184 211
       }
185 212

  
186 213
   }
......
190 217
   * @param checked
191 218
   */
192 219
  private void grayParents(final Object element, boolean checked) {
193
      TermContentProvider tcp = new TermContentProvider();
220
      DistributionContentProvider tcp = new DistributionContentProvider();
194 221

  
195 222
      if (element == null) {
196 223
          return;
......
200 227
      if (parent != null) {
201 228

  
202 229
          boolean allUnchecked = true;
230
          boolean allChecked = true;
203 231
          //if element is checked then the parent should be grayed if it is unchecked it have to be computed whether the parent should be checked
204
          if (checked){
205
              if (!((CheckboxTreeViewer)getViewer()).getChecked(parent)){
206
                  ((CheckboxTreeViewer)getViewer()).setGrayChecked(parent, true);
207
              }
208

  
209
          }else{
232
//          if (checked){
233
//              if (!((CheckboxTreeViewer)getViewer()).getChecked(parent)){
234
//                  ((CheckboxTreeViewer)getViewer()).setGrayChecked(parent, true);
235
//              }
236
//
237
//          }else{
210 238
              for (final Object fieldElement : tcp.getChildren(parent)) {
239
                  allChecked = allChecked && ((CheckboxTreeViewer)getViewer()).getChecked(fieldElement);
211 240
                  allUnchecked = allUnchecked && !((CheckboxTreeViewer)getViewer()).getChecked(fieldElement);
212 241
                  allUnchecked = allUnchecked && !((CheckboxTreeViewer)getViewer()).getGrayed(fieldElement);
213 242
              }
214 243
              if (allUnchecked) {
215
                  ((CheckboxTreeViewer)getViewer()).setChecked(parent, false);
244
//                  if (!((CheckboxTreeViewer)getViewer()).getChecked(parent)){
245
                      ((CheckboxTreeViewer)getViewer()).setChecked(parent, false);
246
                      ((CheckboxTreeViewer)getViewer()).setGrayed(parent, false);
247
//                  }else{
248
//                      checked = true;
249
//                  }
250
              } else if (allChecked){
251
                  ((CheckboxTreeViewer)getViewer()).setChecked(parent, true);
216 252
                  ((CheckboxTreeViewer)getViewer()).setGrayed(parent, false);
217
              } else {
218
                if (!((CheckboxTreeViewer)getViewer()).getChecked(parent)){
253
              }else {
254
//                if (!((CheckboxTreeViewer)getViewer()).getChecked(parent)){
219 255
                    ((CheckboxTreeViewer)getViewer()).setGrayChecked(parent, true);
220
                }
256
                    ((CheckboxTreeViewer)getViewer()).setChecked(parent, true);
257
//                }
221 258
                checked = true;
222 259

  
223 260
              }
224
          }
261
//          }
225 262
        grayParents(parent, checked);
226 263
      }
227 264
  }
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/wizard/AvailableDistributionWizard.java
20 20

  
21 21
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
22 22
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
23
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
24 23
import eu.etaxonomy.cdm.model.common.OrderedTermVocabulary;
25 24
import eu.etaxonomy.cdm.model.location.NamedArea;
26 25
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
......
60 59
            ArrayList<UUID> listUIIDChecked = new ArrayList<UUID>();
61 60
            ArrayList<UUID> listUIIDGrayed = new ArrayList<UUID>();
62 61
            for (Object o : checkedList) {
63
                if (o instanceof NamedArea) {
64
                    NamedArea na = (NamedArea) o;
62
                if (o instanceof NamedAreaWrapper) {
63
                    NamedArea na = (NamedArea)((NamedAreaWrapper) o).getNamedArea();
65 64
                    listUIIDChecked.add(na.getUuid());
66 65

  
67 66
                }else if(o instanceof OrderedTermVocabulary){
......
70 69
                }
71 70
            }
72 71
            for (Object o : grayedList) {
73
                if(o instanceof DefinedTermBase){
74
                    DefinedTermBase dt = (DefinedTermBase) o;
75
                    listUIIDGrayed.add(dt.getUuid());
72
                if (o instanceof NamedAreaWrapper) {
73
                    NamedArea na = (NamedArea)((NamedAreaWrapper) o).getNamedArea();
74
                    listUIIDGrayed.add(na.getUuid());
76 75
                }else if(o instanceof OrderedTermVocabulary){
77 76
                    OrderedTermVocabulary otb = (OrderedTermVocabulary) o;
78 77
                    listUIIDGrayed.add(otb.getUuid());
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/wizard/DistributionContentProvider.java
1
/**
2
* Copyright (C) 2018 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.taxeditor.preference.wizard;
10

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

  
15
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
16
import eu.etaxonomy.cdm.model.common.TermVocabulary;
17
import eu.etaxonomy.taxeditor.editor.definedterm.TermContentProvider;
18
import eu.etaxonomy.taxeditor.store.CdmStore;
19

  
20
/**
21
 * @author k.luther
22
 * @since 04.10.2018
23
 *
24
 */
25
public class DistributionContentProvider extends TermContentProvider {
26

  
27
    /* (non-Javadoc)
28
     * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
29
     */
30
    @Override
31
    public Object[] getChildren(Object parentElement) {
32
        Set<NamedAreaWrapper> allChildrenWrapper = new HashSet();
33
        if(parentElement instanceof TermVocabulary){
34
            return getTopLevelElements((TermVocabulary)parentElement);
35
        } else if (parentElement instanceof NamedAreaWrapper && !((NamedAreaWrapper)parentElement).isBaseElement) {
36
            NamedAreaWrapper wrapper = (NamedAreaWrapper)parentElement;
37
            if (wrapper.children == null){
38
                DefinedTermBase term = wrapper.getNamedArea();
39
                Set<DefinedTermBase> includes = term.getIncludes();
40
                Set<DefinedTermBase> generalizationOfs = term.getGeneralizationOf();
41
                generalizationOfs.addAll(includes);
42
                for (DefinedTermBase termBase: generalizationOfs){
43
                    allChildrenWrapper.add(new NamedAreaWrapper(termBase, false, wrapper));
44
                }
45
                if(allChildrenWrapper.size()>0){
46
                    allChildrenWrapper.add(new NamedAreaWrapper(term, true, wrapper));
47
                }
48
                wrapper.children = allChildrenWrapper;
49
                return allChildrenWrapper.toArray();
50
            }else{
51
               return wrapper.children.toArray();
52
            }
53
        }
54
        return null;
55
    }
56

  
57

  
58
    /**
59
    *
60
    * @param vocabulary
61
    * @return An array of DefinedTermBase objects that do not have parents
62
    *
63
    * TODO: Needs to be implemented in cdmlib
64
    */
65

  
66
   private Object[] getTopLevelElements(TermVocabulary vocabulary) {
67

  
68
       SortedSet<DefinedTermBase> terms = vocabulary.getTermsOrderedByLabels(CdmStore.getDefaultLanguage());
69
       Set<NamedAreaWrapper> topLevelTerms = new HashSet();
70
       NamedAreaWrapper wrapper;
71
       for (DefinedTermBase term : terms){
72
            if (term.getPartOf() == null && term.getKindOf() == null){
73
                wrapper = new NamedAreaWrapper(term, false, vocabulary);
74
                topLevelTerms.add(wrapper);
75
            }
76
       }
77
       return topLevelTerms.toArray();
78
   }
79

  
80
   /* (non-Javadoc)
81
    * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
82
    */
83
   @Override
84
   public Object getParent(Object element) {
85

  
86
       if(element instanceof NamedAreaWrapper){
87
           if (((NamedAreaWrapper)element).parent!= null){
88
               return ((NamedAreaWrapper)element).parent;
89
           }else{
90
               NamedAreaWrapper child = (NamedAreaWrapper)element;
91
               DefinedTermBase parent = child.getNamedArea().getKindOf();
92
               if (parent == null){
93
                   return child.getNamedArea().getVocabulary();
94
               }
95
               return new NamedAreaWrapper(parent, false, null);
96
           }
97
       }
98
       return null;
99

  
100
   }
101

  
102
   /* (non-Javadoc)
103
    * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object)
104
    */
105
   @Override
106
   public boolean hasChildren(Object element) {
107
       if (element instanceof TermVocabulary){
108
           if (((TermVocabulary)element).getTerms() != null){
109
               return((TermVocabulary)element).getTerms().size()>0;
110
           }else{
111
               return false;
112
           }
113
       }else if (element instanceof DefinedTermBase){
114
           boolean hasChildren = false;
115
           if (((DefinedTermBase)element).getGeneralizationOf()!= null){
116
               if (((DefinedTermBase)element).getGeneralizationOf().size()>0){
117
                   return true;
118
               }
119
           }
120
           if (((DefinedTermBase)element).getIncludes()!= null){
121
               if (((DefinedTermBase)element).getIncludes().size()>0){
122
                   return true;
123
               }
124
           }
125
           return false;
126
       }else if (element instanceof NamedAreaWrapper){
127
           NamedAreaWrapper wrapper = (NamedAreaWrapper)element;
128
           if (wrapper.isBaseElement){
129
               return false;
130
           }
131

  
132
           if (wrapper.getNamedArea().getGeneralizationOf()!= null){
133
               if (wrapper.getNamedArea().getGeneralizationOf().size()>0){
134
                   return true;
135
               }
136
           }
137
           if (wrapper.getNamedArea().getIncludes()!= null){
138
               if (wrapper.getNamedArea().getIncludes().size()>0){
139
                   return true;
140
               }
141
           }
142
           return false;
143

  
144
       }
145

  
146
       return false;
147
   }
148
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/wizard/NamedAreaWrapper.java
1
/**
2
* Copyright (C) 2018 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.taxeditor.preference.wizard;
10

  
11
import java.util.Set;
12

  
13
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
14

  
15
/**
16
 * @author k.luther
17
 * @since 04.10.2018
18
 *
19
 */
20
public class NamedAreaWrapper {
21

  
22
    boolean isBaseElement;
23
    DefinedTermBase namedArea;
24
    Set<NamedAreaWrapper> children;
25
    Object parent;
26

  
27
    public NamedAreaWrapper(DefinedTermBase namedArea, boolean isBaseElement, Object parent){
28
        this.isBaseElement = isBaseElement;
29
        this.namedArea = namedArea;
30
        this.parent = parent;
31

  
32
    }
33

  
34
    /**
35
     * @return
36
     */
37
    public DefinedTermBase getNamedArea() {
38
        return namedArea;
39
    }
40

  
41
    public Set<NamedAreaWrapper> getChildren(){
42
        return children;
43
    }
44
    @Override
45
    public boolean equals(Object wrapper){
46
        if (!(wrapper instanceof NamedAreaWrapper)){
47
            return false;
48
        }
49
        return (this.namedArea == ((NamedAreaWrapper)wrapper).namedArea && this.isBaseElement == ((NamedAreaWrapper)wrapper).isBaseElement);
50
    }
51

  
52
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)