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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: editor/tools/plugins/com.xored.glance.ui/src/com/xored/glance/ui/controls/tree/TreePath.java
===================================================================
--- editor/tools/plugins/com.xored.glance.ui/src/com/xored/glance/ui/controls/tree/TreePath.java (revision 0)
+++ editor/tools/plugins/com.xored.glance.ui/src/com/xored/glance/ui/controls/tree/TreePath.java (revision 0)
@@ -0,0 +1,103 @@
+/*******************************************************************************
+ * Copyright (c) 2012 xored software, Inc. All rights reserved. This program and the accompanying
+ * materials are made available under the terms of the Eclipse Public License v1.0 which accompanies
+ * this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html Contributors:
+ * xored software, Inc. - initial API and implementation (Yuri Strot)
+ ******************************************************************************/
+package com.xored.glance.ui.controls.tree;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Tree;
+import org.eclipse.swt.widgets.TreeItem;
+import org.eclipse.ui.progress.PendingUpdateAdapter;
+
+import com.xored.glance.ui.controls.decor.IPath;
+
+public class TreePath implements IPath {
+
+ protected List<TreeNode> list = new ArrayList<TreeNode>();
+ protected TreeContent content;
+
+ private boolean cancel;
+
+ public TreePath(TreeNode node) {
+ content = node.getRoot();
+ TreeNode cur = node;
+ while (cur != null && cur != content) {
+ list.add(0, cur);
+ cur = cur.parent;
+ }
+ }
+
+ public void select(Composite composite) {
+ Tree tree = (Tree) composite;
+ select(tree.getItems(), 0);
+ }
+
+ public void discardSelection() {
+ this.cancel = true;
+ }
+
+ private void select(final TreeItem[] items, final int index) {
+ if (cancel) {
+ return;
+ }
+ TreeNode node = list.get(index);
+ for (final TreeItem item : items) {
+ if (getNode(item) == node) {
+ final Tree tree = item.getParent();
+ if (index == list.size() - 1) {
+ // After tree item removes tree selection restores
+ // we should set selection after this
+ tree.getDisplay().asyncExec(new Runnable() {
+ public void run() {
+ tree.setSelection(item);
+ tree.showSelection();
+ }
+ });
+ } else {
+ if (!item.getExpanded()) {
+ expand(item);
+ }
+ select(item.getItems(), index + 1);
+ }
+ return;
+ }
+ }
+ if (items.length > 0) {
+ TreeItem item = items[0];
+ final TreeItem parent = item.getParentItem();
+ if (item.getData() instanceof PendingUpdateAdapter) {
+ item.addDisposeListener(new DisposeListener() {
+ public void widgetDisposed(DisposeEvent e) {
+ select(parent.getItems(), index);
+ }
+ });
+ }
+ }
+ }
+
+ private TreeNode getNode(TreeItem item) {
+ TreeCell cell = new TreeCell(item, 0);
+ TreeItemContent itemContent = content.getContent(cell);
+ return itemContent != null ? itemContent.getNode() : null;
+ }
+
+ private void expand(TreeItem item) {
+ Event event = new Event();
+ event.item = item;
+ event.type = SWT.Expand;
+ event.widget = item.getParent();
+ event.display = item.getDisplay();
+ event.widget.notifyListeners(SWT.Expand, event);
+ item.setExpanded(true);
+ }
+
+}

Powered by Google App Engine
This is Rietveld 408576698