Exemple #1
0
  public void testSetGrayedElements() {
    CheckboxTreeViewer ctv = (CheckboxTreeViewer) fViewer;

    TestElement[] children = fRootElement.getChildren();

    List toGray = new ArrayList((children.length + 1) / 2);

    for (int i = 0; i < children.length; i += 2) {
      toGray.add(children[i]);
    }

    ctv.setGrayedElements(toGray.toArray());

    for (int i = 0; i < children.length; i++) {
      if (i % 2 == 0) {
        assertTrue(
            "an element passed through setGrayedElements should be grayed",
            ctv.getGrayed(children[i]));
      } else {
        assertFalse(
            "an element not passed through setGrayedElements should not be grayed",
            ctv.getGrayed(children[i]));
      }
    }
  }
Exemple #2
0
  public void testGrayed() {
    CheckboxTreeViewer ctv = (CheckboxTreeViewer) fViewer;
    TestElement element = fRootElement.getFirstChild();

    assertTrue(ctv.getGrayedElements().length == 0);
    assertTrue(!ctv.getGrayed(element));

    ctv.setGrayed(element, true);
    assertTrue(ctv.getGrayedElements().length == 1);
    assertTrue(ctv.getGrayed(element));

    ctv.setGrayed(element, false);
    assertTrue(ctv.getGrayedElements().length == 0);
    assertTrue(!ctv.getGrayed(element));
  }
  private void updateParentState(Object child, boolean baseChildState) {
    if (child == null) return;
    if (child instanceof IAdaptable) {
      IResource resource = (IResource) ((IAdaptable) child).getAdapter(IResource.class);
      if (resource != null && !resource.isAccessible()) return;
    }
    Object parent = fTreeContentProvider.getParent(child);
    if (parent == null) return;

    boolean allSameState = true;
    Object[] children = null;
    children = fTreeContentProvider.getChildren(parent);

    for (int i = children.length - 1; i >= 0; i--) {
      if (fTree.getChecked(children[i]) != baseChildState || fTree.getGrayed(children[i])) {
        allSameState = false;
        break;
      }
    }

    fTree.setGrayed(parent, !allSameState);
    fTree.setChecked(parent, !allSameState || baseChildState);

    updateParentState(parent, baseChildState);
  }
 private void findCheckedElements(List checkedResources, Object parent) {
   Object[] children = fTreeContentProvider.getChildren(parent);
   for (int i = 0; i < children.length; i++) {
     if (fTree.getGrayed(children[i])) findCheckedElements(checkedResources, children[i]);
     else if (fTree.getChecked(children[i])) checkedResources.add(children[i]);
   }
 }
 public boolean areChildrenUnchecked(final CheckboxTreeViewer tree) {
   for (final DebugTreeItem i : children) {
     if (tree.getChecked(i) || tree.getGrayed(i)) {
       return false;
     }
   }
   return true;
 }
Exemple #6
0
  public void testSetGrayChecked() {
    CheckboxTreeViewer ctv = (CheckboxTreeViewer) fViewer;

    TestElement[] children = fRootElement.getChildren();

    ctv.setGrayChecked(children[0], true);
    ctv.setGrayChecked(children[1], false);

    assertTrue(
        "an item invoked with setGrayChecked(true) should be checked", ctv.getChecked(children[0]));
    assertTrue(
        "an item invoked with setGrayChecked(true) should be grayed", ctv.getGrayed(children[0]));

    assertFalse(
        "an item invoked with setGrayChecked(false) should be unchecked",
        ctv.getChecked(children[1]));
    assertFalse(
        "an item invoked with setGrayChecked(false) should not be grayed",
        ctv.getGrayed(children[1]));
  }
Exemple #7
0
  public void testParentGrayed() {
    CheckboxTreeViewer ctv = (CheckboxTreeViewer) fViewer;
    TestElement first = fRootElement.getFirstChild();
    TestElement firstfirst = first.getFirstChild();
    TestElement firstfirstfirst = firstfirst.getFirstChild();
    ctv.expandToLevel(firstfirstfirst, 0);

    ctv.setParentsGrayed(firstfirstfirst, true);
    Object[] elements = ctv.getGrayedElements();
    assertTrue(elements.length == 3);
    for (int i = 0; i < elements.length; ++i) {
      assertTrue(ctv.getGrayed(elements[i]));
    }

    assertTrue(elements[0] == first);
    assertTrue(elements[1] == firstfirst);
    assertTrue(elements[2] == firstfirstfirst);
    ctv.setParentsGrayed(firstfirstfirst, false);
  }
 /**
  * Checks if an element is grey checked.
  *
  * @param object
  * @return if an element is grey checked.
  */
 public boolean isTreeItemGreyChecked(Object object) {
   return fTreeViewer.getGrayed(object);
 }
