if (label.viewable) {
labelPanel.setWidget(i, 0, new PLabel(nextViewableIndex + ""));
nextViewableIndex++;
}
final PHorizontalPanel panel = new PHorizontalPanel();
panel.setSizeFull();
panel.add(label);
final PHorizontalPanel simplePanel = new PHorizontalPanel();
final PHorizontalPanel buttonPanel = new PHorizontalPanel();
panel.add(simplePanel);
panel.setCellHorizontalAlignment(simplePanel, PHorizontalAlignment.ALIGN_RIGHT);
labelPanel.setWidget(i, 1, panel);
// hide button panel : shoul only be visible when mouse hover panel
buttonPanel.setSizeFull();
buttonPanel.setVisible(false);
panel.addDomHandler(new PMouseOverHandler() {
@Override
public void onMouseOver(final PMouseOverEvent mouseOverEvent) {
buttonPanel.setVisible(true);
}
}, PMouseOverEvent.TYPE);
panel.addDomHandler(new PMouseOutHandler() {
@Override
public void onMouseOut(final PMouseOutEvent event) {
buttonPanel.setVisible(false);
}
}, PMouseOutEvent.TYPE);
simplePanel.setWidth("30px");
simplePanel.add(buttonPanel);
if (i != 1) {
// up image
final PImage upImage = new PImage(ARROW_UP_IMAGE_URL);
upImage.setTitle("Move column up");
buttonPanel.add(upImage);
buttonPanel.setCellHorizontalAlignment(upImage, PHorizontalAlignment.ALIGN_LEFT);
upImage.addClickHandler(new PClickHandler() {
@Override
public void onClick(final PClickEvent event) {
final int index = labels.indexOf(label) - 1;
labels.remove(label);
labels.add(index, label);
fireColumnMoved();
for (int row = 1; row <= labels.size(); row++) {
labelPanel.getRowFormatter().removeStyleName(row, PonySDKTheme.SIMPLELIST_SELECTEDROW);
}
labelPanel.getRowFormatter().addStyleName(index + 1, PonySDKTheme.SIMPLELIST_SELECTEDROW);
}
});
}
if (i != labels.size()) {
// down image
final PImage downImage = new PImage(ARROW_DOWN_IMAGE_URL);
downImage.setTitle("Move column down");
buttonPanel.add(downImage);
buttonPanel.setCellHorizontalAlignment(downImage, PHorizontalAlignment.ALIGN_RIGHT);
downImage.addClickHandler(new PClickHandler() {
@Override
public void onClick(final PClickEvent event) {
final int index = labels.indexOf(label) + 1;
labels.remove(label);
labels.add(index, label);
fireColumnMoved();
for (int row = 1; row <= labels.size(); row++) {
labelPanel.getRowFormatter().removeStyleName(row, PonySDKTheme.SIMPLELIST_SELECTEDROW);
}
labelPanel.getRowFormatter().addStyleName(index + 1, PonySDKTheme.SIMPLELIST_SELECTEDROW);
}
});
}
// add erase button for custom column
if (label.custom) {
final PButton eraseButton = new PButton("Erase");
eraseButton.addClickHandler(new PClickHandler() {
@Override
public void onClick(final PClickEvent event) {
eventBus.fireEvent(new RemoveColumnDescriptorEvent(PreferenceForm.this, label.getText(), tableName));
labels.remove(label);
refreshLabels();
}
});
buttonPanel.add(eraseButton);
}
labelPanel.setWidget(i, 2, label.checkBox);
labelPanel.getRowFormatter().addStyleName(i, PonySDKTheme.SIMPLELIST_ROW);
i++;