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

The following examples show how to use org.eclipse.jface.viewers.ITreeContentProvider#getElements() . 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: ContactSelectionComposite.java    From saros with GNU General Public License v2.0 6 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 treeViewer to be traversed
 * @return
 */
protected static List<RosterEntryElement> collectAllRosterEntryElement(TreeViewer treeViewer) {
  ITreeContentProvider treeContentProvider =
      (ITreeContentProvider) treeViewer.getContentProvider();

  List<Object> collectedObjects = new ArrayList<Object>();

  Object[] objects = treeContentProvider.getElements(treeViewer.getInput());

  for (Object object : objects) {
    collectedObjects.add(object);
    collectAllRosterEntryElement(collectedObjects, treeViewer, object);
  }

  return ArrayUtils.getInstances(collectedObjects.toArray(), RosterEntryElement.class);
}
 
Example 2
Source File: PShelfViewer.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
protected void internalInitializeWidget() {
	// create items, assuming there are no items yet
	if (pshelf.getItems().length > 0)
		throw new IllegalStateException("Cannot initialize nonempty pshelf widget.");

	ITreeContentProvider cp = (ITreeContentProvider) getContentProvider();
	Object[] elements = cp.getElements(getInput());
	for (int i = 0; i < elements.length; i++) {
		Object modelNode = elements[i];
		PShelfItem item;

		item = new PShelfItem(pshelf, SWT.NONE);
		item.setData(modelNode);
		item.getBody().setLayout(new FillLayout());

		// re-query texts and images for pshelf items
		ILabelProvider lp = (ILabelProvider) getLabelProvider();
		item.setText(lp.getText(modelNode));

		// create viewer for the item and initialize it
		Viewer contentViewer = viewerFactory.createViewerForContent(item.getBody(), modelNode);

		item.setImage(lp.getImage(modelNode));

		if (contentViewer != null) {
			viewersMap.put(item, contentViewer);
			contentViewer.setInput(cp.getChildren(modelNode));
			contentViewer.addSelectionChangedListener(sharedViewersListener);
		}

	}

	pshelf.addSelectionListener(pshelfSelectionListener);
	pshelfSelectionListener.widgetSelected(null); // initial selection notification
}
 
Example 3
Source File: BugExplorerViewTest.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testViewContents_Empty() throws PartInitException {
    // Get the content provider
    ITreeContentProvider contentProvider = getNavigatorContentProvider();
    assertNotNull(contentProvider);

    // Get the top level elements from the content provider
    Object[] projects = contentProvider.getElements(getWorkspaceRoot());
    assertNotNull(projects);
    assertEquals(0, projects.length);
}
 
Example 4
Source File: IndexViewContentProvider.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
public Object[] getElements(Object inputElement)
{
	List<ITreeContentProvider> providers = this.getProcessors();
	List<Object> result = new ArrayList<Object>();

	for (ITreeContentProvider provider : providers)
	{
		Object[] items = provider.getElements(inputElement);

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

	return result.toArray();
}
 
Example 5
Source File: AbstractBugExplorerViewTest.java    From spotbugs with GNU Lesser General Public License v2.1 4 votes vote down vote up
protected Object getSingleElement(ITreeContentProvider contentProvider) {
    Object[] elements = contentProvider.getElements(getWorkspaceRoot());
    assertNotNull(elements);
    assertEquals(1, elements.length);
    return elements[0];
}
 
Example 6
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 7
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;
}
 
Example 8
Source File: PyCodeCoverageTestWorkbench.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
public void testPyCodeCoverageView() throws Exception {

        final PyCodeCoverageView view = PyCodeCoverageView.getView(true);
        //At this point it should have no folder selected and the option to run things in coverage should be
        //set to false.
        assertTrue(!PyCoveragePreferences.getAllRunsDoCoverage());
        assertTrue(PyCodeCoverageView.getChosenDir() == null);

        assertTrue(!view.allRunsGoThroughCoverage.getSelection());
        assertTrue(!PyCoveragePreferences.getInternalAllRunsDoCoverage());
        view.allRunsGoThroughCoverage.setSelection(true);
        view.allRunsGoThroughCoverage.notifyListeners(SWT.Selection, new Event());

        assertTrue(PyCoveragePreferences.getInternalAllRunsDoCoverage());
        assertTrue(!PyCoveragePreferences.getAllRunsDoCoverage());

        view.setSelectedContainer(sourceFolder);
        TreeViewer treeViewer = view.getTreeViewer();
        ITreeContentProvider cp = (ITreeContentProvider) treeViewer.getContentProvider();
        Object[] elements = cp.getElements(treeViewer.getInput());
        assertEquals(1, elements.length);
        ILabelProvider labelProvider = (ILabelProvider) treeViewer.getLabelProvider();
        assertEquals("pack_cov", labelProvider.getText(elements[0]));

        TestCaseUtils.assertContentsEqual(getInitialCoverageText(), view.getCoverageText());

        Object[] expandedElements = treeViewer.getExpandedElements();
        assertEquals(0, expandedElements.length);
        treeViewer.expandAll();
        expandedElements = treeViewer.getExpandedElements();
        assertEquals(1, expandedElements.length);

        view.executeRefreshAction(new NullProgressMonitor());
        expandedElements = treeViewer.getExpandedElements();
        assertEquals(1, expandedElements.length);

        assertTrue(PyCoveragePreferences.getAllRunsDoCoverage());

        final IWorkbench workBench = PydevPlugin.getDefault().getWorkbench();
        Display display = workBench.getDisplay();

        // Make sure to run the UI thread.
        final PyEdit modCovEditor = (PyEdit) PyOpenEditor.doOpenEditor(modCov);
        try {
            display.syncExec(new Runnable() {
                @Override
                public void run() {
                    LaunchShortcut launchShortcut = new LaunchShortcut();
                    launchShortcut.launch(modCovEditor, "run");
                }
            });

            final String modCovCoverageText = StringUtils.replaceNewLines(getModCovCoverageText(), "\n");
            //Should be enough time for the refresh to happen!
            goToManual(10000, new ICallback<Boolean, Object>() {

                @Override
                public Boolean call(Object arg) {
                    return modCovCoverageText.equals(StringUtils.replaceNewLines(view.getCoverageText(), "\n"));
                }
            });

            TestCaseUtils.assertContentsEqual(modCovCoverageText, view.getCoverageText());

            //goToManual();
        } finally {
            try {
                modCovEditor.close(false);
            } catch (Exception e) {
                //ignore anything here
            }
        }

    }
 
Example 9
Source File: ClipboardHandlerTree.java    From arx with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the number of items.
 *
 * @param tree
 * @return
 */
private int getItemCount(TreeViewer tree) {
    ITreeContentProvider provider = (ITreeContentProvider)tree.getContentProvider();
    return provider.getElements(null).length;
}