Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(39)

Side by Side Diff: editor/tools/plugins/com.xored.glance.ui/src/com/xored/glance/ui/controls/tree/TreePath.java

Issue 17431004: New UI for Find command: find-as-you-type. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 /*******************************************************************************
2 * Copyright (c) 2012 xored software, Inc. All rights reserved. This program and the accompanying
3 * materials are made available under the terms of the Eclipse Public License v1 .0 which accompanies
4 * this distribution, and is available at http://www.eclipse.org/legal/epl-v10.h tml Contributors:
5 * xored software, Inc. - initial API and implementation (Yuri Strot)
6 ******************************************************************************/
7 package com.xored.glance.ui.controls.tree;
8
9 import java.util.ArrayList;
10 import java.util.List;
11
12 import org.eclipse.swt.SWT;
13 import org.eclipse.swt.events.DisposeEvent;
14 import org.eclipse.swt.events.DisposeListener;
15 import org.eclipse.swt.widgets.Composite;
16 import org.eclipse.swt.widgets.Event;
17 import org.eclipse.swt.widgets.Tree;
18 import org.eclipse.swt.widgets.TreeItem;
19 import org.eclipse.ui.progress.PendingUpdateAdapter;
20
21 import com.xored.glance.ui.controls.decor.IPath;
22
23 public class TreePath implements IPath {
24
25 protected List<TreeNode> list = new ArrayList<TreeNode>();
26 protected TreeContent content;
27
28 private boolean cancel;
29
30 public TreePath(TreeNode node) {
31 content = node.getRoot();
32 TreeNode cur = node;
33 while (cur != null && cur != content) {
34 list.add(0, cur);
35 cur = cur.parent;
36 }
37 }
38
39 public void select(Composite composite) {
40 Tree tree = (Tree) composite;
41 select(tree.getItems(), 0);
42 }
43
44 public void discardSelection() {
45 this.cancel = true;
46 }
47
48 private void select(final TreeItem[] items, final int index) {
49 if (cancel) {
50 return;
51 }
52 TreeNode node = list.get(index);
53 for (final TreeItem item : items) {
54 if (getNode(item) == node) {
55 final Tree tree = item.getParent();
56 if (index == list.size() - 1) {
57 // After tree item removes tree selection restores
58 // we should set selection after this
59 tree.getDisplay().asyncExec(new Runnable() {
60 public void run() {
61 tree.setSelection(item);
62 tree.showSelection();
63 }
64 });
65 } else {
66 if (!item.getExpanded()) {
67 expand(item);
68 }
69 select(item.getItems(), index + 1);
70 }
71 return;
72 }
73 }
74 if (items.length > 0) {
75 TreeItem item = items[0];
76 final TreeItem parent = item.getParentItem();
77 if (item.getData() instanceof PendingUpdateAdapter) {
78 item.addDisposeListener(new DisposeListener() {
79 public void widgetDisposed(DisposeEvent e) {
80 select(parent.getItems(), index);
81 }
82 });
83 }
84 }
85 }
86
87 private TreeNode getNode(TreeItem item) {
88 TreeCell cell = new TreeCell(item, 0);
89 TreeItemContent itemContent = content.getContent(cell);
90 return itemContent != null ? itemContent.getNode() : null;
91 }
92
93 private void expand(TreeItem item) {
94 Event event = new Event();
95 event.item = item;
96 event.type = SWT.Expand;
97 event.widget = item.getParent();
98 event.display = item.getDisplay();
99 event.widget.notifyListeners(SWT.Expand, event);
100 item.setExpanded(true);
101 }
102
103 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698