protected void populateSubMenus(
      Menu subMenu, final Object node, ITreeContentProvider provider, final boolean isRunTo) {
    if (provider.hasChildren(node)) {
      /*
       * this is a submenu mark
       */
      MenuItem header = new MenuItem(subMenu, SWT.CASCADE);
      header.setText(node.toString());
      Menu newSubMenu = new Menu(header);
      header.setMenu(newSubMenu);
      for (Object child : provider.getChildren(node))
        populateSubMenus(newSubMenu, child, provider, isRunTo);
    } else {
      /** lone item, this is a runner. */
      ITimeBasedAction action = new TimeBasedAction(this, node, isRunTo);

      action.setText(
          String.format("%s %s", isRunTo ? "Skip to " : "Run for ", _labelProvider.getText(node)));

      _allActions.add(action);

      ActionContributionItem aci = new ActionContributionItem(action);
      aci.fill(subMenu, -1);
    }
  }
Example #2
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);
  }
  /**
   * @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);
  }
 @Override
 public Object[] getChildren(Object parentElement) {
   if (parentElement instanceof Resource) {
     return contentProvider.getElements(parentElement);
   }
   if (parentElement instanceof EObject) {
     return contentProvider.getChildren(parentElement);
   }
   return new Object[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();
   }
 }
 /**
  * Return whether or not there are less than two pages.
  *
  * @return <code>true</code> if there are less than two pages.
  */
 private boolean hasAtMostOnePage() {
   ITreeContentProvider contentProvider = new PreferenceContentProvider();
   try {
     Object[] children = contentProvider.getElements(getPreferenceManager());
     return children.length == 0
         || children.length == 1 && !contentProvider.hasChildren(children[0]);
   } finally {
     contentProvider.dispose();
   }
 }
 void setInput(Collection<?> javaElementsOrResources) {
   fInput = new JERoot(javaElementsOrResources);
   fViewer.setInput(fInput);
   ITreeContentProvider tcp = (ITreeContentProvider) fViewer.getContentProvider();
   Object[] elements = tcp.getElements(fInput);
   if (elements.length > 0) {
     fViewer.setSelection(new StructuredSelection(elements[0]));
     if (elements.length == 1) {
       fViewer.setExpandedState(elements[0], true);
     }
   }
   fDrillDownAdapter.reset();
 }
