if (index < 0) {
// Trigger a Table._getItem, which assigns the item to the array
// in Table, so indexOf(..) can find it. This is a workaround for
// a WinXP bug.
Rectangle r = item.getBounds(0);
table.getItem(new Point(r.x, r.y));
index = table.indexOf(item);
if (index < 0)
return;
}
if (index % 2 == 0)
item.setBackground(ROW_ALTERNATE_COLOR_2);
else
item.setBackground(ROW_ALTERNATE_COLOR_1);
TableColumn tableColumn = tableColumns.get(index);
//String sTitleLanguageKey = tableColumn.getTitleLanguageKey();
item.setText(0, tableColumn.getText());
item.setText(1, (String)tableColumn.getData(SWTConstants.COLUMN_DESC_KEY));
//Causes SetData listener to be triggered again, which messes up SWT
//table.getColumn(1).pack();
final boolean bChecked = ((Boolean) newEnabledState.get(tableColumn));
item.setChecked(bChecked);
}
});
table.setItemCount(tableColumns.size());
table.addMouseListener(new MouseAdapter() {
public void mouseDown(MouseEvent arg0) {
mousePressed = true;
selectedItem = table.getItem(new Point(arg0.x,arg0.y));
}
public void mouseUp(MouseEvent e) {
mousePressed = false;
//1. Restore old image
if(oldPoint != null) {
table.redraw(oldPoint.x, oldPoint.y, shell.getSize().x,
oldPoint.y + 2, false);
oldPoint = null;
}
Point p = new Point(e.x,e.y);
TableItem item = table.getItem(p);
if(item != null && selectedItem != null) {
int index = table.indexOf(item);
int oldIndex = table.indexOf(selectedItem);
if(index == oldIndex)
return;
TableColumn tableColumn =
(TableColumn)tableColumns.get(oldIndex);
tableColumns.remove(tableColumn);
tableColumns.add(index, tableColumn);
table.clearAll();
}
}
});
table.addMouseMoveListener(new MouseMoveListener(){
public void mouseMove(MouseEvent e) {
if (!mousePressed || selectedItem == null)
return;
Point p = new Point(e.x,e.y);
TableItem item = table.getItem(p);
if (item == null)
return;
Rectangle bounds = item.getBounds(0);
int selectedPosition = table.indexOf(selectedItem);
int newPosition = table.indexOf(item);
//1. Restore old area
if(oldPoint != null) {
table.redraw(oldPoint.x, oldPoint.y, bounds.width, oldPoint.y + 2, false);
oldPoint = null;
}
bounds.y += VerticalAligner.getTableAdjustVerticalBy(table);
if(newPosition <= selectedPosition)
oldPoint = new Point(bounds.x,bounds.y);
else
oldPoint = new Point(bounds.x,bounds.y+bounds.height);
//3. Draw a thick line
table.redraw(oldPoint.x, oldPoint.y, bounds.width, oldPoint.y + 2, false);
}
});
table.addPaintListener(new PaintListener() {
public void paintControl(PaintEvent e) {
if (!mousePressed || selectedItem == null || oldPoint == null) {
return;
}
Point p = new Point(e.x,e.y);
TableItem item = table.getItem(p);
if (item == null)
return;
Rectangle bounds = item.getBounds(0);
GC gc = new GC(table);
gc.setBackground(blue);
gc.fillRectangle(oldPoint.x,oldPoint.y,bounds.width,2);
gc.dispose();
}
});
shell.pack();
Point p = shell.getSize();
p.x = 550;
// For Windows, to get rid of the scrollbar
p.y += 2;
if (p.y + 64 > display.getClientArea().height)