cellTable.addColumn(columnMeta.getColumn(), columnMeta.getHeader());
}
}
public ToggleButton createToggleButton() {
final ToggleButton button = new ToggleButton(COLUMN_PICKER_IMAGE);
final PopupPanel popup = new PopupPanel(true);
popup.addCloseHandler(new CloseHandler<PopupPanel>() {
public void onClose(CloseEvent<PopupPanel> popupPanelCloseEvent) {
button.setDown(false);
}
});
VerticalPanel popupContent = new VerticalPanel();
for (final ColumnMeta<T> columnMeta : columnMetaList) {
final CheckBox checkBox = new CheckBox(columnMeta.getHeader().getValue());
checkBox.setValue(columnMeta.isVisible());
checkBox.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
public void onValueChange(ValueChangeEvent<Boolean> booleanValueChangeEvent) {
boolean visible = booleanValueChangeEvent.getValue();
if (visible) {
// WORKAROUND because CellTable does not support insertColumn at this time
for (ColumnMeta<T> resettingColumnMeta : columnMetaList) {
if (resettingColumnMeta.isVisible()) {
cellTable.removeColumn(resettingColumnMeta.getColumn());
}
}
columnMeta.setVisible(visible);
for (ColumnMeta<T> resettingColumnMeta : columnMetaList) {
if (resettingColumnMeta.isVisible()) {
cellTable.addColumn(resettingColumnMeta.getColumn(), resettingColumnMeta.getHeader());
}
}
} else {
columnMeta.setVisible(visible);
cellTable.removeColumn(columnMeta.getColumn());
}
}
});
popupContent.add(checkBox);
}
popup.add(popupContent);
button.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
if (button.isDown()) {
popup.setPopupPosition(button.getAbsoluteLeft(), button.getAbsoluteTop() + button.getOffsetHeight());
popup.show();
}
// Note: no need to hide the popup when clicked when down,
// because clicking anywhere outside the popup will hide the popup
}