Mercurial > projects > dwt2
comparison org.eclipse.jface/src/org/eclipse/jface/viewers/TableViewerFocusCellManager.d @ 12:bc29606a740c
Added dwt-addons in original directory structure of eclipse.org
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sat, 14 Mar 2009 18:23:29 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
11:43904fec5dca | 12:bc29606a740c |
---|---|
1 /******************************************************************************* | |
2 * Copyright (c) 2007, 2008 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 * Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation | |
11 * fix in bug: 210752 | |
12 * Port to the D programming language: | |
13 * Frank Benoit <benoit@tionex.de> | |
14 *******************************************************************************/ | |
15 | |
16 module org.eclipse.jface.viewers.TableViewerFocusCellManager; | |
17 | |
18 import org.eclipse.jface.viewers.SWTFocusCellManager; | |
19 import org.eclipse.jface.viewers.CellNavigationStrategy; | |
20 import org.eclipse.jface.viewers.TableViewer; | |
21 import org.eclipse.jface.viewers.FocusCellHighlighter; | |
22 import org.eclipse.jface.viewers.ViewerCell; | |
23 | |
24 import org.eclipse.swt.widgets.Table; | |
25 | |
26 import java.lang.all; | |
27 import java.util.Set; | |
28 | |
29 /** | |
30 * This class is responsible to provide the concept of cells for {@link Table}. | |
31 * This concept is needed to provide features like editor activation with the | |
32 * keyboard | |
33 * | |
34 * @since 3.3 | |
35 * | |
36 */ | |
37 public class TableViewerFocusCellManager : SWTFocusCellManager { | |
38 private static const CellNavigationStrategy TABLE_NAVIGATE; | |
39 static this(){ | |
40 TABLE_NAVIGATE = new CellNavigationStrategy(); | |
41 } | |
42 | |
43 /** | |
44 * Create a new manager with a default navigation strategy: | |
45 * <ul> | |
46 * <li><code>SWT.ARROW_UP</code>: navigate to cell above</li> | |
47 * <li><code>SWT.ARROW_DOWN</code>: navigate to cell below</li> | |
48 * <li><code>SWT.ARROW_RIGHT</code>: navigate to next visible cell on | |
49 * the right</li> | |
50 * <li><code>SWT.ARROW_LEFT</code>: navigate to next visible cell on the | |
51 * left</li> | |
52 * </ul> | |
53 * | |
54 * @param viewer | |
55 * the viewer the manager is bound to | |
56 * @param focusDrawingDelegate | |
57 * the delegate responsible to highlight selected cell | |
58 */ | |
59 public this(TableViewer viewer, | |
60 FocusCellHighlighter focusDrawingDelegate) { | |
61 this(viewer, focusDrawingDelegate, TABLE_NAVIGATE); | |
62 } | |
63 | |
64 /** | |
65 * Create a new manager | |
66 * | |
67 * @param viewer | |
68 * the viewer the manager is bound to | |
69 * @param focusDrawingDelegate | |
70 * the delegate responsible to highlight selected cell | |
71 * @param navigationStrategy | |
72 * the strategy used to navigate the cells | |
73 * @since 3.4 | |
74 */ | |
75 public this(TableViewer viewer, | |
76 FocusCellHighlighter focusDrawingDelegate, | |
77 CellNavigationStrategy navigationStrategy) { | |
78 super(viewer, focusDrawingDelegate, navigationStrategy); | |
79 } | |
80 | |
81 override ViewerCell getInitialFocusCell() { | |
82 Table table = cast(Table) getViewer().getControl(); | |
83 | |
84 if (! table.isDisposed() && table.getItemCount() > 0 && ! table.getItem(0).isDisposed()) { | |
85 return getViewer().getViewerRowFromItem_package(table.getItem(0)) | |
86 .getCell(0); | |
87 } | |
88 | |
89 return null; | |
90 } | |
91 | |
92 public ViewerCell getFocusCell() { | |
93 ViewerCell cell = super.getFocusCell(); | |
94 Table t = cast(Table) getViewer().getControl(); | |
95 | |
96 // It is possible that the selection has changed under the hood | |
97 if (cell !is null) { | |
98 if (t.getSelection().length is 1 | |
99 && t.getSelection()[0] !is cell.getItem()) { | |
100 setFocusCell(getViewer().getViewerRowFromItem_package( | |
101 t.getSelection()[0]).getCell(cell.getColumnIndex())); | |
102 } | |
103 } | |
104 | |
105 return super.getFocusCell(); | |
106 } | |
107 | |
108 } |