List of usage examples for org.eclipse.jface.viewers TreeViewer setAutoExpandLevel
public void setAutoExpandLevel(int level)
From source file:bndtools.editor.BndEditorContentOutlinePage.java
License:Open Source License
@Override public void createControl(Composite parent) { super.createControl(parent); TreeViewer viewer = getTreeViewer(); viewer.setAutoExpandLevel(2); viewer.setContentProvider(new BndEditorContentOutlineProvider(viewer)); viewer.setLabelProvider(new BndEditorContentOutlineLabelProvider()); viewer.addSelectionChangedListener(new ISelectionChangedListener() { @Override/*from w w w . j av a 2 s.c o m*/ public void selectionChanged(SelectionChangedEvent event) { IStructuredSelection selection = (IStructuredSelection) event.getSelection(); Object element = selection.getFirstElement(); if (element instanceof String) { if (BndEditorContentOutlineProvider.EXPORTS.equals(element)) { editor.setActivePage(BndEditor.CONTENT_PAGE); } else if (BndEditorContentOutlineProvider.IMPORT_PATTERNS.equals(element)) { editor.setActivePage(BndEditor.CONTENT_PAGE); } else if (BndEditorContentOutlineProvider.PRIVATE_PKGS.equals(element)) { editor.setActivePage(BndEditor.CONTENT_PAGE); } else if (BndEditorContentOutlineProvider.PLUGINS.equals(element)) { editor.setActivePage(BndEditor.WORKSPACE_PAGE); } else { editor.setActivePage((String) element); } } else if (element instanceof ExportedPackage) { BundleContentPage contentsPage = (BundleContentPage) editor .setActivePage(BndEditor.CONTENT_PAGE); if (contentsPage != null) { contentsPage.setSelectedExport((ExportedPackage) element); } } else if (element instanceof PrivatePkg) { BundleContentPage contentsPage = (BundleContentPage) editor .setActivePage(BndEditor.CONTENT_PAGE); if (contentsPage != null) { contentsPage.setSelectedPrivatePkg(((PrivatePkg) element).pkg); } } else if (element instanceof ImportPattern) { BundleContentPage contentsPage = (BundleContentPage) editor .setActivePage(BndEditor.CONTENT_PAGE); if (contentsPage != null) { contentsPage.setSelectedImport((ImportPattern) element); } } else if (element instanceof PluginClause) { WorkspacePage workspacePage = (WorkspacePage) editor.setActivePage(BndEditor.WORKSPACE_PAGE); if (workspacePage != null) workspacePage.setSelectedPlugin(((PluginClause) element).header); } } }); viewer.setInput(model); }
From source file:com.amazonaws.eclipse.cloudformation.templates.editor.TemplateContentOutlinePage.java
License:Apache License
public void createControl(Composite parent) { super.createControl(parent); final TreeViewer viewer = getTreeViewer(); viewer.setContentProvider(new TemplateOutlineContentProvider()); viewer.setLabelProvider(new TemplateOutlineLabelProvider()); viewer.addSelectionChangedListener(this); viewer.setAutoExpandLevel(2); viewer.addOpenListener(new IOpenListener() { public void open(OpenEvent event) { TemplateOutlineNode selectedNode = (TemplateOutlineNode) ((StructuredSelection) event .getSelection()).getFirstElement(); JsonLocation startLocation = selectedNode.getNode().getStartLocation(); JsonLocation endLocation = selectedNode.getNode().getEndLocation(); IEditorPart activeEditor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage() .getActiveEditor();//from w ww. ja v a 2s . c om if (activeEditor != null) { TemplateEditor templateEditor = (TemplateEditor) activeEditor; templateEditor.setHighlightRange((int) startLocation.getCharOffset(), (int) endLocation.getCharOffset() - (int) startLocation.getCharOffset(), true); } } }); document.addTemplateDocumentListener(this); updateContent(); }
From source file:com.android.ide.eclipse.adt.internal.editors.layout.gle2.OutlinePage.java
License:Open Source License
private void createOutline(Composite parent) { if (AdtUtils.isEclipse4()) { // This is a workaround for the focus behavior in Eclipse 4 where // the framework ends up calling setFocus() on the first widget in the outline // AFTER a mouse click has been received. Specifically, if the user clicks in // the embedded property sheet to for example give a Text property editor focus, // then after the mouse click, the Outline window activation event is processed, // and this event causes setFocus() to be called first on the PageBookView (which // ends up calling setFocus on the first control, normally the TreeViewer), and // then on the Page itself. We're dealing with the page setFocus() in the override // of that method in the class, such that it does nothing. // However, we have to also disable the setFocus on the first control in the // outline page. To deal with that, we create our *own* first control in the // outline, and make its setFocus() a no-op. We also make it invisible, since we // don't actually want anything but the tree viewer showing in the outline. Text text = new Text(parent, SWT.NONE) { @Override/*w w w . ja v a2 s.c o m*/ public boolean setFocus() { // Focus no-op return true; } @Override protected void checkSubclass() { // Disable the check that prevents subclassing of SWT components } }; text.setVisible(false); } super.createControl(parent); TreeViewer tv = getTreeViewer(); tv.setAutoExpandLevel(2); tv.setContentProvider(new ContentProvider()); tv.setLabelProvider(new LabelProvider()); tv.setInput(mRootWrapper); tv.expandToLevel(mRootWrapper.getRoot(), 2); int supportedOperations = DND.DROP_COPY | DND.DROP_MOVE; Transfer[] transfers = new Transfer[] { SimpleXmlTransfer.getInstance() }; tv.addDropSupport(supportedOperations, transfers, new OutlineDropListener(this, tv)); tv.addDragSupport(supportedOperations, transfers, new OutlineDragListener(this, tv)); // The tree viewer will hold CanvasViewInfo instances, however these // change each time the canvas is reloaded. OTOH layoutlib gives us // constant UiView keys which we can use to perform tree item comparisons. tv.setComparer(new IElementComparer() { @Override public int hashCode(Object element) { if (element instanceof CanvasViewInfo) { UiViewElementNode key = ((CanvasViewInfo) element).getUiViewNode(); if (key != null) { return key.hashCode(); } } if (element != null) { return element.hashCode(); } return 0; } @Override public boolean equals(Object a, Object b) { if (a instanceof CanvasViewInfo && b instanceof CanvasViewInfo) { UiViewElementNode keyA = ((CanvasViewInfo) a).getUiViewNode(); UiViewElementNode keyB = ((CanvasViewInfo) b).getUiViewNode(); if (keyA != null) { return keyA.equals(keyB); } } if (a != null) { return a.equals(b); } return false; } }); tv.addDoubleClickListener(new IDoubleClickListener() { @Override public void doubleClick(DoubleClickEvent event) { // This used to open the property view, but now that properties are docked // let's use it for something else -- such as showing the editor source /* // Front properties panel; its selection is already linked IWorkbenchPage page = getSite().getPage(); try { page.showView(IPageLayout.ID_PROP_SHEET, null, IWorkbenchPage.VIEW_ACTIVATE); } catch (PartInitException e) { AdtPlugin.log(e, "Could not activate property sheet"); } */ TreeItem[] selection = getTreeViewer().getTree().getSelection(); if (selection.length > 0) { CanvasViewInfo vi = getViewInfo(selection[0].getData()); if (vi != null) { LayoutCanvas canvas = mGraphicalEditorPart.getCanvasControl(); canvas.show(vi); } } } }); setupContextMenu(); // Listen to selection changes from the layout editor getSite().getPage().addSelectionListener(this); getControl().addDisposeListener(new DisposeListener() { @Override public void widgetDisposed(DisposeEvent e) { dispose(); } }); Tree tree = tv.getTree(); tree.addKeyListener(new KeyListener() { @Override public void keyPressed(KeyEvent e) { if (e.character == '-') { if (mMoveUpAction.isEnabled()) { mMoveUpAction.run(); } } else if (e.character == '+') { if (mMoveDownAction.isEnabled()) { mMoveDownAction.run(); } } } @Override public void keyReleased(KeyEvent e) { } }); setupTooltip(); }
From source file:com.android.ide.eclipse.adt.internal.editors.layout.gle2.OutlinePage2.java
License:Open Source License
@Override public void createControl(Composite parent) { super.createControl(parent); TreeViewer tv = getTreeViewer(); tv.setAutoExpandLevel(2); tv.setContentProvider(new ContentProvider()); tv.setLabelProvider(new LabelProvider()); tv.setInput(mRootWrapper);/*www .j a v a 2 s . c o m*/ // The tree viewer will hold CanvasViewInfo instances, however these // change each time the canvas is reloaded. OTOH liblayout gives us // constant UiView keys which we can use to perform tree item comparisons. tv.setComparer(new IElementComparer() { public int hashCode(Object element) { if (element instanceof CanvasViewInfo) { UiViewElementNode key = ((CanvasViewInfo) element).getUiViewKey(); if (key != null) { return key.hashCode(); } } if (element != null) { return element.hashCode(); } return 0; } public boolean equals(Object a, Object b) { if (a instanceof CanvasViewInfo && b instanceof CanvasViewInfo) { UiViewElementNode keyA = ((CanvasViewInfo) a).getUiViewKey(); UiViewElementNode keyB = ((CanvasViewInfo) b).getUiViewKey(); if (keyA != null) { return keyA.equals(keyB); } } if (a != null) { return a.equals(b); } return false; } }); // Listen to selection changes from the layout editor getSite().getPage().addSelectionListener(this); }
From source file:com.appnativa.studio.editors.SDFOutlinePage.java
License:Open Source License
public void createControl(Composite parent) { super.createControl(parent); TreeViewer viewer = getTreeViewer(); outlineContentProvider = new OutlineContentProvider(editor.getDocumentProvider()); viewer.setContentProvider(outlineContentProvider); outlineLabelProvider = new OutlineLabelProvider(); viewer.setLabelProvider(outlineLabelProvider); viewer.addSelectionChangedListener(this); viewer.setAutoExpandLevel(TreeViewer.ALL_LEVELS); //control is created after input is set if (input != null) { viewer.setInput(input);/*from w ww . j a va2s . co m*/ } }
From source file:com.aptana.ide.syncing.ui.old.views.SmartSyncViewer.java
License:Open Source License
private TreeViewer createContents(final Composite parent) { final TreeViewer viewer = new TreeViewer(parent, SWT.FULL_SELECTION | SWT.SINGLE | SWT.BORDER); viewer.setContentProvider(fContentProvider = new SmartSyncContentProvider()); viewer.setLabelProvider(fLabelProvider = new SmartSyncLabelProvider(parent.getDisplay())); Tree tree = viewer.getTree();/*from w ww . j av a 2 s . c o m*/ tree.setLinesVisible(true); tree.setHeaderVisible(true); viewer.setAutoExpandLevel(2); tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); fInitBackground = new Color(tree.getDisplay(), 175, 238, 238); fProgressBackground = new Color(tree.getDisplay(), 72, 209, 204); tree.addDisposeListener(new DisposeListener() { public void widgetDisposed(DisposeEvent e) { fInitBackground.dispose(); fProgressBackground.dispose(); } }); parent.addControlListener(new ControlAdapter() { public void controlResized(ControlEvent e) { setWidth(parent.getSize().x); } }); // file column TreeColumn file = new TreeColumn(tree, SWT.LEFT); file.setWidth(250); file.setText(Messages.SmartSyncDialog_ColumnResources); file.setToolTipText(Messages.SmartSyncViewer_ColumnResourcesTooltip); // the column to specify whether the file should be skipped TreeColumn skip = new TreeColumn(tree, SWT.CENTER); skip.setWidth(40); skip.setText(Messages.SmartSyncDialog_ColumnSkip); skip.setToolTipText(Messages.SmartSyncViewer_ColumnSkipTooltip); // the state column on what will be done, if any, to the files from first end point fColumnEnd1 = new TreeColumn(tree, SWT.CENTER); fColumnEnd1.setWidth(125); // the state column on what will be done, if any, to the files from second end point fColumnEnd2 = new TreeColumn(tree, SWT.CENTER); fColumnEnd2.setWidth(125); Menu menu = new Menu(tree); fShowDiffs = new MenuItem(menu, SWT.PUSH); fShowDiffs.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { if (!viewer.getSelection().isEmpty() && viewer.getSelection() instanceof IStructuredSelection) { Object selection = ((IStructuredSelection) viewer.getSelection()).getFirstElement(); if (selection instanceof SyncFile) { SyncFile file = (SyncFile) selection; if (file.getSyncState() == SyncState.ClientItemIsNewer || file.getSyncState() == SyncState.ServerItemIsNewer) { final VirtualFileSyncPair pair = file.getPair(); FileStoreCompareEditorInput input = new FileStoreCompareEditorInput( new CompareConfiguration()); input.setLeftFileStore(pair.getSourceFile()); IFileStore destinationFile = pair.getDestinationFile(); String name = destinationFile.getName(); if (destinationFile instanceof IExtendedFileStore) { // this is a remote file, so downloads to a local temp copy first for speed purpose try { File localFile = destinationFile.toLocalFile(EFS.CACHE, null); destinationFile = EFS.getLocalFileSystem() .getStore(Path.fromOSString(localFile.getAbsolutePath())); } catch (CoreException ce) { // logs as warning since we will fall back to use the remote file store directly in // this case IdeLog.logWarning(SyncingUIPlugin.getDefault(), ce); } } input.setRightFileStore(destinationFile, name); input.initializeCompareConfiguration(); CompareUI.openCompareDialog(input); } } } } }); fShowDiffs.setImage(SyncingUIPlugin.getImage("icons/full/obj16/compare_view.gif")); //$NON-NLS-1$ fShowDiffs.setText(Messages.SmartSyncDialog_ShowDiffs); fShowDiffs.setEnabled(true); tree.setMenu(menu); viewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { if (!viewer.getSelection().isEmpty() && viewer.getSelection() instanceof IStructuredSelection) { Object selection = ((IStructuredSelection) viewer.getSelection()).getFirstElement(); if (selection instanceof SyncFile) { SyncFile file = (SyncFile) selection; if (file.getSyncState() == SyncState.ClientItemIsNewer || file.getSyncState() == SyncState.ServerItemIsNewer) { fShowDiffs.setEnabled(true); return; } } } fShowDiffs.setEnabled(false); } }); viewer.setCellEditors(new CellEditor[] { null, new CheckboxCellEditor(), null, null }); viewer.setColumnProperties( new String[] { Messages.SmartSyncDialog_ColumnName, Messages.SmartSyncDialog_ColumnSkip, Messages.SmartSyncDialog_ColumnLocal, Messages.SmartSyncDialog_ColumnRemote }); return viewer; }
From source file:com.aptana.ide.syncing.ui.views.SmartSyncViewer.java
License:Open Source License
private TreeViewer createContents(final Composite parent) { final TreeViewer viewer = new TreeViewer(parent, SWT.FULL_SELECTION | SWT.SINGLE | SWT.BORDER); viewer.setContentProvider(fContentProvider = new SmartSyncContentProvider()); viewer.setLabelProvider(fLabelProvider = new SmartSyncLabelProvider(parent.getDisplay())); Tree tree = viewer.getTree();//w w w .j a v a 2s . c o m tree.setLinesVisible(true); tree.setHeaderVisible(true); viewer.setAutoExpandLevel(2); tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); fInitBackground = new Color(tree.getDisplay(), 175, 238, 238); fProgressBackground = new Color(tree.getDisplay(), 72, 209, 204); tree.addDisposeListener(new DisposeListener() { public void widgetDisposed(DisposeEvent e) { fInitBackground.dispose(); fProgressBackground.dispose(); } }); parent.addControlListener(new ControlAdapter() { public void controlResized(ControlEvent e) { setWidth(parent.getSize().x); } }); // file column TreeColumn file = new TreeColumn(tree, SWT.LEFT); file.setWidth(250); file.setText(Messages.SmartSyncDialog_ColumnResources); file.setToolTipText(Messages.SmartSyncViewer_ColumnResourcesTooltip); // the column to specify whether the file should be skipped TreeColumn skip = new TreeColumn(tree, SWT.CENTER); skip.setWidth(40); skip.setText(Messages.SmartSyncDialog_ColumnSkip); skip.setToolTipText(Messages.SmartSyncViewer_ColumnSkipTooltip); // the state column on what will be done, if any, to the files from first end point fColumnEnd1 = new TreeColumn(tree, SWT.CENTER); fColumnEnd1.setWidth(125); // the state column on what will be done, if any, to the files from second end point fColumnEnd2 = new TreeColumn(tree, SWT.CENTER); fColumnEnd2.setWidth(125); Menu menu = new Menu(tree); fShowDiffs = new MenuItem(menu, SWT.PUSH); fShowDiffs.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { if (!viewer.getSelection().isEmpty() && viewer.getSelection() instanceof IStructuredSelection) { Object selection = ((IStructuredSelection) viewer.getSelection()).getFirstElement(); if (selection instanceof SyncFile) { SyncFile file = (SyncFile) selection; if (file.getSyncState() == SyncState.ClientItemIsNewer || file.getSyncState() == SyncState.ServerItemIsNewer) { final VirtualFileSyncPair pair = file.getPair(); File local = null; try { local = pair.getSourceFile().toLocalFile(EFS.CACHE, null); } catch (CoreException ex) { ex.printStackTrace(); } FileCompareEditorInput input = new FileCompareEditorInput(new CompareConfiguration()) { protected void prepareFiles() { File temp = null; try { temp = pair.getDestinationFile().toLocalFile(EFS.CACHE, null); } catch (CoreException e) { e.printStackTrace(); } setRightResource(temp); } }; input.setLeftResource(local); CompareUI.openCompareDialog(input); } } } } }); fShowDiffs.setImage(SyncingUIPlugin.getImage("icons/full/obj16/compare_view.gif")); //$NON-NLS-1$ fShowDiffs.setText(Messages.SmartSyncDialog_ShowDiffs); fShowDiffs.setEnabled(true); tree.setMenu(menu); viewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { if (!viewer.getSelection().isEmpty() && viewer.getSelection() instanceof IStructuredSelection) { Object selection = ((IStructuredSelection) viewer.getSelection()).getFirstElement(); if (selection instanceof SyncFile) { SyncFile file = (SyncFile) selection; if (file.getSyncState() == SyncState.ClientItemIsNewer || file.getSyncState() == SyncState.ServerItemIsNewer) { fShowDiffs.setEnabled(true); return; } } } fShowDiffs.setEnabled(false); } }); viewer.setCellEditors(new CellEditor[] { null, new CheckboxCellEditor(), null, null }); viewer.setColumnProperties( new String[] { Messages.SmartSyncDialog_ColumnName, Messages.SmartSyncDialog_ColumnSkip, Messages.SmartSyncDialog_ColumnLocal, Messages.SmartSyncDialog_ColumnRemote }); return viewer; }
From source file:com.github.seed.ui.editor.ScalaOutlinePage.java
License:Open Source License
@Override public void createControl(Composite parent) { super.createControl(parent); TreeViewer viewer = getTreeViewer(); viewer.setAutoExpandLevel(-1); viewer.setContentProvider(new ScalaModelContentProvider()); viewer.setLabelProvider(new ScalaModelLabelProvider()); // XXX: just for quick M0 demo IDocument document = fEditor.getDocumentProvider().getDocument(fInput); CompilationUnit cu = ScalaModelScanner.getModelRoot(document.get()); cu.setName(fInput.getName());//from w w w . j av a 2 s. c o m viewer.setInput(cu); }
From source file:com.google.dart.tools.ui.internal.text.functions.DartOutlineInformationControl.java
License:Open Source License
/** * {@inheritDoc}//from w w w . j a v a2s. com */ @Override protected TreeViewer createTreeViewer(Composite parent, int style) { Tree tree = new Tree(parent, SWT.SINGLE | (style & ~SWT.MULTI)); GridData gd = new GridData(GridData.FILL_BOTH); gd.heightHint = tree.getItemHeight() * 12; tree.setLayoutData(gd); final TreeViewer treeViewer = new OutlineTreeViewer(tree); ColoredViewersManager.install(treeViewer); // Hard-coded filters treeViewer.addFilter(new NamePatternFilter()); treeViewer.addFilter(new MemberFilter()); fInnerLabelProvider = new OutlineLabelProvider(); fInnerLabelProvider.addLabelDecorator(new ProblemsLabelDecorator(null)); IDecoratorManager decoratorMgr = PlatformUI.getWorkbench().getDecoratorManager(); if (decoratorMgr.getEnabled("com.google.dart.tools.ui.override.decorator")) { fInnerLabelProvider.addLabelDecorator(new OverrideIndicatorLabelDecorator(null)); } treeViewer.setLabelProvider(fInnerLabelProvider); fLexicalSortingAction = new LexicalSortingAction(treeViewer); fSortByDefiningTypeAction = new SortByDefiningTypeAction(treeViewer); // fShowOnlyMainTypeAction = new ShowOnlyMainTypeAction(treeViewer); DartX.todo(); // fCategoryFilterActionGroup= new CategoryFilterActionGroup(treeViewer, // getId(), getInputForCategories()); fOutlineContentProvider = new OutlineContentProvider(false); treeViewer.setContentProvider(fOutlineContentProvider); fOutlineSorter = new OutlineSorter(); treeViewer.setComparator(fOutlineSorter); treeViewer.setAutoExpandLevel(AbstractTreeViewer.ALL_LEVELS); treeViewer.getTree().addKeyListener(getKeyAdapter()); Font newFont = JFaceResources.getFont(FontPreferencePage.BASE_FONT_KEY); Font oldFont = treeViewer.getTree().getFont(); Font font = SWTUtil.changeFontSize(oldFont, newFont); treeViewer.getTree().setFont(font); return treeViewer; }
From source file:com.google.dart.tools.ui.internal.typehierarchy.HierarchyInformationControl.java
License:Open Source License
@Override protected TreeViewer createTreeViewer(Composite parent, int style) { Tree tree = new Tree(parent, SWT.SINGLE | (style & ~SWT.MULTI)); GridData gd = new GridData(GridData.FILL_BOTH); gd.heightHint = tree.getItemHeight() * 12; tree.setLayoutData(gd);/*from w ww . j a v a 2 s. com*/ TreeViewer treeViewer = new TreeViewer(tree); treeViewer.setAutoExpandLevel(AbstractTreeViewer.ALL_LEVELS); treeViewer.addFilter(new ViewerFilter() { @Override public boolean select(Viewer viewer, Object parentElement, Object element) { return element instanceof Type; } }); contentProvider = new TypeHierarchyContentProvider(); treeViewer.setContentProvider(contentProvider); labelProvider = new HierarchyLabelProvider(contentProvider.getLightPredicate()); ColoringLabelProvider coloringLabelProvider = new ColoringLabelProvider(labelProvider); treeViewer.setLabelProvider(coloringLabelProvider); coloringLabelProvider.setOwnerDrawEnabled(true); return treeViewer; }