01: /*******************************************************************************
02: * Copyright (c) 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.pde.internal.ui.editor.outline;
11:
12: import org.eclipse.jface.viewers.TreeViewer;
13: import org.eclipse.swt.events.MouseEvent;
14: import org.eclipse.swt.events.MouseMoveListener;
15: import org.eclipse.swt.graphics.Point;
16: import org.eclipse.swt.widgets.Item;
17: import org.eclipse.swt.widgets.Tree;
18: import org.eclipse.swt.widgets.TreeItem;
19:
20: /**
21: * QuickOutlineMouseMoveListener
22: *
23: */
24: public class QuickOutlineMouseMoveListener implements MouseMoveListener {
25:
26: private TreeItem fLastItem;
27:
28: private TreeViewer fTreeViewer;
29:
30: /**
31: *
32: */
33: public QuickOutlineMouseMoveListener(TreeViewer treeViewer) {
34: fLastItem = null;
35: fTreeViewer = treeViewer;
36: }
37:
38: /* (non-Javadoc)
39: * @see org.eclipse.swt.events.MouseMoveListener#mouseMove(org.eclipse.swt.events.MouseEvent)
40: */
41: public void mouseMove(MouseEvent e) {
42: Tree tree = fTreeViewer.getTree();
43: if (tree.equals(e.getSource())) {
44: Object o = tree.getItem(new Point(e.x, e.y));
45: if (o instanceof TreeItem) {
46: if (!o.equals(fLastItem)) {
47: fLastItem = (TreeItem) o;
48: tree.setSelection(new TreeItem[] { fLastItem });
49: } else if (e.y < tree.getItemHeight() / 4) {
50: // Scroll up
51: Point p = tree.toDisplay(e.x, e.y);
52: Item item = fTreeViewer.scrollUp(p.x, p.y);
53: if (item instanceof TreeItem) {
54: fLastItem = (TreeItem) item;
55: tree.setSelection(new TreeItem[] { fLastItem });
56: }
57: } else if (e.y > tree.getBounds().height
58: - tree.getItemHeight() / 4) {
59: // Scroll down
60: Point p = tree.toDisplay(e.x, e.y);
61: Item item = fTreeViewer.scrollDown(p.x, p.y);
62: if (item instanceof TreeItem) {
63: fLastItem = (TreeItem) item;
64: tree.setSelection(new TreeItem[] { fLastItem });
65: }
66: }
67: }
68: }
69: }
70:
71: }
|