Java Code Examples for org.eclipse.jface.viewers.TreeViewer#getExpandedElements()

The following examples show how to use org.eclipse.jface.viewers.TreeViewer#getExpandedElements() . 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: LogicalPackagesProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent)
 */
public void propertyChange(PropertyChangeEvent event) {
	if (fCompoundState == isInCompoundState())
		return;
	else
		fCompoundState= isInCompoundState();

	if (!isInCompoundState()) {
		fMapToLogicalPackage.clear();
		fMapToPackageFragments.clear();
	}

	if(fViewer instanceof TreeViewer){
		TreeViewer viewer= (TreeViewer) fViewer;
		Object[] expandedObjects= viewer.getExpandedElements();
		viewer.refresh();
		viewer.setExpandedElements(expandedObjects);
	} else
		fViewer.refresh();
}
 
Example 2
Source File: AbstractOutlineWorkbenchTest.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
protected void assertExpanded(TreeViewer aTreeViewer, IOutlineNode... expectedExpansion) {
	Object[] expandedElements = aTreeViewer.getExpandedElements();
	assertEquals(expectedExpansion.length, expandedElements.length);
	OUTER: for (Object expandedObject : expandedElements) {
		assertTrue(expandedObject instanceof IOutlineNode);
		for (IOutlineNode expectedExpanded : expectedExpansion) {
			if (nodeComparer.equals((IOutlineNode) expandedObject, expectedExpanded))
				continue OUTER;
		}
		fail("Unexpected expansion" + expandedObject.toString());
	}
}
 
Example 3
Source File: AbstractOutlineWorkbenchTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected void assertExpanded(TreeViewer treeViewer, IOutlineNode... expectedExpansion) {
	Object[] expandedElements = treeViewer.getExpandedElements();
	assertEquals(expectedExpansion.length, expandedElements.length);
	OUTER: for (Object expandedObject : expandedElements) {
		assertTrue(expandedObject instanceof IOutlineNode);
		for (IOutlineNode expectedExpanded : expectedExpansion) {
			if (nodeComparer.equals((IOutlineNode) expandedObject, expectedExpanded))
				continue OUTER;
		}
		fail("Unexpected expansion" + expandedObject.toString());
	}
}
 
Example 4
Source File: TexOutlinePage.java    From texlipse with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Updates the outline with new content. Called by TexDocumentModel
 * through the editor. Saves the visible state of the outline,
 * sets the new content and restores the state.
 *
 * @param input the new outline input
 */
public void update(TexOutlineInput input) {
    this.input = input;
    
    TreeViewer viewer= getTreeViewer();
    if (viewer != null) {
        
        Control control= viewer.getControl();
        if (control != null && !control.isDisposed()) {
            control.setRedraw(false);
                            
            //First try smart update
            boolean succUpdate = ((TexContentProvider) viewer.getContentProvider()).updateElements(viewer, input.getRootNodes());
            if (!succUpdate) {
                viewer.getTree().deselectAll();
                // save viewer state
            	Object[] expandedElements = viewer.getExpandedElements();
                // set new input
            	viewer.setInput(input.getRootNodes());
                /*viewer.getContentProvider().inputChanged(viewer, null, input.getRootNodes());
                viewer.refresh(true);*/
                // restore viewer state
            	viewer.setExpandedElements(expandedElements);
            }
            control.setRedraw(true);
            
            // disable the refresh button, enable context stuff
            outlineActions.get(ACTION_UPDATE).setEnabled(false);
            outlineActions.get(ACTION_COPY).setEnabled(true);
            outlineActions.get(ACTION_CUT).setEnabled(true);
            outlineActions.get(ACTION_PASTE).setEnabled(true);
            outlineActions.get(ACTION_DELETE).setEnabled(true);
        }
    }
}
 
Example 5
Source File: JsonContentOutlinePage.java    From KaiZen-OpenAPI-Editor with Eclipse Public License 1.0 5 votes vote down vote up
protected void update() {
    final IDocument document = documentProvider.getDocument(currentInput);

    if (document instanceof JsonDocument) {
        final Model model = ((JsonDocument) document).getModel();
        if (model == null) {
            return;
        }

        final TreeViewer viewer = getTreeViewer();

        if (viewer != null && viewer.getControl() != null && !viewer.getControl().isDisposed()) {
            // we keep all elements that have been previously expanded
            // so the tree stay in the same state between updates.
            final Object[] expandedElements = viewer.getExpandedElements();
            final List<Object> elements = expandedElements != null ? Arrays.asList(expandedElements) : null;

            viewer.setInput(model);

            if (elements != null && !elements.isEmpty()) {
                List<AbstractNode> newElements = new ArrayList<>();
                model.allNodes().forEach(node -> {
                    if (elements.contains(node))
                        newElements.add(node);
                });
                viewer.setExpandedElements(newElements.toArray());
            }
        }
    }
}
 
Example 6
Source File: HierarchyInformationControl.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
protected void toggleHierarchy() {
	TreeViewer treeViewer= getTreeViewer();

	treeViewer.getTree().setRedraw(false);

	Object[] expandedElements= treeViewer.getExpandedElements();
	TypeHierarchyContentProvider contentProvider= (TypeHierarchyContentProvider) treeViewer.getContentProvider();
	treeViewer.setContentProvider(fOtherContentProvider);

	treeViewer.refresh();
	if (fOtherExpandedElements != null) {
		treeViewer.setExpandedElements(fOtherExpandedElements);
	} else {
		treeViewer.expandAll();
	}

	// reveal selection
	Object selectedElement= getSelectedElement();
	if (selectedElement != null)
		getTreeViewer().reveal(selectedElement);
	else
		selectFirstMatch();

	treeViewer.getTree().setRedraw(true);

	fOtherContentProvider= contentProvider;
	fOtherExpandedElements= expandedElements;

	updateStatusFieldText();
}
 
Example 7
Source File: AbstractOutlineWorkbenchTest.java    From xsemantics with Eclipse Public License 1.0 5 votes vote down vote up
protected void assertExpanded(TreeViewer treeViewer,
		IOutlineNode... expectedExpansion) {
	Object[] expandedElements = treeViewer.getExpandedElements();
	assertEquals(expectedExpansion.length, expandedElements.length);
	OUTER: for (Object expandedObject : expandedElements) {
		assertTrue(expandedObject instanceof IOutlineNode);
		for (IOutlineNode expectedExpanded : expectedExpansion) {
			if (nodeComparer.equals((IOutlineNode) expandedObject,
					expectedExpanded))
				continue OUTER;
		}
		fail("Unexpected expansion" + expandedObject.toString());
	}
}
 
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
            }
        }

    }