KickJava   Java API By Example, From Geeks To Geeks.

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


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  *******************************************************************************/

13
14 package org.eclipse.jface.viewers;
15
16 import org.eclipse.swt.graphics.Color;
17 import org.eclipse.swt.graphics.Font;
18 import org.eclipse.swt.graphics.Image;
19 import org.eclipse.swt.graphics.Rectangle;
20 import org.eclipse.swt.widgets.Control;
21 import org.eclipse.swt.widgets.TableItem;
22 import org.eclipse.swt.widgets.Widget;
23
24 /**
25  * TableViewerRow is the Table specific implementation of ViewerRow
26  * @since 3.3
27  *
28  */

29 public class TableViewerRow extends ViewerRow {
30     private TableItem item;
31     
32     /**
33      * Create a new instance of the receiver from item.
34      * @param item
35      */

36     TableViewerRow(TableItem item) {
37         this.item = item;
38     }
39     
40     /* (non-Javadoc)
41      * @see org.eclipse.jface.viewers.ViewerRow#getBounds(int)
42      */

43     public Rectangle getBounds(int columnIndex) {
44         return item.getBounds(columnIndex);
45     }
46
47     /* (non-Javadoc)
48      * @see org.eclipse.jface.viewers.ViewerRow#getBounds()
49      */

50     public Rectangle getBounds() {
51         return item.getBounds();
52     }
53
54     /* (non-Javadoc)
55      * @see org.eclipse.jface.viewers.ViewerRow#getItem()
56      */

57     public Widget getItem() {
58         return item;
59     }
60
61     void setItem(TableItem item) {
62         this.item = item;
63     }
64     
65     /* (non-Javadoc)
66      * @see org.eclipse.jface.viewers.ViewerRow#getColumnCount()
67      */

68     public int getColumnCount() {
69         return item.getParent().getColumnCount();
70     }
71
72     /* (non-Javadoc)
73      * @see org.eclipse.jface.viewers.ViewerRow#getBackground(int)
74      */

75     public Color getBackground(int columnIndex) {
76         return item.getBackground(columnIndex);
77     }
78
79     /* (non-Javadoc)
80      * @see org.eclipse.jface.viewers.ViewerRow#getFont(int)
81      */

82     public Font getFont(int columnIndex) {
83         return item.getFont(columnIndex);
84     }
85
86     /* (non-Javadoc)
87      * @see org.eclipse.jface.viewers.ViewerRow#getForeground(int)
88      */

89     public Color getForeground(int columnIndex) {
90         return item.getForeground(columnIndex);
91     }
92
93     /* (non-Javadoc)
94      * @see org.eclipse.jface.viewers.ViewerRow#getImage(int)
95      */

96     public Image getImage(int columnIndex) {
97         return item.getImage(columnIndex);
98     }
99
100     /* (non-Javadoc)
101      * @see org.eclipse.jface.viewers.ViewerRow#getText(int)
102      */

103     public String JavaDoc getText(int columnIndex) {
104         return item.getText(columnIndex);
105     }
106
107     /* (non-Javadoc)
108      * @see org.eclipse.jface.viewers.ViewerRow#setBackground(int, org.eclipse.swt.graphics.Color)
109      */

110     public void setBackground(int columnIndex, Color color) {
111         item.setBackground(columnIndex, color);
112     }
113
114     /* (non-Javadoc)
115      * @see org.eclipse.jface.viewers.ViewerRow#setFont(int, org.eclipse.swt.graphics.Font)
116      */

117     public void setFont(int columnIndex, Font font) {
118         item.setFont(columnIndex, font);
119     }
120
121     /* (non-Javadoc)
122      * @see org.eclipse.jface.viewers.ViewerRow#setForeground(int, org.eclipse.swt.graphics.Color)
123      */

124     public void setForeground(int columnIndex, Color color) {
125         item.setForeground(columnIndex, color);
126     }
127
128     /* (non-Javadoc)
129      * @see org.eclipse.jface.viewers.ViewerRow#setImage(int, org.eclipse.swt.graphics.Image)
130      */

131     public void setImage(int columnIndex, Image image) {
132         Image oldImage = item.getImage(columnIndex);
133         if (oldImage != image) {
134             item.setImage(columnIndex,image);
135         }
136     }
137
138     /* (non-Javadoc)
139      * @see org.eclipse.jface.viewers.ViewerRow#setText(int, java.lang.String)
140      */

141     public void setText(int columnIndex, String JavaDoc text) {
142         item.setText(columnIndex, text == null ? "" : text); //$NON-NLS-1$
143
}
144     
145     /* (non-Javadoc)
146      * @see org.eclipse.jface.viewers.ViewerRow#getControl()
147      */

148     public Control getControl() {
149         return item.getParent();
150     }
151
152     public ViewerRow getNeighbor(int direction, boolean sameLevel) {
153         if( direction == ViewerRow.ABOVE ) {
154             return getRowAbove();
155         } else if( direction == ViewerRow.BELOW ) {
156             return getRowBelow();
157         } else {
158             throw new IllegalArgumentException JavaDoc("Illegal value of direction argument."); //$NON-NLS-1$
159
}
160     }
161
162     
163     private ViewerRow getRowAbove() {
164         int index = item.getParent().indexOf(item) - 1;
165         
166         if( index >= 0 ) {
167             return new TableViewerRow(item.getParent().getItem(index));
168         }
169         
170         return null;
171     }
172
173     private ViewerRow getRowBelow() {
174         int index = item.getParent().indexOf(item) + 1;
175         
176         if( index < item.getParent().getItemCount() ) {
177             TableItem tmp = item.getParent().getItem(index);
178             //TODO NULL can happen in case of VIRTUAL => How do we deal with that
179
if( tmp != null ) {
180                 return new TableViewerRow(tmp);
181             }
182         }
183         
184         return null;
185     }
186
187     public TreePath getTreePath() {
188         return new TreePath(new Object JavaDoc[] {item.getData()});
189     }
190     
191     public Object JavaDoc clone() {
192         return new TableViewerRow(item);
193     }
194             
195     public Object JavaDoc getElement() {
196         return item.getData();
197     }
198 }
199
Popular Tags