Example #8
0
 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]);
   }
 }
 /**
  * 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);
 }
  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());
      }
    }
  }
Example #11
0
  /*
   * (non-Javadoc)
   *
   * @see
   * org.eclipse.ui.dialogs.PatternFilter#isElementVisible(org.eclipse.jface
   * .viewers.Viewer, java.lang.Object)
   */
  public boolean isElementVisible(Viewer viewer, Object element) {
    if (isLeafMatch(viewer, element)) {
      return true;
    }

    if (element instanceof DataSourceType) {
      ITreeContentProvider contentProvider =
          (ITreeContentProvider) ((TreeViewer) viewer).getContentProvider();
      DataSourceType node = (DataSourceType) element;
      Object[] children = contentProvider.getChildren(node);
      // Will return true if any subnode of the element matches the search
      if (filter(viewer, element, children).length > 0) {
        return true;
      }
    }
    return false;
  }
 /** Updates the check states of process tree viewer. */
 private void updateCheckedStates() {
   ITreeContentProvider cp = (ITreeContentProvider) processViewer.getContentProvider();
   if (config != null) {
     Object[] plugins = null;
     if (ConfigFreeProcessPublishUtil.getInstance().isSameMethodConfiguration(config)) {
       // For config free process publish
       plugins = cp.getChildren(LibraryService.getInstance().getCurrentMethodLibrary());
     } else {
       plugins = cp.getChildren(config);
     }
     for (int i = 0; i < plugins.length; i++) {
       Object[] uiFolders = cp.getChildren(plugins[i]);
       int totalUIFolders = uiFolders.length;
       int checkedUIFolders = 0;
       for (int j = 0; j < uiFolders.length; j++) {
         Object[] processes = cp.getChildren(uiFolders[j]);
         int totalProcesses = processes.length;
         int checkedProcesses = 0;
         for (int k = 0; k < processes.length; k++) {
           if (processViewer.getChecked(processes[k])) {
             checkedProcesses++;
           }
         }
         if (checkedProcesses == 0) {
           processViewer.setGrayChecked(uiFolders[j], false);
         } else if (checkedProcesses == totalProcesses) {
           processViewer.setGrayed(uiFolders[j], false);
           processViewer.setChecked(uiFolders[j], true);
         } else {
           processViewer.setGrayChecked(uiFolders[j], true);
         }
         if (processViewer.getChecked(uiFolders[j])) {
           checkedUIFolders++;
         }
       }
       if (checkedUIFolders == totalUIFolders) {
         processViewer.setGrayed(plugins[i], false);
         processViewer.setChecked(plugins[i], true);
       } else if (checkedUIFolders == 0) {
         processViewer.setGrayChecked(plugins[i], false);
       } else {
         processViewer.setGrayChecked(plugins[i], true);
       }
     }
   }
 }
  private void initializeCheckedNodes() {
    final Collection<IModelTransferNode> initialSet = importConfig.getModelsToTransfer();
    final ITreeContentProvider contents = (ITreeContentProvider) modelsTree.getContentProvider();
    final ICheckable checkable = (ICheckable) modelsTree;

    final Set<IModelTransferNode> visited = Sets.newHashSet();
    final Queue<Object> queue =
        new java.util.ArrayDeque<Object>(Arrays.asList(contents.getElements(importConfig)));

    for (Object next = queue.poll(); next != null; next = queue.poll()) {
      ITreeNode parent = (ITreeNode) next;

      // we must check a parent if the user initially selected it on opening the wizard
      // or we are importing and it is a dependent of a checked node,
      // or we are exporting and it is a dependency of a checked node,
      // or it is a model sub-unit (required dependency) of a checked node
      boolean mustCheck = initialSet.contains(parent.getElement());
      if (mustCheck) {
        checkable.setChecked(next, true);
      }

      if (visited.add(parent.getElement())) {
        // recurse into the children
        for (Object child : contents.getChildren(next)) {
          ITreeNode treeNode = (ITreeNode) child;
          queue.add(treeNode);

          // we must check a node if either the user initially selected it on opening the wizard,
          // or we are importing and it is a dependent of a checked node,
          // or we are exporting and it is a dependency of a checked node,
          // or it is a model sub-unit (required dependency) of a checked node
          mustCheck =
              initialSet.contains(treeNode.getElement()) //
                  || (isImport ? treeNode.isDependent() : treeNode.isDependency()) //
                  || (checkable.getChecked(parent)
                      && parent.getElement().isModelSubUnit(treeNode.getElement()));

          if (mustCheck) {
            checkable.setChecked(child, true);
            importConfig.addModelToTransfer(treeNode.getElement().getPrimaryResourceURI());
          }
        }
      }
    }
  }
  /* (non-Javadoc)
   * @see org.eclipse.jface.viewers.CheckboxTreeViewer#setCheckedElements(java.lang.Object[])
   */
  public void setCheckedElements(Object[] elements) {
    super.setCheckedElements(elements);
    checkState.clear();

    ITreeContentProvider contentProvider = null;
    if (getContentProvider() instanceof ITreeContentProvider) {
      contentProvider = (ITreeContentProvider) getContentProvider();
    }

    for (int i = 0; i < elements.length; i++) {
      Object[] children = contentProvider != null ? contentProvider.getChildren(elements[i]) : null;
      if (!getGrayed(elements[i]) && (children == null || children.length == 0)) {
        if (!checkState.contains(elements[i])) {
          checkState.add(elements[i]);
        }
      }
    }
  }
  /**
   * 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);
  }
        public boolean hasChildren(Object element) {
          if (myProvider.hasChildren(element)) {
            return true;
          }

          if (element instanceof IContainer == false) {
            return false;
          }

          return !getCreatedChildren((IContainer) element).isEmpty();
        }
 /**
  * If the element is a leaf node, it is added to the result collection. If the element has
  * children, this method will recursively look at the children and add any visible leaf nodes to
  * the collection.
  *
  * @param element element to check
  * @param contentProvider tree content provider to check for children
  * @param result collection to collect leaf nodes in
  */
 private void addFilteredChildren(
     Object element, ITreeContentProvider contentProvider, Collection<Object> result) {
   if (!contentProvider.hasChildren(element)) {
     result.add(element);
   } else {
     Object[] visibleChildren = getFilteredChildren(element);
     for (int i = 0; i < visibleChildren.length; i++) {
       addFilteredChildren(visibleChildren[i], contentProvider, result);
     }
   }
 }
  /**
   * 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);
  }
 protected boolean evaluateIfTreeEmpty(Object input) {
   Object[] elements = fContentProvider.getElements(input);
   if (elements.length > 0) {
     if (fFilters != null) {
       for (int i = 0; i < fFilters.size(); i++) {
         ViewerFilter curr = (ViewerFilter) fFilters.get(i);
         elements = curr.filter(fViewer, input, elements);
       }
     }
   }
   return elements.length == 0;
 }
  /**
   * @param element
   * @param state
   */
  protected void updateCheckState(final Object element, final boolean state) {
    if (state) {
      // Add the item (or its children) to the cache

      ITreeContentProvider contentProvider = null;
      if (getContentProvider() instanceof ITreeContentProvider) {
        contentProvider = (ITreeContentProvider) getContentProvider();
      }

      if (contentProvider != null) {
        Object[] children = contentProvider.getChildren(element);
        if (children != null && children.length > 0) {
          for (int i = 0; i < children.length; i++) {
            updateCheckState(children[i], state);
          }
        } else {
          checkState.add(element);
        }
      } else {
        checkState.add(element);
      }
    } else if (checkState != null) {
      // Remove the item (or its children) from the cache
      ITreeContentProvider contentProvider = null;
      if (getContentProvider() instanceof ITreeContentProvider) {
        contentProvider = (ITreeContentProvider) getContentProvider();
      }

      if (contentProvider != null) {
        Object[] children = contentProvider.getChildren(element);
        if (children != null && children.length > 0) {
          for (int i = 0; i < children.length; i++) {
            updateCheckState(children[i], state);
          }
        }
      }
      checkState.remove(element);
    }
  }
