body.getStyles().put("wrapText", true);
final Prompt prompt = new Prompt(MessageType.QUESTION, message, options, body);
prompt.setSelectedOptionIndex(0);
prompt.open(TablePanes.this, new SheetCloseListener() {
@Override
public void sheetClosed(Sheet sheet) {
if (prompt.getResult() && prompt.getSelectedOptionIndex() == 0) {
int rowIndex = tablePane.getRowAt(contextMenuHandler.getY());
tablePane.getRows().remove(rowIndex, 1);
}
}
});
}
});
namedActions.put("configureColumn", new Action() {
@Override
public void perform(Component source) {
BXMLSerializer bxmlSerializer = new BXMLSerializer();
Sheet sheet;
// Make the selected column available to script blocks
int columnIndex = tablePane.getColumnAt(contextMenuHandler.getX());
TablePane.Column column = tablePane.getColumns().get(columnIndex);
bxmlSerializer.getNamespace().put("column", column);
try {
sheet = (Sheet)bxmlSerializer.readObject(TablePanes.class,
"table_panes_configure_column.bxml");
} catch (SerializationException exception) {
throw new RuntimeException(exception);
} catch (IOException exception) {
throw new RuntimeException(exception);
}
sheet.open(TablePanes.this);
}
});
namedActions.put("insertColumn", new Action() {
@Override
public void perform(Component source) {
BXMLSerializer bxmlSerializer = new BXMLSerializer();
Sheet sheet;
// Create and insert a new column
TablePane.Column column = new TablePane.Column();
int columnIndex = tablePane.getColumnAt(contextMenuHandler.getX());
tablePane.getColumns().insert(column, columnIndex);
// Populate the column with the expected content
TablePane.RowSequence rows = tablePane.getRows();
rows.get(0).insert(new Label("-1"), columnIndex);
for (int i = 1, n = rows.getLength(); i < n; i++) {
Panel panel = new Panel();
panel.getStyles().put("backgroundColor", "#dddcd5");
rows.get(i).insert(panel, columnIndex);
}
// Make the new column available to script blocks
bxmlSerializer.getNamespace().put("column", column);
try {
sheet = (Sheet)bxmlSerializer.readObject(TablePanes.class,
"table_panes_configure_column.bxml");
} catch (SerializationException exception) {
throw new RuntimeException(exception);
} catch (IOException exception) {
throw new RuntimeException(exception);
}
sheet.open(TablePanes.this);
}
});
namedActions.put("removeColumn", new Action() {
@Override
public void perform(Component source) {
ArrayList<String> options = new ArrayList<String>("OK", "Cancel");
String message = "Remove Column?";
Label body = new Label("Are you sure you want to remove the column?");
body.getStyles().put("wrapText", true);
final Prompt prompt = new Prompt(MessageType.QUESTION, message, options, body);
prompt.setSelectedOptionIndex(0);
prompt.open(TablePanes.this, new SheetCloseListener() {
@Override
public void sheetClosed(Sheet sheet) {
if (prompt.getResult() && prompt.getSelectedOptionIndex() == 0) {
int columnIndex = tablePane.getColumnAt(contextMenuHandler.getX());