Java Code Examples for org.eclipse.jface.viewers.TreeViewer#expandToLevel()
The following examples show how to use
org.eclipse.jface.viewers.TreeViewer#expandToLevel() .
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: ChangeTypeWizard.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * Tree-viewer that shows the allowable types in a tree view. * @param parent the parent */ private void addTreeComponent(Composite parent) { fTreeViewer= new TreeViewer(parent, SWT.SINGLE | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); GridData gd= new GridData(GridData.FILL_BOTH); gd.grabExcessHorizontalSpace= true; gd.grabExcessVerticalSpace= true; Tree tree= fTreeViewer.getTree(); Dialog.applyDialogFont(tree); gd.heightHint= tree.getItemHeight() * 12; tree.setLayoutData(gd); fTreeViewer.setContentProvider(new ChangeTypeContentProvider(((ChangeTypeRefactoring)getRefactoring()))); fLabelProvider= new ChangeTypeLabelProvider(); fTreeViewer.setLabelProvider(fLabelProvider); ISelectionChangedListener listener= new ISelectionChangedListener(){ public void selectionChanged(SelectionChangedEvent event) { IStructuredSelection selection= (IStructuredSelection)event.getSelection(); typeSelected((ITypeBinding)selection.getFirstElement()); } }; fTreeViewer.addSelectionChangedListener(listener); fTreeViewer.setInput(new ChangeTypeContentProvider.RootType(getGeneralizeTypeRefactoring().getOriginalType())); fTreeViewer.expandToLevel(10); }
Example 2
Source File: TLCErrorView.java From tlaplus with MIT License | 5 votes |
/** * Sets the input of the trace viewer to states * and sets the value viewer to "Select line in Error Trace to show its value here." * if the list of states is not empty. * * @param states */ void setTraceInput(final TLCError error, final boolean isNew) { if (isNew) { unfilteredInput = error; } // If itemCount is large (>10.000 items), the underlying OS window // toolkit can be slow. As a possible fix, look into // http://www.eclipse.org/nattable/. For background, read // https://bugs.eclipse.org/bugs/show_bug.cgi?id=129457#c27 error.restrictTraceTo(numberOfStatesToShow); final TreeViewer treeViewer = errorTraceTreeViewer.getTreeViewer(); treeViewer.getTree().setItemCount(error.getTraceSize() + (error.isTraceRestricted() ? 1 : 0)); treeViewer.setInput(error); // If the number of states in the trace is sufficiently small, eagerly // expand all root level items (which translates to the states // variables). This causes the TreeViewer to correctly determine the // vertical scroll bar's height. For larger number of states, we accept // an incorrect scroll bar height in return for lazy and thus much // faster item handling. I pulled the limit out of thin air, but // tested it on three modern (2015) laptops with Win/Mac/Linux. // // There seems to be an implementation inside the Eclipse SDK that // correctly handles the expanded state of a virtual tree: // https://bugs.eclipse.org/bugs/show_bug.cgi?id=201135 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=266189 final int level = 1; if (error.getTraceSize(level) < 1000) { treeViewer.expandToLevel(level + 1); // viewer counts root node. } if (!error.isTraceEmpty()) { valueViewer.setDocument(NO_VALUE_DOCUMENT()); } else { valueViewer.setDocument(EMPTY_DOCUMENT()); } }
Example 3
Source File: GraphEditorNodeViewProvider.java From depan with Apache License 2.0 | 5 votes |
@Override public void updateExpandState(TreeViewer viewer) { TreePath[] expandState = graphData.getExpandState(); if (expandState.length > 0) { viewer.setExpandedTreePaths(expandState); return; } if (graphData.countTreeNodes() < NodeViewerProvider.AUTO_EXPAND_LIMIT) { viewer.expandAll(); } else { viewer.expandToLevel(1); } graphData.saveExpandState(viewer.getExpandedTreePaths()); }
Example 4
Source File: ViewEditorNodeViewerProvider.java From depan with Apache License 2.0 | 5 votes |
@Override public void updateExpandState(TreeViewer viewer) { int nodeCnt = editor.getViewGraph().getNodes().size(); if (nodeCnt < NodeViewerProvider.AUTO_EXPAND_LIMIT) { viewer.expandAll(); } else { viewer.expandToLevel(1); } }
Example 5
Source File: JavaWorkingSetPage.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * {@inheritDoc} */ @Override protected void configureTree(TreeViewer tree) { tree.setContentProvider(new JavaWorkingSetPageContentProvider()); AppearanceAwareLabelProvider javaElementLabelProvider= new AppearanceAwareLabelProvider( AppearanceAwareLabelProvider.DEFAULT_TEXTFLAGS | JavaElementLabels.P_COMPRESSED, AppearanceAwareLabelProvider.DEFAULT_IMAGEFLAGS | JavaElementImageProvider.SMALL_ICONS ); tree.setLabelProvider(new DecoratingJavaLabelProvider(javaElementLabelProvider)); tree.setComparator(new JavaElementComparator()); tree.addFilter(new EmptyInnerPackageFilter()); tree.setInput(JavaCore.create(ResourcesPlugin.getWorkspace().getRoot())); if (getSelection() == null) return; Object[] selection= getInitialTreeSelection(); if (selection.length > 0) { try { tree.getTree().setRedraw(false); for (int i= 0; i < selection.length; i++) { tree.expandToLevel(selection[i], 0); } tree.setSelection(new StructuredSelection(selection)); } finally { tree.getTree().setRedraw(true); } } }
Example 6
Source File: LibraryExplorerTreeViewPage.java From birt with Eclipse Public License 1.0 | 5 votes |
private void handleTreeViewerRefresh( ) { TreeViewer treeViewer = getTreeViewer( ); if ( libraryBackup != null ) { libraryBackup.restoreBackup( treeViewer ); } else { libraryBackup = new TreeViewerBackup( ); treeViewer.expandToLevel( 2 ); libraryBackup.updateStatus( treeViewer ); } }
Example 7
Source File: TreeViewerBackup.java From birt with Eclipse Public License 1.0 | 5 votes |
public void restoreBackup( TreeViewer treeviewer ) { for ( int i = 0; i < leafList.size( ); i++ ) { treeviewer.expandToLevel( leafList.get( i ), 1 ); } }
Example 8
Source File: RecordToSourceCoupler.java From tlaplus with MIT License | 4 votes |
private void performSourceCoupling(final ISelection selection, final boolean jumpToPCal, final boolean dueToArrowKeys) { if (selection != null && !selection.isEmpty()) { if (selection instanceof StructuredSelection) { final StructuredSelection structuredSelection = (StructuredSelection) selection; // on a double click there should not be multiple selections, // so taking the first element of the structured selection // should work final Object firstElement = structuredSelection.getFirstElement(); if (firstElement instanceof LoaderTLCState) { final LoaderTLCState loader = (LoaderTLCState) firstElement; // Loading more states can potentially block for a couple // seconds. Thus, give feedback to user. BusyIndicator.showWhile(Display.getCurrent(), new Runnable() { public void run() { loader.loadMore(); } }); } else if (firstElement instanceof IModuleLocatable) { final IModuleLocatable moduleLocatable = (IModuleLocatable) firstElement; Location location = moduleLocatable.getModuleLocation(); if (moduleLocatable instanceof ActionInformationItem) { ActionInformationItem aii = (ActionInformationItem) moduleLocatable; if (aii.hasDefinition()) { // Do not jump to a sub-actions identifier but to its actual definition if a // sub-action has a definition. Consider this partial spec: // ... // Next == \/ /\ x = 42 // /\ x' = 23 // \/ /\ x = 23 // /\ x' = 4711 // ... // getModuleLocation called on the ActionInformationItem for sub-action // "x = 42 /\ x' = 23" returns the location of "x = 42 /\ x' = 23" and not // that of "Next". // This relevant in the Sub-actions for next-state table of the Model Checking // Results page. location = aii.getDefinition(); } } if (location != null) { /* * jumpToNested will be true if the location could be * shown in a nested saved module editor. If it is * false, we jump to the regular TLA editor instead. */ Model model = ToolboxHandle.getCurrentSpec().getAdapter(TLCSpec.class).getModel(moduleLocatable .getModelName()); if (!TLCUIHelper.jumpToSavedLocation(location, model, blacklist)) { final IWorkbenchPart iwp; if (dueToArrowKeys || FocusRetentionPolicy.ALWAYS.equals(focusRetentionPolicy)) { iwp = partToRefocus; } else { iwp = null; } UIHelper.jumpToLocation(location, jumpToPCal, iwp); if (iwp != null) { viewer.getControl().getDisplay().asyncExec(() -> { viewer.getControl().forceFocus(); }); } } } } else if (!Platform.getWS().equals(Platform.WS_WIN32) && viewer instanceof TreeViewer) { // Windows has built-in expand/collapse on double click TreeViewer treeViewer = (TreeViewer) viewer; if (treeViewer.getExpandedState(firstElement)) { treeViewer.collapseToLevel(firstElement, 1); } else { treeViewer.expandToLevel(firstElement, 1); } } } } }
Example 9
Source File: MoveRemoteResourceWizardMainPage.java From APICloud-Studio with GNU General Public License v3.0 | 4 votes |
/** * 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.MOVE_RENAME_REMOTE_RESOURCE_PAGE); Listener listener = new Listener() { public void handleEvent(Event event) { resourceName = resourceNameText.getText(); validateFields(); } }; // the text field for the parent folder createLabel(composite, Policy.bind("MoveRemoteResourceWizardMainPage.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()); viewer.setContentProvider(new RemoteContentProvider()); viewer.setInput(new AllRootsElement()); viewer.addFilter(RepositoryFilters.FOLDERS_ONLY); viewer.addSelectionChangedListener(treeSelectionChangedListener); // the text field for the resource name createLabel(composite, Policy.bind("MoveRemoteResourceWizardMainPage.resourceName")); //$NON-NLS-1$ resourceNameText = createTextField(composite); resourceNameText.addListener(SWT.Selection, listener); resourceNameText.addListener(SWT.Modify, listener); resourceNameText.setText(resourceName); validateFields(); resourceNameText.setFocus(); setControl(composite); // set the initial selection in the tree if (parentFolder != null) { Object toSelect = null; if (parentFolder.getParent() == null) { // the root folder : select the repository toSelect = parentFolder.getRepository(); } else toSelect = parentFolder; viewer.expandToLevel(toSelect,0); viewer.setSelection(new StructuredSelection(toSelect),true); } }
Example 10
Source File: WorkspaceDialog.java From APICloud-Studio with GNU General Public License v3.0 | 4 votes |
protected Control createDialogArea(Composite parent){ Composite composite = (Composite) super.createDialogArea(parent); GridLayout layout = new GridLayout(); layout.numColumns = 1; layout.marginHeight= convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN); layout.marginWidth= convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN); composite.setLayout(layout); final GridData data = new GridData(SWT.FILL, SWT.FILL, true, true); composite.setLayoutData(data); getShell().setText(windowTitle); treeViewer = new TreeViewer(composite, SWT.BORDER); final GridData gd= new GridData(SWT.FILL, SWT.FILL, true, true); gd.widthHint= 550; gd.heightHint= 250; treeViewer.getTree().setLayoutData(gd); treeViewer.setContentProvider(new LocationPageContentProvider()); treeViewer.setLabelProvider(new WorkbenchLabelProvider()); treeViewer.setInput(ResourcesPlugin.getWorkspace()); //Open to whatever is selected in the workspace field IPath existingWorkspacePath = new Path(pathText.getText()); if (existingWorkspacePath != null){ //Ensure that this workspace path is valid IResource selectedResource = ResourcesPlugin.getWorkspace().getRoot().findMember(existingWorkspacePath); if (selectedResource != null) { treeViewer.expandToLevel(selectedResource, 0); treeViewer.setSelection(new StructuredSelection(selectedResource)); } } final Composite group = new Composite(composite, SWT.NONE); layout = new GridLayout(2, false); layout.marginWidth = 0; group.setLayout(layout); group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); final Label label = new Label(group, SWT.NONE); label.setLayoutData(new GridData()); label.setText(Policy.bind("WorkspaceDialog.fileName")); //$NON-NLS-1$ fileNameText = new Text(group,SWT.BORDER); fileNameText.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); setupListeners(); return parent; }
Example 11
Source File: TreeViewerBackup.java From birt with Eclipse Public License 1.0 | 4 votes |
public void updateExpandedStatus( TreeViewer treeViewer, Object data ) { treeViewer.expandToLevel( data, 1 ); updateStatus( treeViewer ); }
Example 12
Source File: SelectProcessWizardPage.java From bonita-studio with GNU General Public License v2.0 | 4 votes |
@Override public void createControl(Composite parent) { Composite mainComposite = new Composite(parent, SWT.NONE) ; mainComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create()) ; mainComposite.setLayout(GridLayoutFactory.fillDefaults().numColumns(1).create()) ; databindingContext = new DataBindingContext() ; final FilteredTree tree = new FilteredTree(mainComposite, SWT.FULL_SELECTION | SWT.BORDER | SWT.SINGLE,new PatternFilter(), false) ; tree.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create()) ; TreeViewer viewer = tree.getViewer() ; viewer.setContentProvider(new ProcessContentProvider()) ; viewer.setLabelProvider(new ProcessTreeLabelProvider()) ; UpdateValueStrategy startegy = new UpdateValueStrategy() ; startegy.setBeforeSetValidator(new IValidator() { @Override public IStatus validate(Object value) { if(value instanceof AbstractProcess && !(value instanceof MainProcess)){ return Status.OK_STATUS ; } return ValidationStatus.error(Messages.mustSelectProcessError); } }) ; if(diagram == null){ viewer.setInput(new Object[]{ProcessContentProvider.OTHER_PROCESSES}) ; }else{ viewer.setInput(new Object[]{diagram,ProcessContentProvider.OTHER_PROCESSES}) ; } if(diagram != null){ if(((ITreeContentProvider) viewer.getContentProvider()).hasChildren(diagram)){ viewer.expandToLevel(diagram, 1) ; } }else{ if(((ITreeContentProvider) viewer.getContentProvider()).hasChildren(ProcessContentProvider.OTHER_PROCESSES)){ viewer.expandToLevel(ProcessContentProvider.OTHER_PROCESSES, 1) ; } } WizardPageSupport.create(this,databindingContext) ; databindingContext.bindValue(ViewersObservables.observeSingleSelection(viewer), PojoObservables.observeValue(this, "selection"),startegy,null) ; setControl(mainComposite) ; }