Java Code Examples for org.eclipse.jface.viewers.ITreeContentProvider#getChildren()

The following examples show how to use org.eclipse.jface.viewers.ITreeContentProvider#getChildren() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UIUtil.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
private static boolean containElement( Object parent,
		ITreeContentProvider provider, Object element )
{
	if ( parent == null )
	{
		return false;
	}
	if ( parent == element || parent.equals( element ) )
	{
		return true;
	}

	if ( provider == null )
	{
		return false;
	}
	Object[] children = provider.getChildren( parent );
	for ( int i = 0; i < children.length; i++ )
	{
		if ( containElement( children[i], provider, element ) )
		{
			return true;
		}
	}
	return false;
}
 
Example 2
Source File: LabItemTreeSelectionComposite.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public boolean select(Viewer viewer, Object parentElement, Object element){
	if (searchString == null || searchString.length() == 0) {
		return true;
	}
	
	StructuredViewer sviewer = (StructuredViewer) viewer;
	ITreeContentProvider provider = (ITreeContentProvider) sviewer.getContentProvider();
	Object[] children = provider.getChildren(element);
	if (children != null && children.length > 0) {
		for (Object child : children) {
			if (select(viewer, element, child)) {
				return true;
			}
		}
	}
	return isSelect(element);
}
 
Example 3
Source File: ExportBarWizardPage.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
protected boolean queryElementAndChildren(final String searchQuery, final Object element) {
    final String processName = ((AbstractProcess) element).getName();
    final String processVersion = ((AbstractProcess) element).getVersion();
    if (processName != null && processName.toLowerCase().contains(searchQuery.toLowerCase())
            || processVersion != null && processVersion.toLowerCase().contains(searchQuery.toLowerCase())) {
        Display.getDefault().asyncExec(new Runnable() {

            @Override
            public void run() {
                viewer.expandAll();
            }
        });
        return true;
    }
    final ITreeContentProvider contentProvider = (ITreeContentProvider) viewer.getContentProvider();
    if (contentProvider.hasChildren(element)) {
        for (final Object child : contentProvider.getChildren(element)) {
            if (queryElementAndChildren(searchQuery, child)) {
                return true;
            }
        }
    }
    return false;
}
 
Example 4
Source File: GroupsWizardPage.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
private void updateParentPath(final org.bonitasoft.studio.actors.model.organization.Group group, final String pathToReplace, final String newPath,
        final ITreeContentProvider provider) {
    if (provider.hasChildren(group)) {
        for (final Object child : provider.getChildren(group)) {
            final org.bonitasoft.studio.actors.model.organization.Group childGroup = (org.bonitasoft.studio.actors.model.organization.Group) child;
            updateParentPath(childGroup, pathToReplace, newPath, provider);
            String path = childGroup.getParentPath().replace(pathToReplace, newPath);
            if (path.endsWith(GroupContentProvider.GROUP_SEPARATOR)) {
                path = path.substring(0, path.length() - 1);
            }
            if (path != null && path.equals(GroupContentProvider.GROUP_SEPARATOR)) {
                childGroup.setParentPath(null);
            } else {
                childGroup.setParentPath(path);
            }
        }
    }
}
 
Example 5
Source File: PyCodeCoverageView.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
public void setSelectedContainer(IContainer container) {
    lastSelectedFile = null;
    PyCoveragePreferences.setLastChosenDir(container);
    updateErrorMessages();

    File input = container.getLocation().toFile();
    viewer.setInput(input);

    ITreeContentProvider contentProvider = (ITreeContentProvider) viewer.getContentProvider();
    Object[] children = contentProvider.getChildren(input);
    if (children.length > 0) {
        viewer.setSelection(new StructuredSelection(children[0]));
    } else {
        viewer.setSelection(new StructuredSelection());
    }

    ProgressOperation.startAction(getSite().getShell(), refreshAction, true);
}
 
Example 6
Source File: DataSetBasePage.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
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;
}
 
Example 7
Source File: ProblemsTreeEditor.java    From cppcheclipse with Apache License 2.0 6 votes vote down vote up
public void checkStateChanged(CheckStateChangedEvent event) {
	Object element = event.getElement();
	// in case of changed category, go to all problems
	if (element instanceof String) {
		ITreeContentProvider contentProvider = (ITreeContentProvider)getTreeViewer().getContentProvider();
		Object[] problems = contentProvider.getChildren(element);
		for (Object problem : problems) {
			if (problem instanceof Problem) {
				((Problem)problem).setEnabled(event.getChecked());
			}
		}
	}
	
	if (element instanceof Problem) {
		((Problem) element).setEnabled(event.getChecked());
	}

}
 
