Methods Summary |
---|
private boolean | _isVisible()
// Least time consuming checks first
int index = table.indexOf(item);
if (index == -1)
return false;
int iTopIndex = table.getTopIndex();
if (index < iTopIndex)
return false;
int iBottomIndex = Utils.getTableBottomIndex(table, iTopIndex);
if (index > iBottomIndex)
return false;
return true;
|
public boolean | checkWidget(int checkFlags)Checks if the widget is valid
boolean bWidgetOk = !table.isDisposed() && item != null
&& !item.isDisposed() && item.getData("TableRow") == this;
final boolean bCheckVisibility = (checkFlags & REQUIRE_VISIBILITY) > 0;
final boolean bCheckInitialized = (checkFlags & REQUIRE_TABLEITEM_INITIALIZED) > 0;
if (bWidgetOk && bCheckInitialized) {
bWidgetOk = (table.getStyle() & SWT.VIRTUAL) == 0
|| item.getData("SD") != null;
}
if (bWidgetOk && bCheckVisibility) {
if (_isVisible()) {
// Caller assumes that a visible item can be modified, so
// make sure we initialize it.
if (!bCheckInitialized && (table.getStyle() & SWT.VIRTUAL) != 0
&& item.getData("SD") == null) {
// This is catch is temporary for SWT 3212, because there are cases where
// it says it isn't disposed, when it really almost is
try {
item.setData("SD", "1");
} catch (NullPointerException badSWT) {
}
setAlternatingBGColor(true);
setIconSize(ptIconSize);
invalidate();
}
} else {
bWidgetOk = false;
}
}
return bWidgetOk;
|
private void | copyToItem(org.eclipse.swt.widgets.TableItem newItem)
Table table = getTable();
if (table == null || item == null)
return;
// newItem.setText(text_values);
newItem.setImage(image_values);
Color colorFG = item.getForeground();
Color colorBG = item.getBackground();
newItem.setForeground(colorFG);
newItem.setBackground(colorBG);
int numColumns = table.getColumnCount();
for (int i = 0; i < numColumns; i++) {
try {
newItem.setText(i, item.getText(i));
Color colorColumnFG = item.getForeground(i);
Color colorColumnBG = item.getBackground(i);
if (!colorColumnFG.equals(colorFG))
newItem.setForeground(i, colorColumnFG);
if (!colorColumnBG.equals(colorBG))
newItem.setBackground(i, colorColumnBG);
} catch (NoSuchMethodError e) {
/* Ignore for Pre 3.0 SWT.. */
}
}
if (isSelected())
table.select(table.indexOf(newItem));
else
table.deselect(table.indexOf(newItem));
newItem.setData("TableRow", item.getData("TableRow"));
|
public void | createSWTRow()Create a row in the SWT table
item = new TableItem(table, SWT.NULL);
setAlternatingBGColor(true);
|
public void | createSWTRow(int index)
new TableItem(table, SWT.NULL);
setTableItem(index, false);
|
public void | dispose()Disposes of underlying SWT TableItem. If no TableItem has been
assigned to the row yet, an unused TableItem will be disposed of, if
available.
Disposing of fonts, colors and other resources are the responsibilty of
the caller.
if (table != null && !table.isDisposed() && Utils.isThisThreadSWT()) {
if (!checkWidget(REQUIRE_TABLEITEM)) {
// No assigned spot yet, or not our spot:
// find a row with no TableRow data
TableItem[] items = table.getItems();
for (int i = items.length - 1; i >= 0; i--) {
TableItem item = items[i];
if (!item.isDisposed()) {
Object itemRow = item.getData("TableRow");
if (itemRow == null || itemRow == this) {
this.item = item;
break;
}
}
}
}
if (item != null && !item.isDisposed())
item.dispose();
else if (table.getItemCount() > 0)
System.err.println("No table row was found to dispose");
} else {
if (!Utils.isThisThreadSWT()) {
System.err.println("Calling BufferedTableRow.dispose on non-SWT thread!");
System.err.println(Debug.getStackTrace(false, false));
}
}
item = null;
|
public org.eclipse.swt.graphics.Color | getBackground()
if (!checkWidget(REQUIRE_TABLEITEM_INITIALIZED))
return null;
return item.getBackground();
|
public org.eclipse.swt.graphics.Rectangle | getBounds(int index)
if (!checkWidget(REQUIRE_TABLEITEM_INITIALIZED))
return null;
// Some Platforms (OSX) don't handle getBounds properly (3.2M4) when
// item doesn't exist in table
if (table.indexOf(item) == -1)
return null;
Rectangle r = item.getBounds(index);
if (r == null || r.width == 0 || r.height == 0)
return null;
return r;
|
public org.eclipse.swt.graphics.Color | getForeground()
if (!checkWidget(REQUIRE_TABLEITEM_INITIALIZED))
return null;
return( item.getForeground());
|
public org.eclipse.swt.graphics.Color | getForeground(int index)
if (!checkWidget(REQUIRE_TABLEITEM_INITIALIZED))
return null;
if (index >= foreground_colors.length)
return item.getForeground();
return foreground_colors[index];
|
public org.eclipse.swt.graphics.Image | getImage(int index)
if (!checkWidget(REQUIRE_TABLEITEM_INITIALIZED))
return null;
return item.getImage(index);
|
public int | getIndex()The Index is this item's the position in list.
if (!checkWidget(REQUIRE_TABLEITEM))
return -1;
return table.indexOf(item);
|
protected org.eclipse.swt.widgets.Table | getTable()
return table;
|
protected java.lang.String | getText(int index)
if (!checkWidget(REQUIRE_TABLEITEM_INITIALIZED))
return "";
// SWT >= 3041(Win),3014(GTK),3002(Carbon) and returns "" if range check
// fails
return item.getText(index);
|
public void | invalidate()Overridable function that is called when row needs invalidation.
if (!checkWidget(REQUIRE_TABLEITEM_INITIALIZED | REQUIRE_VISIBILITY))
return;
Rectangle r = item.getBounds(0);
table.redraw(0, r.y, table.getClientArea().width, r.height, true);
|
public boolean | isSelected()
if (!checkWidget(REQUIRE_TABLEITEM))
return false;
// Invalid Indexes are checked/ignored by SWT.
return table.isSelected(table.indexOf(item));
|
public boolean | isVisible()Whether the row is currently visible to the user
return checkWidget(REQUIRE_VISIBILITY);
|
public void | setAlternatingBGColor(boolean bEvenIfNotVisible)
if (Utils.TABLE_GRIDLINE_IS_ALTERNATING_COLOR)
return;
if ((table.getStyle() & SWT.VIRTUAL) != 0 && !bEvenIfNotVisible
&& !isVisible()) {
return;
} else if (item == null || item.isDisposed()) {
return;
}
int index = table.indexOf(item);
if (index == -1) {
return;
}
if (alternatingColors == null || alternatingColors[1].isDisposed()) {
alternatingColors = new Color[] {
table.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND),
Colors.colorAltRow };
}
Color newColor = alternatingColors[index % alternatingColors.length];
if (!newColor.equals(getBackground()))
item.setBackground(newColor);
|
public void | setForeground(org.eclipse.swt.graphics.Color c)
if (!checkWidget(REQUIRE_TABLEITEM_INITIALIZED))
return;
if (foreground != null && foreground.equals(c))
return;
foreground = c;
item.setForeground(foreground);
|
public boolean | setForeground(int index, org.eclipse.swt.graphics.Color new_color)
if (!checkWidget(REQUIRE_TABLEITEM_INITIALIZED))
return false;
if ( index >= foreground_colors.length ){
int new_size = Math.max( index+1, foreground_colors.length+VALUE_SIZE_INC );
Color[] new_colors = new Color[new_size];
System.arraycopy( foreground_colors, 0, new_colors, 0, foreground_colors.length );
foreground_colors = new_colors;
}
Color value = foreground_colors[index];
if ( new_color == value ){
return false;
}
if ( new_color != null &&
value != null &&
new_color.equals( value )){
return false;
}
foreground_colors[index] = new_color;
try {
item.setForeground(index, new_color);
} catch (NoSuchMethodError e) {
/* Ignore for Pre 3.0 SWT.. */
}
return true;
|
public boolean | setHeight(int iHeight)
return setIconSize(new Point(1, iHeight));
|
public boolean | setIconSize(org.eclipse.swt.graphics.Point pt)
ptIconSize = pt;
if (pt == null)
return false;
if (!checkWidget(REQUIRE_TABLEITEM_INITIALIZED))
return false;
Image oldImage = item.getImage(0);
if (oldImage != null) {
Rectangle r = oldImage.getBounds();
if (r.width == pt.x && r.height == pt.y)
return false;
}
// set row height by setting image
Image image = new Image(item.getDisplay(), pt.x, pt.y);
item.setImage(0, image);
item.setImage(0, null);
image.dispose();
return true;
|
public void | setImage(int index, org.eclipse.swt.graphics.Image new_image)Sets the receiver's image at a column.
if (!checkWidget(REQUIRE_TABLEITEM_INITIALIZED))
return;
if ( index >= image_values.length ){
int new_size = Math.max( index+1, image_values.length+VALUE_SIZE_INC );
Image[] new_images = new Image[new_size];
System.arraycopy( image_values, 0, new_images, 0, image_values.length );
image_values = new_images;
}
Image image = image_values[index];
if ( new_image == image ){
return;
}
image_values[index] = new_image;
item.setImage( index, new_image );
|
public void | setSelected(boolean bSelected)
if (!checkWidget(REQUIRE_TABLEITEM))
return;
if (bSelected)
table.select(getIndex());
else
table.deselect(getIndex());
|
public boolean | setTableItem(int newIndex, boolean bCopyFromOld)Set the TableItem associated with this row to the TableItem at the
specified index.
TableItem newRow;
try {
newRow = table.getItem(newIndex);
} catch (IllegalArgumentException er) {
if (item == null || item.isDisposed()) {
return false;
}
item = null;
return true;
} catch (Throwable e) {
System.out.println("setTableItem(" + newIndex + ", " + bCopyFromOld + ")");
e.printStackTrace();
return false;
}
if (newRow.isDisposed()) {
Debug.out("newRow disposed from " + Debug.getCompressedStackTrace());
return false;
}
if (newRow == item) {
if (newRow == null || newRow.getData("TableRow") == this) {
setAlternatingBGColor(false);
return false;
}
}
if (newRow != null) {
if (newRow.getParent() != table)
return false;
if (bCopyFromOld) {
copyToItem(newRow);
} else if (newRow.getData("SD") != null) {
// clear causes too much flicker
//table.clear(table.indexOf(newRow));
newRow.setForeground(null);
//newRow.setBackground(null);
int numColumns = table.getColumnCount();
for (int i = 0; i < numColumns; i++) {
try {
newRow.setImage(i, null);
newRow.setForeground(i, null);
} catch (NoSuchMethodError e) {
/* Ignore for Pre 3.0 SWT.. */
}
}
} else {
newRow.setData("SD", "1");
setIconSize(ptIconSize);
}
setAlternatingBGColor(false);
try {
newRow.setData("TableRow", this);
} catch (Exception e) {
e.printStackTrace();
System.out.println("Disposed? " + newRow.isDisposed());
if (!newRow.isDisposed()) {
System.out.println("TR? " + newRow.getData("TableRow"));
System.out.println("SD? " + newRow.getData("SD"));
}
}
}
image_values = new Image[0];
foreground_colors = new Color[0];
foreground = null;
// unlink old item from tablerow
if (item != null && !item.isDisposed() && item.getData("TableRow") == this && newRow != item) {
item.setData("TableRow", null);
int numColumns = table.getColumnCount();
for (int i = 0; i < numColumns; i++) {
try {
item.setImage(i, null);
item.setForeground(i, null);
} catch (NoSuchMethodError e) {
/* Ignore for Pre 3.0 SWT.. */
}
}
}
item = newRow;
invalidate();
return true;
|
public boolean | setText(int index, java.lang.String new_value)
if (!checkWidget(REQUIRE_TABLEITEM_INITIALIZED))
return false;
if (index < 0 || index >= table.getColumnCount())
return false;
if (new_value == null)
new_value = "";
if (item.getText(index).equals(new_value))
return false;
item.setText( index, new_value );
return true;
|