Search in sources :

Example 1 with ProblemTreeViewer

use of org.eclipse.jdt.internal.ui.viewsupport.ProblemTreeViewer in project eclipse.jdt.ui by eclipse-jdt.

the class ProjectsView method createViewer.

@Override
protected StructuredViewer createViewer(Composite parent) {
    ProblemTreeViewer result = new ProblemTreeViewer(parent, SWT.MULTI);
    fFilterUpdater = new FilterUpdater(result);
    ResourcesPlugin.getWorkspace().addResourceChangeListener(fFilterUpdater);
    return result;
}
Also used : ProblemTreeViewer(org.eclipse.jdt.internal.ui.viewsupport.ProblemTreeViewer) FilterUpdater(org.eclipse.jdt.internal.ui.viewsupport.FilterUpdater)

Example 2 with ProblemTreeViewer

use of org.eclipse.jdt.internal.ui.viewsupport.ProblemTreeViewer in project eclipse.jdt.ui by eclipse-jdt.

the class BreadcrumbItemDropDown method showMenu.

/**
 * Opens the drop down menu.
 */
public void showMenu() {
    if (JavaPlugin.DEBUG_BREADCRUMB_ITEM_DROP_DOWN)
        // $NON-NLS-1$
        System.out.println("BreadcrumbItemDropDown.showMenu()");
    if (!fEnabled || fMenuIsShown)
        return;
    fMenuIsShown = true;
    fShell = new Shell(fToolBar.getShell(), SWT.RESIZE | SWT.TOOL | SWT.ON_TOP);
    if (JavaPlugin.DEBUG_BREADCRUMB_ITEM_DROP_DOWN)
        // $NON-NLS-1$
        System.out.println("	creating new shell");
    GridLayout layout = new GridLayout(1, false);
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    fShell.setLayout(layout);
    Composite composite = new Composite(fShell, SWT.NONE);
    composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    GridLayout gridLayout = new GridLayout(1, false);
    gridLayout.marginHeight = 0;
    gridLayout.marginWidth = 0;
    composite.setLayout(gridLayout);
    fDropDownViewer = new ProblemTreeViewer(composite, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL);
    fDropDownViewer.setUseHashlookup(true);
    final Tree tree = (Tree) fDropDownViewer.getControl();
    tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    Object input = fParent.getData();
    fParent.getViewer().configureDropDownViewer(fDropDownViewer, input);
    fDropDownViewer.setInput(input);
    setShellBounds(fShell);
    fShell.addControlListener(new ControlAdapter() {

        /*
			 * @see org.eclipse.swt.events.ControlAdapter#controlResized(org.eclipse.swt.events.ControlEvent)
			 */
        @Override
        public void controlResized(ControlEvent e) {
            if (isResizingProgrammatically)
                return;
            Point size = fShell.getSize();
            getDialogSettings().put(DIALOG_HEIGHT, size.y);
        }
    });
    fDropDownViewer.addOpenListener(event -> {
        if (JavaPlugin.DEBUG_BREADCRUMB_ITEM_DROP_DOWN)
            // $NON-NLS-1$
            System.out.println("BreadcrumbItemDropDown.showMenu()$treeViewer>open");
        ISelection selection = event.getSelection();
        if (!(selection instanceof IStructuredSelection))
            return;
        Object element = ((IStructuredSelection) selection).getFirstElement();
        if (element == null)
            return;
        openElement(element);
    });
    tree.addMouseListener(new MouseListener() {

        @Override
        public void mouseUp(MouseEvent e) {
            if (JavaPlugin.DEBUG_BREADCRUMB_ITEM_DROP_DOWN)
                // $NON-NLS-1$
                System.out.println("BreadcrumbItemDropDown.showMenu()$treeViewer>mouseUp");
            if (e.button != 1)
                return;
            if ((OpenStrategy.getOpenMethod() & OpenStrategy.SINGLE_CLICK) != 0)
                return;
            Item item = tree.getItem(new Point(e.x, e.y));
            if (item == null)
                return;
            openElement(item.getData());
        }

        @Override
        public void mouseDown(MouseEvent e) {
        }

        @Override
        public void mouseDoubleClick(MouseEvent e) {
        }
    });
    tree.addMouseMoveListener(new MouseMoveListener() {

        TreeItem fLastItem = null;

        @Override
        public void mouseMove(MouseEvent e) {
            if (tree.equals(e.getSource())) {
                TreeItem o = tree.getItem(new Point(e.x, e.y));
                if ((o != null && !o.equals(fLastItem)) || (fLastItem != null && o == null)) {
                    boolean showHandPointer = false;
                    if (o != null) {
                        Object itemData = o.getData();
                        if (itemData instanceof IJavaElement) {
                            int elementType = ((IJavaElement) itemData).getElementType();
                            if (elementType != IJavaElement.JAVA_PROJECT && elementType != IJavaElement.PACKAGE_FRAGMENT && elementType != IJavaElement.PACKAGE_FRAGMENT_ROOT) {
                                showHandPointer = true;
                            }
                        } else if (itemData instanceof IFile) {
                            showHandPointer = true;
                        } else if (itemData instanceof IJarEntryResource) {
                            showHandPointer = ((IJarEntryResource) itemData).isFile();
                        }
                    }
                    tree.setCursor(showHandPointer ? tree.getDisplay().getSystemCursor(SWT.CURSOR_HAND) : null);
                }
                if (o != null) {
                    Rectangle clientArea = tree.getClientArea();
                    TreeItem currentItem = o;
                    if (!o.equals(fLastItem)) {
                        fLastItem = o;
                        tree.setSelection(new TreeItem[] { fLastItem });
                    } else if (e.y - clientArea.y < tree.getItemHeight() / 4) {
                        // Scroll up
                        if (currentItem.getParentItem() == null) {
                            int index = tree.indexOf(o);
                            if (index < 1)
                                return;
                            fLastItem = tree.getItem(index - 1);
                            tree.setSelection(new TreeItem[] { fLastItem });
                        } else {
                            Point p = tree.toDisplay(e.x, e.y);
                            Item item = fDropDownViewer.scrollUp(p.x, p.y);
                            if (item instanceof TreeItem) {
                                fLastItem = (TreeItem) item;
                                tree.setSelection(new TreeItem[] { fLastItem });
                            }
                        }
                    } else if (clientArea.y + clientArea.height - e.y < tree.getItemHeight() / 4) {
                        // Scroll down
                        if (currentItem.getParentItem() == null) {
                            int index = tree.indexOf(o);
                            if (index >= tree.getItemCount() - 1)
                                return;
                            fLastItem = tree.getItem(index + 1);
                            tree.setSelection(new TreeItem[] { fLastItem });
                        } else {
                            Point p = tree.toDisplay(e.x, e.y);
                            Item item = fDropDownViewer.scrollDown(p.x, p.y);
                            if (item instanceof TreeItem) {
                                fLastItem = (TreeItem) item;
                                tree.setSelection(new TreeItem[] { fLastItem });
                            }
                        }
                    }
                } else {
                    fLastItem = null;
                }
            }
        }
    });
    tree.addKeyListener(new KeyListener() {

        @Override
        public void keyPressed(KeyEvent e) {
            if (e.keyCode == SWT.ARROW_UP) {
                TreeItem[] selection = tree.getSelection();
                if (selection.length != 1)
                    return;
                int selectionIndex = tree.indexOf(selection[0]);
                if (selectionIndex != 0)
                    return;
                fShell.close();
            }
        }

        @Override
        public void keyReleased(KeyEvent e) {
        }
    });
    fDropDownViewer.addTreeListener(new ITreeViewerListener() {

        @Override
        public void treeCollapsed(TreeExpansionEvent event) {
        }

        @Override
        public void treeExpanded(TreeExpansionEvent event) {
            tree.setRedraw(false);
            fShell.getDisplay().asyncExec(() -> {
                if (fShell.isDisposed())
                    return;
                try {
                    resizeShell(fShell);
                } finally {
                    tree.setRedraw(true);
                }
            });
        }
    });
    int index = fParent.getViewer().getIndexOfItem(fParent);
    if (index < fParent.getViewer().getItemCount() - 1) {
        BreadcrumbItem childItem = fParent.getViewer().getItem(index + 1);
        Object child = childItem.getData();
        fDropDownViewer.setSelection(new StructuredSelection(child), true);
        TreeItem[] selection = tree.getSelection();
        if (selection.length > 0) {
            tree.setTopItem(selection[0]);
        }
    }
    fShell.setVisible(true);
    installCloser(fShell);
}
Also used : IFile(org.eclipse.core.resources.IFile) ControlAdapter(org.eclipse.swt.events.ControlAdapter) TreeItem(org.eclipse.swt.widgets.TreeItem) Rectangle(org.eclipse.swt.graphics.Rectangle) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) KeyEvent(org.eclipse.swt.events.KeyEvent) Item(org.eclipse.swt.widgets.Item) TreeItem(org.eclipse.swt.widgets.TreeItem) Shell(org.eclipse.swt.widgets.Shell) GridLayout(org.eclipse.swt.layout.GridLayout) MouseListener(org.eclipse.swt.events.MouseListener) ISelection(org.eclipse.jface.viewers.ISelection) Tree(org.eclipse.swt.widgets.Tree) TreeExpansionEvent(org.eclipse.jface.viewers.TreeExpansionEvent) IJavaElement(org.eclipse.jdt.core.IJavaElement) MouseEvent(org.eclipse.swt.events.MouseEvent) Composite(org.eclipse.swt.widgets.Composite) ProblemTreeViewer(org.eclipse.jdt.internal.ui.viewsupport.ProblemTreeViewer) ITreeViewerListener(org.eclipse.jface.viewers.ITreeViewerListener) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) MouseMoveListener(org.eclipse.swt.events.MouseMoveListener) IJarEntryResource(org.eclipse.jdt.core.IJarEntryResource) GridData(org.eclipse.swt.layout.GridData) KeyListener(org.eclipse.swt.events.KeyListener) ControlEvent(org.eclipse.swt.events.ControlEvent)

