Mercurial > projects > dwt-addons
diff dwtx/jface/viewers/TreeViewerFocusCellManager.d @ 10:b6c35faf97c8
Viewers
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Mon, 31 Mar 2008 00:47:19 +0200 |
parents | |
children | ea8ff534f622 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dwtx/jface/viewers/TreeViewerFocusCellManager.d Mon Mar 31 00:47:19 2008 +0200 @@ -0,0 +1,99 @@ +/******************************************************************************* + * Copyright (c) 2007 IBM Corporation and others. + * 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: + * IBM Corporation - initial API and implementation + * Port to the D programming language: + * Frank Benoit <benoit@tionex.de> + ******************************************************************************/ + +module dwtx.jface.viewers.TreeViewerFocusCellManager; + +import dwtx.jface.viewers.SWTFocusCellManager; +import dwtx.jface.viewers.CellNavigationStrategy; +import dwtx.jface.viewers.TreeViewer; +import dwtx.jface.viewers.FocusCellHighlighter; +import dwtx.jface.viewers.ViewerCell; +import dwtx.jface.viewers.ColumnViewer; + +import dwt.DWT; +import dwt.widgets.Event; +import dwt.widgets.Item; +import dwt.widgets.Tree; +import dwt.widgets.TreeItem; + +import dwt.dwthelper.utils; + +/** + * This class is responsible to provide the concept of cells for {@link Tree}. + * This concept is needed to provide features like editor activation with the + * keyboard + * + * @since 3.3 + * + */ +public class TreeViewerFocusCellManager : SWTFocusCellManager { + private static /+final+/ CellNavigationStrategy TREE_NAVIGATE; + static this(){ + TREE_NAVIGATE = new class CellNavigationStrategy { + public void collapse(ColumnViewer viewer, ViewerCell cellToCollapse, + Event event) { + if (cellToCollapse !is null) { + (cast(TreeItem) cellToCollapse.getItem()).setExpanded(false); + } + } + + public void expand(ColumnViewer viewer, ViewerCell cellToExpand, + Event event) { + if (cellToExpand !is null) { + TreeViewer v = cast(TreeViewer) viewer; + v.setExpandedState(v + .getTreePathFromItem_package(cast(Item)cellToExpand.getItem()), true); + } + } + + public bool isCollapseEvent(ColumnViewer viewer, + ViewerCell cellToCollapse, Event event) { + return cellToCollapse !is null + && (cast(TreeItem) cellToCollapse.getItem()).getExpanded() + && cellToCollapse.getColumnIndex() is 0 + && event.keyCode is DWT.ARROW_LEFT; + } + + public bool isExpandEvent(ColumnViewer viewer, + ViewerCell cellToExpand, Event event) { + return cellToExpand !is null + && (cast(TreeItem) cellToExpand.getItem()).getItemCount() > 0 + && !(cast(TreeItem) cellToExpand.getItem()).getExpanded() + && cellToExpand.getColumnIndex() is 0 + && event.keyCode is DWT.ARROW_RIGHT; + } + }; + } + /** + * Create a new manager + * + * @param viewer + * the viewer the manager is bound to + * @param focusDrawingDelegate + * the delegate responsible to highlight selected cell + */ + public this(TreeViewer viewer, + FocusCellHighlighter focusDrawingDelegate) { + super(viewer, focusDrawingDelegate,TREE_NAVIGATE); + } + + ViewerCell getInitialFocusCell() { + Tree tree = cast(Tree) getViewer().getControl(); + + if( tree.getItemCount() > 0 ) { + return getViewer().getViewerRowFromItem_package(tree.getItem(0)).getCell(0); + } + + return null; + } +}