Example #21
0
  private List<Object> getAllChildren(Object element) {
    ArrayList<Object> list = new ArrayList<Object>();

    Object[] children = contentProvider.getChildren(element);
    if (children == null) {
      return list;
    }
    for (Object object : children) {
      list.add(object);
      list.addAll(getAllChildren(object));
    }
    return list;
  }
        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();
        }
 public static List<TreeDifference> scanChildrenForDifferences(
     Object parent,
     TreeDifferencer differencer,
     ITreeContentProvider contentProvider,
     boolean left) {
   List<TreeDifference> differences = new ArrayList<TreeDifference>();
   Object[] rawChildren = contentProvider.getChildren(parent);
   for (int i = 0; i < rawChildren.length; i++) {
     differences.addAll(differencer.getDifferences(rawChildren[i], left));
     differences.addAll(
         scanChildrenForDifferences(rawChildren[i], differencer, contentProvider, left));
   }
   return differences;
 }
  /**
   * 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);
  }
  protected Object getApropriateFolderForAction(String folderName) {
    Object[] expandedElements = projectViewer.getViewer().getExpandedElements();
    if (expandedElements == null || expandedElements.length == 0) {
      return null;
    }
    ITreeContentProvider contentProvider =
        (ITreeContentProvider) projectViewer.getViewer().getContentProvider();
    IResource sourceResource = getModel().getSourceResource();
    if (sourceResource != null) {
      String[] segments = sourceResource.getLocation().segments();
      for (String segment : segments) {
        if (segment.equals(folderName)) {
          return sourceResource;
        }
      }
    }

    // backup variant if selection is on different artifact type or on
    // project level
    try {
      if (sourceResource != null) {
        IProject project = sourceResource.getProject();
        Object[] children = contentProvider.getChildren(project);
        for (Object object : children) {
          IResource r = (IResource) object;
          if ((r instanceof IFolder) && r.getName().equals(folderName)) {
            return r;
          }
        }
      } else {
        return null;
      }
    } catch (NullPointerException e) {
      // project is not selected, return null
    }
    return null;
  }
Example #26
0
  private void setSubtreeChecked(Object parent, boolean state, boolean checkExpandedState) {
    if (!(parent instanceof IAdaptable)) return;
    IContainer container = (IContainer) ((IAdaptable) parent).getAdapter(IContainer.class);
    if ((!fTree.getExpandedState(parent) && checkExpandedState)
        || (container != null && !container.isAccessible())) return;

    Object[] children = fTreeContentProvider.getChildren(parent);
    for (int i = children.length - 1; i >= 0; i--) {
      Object element = children[i];
      if (state) {
        fTree.setChecked(element, true);
        fTree.setGrayed(element, false);
      } else fTree.setGrayChecked(element, false);
      if (isExpandable(element)) setSubtreeChecked(element, state, true);
    }
  }
  /**
   * 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);
    }
  }
        public Object[] getChildren(Object parentElement) {
          Object[] children = myProvider.getChildren(parentElement);
          if (myOnlyExisting) {
            return children;
          }

          if (parentElement instanceof IContainer == false) {
            return children;
          }

          List<Object> allChildren = new ArrayList<Object>();
          if (children != null) {
            allChildren.addAll(Arrays.asList(children));
          }

          IContainer container = (IContainer) parentElement;
          allChildren.addAll(getCreatedChildren(container));

          return allChildren.toArray();
        }
Example #29
0
 /**
  * Returns the number of items.
  *
  * @param tree
  * @return
  */
 private int getItemCount(TreeViewer tree) {
   ITreeContentProvider provider = (ITreeContentProvider) tree.getContentProvider();
   return provider.getElements(null).length;
 }
  @Override
  public void dispose() {
    if (provider != null) provider.dispose();

    super.dispose();
  }