Example 3 with ProblemTreeViewer

use of org.eclipse.jdt.internal.ui.viewsupport.ProblemTreeViewer in project eclipse.jdt.ui by eclipse-jdt.

the class MembersView method createViewer.

@Override
protected StructuredViewer createViewer(Composite parent) {
    ProblemTreeViewer viewer = new ProblemTreeViewer(parent, SWT.MULTI);
    fMemberFilterActionGroup = new MemberFilterActionGroup(viewer, JavaUI.ID_MEMBERS_VIEW);
    return viewer;
}
Also used : MemberFilterActionGroup(org.eclipse.jdt.ui.actions.MemberFilterActionGroup) ProblemTreeViewer(org.eclipse.jdt.internal.ui.viewsupport.ProblemTreeViewer)

Aggregations

ProblemTreeViewer (org.eclipse.jdt.internal.ui.viewsupport.ProblemTreeViewer)3 IFile (org.eclipse.core.resources.IFile)1 IJarEntryResource (org.eclipse.jdt.core.IJarEntryResource)1 IJavaElement (org.eclipse.jdt.core.IJavaElement)1 FilterUpdater (org.eclipse.jdt.internal.ui.viewsupport.FilterUpdater)1 MemberFilterActionGroup (org.eclipse.jdt.ui.actions.MemberFilterActionGroup)1 ISelection (org.eclipse.jface.viewers.ISelection)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 ITreeViewerListener (org.eclipse.jface.viewers.ITreeViewerListener)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 TreeExpansionEvent (org.eclipse.jface.viewers.TreeExpansionEvent)1 ControlAdapter (org.eclipse.swt.events.ControlAdapter)1 ControlEvent (org.eclipse.swt.events.ControlEvent)1 KeyEvent (org.eclipse.swt.events.KeyEvent)1 KeyListener (org.eclipse.swt.events.KeyListener)1 MouseEvent (org.eclipse.swt.events.MouseEvent)1 MouseListener (org.eclipse.swt.events.MouseListener)1 MouseMoveListener (org.eclipse.swt.events.MouseMoveListener)1 Point (org.eclipse.swt.graphics.Point)1 Rectangle (org.eclipse.swt.graphics.Rectangle)1