KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jface > viewers > ViewerRow


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 166346, bug 167325s
12  * - Fix for bug 174355
13  *******************************************************************************/

14
15 package org.eclipse.jface.viewers;
16
17 import org.eclipse.swt.graphics.Color;
18 import org.eclipse.swt.graphics.Font;
19 import org.eclipse.swt.graphics.Image;
20 import org.eclipse.swt.graphics.Point;
21 import org.eclipse.swt.graphics.Rectangle;
22 import org.eclipse.swt.widgets.Control;
23 import org.eclipse.swt.widgets.Widget;
24
25 /**
26  * ViewerRow is the abstract superclass of the part that represents items in a
27  * Table or Tree. Implementors of {@link ColumnViewer} have to provide a
28  * concrete implementation for the underlying widget
29  *
30  * @since 3.3
31  *
32  */

33 public abstract class ViewerRow implements Cloneable JavaDoc {
34
35     /**
36      * Constant denoting the row above the current one (value is 1).
37      *
38      * @see #getNeighbor(int, boolean)
39      */

40     public static final int ABOVE = 1;
41
42     /**
43      * Constant denoting the row below the current one (value is 2).
44      *
45      * @see #getNeighbor(int, boolean)
46      */

47     public static final int BELOW = 2;
48
49     /**
50      * Get the bounds of the entry at the columnIndex,
51      *
52      * @param columnIndex
53      * @return {@link Rectangle}
54      */

55     public abstract Rectangle getBounds(int columnIndex);
56
57     /**
58      * Return the bounds for the whole item.
59      *
60      * @return {@link Rectangle}
61      */

62     public abstract Rectangle getBounds();
63
64     /**
65      * Return the item for the receiver.
66      *
67      * @return {@link Widget}
68      */

69     public abstract Widget getItem();
70
71     /**
72      * Return the number of columns for the receiver.
73      *
74      * @return the number of columns
75      */

76     public abstract int getColumnCount();
77
78     /**
79      * Return the image at the columnIndex.
80      *
81      * @param columnIndex
82      * @return {@link Image} or <code>null</code>
83      */

84     public abstract Image getImage(int columnIndex);
85
86     /**
87      * Set the image at the columnIndex
88      *
89      * @param columnIndex
90      * @param image
91      */

92     public abstract void setImage(int columnIndex, Image image);
93
94     /**
95      * Get the text at the columnIndex.
96      *
97      * @param columnIndex
98      * @return {@link String}
99      */

100     public abstract String JavaDoc getText(int columnIndex);
101
102     /**
103      * Set the text at the columnIndex
104      *
105      * @param columnIndex
106      * @param text
107      */

108     public abstract void setText(int columnIndex, String JavaDoc text);
109
110     /**
111      * Get the background at the columnIndex,
112      *
113      * @param columnIndex
114      * @return {@link Color} or <code>null</code>
115      */

116     public abstract Color getBackground(int columnIndex);
117
118     /**
119      * Set the background at the columnIndex.
120      *
121      * @param columnIndex
122      * @param color
123      */

124     public abstract void setBackground(int columnIndex, Color color);
125
126     /**
127      * Get the foreground at the columnIndex.
128      *
129      * @param columnIndex
130      * @return {@link Color} or <code>null</code>
131      */

132     public abstract Color getForeground(int columnIndex);
133
134     /**
135      * Set the foreground at the columnIndex.
136      *
137      * @param columnIndex
138      * @param color
139      */

140     public abstract void setForeground(int columnIndex, Color color);
141
142     /**
143      * Get the font at the columnIndex.
144      *
145      * @param columnIndex
146      * @return {@link Font} or <code>null</code>
147      */

148     public abstract Font getFont(int columnIndex);
149
150     /**
151      * Set the {@link Font} at the columnIndex.
152      *
153      * @param columnIndex
154      * @param font
155      */

156     public abstract void setFont(int columnIndex, Font font);
157
158     /**
159      * Get the ViewerCell at point.
160      *
161      * @param point
162      * @return {@link ViewerCell}
163      */

164     public ViewerCell getCell(Point point) {
165         int index = getColumnIndex(point);
166         return getCell(index);
167     }
168
169     /**
170      * Get the columnIndex of the point.
171      *
172      * @param point
173      * @return int or -1 if it cannot be found.
174      */

175     public int getColumnIndex(Point point) {
176         int count = getColumnCount();
177
178         // If there are no columns the column-index is 0
179
if (count == 0) {
180             return 0;
181         }
182
183         for (int i = 0; i < count; i++) {
184             if (getBounds(i).contains(point)) {
185                 return i;
186             }
187         }
188
189         return -1;
190     }
191
192     /**
193      * Get a ViewerCell for the column at index.
194      *
195      * @param column
196      * @return {@link ViewerCell} or <code>null</code> if the index is
197      * negative.
198      */

199     public ViewerCell getCell(int column) {
200         if (column >= 0)
201             return new ViewerCell((ViewerRow) clone(), column, getElement());
202
203         return null;
204     }
205
206     /**
207      * Get the Control for the receiver.
208      *
209      * @return {@link Control}
210      */

211     public abstract Control getControl();
212
213     /**
214      * Returns a neighboring row, or <code>null</code> if no neighbor exists
215      * in the given direction. If <code>sameLevel</code> is <code>true</code>,
216      * only sibling rows (under the same parent) will be considered.
217      *
218      * @param direction
219      * the direction {@link #BELOW} or {@link #ABOVE}
220      *
221      * @param sameLevel
222      * if <code>true</code>, search only within sibling rows
223      * @return the row above/below, or <code>null</code> if not found
224      */

225     public abstract ViewerRow getNeighbor(int direction, boolean sameLevel);
226
227     /**
228      * The tree path used to identify an element by the unique path
229      *
230      * @return the path
231      */

232     public abstract TreePath getTreePath();
233
234     public abstract Object JavaDoc clone();
235
236     /**
237      * @return the model element
238      */

239     public abstract Object JavaDoc getElement();
240
241     public int hashCode() {
242         final int prime = 31;
243         int result = 1;
244         result = prime * result
245                 + ((getItem() == null) ? 0 : getItem().hashCode());
246         return result;
247     }
248
249     public boolean equals(Object JavaDoc obj) {
250         if (this == obj)
251             return true;
252         if (obj == null)
253             return false;
254         if (getClass() != obj.getClass())
255             return false;
256         final ViewerRow other = (ViewerRow) obj;
257         if (getItem() == null) {
258             if (other.getItem() != null)
259                 return false;
260         } else if (!getItem().equals(other.getItem()))
261             return false;
262         return true;
263     }
264
265 }
266
Popular Tags