I've currently implemented a Table with a TableEditor in my Eclipse plugin to support cell-level editing with keyboard support (to traverse cells with the editor).
I also need a way to delete rows, and I didn't want to go with the practice of adding a delete button next to the table as it requires 2 clicks to delete a row (1 to select a row, and 1 to delete it). Instead I want a separate column which is populated with delete icons. I've thought of 2 ways to accomplish this and have run into issues with both:
Add another column to the Table, set the icon with TableItem.setImage(). There are multiple issues with this approach, and you can see them below:

Add a ScrolledComposite next to the table and fill it with delete icons. This sounds a little insane, but I've actually made it pretty far with this one. The idea is to fill a ScrolledComposite with delete icons, force it to scroll with the table's scrollbar, and delete the corresponding row when an icon is clicked. I've only run into one blocking issue with this approach:

So my questions are:
I found a way to hide the scrollbar for my 2nd approach. Basically all you need to do is:
// ScrolledComposite sc;
sc.setAlwaysShowScrollBars(true);
sc.getVerticalBar().setVisible(false);
And then set the width of the ScrolledComposite to 1 to get rid of the extra space the invisible ScrollBar takes up.
And to keep the scrollbars in sync:
// Table table;
// ScrolledComposite sc;
// int tableRowHeight;
protected void createTable() {
...
// Set the listener that dictates the table row height.
table.addListener(SWT.MeasureItem, new Listener() {
@Override
public void handleEvent(Event event) {
event.height = tableRowHeight;
}
});
// Set the listener for keeping the scrollbars in sync.
table.getVerticalBar().addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
syncDeleteColumnScrollBar();
}
});
}
// This is extracted out into a method so it can also be called
// when removing a table row.
protected void syncDeleteColumnScrollBar() {
sc.setOrigin(0, table.getVerticalBar().getSelection() * tableRowHeight);
}
The result:

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With