Example 8
Source File: JavaSearchResultPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private int getMatchCount(ITreeContentProvider cp, Object[] elements) {
	int count= 0;
	for (int j = 0; j < elements.length; j++) {
		count+= getDisplayedMatchCount(elements[j]);
		Object[] children = cp.getChildren(elements[j]);
		count+= getMatchCount(cp, children);
	}
	return count;
}
 
Example 9
Source File: ExpectedViewBugGroup.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void assertChildren(ITreeContentProvider contentProvider, BugGroup bugGroup) throws CoreException {
    // Get the actual children
    Object[] bugGroupChildren = contentProvider.getChildren(bugGroup);
    Assert.assertEquals(children.size(), bugGroupChildren.length);

    // For each expected child, find a match and assert on it
    for (Iterator<ExpectedViewElement> iChildren = children.iterator(); iChildren.hasNext();) {
        ExpectedViewElement expectedChild = iChildren.next();
        Object actualChild = findActualObjectMatch(expectedChild, bugGroupChildren);
        expectedChild.assertEquals(actualChild, contentProvider);
    }
}
 
Example 10
Source File: IndexViewContentProvider.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
public Object[] getChildren(Object parentElement)
{
	List<ITreeContentProvider> providers = this.getProcessors();
	List<Object> result = new ArrayList<Object>();

	for (ITreeContentProvider provider : providers)
	{
		Object[] items = provider.getChildren(parentElement);

		result.addAll(Arrays.asList(items));
	}

	return result.toArray();
}
 
Example 11
Source File: ContactSelectionComposite.java    From saros with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Gathers the checked states of the given widget and its descendants, following a pre-order
 * traversal of the {@link ITreeContentProvider}.
 *
 * @param collectedObjects a writable list of elements (element type: <code>Object</code> )
 * @param treeViewer to be traversed
 * @param parentElement of which to determine the child nodes
 */
protected static void collectAllRosterEntryElement(
    List<Object> collectedObjects, TreeViewer treeViewer, Object parentElement) {

  ITreeContentProvider treeContentProvider =
      (ITreeContentProvider) treeViewer.getContentProvider();

  Object[] objects = treeContentProvider.getChildren(parentElement);

  for (Object object : objects) {
    collectedObjects.add(object);
    collectAllRosterEntryElement(collectedObjects, treeViewer, object);
  }
}
 
Example 12
Source File: AbstractDefinitionSelectionImpementationWizardPage.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
private void getChildrenFlattenTree(final List<Object> flattenTree, final Object parentElement,
        final ITreeContentProvider contentProvider) {
    for (final Object element : contentProvider.getChildren(parentElement)) {
        flattenTree.add(element);
        if (contentProvider.hasChildren(element)) {
            getChildrenFlattenTree(flattenTree, element, contentProvider);
        }
    }
}
 
Example 13
Source File: GroupsWizardPage.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
private void removeChildren(final ITreeContentProvider contentProvider, final Object sel) {
    if (contentProvider.hasChildren(sel)) {
        for (final Object child : contentProvider.getChildren(sel)) {
            removeChildren(contentProvider, child);
            groupList.remove(child);
        }
    }
}
 
Example 14
Source File: TriStateFilteredCheckboxTree.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Ensure that the state of the checkbox and its parents are correct.
 *
 * TODO: Create utils method for use in other checkboxes.
 *
 * @param element
 *            Tree element from which the verification needs to be made
 */
private void maintainCheckIntegrity(final Object element) {
    CheckboxTreeViewer checkboxTreeViewer = getCheckboxTreeViewer();
    ITreeContentProvider contentProvider = (ITreeContentProvider) checkboxTreeViewer.getContentProvider();
    boolean allChecked = true;
    boolean oneChecked = false;
    boolean oneGrayed = false;

    for (Object child : contentProvider.getChildren(element)) {
        if (checkboxTreeViewer.testFindItem(child) == null) {
            continue;
        }

        boolean checked = getChecked(child);
        oneChecked |= checked;
        allChecked &= checked;
        oneGrayed |= (checked && getGrayed(child));

        if (oneGrayed || (oneChecked && !allChecked)) {
            setGrayed(element, true);
            setChecked(element, true);
        } else {
            setGrayed(element, false);
            setChecked(element, allChecked);
        }
    }

    Object parentElement = contentProvider.getParent(element);
    if (parentElement != null) {
        maintainCheckIntegrity(parentElement);
    }
}
 
