Created
June 14, 2010 23:13
-
-
Save minichate/438464 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class MyGridRow extends GridRow<String> { | |
private Label label = new Label(""); | |
private TextBox innerBox = new TextBox(); | |
private ValidatingWidget<String> textBox = new ValidatingWidget<String>(); | |
private DeleteIconWidget<String> deleteIcon = new DeleteIconWidget<String>(); | |
public MyGridRow() { | |
textBox.setWidget(innerBox); | |
textBox.setValidator(new HasValidation<String>() { | |
@Override | |
public boolean isValid(String value) { | |
if (value.contains("ass")) { | |
textBox.setHelpText("Watch your language!"); | |
return false; | |
} | |
return true; | |
} | |
}); | |
textBox.addValueChangeHandler(new ValueChangeHandler<String>() { | |
@Override | |
public void onValueChange(ValueChangeEvent<String> event) { | |
label.setText("" + event.getValue().length()); | |
ValueChangeEvent.fire(MyGridRow.this, event.getValue()); | |
} | |
}); | |
deleteIcon.setAttachedWidget(this); | |
} | |
public TextBox getTextBox() { | |
return innerBox; | |
} | |
@Override | |
public Widget[] getGridCells() { | |
return new Widget[] { textBox, label, deleteIcon }; | |
} | |
@Override | |
public String getValue() { | |
return textBox.getValue(); | |
} | |
@Override | |
public void setValue(String value) { | |
setValue(value, false); | |
} | |
@Override | |
public void setValue(String value, boolean fireEvents) { | |
textBox.setValue(value); | |
ValueChangeEvent.fire(this, value); | |
} | |
public static void addRowTo(final SortingGrid grid) { | |
MyGridRow row = new MyGridRow(); | |
row.addValueChangeHandler(new ValueChangeHandler<String>() { | |
@Override | |
public void onValueChange(ValueChangeEvent<String> event) { | |
addRowTo(grid); | |
} | |
}); | |
grid.addRow(row); | |
row.getTextBox().setFocus(true); | |
} | |
} | |
private void someInitMethod() { | |
// ... | |
SortingGrid myGrid = new SortingGrid(); | |
myGrid.addHeader("Word").setSorting(true); | |
myGrid.addHeader("Length").setGrouping(true).setSorting(true); | |
myGrid.addHeader(""); // Empty header for the delete icon. | |
MyGridRow.addRowTo(myGrid); | |
panel.add(myGrid); | |
// ... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment