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);
    }
  }
  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]);
   }
 }
 /** 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);
       }
     }
   }
 }
 @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];
 }
Beispiel #6
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;
  }
  /**
   * @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);
    }
  }
 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;
 }
  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);
    }
  }
Beispiel #10
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;
  }
  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]);
        }
      }
    }
  }
        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();
        }
  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;
  }
 private Object[] getTreeChildren(Object element) {
   return filter(fTreeViewer.getFilters(), fTreeContentProvider.getChildren(element));
 }