static void Scroll(Tree tree, int x, int y) { TreeItem item = tree.getItem(new Point(x, y)); if (item == null) return; Rectangle area = tree.getClientArea(); int headerHeight = tree.getHeaderHeight(); int itemHeight = tree.getItemHeight(); TreeItem nextItem = null; if (y < area.y + headerHeight + 2 * itemHeight) { nextItem = PreviousItem(tree, item); } if (y > area.y + area.height - 2 * itemHeight) { nextItem = NextItem(tree, item); } if (nextItem != null) tree.showItem(nextItem); }
@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); TreeViewer treeViewer = new TreeViewer(tree); treeViewer.setAutoExpandLevel(AbstractTreeViewer.ALL_LEVELS); contentProvider = new TypeHierarchyContentProvider_OLD(); treeViewer.setContentProvider(contentProvider); labelProvider = new TypeHierarchyLabelProvider_OLD(contentProvider.getLightPredicate()); ColoringLabelProvider coloringLabelProvider = new ColoringLabelProvider(labelProvider); treeViewer.setLabelProvider(coloringLabelProvider); coloringLabelProvider.setOwnerDrawEnabled(true); return treeViewer; }
/** {@inheritDoc} */ 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); // Hard-coded filters treeViewer.addFilter(new NamePatternFilter()); treeViewer.addFilter(new MemberFilter()); fForegroundColor = parent.getDisplay().getSystemColor(SWT.COLOR_DARK_GRAY); fInnerLabelProvider = new OutlineLabelProvider(); fInnerLabelProvider.addLabelDecorator(new ProblemsLabelDecorator(null)); IDecoratorManager decoratorMgr = PlatformUI.getWorkbench().getDecoratorManager(); if (decoratorMgr.getEnabled("org.eclipse.jdt.ui.override.decorator")) // $NON-NLS-1$ fInnerLabelProvider.addLabelDecorator(new OverrideIndicatorLabelDecorator(null)); // AspectJ Change begin // treeViewer.setLabelProvider(fInnerLabelProvider); treeViewer.setLabelProvider(new DecoratingJavaLabelProvider(fInnerLabelProvider)); // AspectJ Change end fLexicalSortingAction = new LexicalSortingAction(treeViewer); fSortByDefiningTypeAction = new SortByDefiningTypeAction(treeViewer); fShowOnlyMainTypeAction = new ShowOnlyMainTypeAction(treeViewer); fOutlineContentProvider = new OutlineContentProvider(false); treeViewer.setContentProvider(fOutlineContentProvider); fOutlineSorter = new OutlineSorter(); treeViewer.setComparator(fOutlineSorter); treeViewer.setAutoExpandLevel(AbstractTreeViewer.ALL_LEVELS); treeViewer.getTree().addKeyListener(getKeyAdapter()); return treeViewer; }
@Override protected TreeViewer createTreeViewer(Composite parent) { Tree tree = new Tree(parent, SWT.SINGLE); GridData gd = new GridData(GridData.FILL_BOTH); gd.heightHint = tree.getItemHeight() * 12; tree.setLayoutData(gd); final TreeViewer treeViewer = new OutlineTreeViewer(tree); lexicalSortingAction = new LexicalSortingAction(treeViewer); hideNonSharedAction = new HideNonSharedAction(treeViewer); outlineContentProvider = new ContentProvider(); labelProvider = new CeylonOutlineLabelProvider() { Font getFont() { return getTreeViewer().getControl().getFont(); } String getPrefix() { return getFilterText().getText(); } }; treeViewer.setLabelProvider(labelProvider); treeViewer.addFilter(new OutlineNamePatternFilter(getFilterText())); // fSortByDefiningTypeAction= new SortByDefiningTypeAction(treeViewer); // fShowOnlyMainTypeAction= new ShowOnlyMainTypeAction(treeViewer); treeViewer.setContentProvider(outlineContentProvider); outlineSorter = new OutlineSorter(); treeViewer.setSorter(outlineSorter); treeViewer.setAutoExpandLevel(getDefaultLevel()); tree.addKeyListener(new ChangeViewListener()); tree.setFont(CeylonPlugin.getOutlineFont()); return treeViewer; }
@Override protected Control createControl(Composite parent) { Composite propertyComposite = new Composite(parent, SWT.BORDER); GridLayout layout = new GridLayout(1, false); layout.marginWidth = layout.marginHeight = 0; propertyComposite.setLayout(layout); if (mPage instanceof Page) { ((Page) mPage) .init( new IPageSite() { public void registerContextMenu( String menuId, MenuManager menuManager, ISelectionProvider selectionProvider) {} public IActionBars getActionBars() { return null; } public IWorkbenchPage getPage() { return getWorkbenchWindow().getActivePage(); } public ISelectionProvider getSelectionProvider() { return null; } public Shell getShell() { return getWorkbenchWindow().getShell(); } public IWorkbenchWindow getWorkbenchWindow() { return PlatformUI.getWorkbench().getActiveWorkbenchWindow(); } public void setSelectionProvider(ISelectionProvider provider) {} @SuppressWarnings("unchecked") public Object getAdapter(Class adapter) { return null; } @SuppressWarnings("unchecked") public Object getService(Class api) { return null; } @SuppressWarnings("unchecked") public boolean hasService(Class api) { return false; } }); } if (mPage instanceof PropertySheetPage) { ((PropertySheetPage) mPage).setPropertySourceProvider(this); } mPage.createControl(propertyComposite); mPage.setActionBars(new DummyActionBars()); final Control control = mPage.getControl(); GridData data = new GridData(SWT.FILL, SWT.FILL, true, true); if (control instanceof Tree) { final Tree tree = (Tree) control; data.heightHint = tree.getItemHeight() * 13 + (tree.getLinesVisible() ? 12 * tree.getGridLineWidth() : 0) + (tree.getHeaderVisible() ? tree.getHeaderHeight() : 0) + 2 * tree.getBorderWidth() + (tree.getHorizontalBar() != null ? tree.getHorizontalBar().getSize().x : 0); tree.addControlListener( new ControlAdapter() { @Override public void controlResized(ControlEvent e) { Rectangle area = tree.getClientArea(); TreeColumn[] columns = tree.getColumns(); if (area.width > 0) { columns[0].setWidth(area.width * 40 / 100); columns[1].setWidth(area.width - columns[0].getWidth() - 4); } } }); } else if (control instanceof Composite) { control.addControlListener( new ControlAdapter() { @Override public void controlResized(ControlEvent e) { ((Composite) control).layout(true, true); } }); } control.setLayoutData(data); ISelection selection; if (mCurrentWidget == null) { Collection<InstallOptionsModelTypeDef> typeDefs = InstallOptionsModel.INSTANCE.getControlTypeDefs(); if (typeDefs.size() > 0) { InstallOptionsModelTypeDef typeDef = typeDefs.iterator().next(); InstallOptionsElementFactory factory = InstallOptionsElementFactory.getFactory(typeDef.getType()); mCurrentWidget = (InstallOptionsWidget) factory.getNewObject(); mDialog.addChild(mCurrentWidget); } } if (mCurrentWidget != null) { mCurrentWidget.addModelCommandListener(InstallOptionsWidgetEditorDialog.this); mCurrentWidget.addPropertyChangeListener(InstallOptionsWidgetEditorDialog.this); if (mCurrentWidget.getParent() != null) { mCurrentWidget.getParent().addPropertyChangeListener(InstallOptionsWidgetEditorDialog.this); } selection = new StructuredSelection(mCurrentWidget); } else { selection = StructuredSelection.EMPTY; } mPage.selectionChanged(null, selection); PlatformUI.getWorkbench().getHelpSystem().setHelp(mPage.getControl(), HELP_CONTEXT); PlatformUI.getWorkbench().getHelpSystem().setHelp(propertyComposite, HELP_CONTEXT); return propertyComposite; }
/** * Used to display the argument ontology tree so an element can be selected * * @param display - points back to the display * @param type - the type of the element being selected to move around the tree */ public SelectRationaleElement_Treeview(Display display, RationaleElementType type) { this.eleType = type; ourDisplay = display; shell = new Shell(display, SWT.DIALOG_TRIM | SWT.PRIMARY_MODAL); shell.setText("Select Rationale Element"); GridLayout gridLayout = new GridLayout(); gridLayout.numColumns = 3; gridLayout.makeColumnsEqualWidth = true; shell.setLayout(gridLayout); new Label(shell, SWT.NONE).setText(""); new Label(shell, SWT.NONE).setText(""); ontologyTree = new Tree(shell, SWT.SINGLE | SWT.V_SCROLL | SWT.H_SCROLL); root = new TreeItem(ontologyTree, SWT.NONE); if (type == RationaleElementType.ALTERNATIVE) { root.setText("Decision"); populateTree(root, "NotNull", RationaleElementType.DECISION, true); } if (type == RationaleElementType.REQUIREMENT) { root.setText(type.toString()); populateTree(root, "NotNull", type, true); } GridData gridData = new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.HORIZONTAL_ALIGN_FILL); gridData.horizontalSpan = 3; gridData.heightHint = ontologyTree.getItemHeight() * 15; ontologyTree.setLayoutData(gridData); new Label(shell, SWT.NONE).setText(""); Button findB = new Button(shell, SWT.PUSH); findB.setText("Select"); gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_BEGINNING); gridData.horizontalIndent = 5; findB.setLayoutData(gridData); if (eleType == RationaleElementType.ALTERNATIVE) eleType = RationaleElementType.DECISION; findB.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { TreeItem[] selected = ontologyTree.getSelection(); selElement = new RationaleElement(); selElement = RationaleDB.getRationaleElement(selected[0].getText(), eleType); shell.close(); shell.dispose(); } }); Button cancelB = new Button(shell, SWT.PUSH); cancelB.setText("Cancel"); GridData gridData2 = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_BEGINNING); gridData2.horizontalIndent = 5; cancelB.setLayoutData(gridData2); cancelB.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { selElement = null; shell.close(); shell.dispose(); } }); // We want the buttons to be of equal size... findB.setSize(cancelB.getSize()); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } }