1 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 29 public class TableViewerRow extends ViewerRow { 30 private TableItem item; 31 32 36 TableViewerRow(TableItem item) { 37 this.item = item; 38 } 39 40 43 public Rectangle getBounds(int columnIndex) { 44 return item.getBounds(columnIndex); 45 } 46 47 50 public Rectangle getBounds() { 51 return item.getBounds(); 52 } 53 54 57 public Widget getItem() { 58 return item; 59 } 60 61 void setItem(TableItem item) { 62 this.item = item; 63 } 64 65 68 public int getColumnCount() { 69 return item.getParent().getColumnCount(); 70 } 71 72 75 public Color getBackground(int columnIndex) { 76 return item.getBackground(columnIndex); 77 } 78 79 82 public Font getFont(int columnIndex) { 83 return item.getFont(columnIndex); 84 } 85 86 89 public Color getForeground(int columnIndex) { 90 return item.getForeground(columnIndex); 91 } 92 93 96 public Image getImage(int columnIndex) { 97 return item.getImage(columnIndex); 98 } 99 100 103 public String getText(int columnIndex) { 104 return item.getText(columnIndex); 105 } 106 107 110 public void setBackground(int columnIndex, Color color) { 111 item.setBackground(columnIndex, color); 112 } 113 114 117 public void setFont(int columnIndex, Font font) { 118 item.setFont(columnIndex, font); 119 } 120 121 124 public void setForeground(int columnIndex, Color color) { 125 item.setForeground(columnIndex, color); 126 } 127 128 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 141 public void setText(int columnIndex, String text) { 142 item.setText(columnIndex, text == null ? "" : text); } 144 145 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 ("Illegal value of direction argument."); } 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 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 [] {item.getData()}); 189 } 190 191 public Object clone() { 192 return new TableViewerRow(item); 193 } 194 195 public Object getElement() { 196 return item.getData(); 197 } 198 } 199 | Popular Tags |