}
private void addEditorToValueSetTable()
{
// Create an editor object to use for text editing
final TableEditor editor = new TableEditor(valueSetTable);
editor.horizontalAlignment = SWT.LEFT;
editor.grabHorizontal = true;
// Use a mouse listener, not a selection listener, since we're interested
// in the selected column as well as row
valueSetTable.addMouseListener(new MouseAdapter()
{
public void mouseDown(MouseEvent event)
{
// Dispose any existing editor
Control old = editor.getEditor();
if (old != null)
old.dispose();
// Determine where the mouse was clicked
Point pt = new Point(event.x, event.y);
// Determine which row was selected
final TableItem item = valueSetTable.getItem(pt);
if (item != null)
{
// Determine which column was selected
int column = -1;
for (int i = 0, n = valueSetTable.getColumnCount(); i < n; i++)
{
Rectangle rect = item.getBounds(i);
if (rect.contains(pt))
{
// This is the selected column
column = i;
break;
}
}
// Column 2 holds dropdowns
if (column == 0)
{
// Create the dropdown and add data to it
final CCombo combo = new CCombo(valueSetTable, SWT.READ_ONLY);
// for (int i = 0, n = sdps.keySet().size(); i < n; i++)
// {
// combo.add(sdps.keySet().toArray()[i].toString());
// }
for (String key : sdps)
{
if (getItemIfPresent(key) == null
|| item.getText(column).equals(key))
{
combo.add(key);
}
}
// Select the previously selected item from the cell
combo.select(combo.indexOf(item.getText(column)));
// Compute the width for the editor
// Also, compute the column width, so that the dropdown fits
editor.minimumWidth = combo.computeSize(SWT.DEFAULT, SWT.DEFAULT).x;
if (valueSetTable.getColumn(column).getWidth() < editor.minimumWidth)
{
valueSetTable.getColumn(column).setWidth(editor.minimumWidth);
}
// Set the focus on the dropdown and set into the editor
combo.setFocus();
editor.setEditor(combo, item, column);
// combo.addModifyListener(fListener);
// Add a listener to set the selected item back into the cell
final int col = column;
combo.addSelectionListener(new SelectionAdapter()
{
public void widgetSelected(SelectionEvent event)
{
item.setText(col, combo.getText());
// setDirty(true);
// updateLaunchConfigurationDialog();
updateLaunchConfigurationDialog();
// They selected an item; end the editing session
combo.dispose();
Button a = new Button(valueSetTable, SWT.PUSH);
TableEditor editor = new TableEditor(valueSetTable);
a.setText("Delete");
a.computeSize(SWT.DEFAULT, valueSetTable.getItemHeight());
editor.grabHorizontal = true;
editor.minimumHeight = a.getSize().y;
editor.minimumWidth = a.getSize().x;
editor.setEditor(a, item, 2);
a.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent e) {
removeItem(valueSetTable, col, e);
}
public void widgetDefaultSelected(SelectionEvent e) {
}
});
}
});
} else if (column > 0)
{
// Create the Text object for our editor
final Text text = new Text(valueSetTable, SWT.NONE);
text.setForeground(item.getForeground());
// Transfer any text from the cell to the Text control,
// set the color to match this row, select the text,
// and set focus to the control
text.setText(item.getText(column));
text.setForeground(item.getForeground());
text.selectAll();
text.setFocus();
// Recalculate the minimum width for the editor
editor.minimumWidth = text.getBounds().width;
// Set the control into the editor
editor.setEditor(text, item, column);
// text.addModifyListener(fListener);
// Add a handler to transfer the text back to the cell
// any time it's modified