Example 15
Source File: DocumentsView.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public boolean select(Viewer viewer, Object parentElement, Object element){
	
	if (searchTitle != null && !searchTitle.isEmpty()) {
		String searchText = searchTitle.toLowerCase();
		
		if (element instanceof ICategory) {
			StructuredViewer sviewer = (StructuredViewer) viewer;
			ITreeContentProvider provider =
				(ITreeContentProvider) sviewer.getContentProvider();
			for (Object child : provider.getChildren(element)) {
				if (select(viewer, element, child))
					return true;
			}
			return false;
		}
		if (element instanceof IDocument) {
			IDocument iDocument = (IDocument) element;
			if (iDocument.getCategory().getName().toLowerCase().startsWith(searchText)) {
				return true;
			}
			if (iDocument.getTitle().toLowerCase().contains(searchText)) {
				return true;
			}
			if (iDocument.getKeywords() != null && iDocument.getKeywords().toLowerCase()
				.contains(searchText.toLowerCase())) {
				return true;
			}
		}
		return false;
	}
	return true;
}
 
Example 16
Source File: ManyEntriesSelectedDialogPreCheckedListener.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
private int getSubTreeSize(ITreeContentProvider contentProvider, Object element) {
    int size = 1;
    for (Object o : contentProvider.getChildren(element)) {
        size += getSubTreeSize(contentProvider, o);
    }
    return size;
}
 
Example 17
Source File: RedirectRulesPanel.java    From XPagesExtensionLibrary with Apache License 2.0 4 votes vote down vote up
/**
 * create new unique text for a "label" attribute, if present, by looking at all existing. 
 * @param displayName
 * @return
 */
protected String generateNewLabel(FacesDefinition def) {
    String label = "Label"; // $NLX-AbstractTreeNodePanel.Label-1$
    String displayName = getLinkDisplayName(def);
    if (null == displayName)
        return label;
    
    Object input = ruleViewer.getInput();
    
    ITreeContentProvider cp = (ITreeContentProvider)ruleViewer.getContentProvider();
    Object[] children = cp.getElements(input);
    
    Stack<Object> stack = new Stack<Object>(); // for non-recursive tree traversal
    stack.push(input);

    Set<String> set = new HashSet<String>(); // collects current names
    
    while (!stack.isEmpty()) {
        if (null != children) {
            for (int i = 0; i < children.length; i++) {
                if (children[i] instanceof Element) {
                    String l = XPagesDOMUtil.getAttribute((Element)children[i], EXT_LIB_ATTR_LABEL);
                    if (StringUtil.isNotEmpty(l))                
                         set.add(l);
                }
                stack.push(children[i]);
            }
        }
        children = cp.getChildren(stack.pop());
    }
    while (!stack.isEmpty());
    
    String prefix = displayName;
    String[] splits = displayName.split(" "); //$NON-NLS-1$
    if (null != splits && splits.length > 0) {
        prefix = splits[0];
        for (int i = 1; i < 100; i++) {
            String thistry = prefix + " " + String.valueOf(i); //$NON-NLS-1$
            if (!set.contains(thistry)) {
                label = thistry;
                break;
            }
        }
    }
    return label;
}
 
Example 18
Source File: AbstractTreeNodePanel.java    From XPagesExtensionLibrary with Apache License 2.0 4 votes vote down vote up
/**
 * create new unique text for a "label" attribute, if present, by looking at all existing. 
 * @param displayName
 * @return
 */
protected String generateNewLabel(FacesDefinition def) {
    if(StringUtil.equals(def.getTagName(), IExtLibTagNames.EXT_LIB_TAG_DOMINO_VIEW_LIST)){
        return null; //for the dominoViewListTreeNode tag we do not want to set the label!
    }
    String label = "Label"; // $NLX-AbstractTreeNodePanel.Label-1$
    String displayName = getLinkDisplayName(def, false);
    if (null == displayName)
        return label;
    
    Object input = _linkViewer.getInput();
    
    ITreeContentProvider cp = (ITreeContentProvider)_linkViewer.getContentProvider();
    Object[] children = cp.getElements(input);
    
    Stack<Object> stack = new Stack<Object>(); // for non-recursive tree traversal
    stack.push(input);

    Set<String> set = new HashSet<String>(); // collects current names
    
    while (!stack.isEmpty()) {
        if (null != children) {
            for (int i = 0; i < children.length; i++) {
                if (children[i] instanceof Element) {
                    String l = XPagesDOMUtil.getAttribute((Element)children[i], EXT_LIB_ATTR_LABEL);
                    if (StringUtil.isNotEmpty(l))                
                         set.add(l);
                }
                stack.push(children[i]);
            }
        }
        children = cp.getChildren(stack.pop());
    }
    while (!stack.isEmpty());
    
    String prefix = displayName;
    String[] splits = displayName.split(" "); //$NON-NLS-1$
    if (null != splits && splits.length > 0) {
        prefix = splits[0];
        for (int i = 1; i < 100; i++) {
            String thistry = prefix + " " + String.valueOf(i); //$NON-NLS-1$
            if (!set.contains(thistry)) {
                label = thistry;
                break;
            }
        }
    }
    return label;
}