10
|
1 /*******************************************************************************
|
|
2 * Copyright (c) 2006, 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 * Tom Shindl <tom.schindl@bestsolution.at> - initial API and implementation
|
|
11 * - Fix for bug 174355
|
|
12 * Port to the D programming language:
|
|
13 * Frank Benoit <benoit@tionex.de>
|
|
14 *******************************************************************************/
|
|
15
|
|
16 module dwtx.jface.viewers.TableViewerRow;
|
|
17
|
|
18 import dwtx.jface.viewers.ViewerRow;
|
|
19 import dwtx.jface.viewers.TreePath;
|
|
20
|
|
21 import dwt.graphics.Color;
|
|
22 import dwt.graphics.Font;
|
|
23 import dwt.graphics.Image;
|
|
24 import dwt.graphics.Rectangle;
|
|
25 import dwt.widgets.Control;
|
|
26 import dwt.widgets.TableItem;
|
|
27 import dwt.widgets.Widget;
|
|
28
|
|
29 import dwt.dwthelper.utils;
|
|
30
|
|
31 /**
|
|
32 * TableViewerRow is the Table specific implementation of ViewerRow
|
|
33 * @since 3.3
|
|
34 *
|
|
35 */
|
|
36 public class TableViewerRow : ViewerRow {
|
|
37 private TableItem item;
|
|
38
|
|
39 /**
|
|
40 * Create a new instance of the receiver from item.
|
|
41 * @param item
|
|
42 */
|
|
43 this(TableItem item) {
|
|
44 this.item = item;
|
|
45 }
|
|
46
|
|
47 /* (non-Javadoc)
|
|
48 * @see dwtx.jface.viewers.ViewerRow#getBounds(int)
|
|
49 */
|
|
50 public Rectangle getBounds(int columnIndex) {
|
|
51 return item.getBounds(columnIndex);
|
|
52 }
|
|
53
|
|
54 /* (non-Javadoc)
|
|
55 * @see dwtx.jface.viewers.ViewerRow#getBounds()
|
|
56 */
|
|
57 public Rectangle getBounds() {
|
|
58 return item.getBounds();
|
|
59 }
|
|
60
|
|
61 /* (non-Javadoc)
|
|
62 * @see dwtx.jface.viewers.ViewerRow#getItem()
|
|
63 */
|
|
64 public Widget getItem() {
|
|
65 return item;
|
|
66 }
|
|
67
|
|
68 void setItem(TableItem item) {
|
|
69 this.item = item;
|
|
70 }
|
|
71
|
|
72 /* (non-Javadoc)
|
|
73 * @see dwtx.jface.viewers.ViewerRow#getColumnCount()
|
|
74 */
|
|
75 public int getColumnCount() {
|
|
76 return item.getParent().getColumnCount();
|
|
77 }
|
|
78
|
|
79 /* (non-Javadoc)
|
|
80 * @see dwtx.jface.viewers.ViewerRow#getBackground(int)
|
|
81 */
|
|
82 public Color getBackground(int columnIndex) {
|
|
83 return item.getBackground(columnIndex);
|
|
84 }
|
|
85
|
|
86 /* (non-Javadoc)
|
|
87 * @see dwtx.jface.viewers.ViewerRow#getFont(int)
|
|
88 */
|
|
89 public Font getFont(int columnIndex) {
|
|
90 return item.getFont(columnIndex);
|
|
91 }
|
|
92
|
|
93 /* (non-Javadoc)
|
|
94 * @see dwtx.jface.viewers.ViewerRow#getForeground(int)
|
|
95 */
|
|
96 public Color getForeground(int columnIndex) {
|
|
97 return item.getForeground(columnIndex);
|
|
98 }
|
|
99
|
|
100 /* (non-Javadoc)
|
|
101 * @see dwtx.jface.viewers.ViewerRow#getImage(int)
|
|
102 */
|
|
103 public Image getImage(int columnIndex) {
|
|
104 return item.getImage(columnIndex);
|
|
105 }
|
|
106
|
|
107 /* (non-Javadoc)
|
|
108 * @see dwtx.jface.viewers.ViewerRow#getText(int)
|
|
109 */
|
|
110 public String getText(int columnIndex) {
|
|
111 return item.getText(columnIndex);
|
|
112 }
|
|
113
|
|
114 /* (non-Javadoc)
|
|
115 * @see dwtx.jface.viewers.ViewerRow#setBackground(int, dwt.graphics.Color)
|
|
116 */
|
|
117 public void setBackground(int columnIndex, Color color) {
|
|
118 item.setBackground(columnIndex, color);
|
|
119 }
|
|
120
|
|
121 /* (non-Javadoc)
|
|
122 * @see dwtx.jface.viewers.ViewerRow#setFont(int, dwt.graphics.Font)
|
|
123 */
|
|
124 public void setFont(int columnIndex, Font font) {
|
|
125 item.setFont(columnIndex, font);
|
|
126 }
|
|
127
|
|
128 /* (non-Javadoc)
|
|
129 * @see dwtx.jface.viewers.ViewerRow#setForeground(int, dwt.graphics.Color)
|
|
130 */
|
|
131 public void setForeground(int columnIndex, Color color) {
|
|
132 item.setForeground(columnIndex, color);
|
|
133 }
|
|
134
|
|
135 /* (non-Javadoc)
|
|
136 * @see dwtx.jface.viewers.ViewerRow#setImage(int, dwt.graphics.Image)
|
|
137 */
|
|
138 public void setImage(int columnIndex, Image image) {
|
|
139 Image oldImage = item.getImage(columnIndex);
|
|
140 if (oldImage !is image) {
|
|
141 item.setImage(columnIndex,image);
|
|
142 }
|
|
143 }
|
|
144
|
|
145 /* (non-Javadoc)
|
|
146 * @see dwtx.jface.viewers.ViewerRow#setText(int, java.lang.String)
|
|
147 */
|
|
148 public void setText(int columnIndex, String text) {
|
|
149 item.setText(columnIndex, text is null ? "" : text); //$NON-NLS-1$
|
|
150 }
|
|
151
|
|
152 /* (non-Javadoc)
|
|
153 * @see dwtx.jface.viewers.ViewerRow#getControl()
|
|
154 */
|
|
155 public Control getControl() {
|
|
156 return item.getParent();
|
|
157 }
|
|
158
|
|
159 public ViewerRow getNeighbor(int direction, bool sameLevel) {
|
|
160 if( direction is ViewerRow.ABOVE ) {
|
|
161 return getRowAbove();
|
|
162 } else if( direction is ViewerRow.BELOW ) {
|
|
163 return getRowBelow();
|
|
164 } else {
|
|
165 throw new IllegalArgumentException("Illegal value of direction argument."); //$NON-NLS-1$
|
|
166 }
|
|
167 }
|
|
168
|
|
169
|
|
170 private ViewerRow getRowAbove() {
|
|
171 int index = item.getParent().indexOf(item) - 1;
|
|
172
|
|
173 if( index >= 0 ) {
|
|
174 return new TableViewerRow(item.getParent().getItem(index));
|
|
175 }
|
|
176
|
|
177 return null;
|
|
178 }
|
|
179
|
|
180 private ViewerRow getRowBelow() {
|
|
181 int index = item.getParent().indexOf(item) + 1;
|
|
182
|
|
183 if( index < item.getParent().getItemCount() ) {
|
|
184 TableItem tmp = item.getParent().getItem(index);
|
|
185 //TODO NULL can happen in case of VIRTUAL => How do we deal with that
|
|
186 if( tmp !is null ) {
|
|
187 return new TableViewerRow(tmp);
|
|
188 }
|
|
189 }
|
|
190
|
|
191 return null;
|
|
192 }
|
|
193
|
|
194 public TreePath getTreePath() {
|
|
195 return new TreePath([item.getData()]);
|
|
196 }
|
|
197
|
|
198 public Object clone() {
|
|
199 return new TableViewerRow(item);
|
|
200 }
|
|
201
|
|
202 public Object getElement() {
|
|
203 return item.getData();
|
|
204 }
|
|
205 }
|