Exemple #9
0
  private void doCheck(ETItem element, boolean checked) {
    if (element instanceof EventTree
        || element instanceof Component
        || element instanceof EventSet) {
      final ETItem eti = element;
      ETItem toCheck = null;
      eti.setCheck(checked);
      for (int i = 0; i < eti.children.size(); i++) {
        toCheck = eti.children.get(i);
        if (treeV.getGrayed(toCheck) || (treeV.getChecked(toCheck) == checked)) {
          continue;
        }
        treeV.setChecked(toCheck, checked);
        doCheck(toCheck, checked);
      }

    } else {
      if (element instanceof Modifier) {
        if (!treeV.getGrayed(element)) {
          (element).checked = checked; // event.getChecked();
        }
      } else {
        if (element instanceof Event) {
          if (!treeV.getGrayed(element)) {
            final Event e = (Event) element;
            e.setCheck(checked); // event.getChecked());

            final Component c = (Component) e.parent.parent;
            // ((ETItem)element).checked=event.getChecked();

            final Set<Integer>[] av = cSelect.getAvailable(c.index, c.eNames);

            if (av == null) {
              return;
            }

            Set<Integer> grey = new HashSet<Integer>(((EventSet) c.children.get(0)).fullSet);

            // Object[]test=((EventSet)c.children.get(0)).fullSet.toArray();
            // for(int i=0;i<test.length;i++)
            // {
            // System.out.println("All: "+test[i]);
            // }
            //
            // test=av[0].toArray();
            // for(int i=0;i<test.length;i++)
            // {
            // System.out.println("Av: "+test[i]);
            // }

            grey.removeAll(av[0]);

            // test=grey.toArray();
            // for(int i=0;i<test.length;i++)
            // {
            // System.out.println("Grey: "+test[i]);
            // }

            // boolean isGrey;
            ArrayList<ETItem> all = ((EventSet) c.children.get(0)).children;

            checkGray(all, grey);

            // for(int i=0;i<all.size();i++){
            // isGrey=!((Event)all.get(i)).checked&&grey.contains(new
            // Integer(((Event)all.get(i)).index));
            // treeV.setGrayed(all.get(i), isGrey);
            // //System.out.println(all.get(i).label+" "+
            // isGrey);//grey.contains(new
            // Integer(((Event)all.get(i)).index)));
            // }

            grey = new HashSet<Integer>(((EventSet) c.children.get(1)).fullSet);
            grey.removeAll(av[1]);

            all = ((EventSet) c.children.get(1)).children;
            checkGray(all, grey);

            // treeV.setChecked(element, checked);

            // for(int i=0;i<all.size();i++){
            // isGrey=(!((Event)all.get(i)).checked)&&grey.contains(new
            // Integer(((Event)all.get(i)).index));
            // treeV.setGrayed(all.get(i),isGrey);//
            // grey.contains(new
            // Integer(((Event)all.get(i)).index)));
            // if(isGrey)treeV.setChecked(all.get(i),isGrey);
            // }

          } else {
            treeV.setChecked(element, true);
          }
          // treeV.refresh();
        }
      }
    }
  }
Exemple #10
0
 /**
  * Invokes the appropriate asserts to verify the state of a TestElement.
  *
  * @param te
  * @param viewer the viewer <code>te</code> is in.
  * @param shift the shift parameter being used
  */
 private void checkState(String comment, TestElement te, CheckboxTreeViewer viewer, int shift) {
   assertEquals(
       comment, CheckStateProviderTestsUtil.shouldBeChecked(te, shift), viewer.getChecked(te));
   assertEquals(
       comment, CheckStateProviderTestsUtil.shouldBeGrayed(te, shift), viewer.getGrayed(te));
 }