10
|
1 /*******************************************************************************
|
|
2 * Copyright (c) 2007 IBM Corporation and others.
|
|
3 * All rights reserved. This program and the accompanying materials
|
|
4 * are made available under the terms of the Eclipse Public License v1.0
|
|
5 * which accompanies this distribution, and is available at
|
|
6 * http://www.eclipse.org/legal/epl-v10.html
|
|
7 *
|
|
8 * Contributors:
|
|
9 * IBM Corporation - initial API and implementation
|
|
10 * Port to the D programming language:
|
|
11 * Frank Benoit <benoit@tionex.de>
|
|
12 ******************************************************************************/
|
|
13
|
|
14 module dwtx.jface.viewers.TreeViewerFocusCellManager;
|
|
15
|
|
16 import dwtx.jface.viewers.SWTFocusCellManager;
|
|
17 import dwtx.jface.viewers.CellNavigationStrategy;
|
|
18 import dwtx.jface.viewers.TreeViewer;
|
|
19 import dwtx.jface.viewers.FocusCellHighlighter;
|
|
20 import dwtx.jface.viewers.ViewerCell;
|
|
21 import dwtx.jface.viewers.ColumnViewer;
|
|
22
|
|
23 import dwt.DWT;
|
|
24 import dwt.widgets.Event;
|
|
25 import dwt.widgets.Item;
|
|
26 import dwt.widgets.Tree;
|
|
27 import dwt.widgets.TreeItem;
|
|
28
|
|
29 import dwt.dwthelper.utils;
|
|
30
|
|
31 /**
|
|
32 * This class is responsible to provide the concept of cells for {@link Tree}.
|
|
33 * This concept is needed to provide features like editor activation with the
|
|
34 * keyboard
|
|
35 *
|
|
36 * @since 3.3
|
|
37 *
|
|
38 */
|
|
39 public class TreeViewerFocusCellManager : SWTFocusCellManager {
|
|
40 private static /+final+/ CellNavigationStrategy TREE_NAVIGATE;
|
|
41 static this(){
|
|
42 TREE_NAVIGATE = new class CellNavigationStrategy {
|
|
43 public void collapse(ColumnViewer viewer, ViewerCell cellToCollapse,
|
|
44 Event event) {
|
|
45 if (cellToCollapse !is null) {
|
|
46 (cast(TreeItem) cellToCollapse.getItem()).setExpanded(false);
|
|
47 }
|
|
48 }
|
|
49
|
|
50 public void expand(ColumnViewer viewer, ViewerCell cellToExpand,
|
|
51 Event event) {
|
|
52 if (cellToExpand !is null) {
|
|
53 TreeViewer v = cast(TreeViewer) viewer;
|
|
54 v.setExpandedState(v
|
|
55 .getTreePathFromItem_package(cast(Item)cellToExpand.getItem()), true);
|
|
56 }
|
|
57 }
|
|
58
|
|
59 public bool isCollapseEvent(ColumnViewer viewer,
|
|
60 ViewerCell cellToCollapse, Event event) {
|
|
61 return cellToCollapse !is null
|
|
62 && (cast(TreeItem) cellToCollapse.getItem()).getExpanded()
|
|
63 && cellToCollapse.getColumnIndex() is 0
|
|
64 && event.keyCode is DWT.ARROW_LEFT;
|
|
65 }
|
|
66
|
|
67 public bool isExpandEvent(ColumnViewer viewer,
|
|
68 ViewerCell cellToExpand, Event event) {
|
|
69 return cellToExpand !is null
|
|
70 && (cast(TreeItem) cellToExpand.getItem()).getItemCount() > 0
|
|
71 && !(cast(TreeItem) cellToExpand.getItem()).getExpanded()
|
|
72 && cellToExpand.getColumnIndex() is 0
|
|
73 && event.keyCode is DWT.ARROW_RIGHT;
|
|
74 }
|
|
75 };
|
|
76 }
|
|
77 /**
|
|
78 * Create a new manager
|
|
79 *
|
|
80 * @param viewer
|
|
81 * the viewer the manager is bound to
|
|
82 * @param focusDrawingDelegate
|
|
83 * the delegate responsible to highlight selected cell
|
|
84 */
|
|
85 public this(TreeViewer viewer,
|
|
86 FocusCellHighlighter focusDrawingDelegate) {
|
|
87 super(viewer, focusDrawingDelegate,TREE_NAVIGATE);
|
|
88 }
|
|
89
|
|
90 ViewerCell getInitialFocusCell() {
|
|
91 Tree tree = cast(Tree) getViewer().getControl();
|
|
92
|
|
93 if( tree.getItemCount() > 0 ) {
|
|
94 return getViewer().getViewerRowFromItem_package(tree.getItem(0)).getCell(0);
|
|
95 }
|
|
96
|
|
97 return null;
|
|
98 }
|
|
99 }
|