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

The following examples show how to use org.eclipse.jface.viewers.TreeViewer#setExpandedElements() . 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: 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 3
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 4
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 5
Source File: NewRemoteFolderWizardMainPage.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Creates the UI part of the page.
 *
 * @param parent  the parent of the created widgets
 */
public void createControl(Composite parent) {
	Composite composite = createComposite(parent, 1);
	// set F1 help
	PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, IHelpContextIds.CREATE_REMOTE_FOLDER_PAGE);

	Listener listener = new Listener() {
		public void handleEvent(Event event) {
			validateFields();
		}
	};

       // the text field for the parent folder
	createLabel(composite, Policy.bind("NewRemoteFolderWizardMainPage.selectParentUrl")); //$NON-NLS-1$

       urlParentText = createTextField(composite);
       urlParentText.addListener(SWT.Selection, listener);
       urlParentText.addListener(SWT.Modify, listener);
       urlParentText.setEditable(false);


       // Create drill down.
       DrillDownComposite drillDown = new DrillDownComposite(composite, SWT.BORDER);
       GridData spec = new GridData(GridData.FILL_BOTH);
       spec.widthHint = LIST_WIDTH;
       spec.heightHint = LIST_HEIGHT;
       drillDown.setLayoutData(spec);

       // Create tree viewer inside drill down.
       viewer = new TreeViewer(drillDown, SWT.H_SCROLL | SWT.V_SCROLL);
       drillDown.setChildTree(viewer);
       viewer.setLabelProvider(new WorkbenchLabelProvider());
       RemoteContentProvider remoteContentProvider = new RemoteContentProvider();
       remoteContentProvider.setUseDeferredContentManager(false);
       viewer.setContentProvider(remoteContentProvider);
       viewer.setInput(new AllRootsElement());
       viewer.addFilter(RepositoryFilters.FOLDERS_ONLY);
       viewer.addSelectionChangedListener(treeSelectionChangedListener);

       // the text field for the folder name
       createLabel(composite, Policy.bind("NewRemoteFolderWizardMainPage.folderName")); //$NON-NLS-1$

       folderNameText = createTextField(composite);
       folderNameText.addListener(SWT.Selection, listener);
       folderNameText.addListener(SWT.Modify, listener);

	validateFields();
       folderNameText.setFocus();

	setControl(composite);

       // set the initial selection in the tree
       if (parentFolder != null) {      	
       	List itemsToExpand = new ArrayList();
       	ISVNRemoteFolder remoteParent = parentFolder.getParent();
       	while (remoteParent != null) {
   			if (remoteParent.getParent() == null) itemsToExpand.add(0, remoteParent.getRepository());
   			else itemsToExpand.add(0, remoteParent);
   			remoteParent = remoteParent.getParent();        		
       	}

       	viewer.setExpandedElements(itemsToExpand.toArray());
       	if (parentFolder.getParent() == null) viewer.setSelection(new StructuredSelection(parentFolder.getRepository()), true);
       	else viewer.setSelection(new StructuredSelection(parentFolder), true);
       }

}