Project

General

Profile

Revision 61cd8ee1

ID61cd8ee116ec6c985a18bfe06384f54d1407f2b1
Parent 1f677abd
Child 5642c43a

Added by Katja Luther almost 3 years ago

ref #7063: optimise setGrayed and check children in distribution selection wizard

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/wizard/AvailableDistributionPage.java
99 99
                try {
100 100

  
101 101
                    checkChildren(event.getElement(), event.getChecked());
102
                    grayParents(event.getElement());
102
                    grayParents(event.getElement(), event.getChecked());
103 103
                    ((CheckboxTreeViewer)getViewer()).refresh();
104 104
                }
105 105
                finally {
......
199 199
       }
200 200
    //   final Object element = path.getLastSegment();
201 201
//       if (element != null) {
202
           ((CheckboxTreeViewer)getViewer()).setChecked(element, checked);
203
           ((CheckboxTreeViewer)getViewer()).setGrayed(element, false);
204
//           int length = tcp.getChildren(element).length;
205
//           if(length>1){
206
//
207
//               ((CheckboxTreeViewer)getViewer()).expandToLevel(element, CheckboxTreeViewer.ALL_LEVELS);
208
//               ((CheckboxTreeViewer)getViewer()).setSubtreeChecked(element, checked);
209
//           }
202
       ((CheckboxTreeViewer)getViewer()).setChecked(element, checked);
203
       ((CheckboxTreeViewer)getViewer()).setGrayed(element, false);
204
       if (((CheckboxTreeViewer)getViewer()).isExpandable(element)){
205
           ((CheckboxTreeViewer)getViewer()).expandToLevel(element, CheckboxTreeViewer.ALL_LEVELS);
206
           ((CheckboxTreeViewer)getViewer()).setSubtreeChecked(element, checked);
207
       }
210 208
//       }
211 209
   }
212 210
   /**
......
214 212
   * @param path
215 213
   * @param checked
216 214
   */
217
  private void grayParents(final Object element) {
215
  private void grayParents(final Object element, boolean checked) {
218 216
      TermContentProvider tcp = new TermContentProvider();
219 217

  
220 218
      if (element == null) {
......
223 221
   //   final Object element = path.getLastSegment();
224 222
      Object parent = tcp.getParent(element);
225 223
      if (parent != null) {
226
          boolean allChecked = true;
227
          boolean allUnchecked = true;
228
          for (final Object fieldElement : tcp.getChildren(parent)) {
229
              allChecked = allChecked && ((CheckboxTreeViewer)getViewer()).getChecked(fieldElement);
230
              allUnchecked = allUnchecked && !((CheckboxTreeViewer)getViewer()).getChecked(fieldElement);
231
          }
232
          if (allUnchecked) {
233
              ((CheckboxTreeViewer)getViewer()).setChecked(parent, false);
234
              ((CheckboxTreeViewer)getViewer()).setGrayed(parent, false);
235
          } else {
236
             // ((CheckboxTreeViewer)getViewer()).setChecked(parent, false);
237
              boolean result = ((CheckboxTreeViewer)getViewer()).setGrayed(parent, true);
238 224

  
225
          boolean allUnchecked = true;
226
          //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
227
          if (checked){
228
              if (!((CheckboxTreeViewer)getViewer()).getChecked(parent)){
229
                  ((CheckboxTreeViewer)getViewer()).setGrayChecked(parent, true);
230
              }
231

  
232
          }else{
233
              for (final Object fieldElement : tcp.getChildren(parent)) {
234
                  allUnchecked = allUnchecked && !((CheckboxTreeViewer)getViewer()).getChecked(fieldElement);
235
                  allUnchecked = allUnchecked && !((CheckboxTreeViewer)getViewer()).getGrayed(fieldElement);
236
              }
237
              if (allUnchecked) {
238
                  ((CheckboxTreeViewer)getViewer()).setChecked(parent, false);
239
                  ((CheckboxTreeViewer)getViewer()).setGrayed(parent, false);
240
              } else {
241
                if (!((CheckboxTreeViewer)getViewer()).getChecked(parent)){
242
                    ((CheckboxTreeViewer)getViewer()).setGrayChecked(parent, true);
243
                }
244
                checked = true;
239 245

  
246
              }
240 247
          }
241

  
242
        grayParents(tcp.getParent(parent));
248
        grayParents(parent, checked);
243 249
      }
244 250
  }
245 251

  

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)