Exemplo n.º 1
0
  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 handleUpdateSelection(Map<Object, List<Object>> items) {
    Iterator<Object> keyIterator = items.keySet().iterator();

    // Update the store before the hierarchy to prevent updating parents before all of the children
    // are done
    while (keyIterator.hasNext()) {
      Object key = keyIterator.next();
      // Replace the items in the checked state store with those from the supplied items
      List<Object> selections = items.get(key);
      if (selections.size() == 0)
        // If it is empty remove it from the list
        fCheckedStateStore.remove(key);
      else {
        fCheckedStateStore.put(key, selections);
        // proceed up the tree element hierarchy
        Object parent = fTreeContentProvider.getParent(key);
        if (parent != null) {
          addToHierarchyToCheckedStore(parent);
        }
      }
    }

    // Now update hierarchies
    keyIterator = items.keySet().iterator();

    while (keyIterator.hasNext()) {
      Object key = keyIterator.next();
      updateHierarchy(key);
      if (fCurrentTreeSelection != null && fCurrentTreeSelection.equals(key)) {
        fListViewer.setAllChecked(false);
        fListViewer.setCheckedElements(items.get(key).toArray());
      }
    }
  }
 /**
  * Sets the initial checked state of the passed list element to true.
  *
  * @param element
  */
 public void initialCheckListItem(Object element) {
   Object parent = fTreeContentProvider.getParent(element);
   fCurrentTreeSelection = parent;
   // As this is not done from the UI then set the box for updating from the selection to false
   listItemChecked(element, true, false);
   updateHierarchy(parent);
 }
  /**
   * @see ListAndViewDialog#computeResult() https://jira.jboss.org/browse/JBIDE-7107 Added support
   *     for returning two results
   */
  @Override
  protected void computeResult() {

    List result = new ArrayList();
    Object sel1[] = getSelectedElements();
    TreeItem sel2[] = fTree.getSelection();
    for (int i = 0; i < sel1.length; ++i) result.add(sel1[i]);
    for (int i = 0; i < sel2.length; ++i) {
      Object data = sel2[i].getData();
      if (data instanceof TreeNode) {
        // list of the selected node's model object ancestry in reverse order
        ArrayList<Object> elements = new ArrayList<Object>();
        TreeNode node = (TreeNode) data;
        ITreeContentProvider prov = (ITreeContentProvider) fTreeViewer.getContentProvider();
        do {
          elements.add(node.getModelObject());
          node = (TreeNode) prov.getParent(node);
        } while (node != null && node.getModelObject() != sel1[0]);

        for (int e = elements.size(); e > 0; --e) {
          result.add(elements.get(e - 1));
        }
      }
    }
    setResult(result);
  }
  /**
   * Adds the receiver and all of it's ancestors to the checkedStateStore if they are not already
   * there.
   *
   * @param treeElement
   */
  private void addToHierarchyToCheckedStore(Object treeElement) {

    // if this tree element is already gray then its ancestors all are as well
    if (!fCheckedStateStore.containsKey(treeElement))
      fCheckedStateStore.put(treeElement, new ArrayList<Object>());

    Object parent = fTreeContentProvider.getParent(treeElement);
    if (parent != null) addToHierarchyToCheckedStore(parent);
  }
Exemplo n.º 6
0
 private void doNewButtonPressed() {
   Object newElement = fCreateTargetQuery.getCreatedTarget(fDestination);
   if (newElement != null) {
     TreeViewer viewer = getTreeViewer();
     ITreeContentProvider contentProvider = (ITreeContentProvider) viewer.getContentProvider();
     viewer.refresh(contentProvider.getParent(newElement));
     viewer.setSelection(new StructuredSelection(newElement), true);
     viewer.getTree().setFocus();
   }
 }
  /**
   * Logically gray-check all ancestors of treeItem by ensuring that they appear in the checked
   * table
   *
   * @param treeElement
   */
  protected void grayCheckHierarchy(Object treeElement) {

    // if this tree element is already gray then its ancestors all are as well
    if (fCheckedStateStore.containsKey(treeElement)) return; // no need to proceed upwards from here

    fCheckedStateStore.put(treeElement, new ArrayList<Object>());
    if (determineShouldBeWhiteChecked(treeElement)) {
      setWhiteChecked(treeElement, true);
    }
    Object parent = fTreeContentProvider.getParent(treeElement);
    if (parent != null) grayCheckHierarchy(parent);
  }
Exemplo n.º 8
0
        public Object getParent(Object element) {
          Object parent = myProvider.getParent(element);
          if (parent != null) {
            return parent;
          }

          if (element instanceof IFile == false) {
            return null;
          }

          IFile file = (IFile) element;
          return file.getParent();
        }
  /**
   * Callback that's invoked when the checked status of an item in the tree is changed by the user.
   *
   * @param treeElement
   * @param state
   */
  protected void treeItemChecked(Object treeElement, boolean state) {

    // recursively adjust all child tree elements appropriately
    setTreeChecked(treeElement, state);

    Object parent = fTreeContentProvider.getParent(treeElement);
    if (parent == null) return;

    // now update upwards in the tree hierarchy
    if (state) grayCheckHierarchy(parent);
    else ungrayCheckHierarchy(parent);

    updateHierarchy(treeElement);
  }
  /**
   * Sets the checked state of self and all ancestors appropriately
   *
   * @param treeElement
   */
  protected void updateHierarchy(Object treeElement) {

    boolean whiteChecked = determineShouldBeWhiteChecked(treeElement);
    boolean shouldBeAtLeastGray = determineShouldBeAtLeastGrayChecked(treeElement);

    fTreeViewer.setChecked(treeElement, whiteChecked || shouldBeAtLeastGray);
    setWhiteChecked(treeElement, whiteChecked);
    if (whiteChecked) fTreeViewer.setGrayed(treeElement, false);
    else fTreeViewer.setGrayed(treeElement, shouldBeAtLeastGray);

    // proceed up the tree element hierarchy
    Object parent = fTreeContentProvider.getParent(treeElement);
    if (parent != null) {
      updateHierarchy(parent);
    }
  }
  /**
   * Logically un-gray-check all ancestors of treeItem iff appropriate.
   *
   * @param treeElement
   */
  protected void ungrayCheckHierarchy(Object treeElement) {
    if (!determineShouldBeAtLeastGrayChecked(treeElement)) fCheckedStateStore.remove(treeElement);

    Object parent = fTreeContentProvider.getParent(treeElement);
    if (parent != null) ungrayCheckHierarchy(parent);
  }
 @Override
 public Object getParent(Object element) {
   return contentProvider.getParent(element);
 }