private TableColumnCore tableColumn;
public void dragStart(DragSourceEvent event) {
event.doit = true;
TableOrTreeSWT table = TableOrTreeUtils.getTableOrTreeSWT(((DragSource) event.widget).getControl());
TableView tv = (TableView) table.getData("TableView");
// drag start happens a bit after the mouse moves, so the
// cursor location isn't accurate
//Point cursorLocation = event.display.getCursorLocation();
//cursorLocation = tv.getTableComposite().toControl(cursorLocation);
//TableRowCore row = tv.getRow(cursorLocation.x, cursorLocation.y);
//System.out.println("" + event.x + ";" + event.y + "/" + cursorLocation);
// event.x and y doesn't always return correct values!
//TableRowCore row = tv.getRow(event.x, event.y);
TableRowCore row = tv.getFocusedRow();
if (row == null) {
event.doit = false;
return;
}
tableColumn = (TableColumnCore) row.getDataSource();
if (event.image != null && !Constants.isLinux) {
try {
GC gc = new GC(event.image);
try {
Rectangle bounds = event.image.getBounds();
gc.fillRectangle(bounds);
String title = MessageText.getString(
tableColumn.getTitleLanguageKey(), tableColumn.getName());
String s = title
+ " Column will be placed at the location you drop it, shifting other columns down";
GCStringPrinter sp = new GCStringPrinter(gc, s, bounds, false, false,
SWT.CENTER | SWT.WRAP);
sp.calculateMetrics();
if (sp.isCutoff()) {
GCStringPrinter.printString(gc, title, bounds, false, false,
SWT.CENTER | SWT.WRAP);
} else {
sp.printString();
}
} finally {
gc.dispose();
}
} catch (Throwable t) {
//ignore
}
}
}
public void dragSetData(DragSourceEvent event) {
TableOrTreeSWT table = TableOrTreeUtils.getTableOrTreeSWT(((DragSource) event.widget).getControl());
TableView tv = (TableView) table.getData("TableView");
event.data = "" + (tv == tvChosen ? "c" : "a");
}
public void dragFinished(DragSourceEvent event) {
}