use of org.gwtproject.cell.client.Cell.Context in project gwtproject by treblereel.
the class ColumnTest method testDelayedValueUpdaer.
/**
* Test that a cell can hold onto the {@link ValueUpdater} and update it
* later.
*/
public void testDelayedValueUpdaer() {
final Element theElem = Document.get().createDivElement();
final NativeEvent theEvent = Document.get().createClickEvent(0, 0, 0, 0, 0, false, false, false, false);
final MockEditableCell cell = new MockEditableCell() {
@Override
public void onBrowserEvent(Context context, Element parent, String value, NativeEvent event, final ValueUpdater<String> valueUpdater) {
setViewData("test", "newViewData");
new Timer() {
@Override
public void run() {
valueUpdater.update("newValue");
}
}.schedule(200);
}
};
final Column<String, String> column = new IdentityColumn<>(cell);
final MockFieldUpdater<String, String> fieldUpdater = new MockFieldUpdater<String, String>() {
@Override
public void update(int index, String object, String value) {
assertEquals("newViewData", cell.getViewData("test"));
super.update(index, object, value);
finishTest();
}
};
column.setFieldUpdater(fieldUpdater);
// Fire the event to the cell.
delayTestFinish(5000);
cell.setViewData("test", "oldViewData");
Context context = new Context(3, 0, null);
column.onBrowserEvent(context, theElem, "test", theEvent);
}
use of org.gwtproject.cell.client.Cell.Context in project gwtproject by treblereel.
the class DefaultSelectionEventManagerTest method testHandleSelectionEventDeselect.
public void testHandleSelectionEventDeselect() {
org.gwtproject.view.client.SingleSelectionModel<String> model = new org.gwtproject.view.client.SingleSelectionModel<String>();
display.setSelectionModel(model);
model.setSelected("test 0", true);
// Deselect a different value.
NativeEvent nativeEvent = Document.get().createClickEvent(0, 0, 0, 0, 0, false, false, false, false);
org.gwtproject.view.client.CellPreviewEvent<String> event = new org.gwtproject.view.client.CellPreviewEvent<String>(nativeEvent, display, new Context(1, 0, null), "test 1", false, false);
manager.handleSelectionEvent(event, SelectAction.DESELECT, model);
assertEquals("test 0", model.getSelectedObject());
// Deselect the same value.
event = new org.gwtproject.view.client.CellPreviewEvent<String>(nativeEvent, display, new Context(0, 0, null), "test 0", false, false);
manager.handleSelectionEvent(event, SelectAction.DESELECT, model);
assertNull(model.getSelectedObject());
}
use of org.gwtproject.cell.client.Cell.Context in project gwtproject by treblereel.
the class DefaultSelectionEventManagerTest method testHandleSelectionEvent.
public void testHandleSelectionEvent() {
org.gwtproject.view.client.SingleSelectionModel<String> model = new org.gwtproject.view.client.SingleSelectionModel<String>();
display.setSelectionModel(model);
model.setSelected("test 0", true);
// Select a different value.
NativeEvent nativeEvent = Document.get().createClickEvent(0, 0, 0, 0, 0, false, false, false, false);
org.gwtproject.view.client.CellPreviewEvent<String> event = new org.gwtproject.view.client.CellPreviewEvent<String>(nativeEvent, display, new Context(1, 0, null), "test 1", false, false);
manager.handleSelectionEvent(event, null, model);
assertEquals("test 1", model.getSelectedObject());
// Select the same value.
manager.handleSelectionEvent(event, null, model);
assertEquals("test 1", model.getSelectedObject());
// Ctrl+Select the same value.
nativeEvent = Document.get().createClickEvent(0, 0, 0, 0, 0, true, false, false, true);
event = new org.gwtproject.view.client.CellPreviewEvent<String>(nativeEvent, display, new Context(1, 0, null), "test 1", false, false);
manager.handleSelectionEvent(event, null, model);
assertNull(model.getSelectedObject());
// Spacebar a different value.
nativeEvent = Document.get().createKeyUpEvent(false, false, false, false, 32);
event = new org.gwtproject.view.client.CellPreviewEvent<String>(nativeEvent, display, new Context(2, 0, null), "test 2", false, false);
manager.handleSelectionEvent(event, null, model);
assertEquals("test 2", model.getSelectedObject());
// Spacebar the same value.
manager.handleSelectionEvent(event, null, model);
assertNull(model.getSelectedObject());
}
use of org.gwtproject.cell.client.Cell.Context in project gwtproject by treblereel.
the class DefaultHeaderOrFooterBuilder method buildTableHeader.
/**
* Build the table header for the column.
*/
private void buildTableHeader(TableRowBuilder tr, Column<T, ?> column, Header<?> header, boolean isSortable, boolean isSorted, boolean isSortAscending, StringBuilder classesBuilder, String sortableStyle, String sortedStyle, int prevColspan, int curColumn) {
if (isSortable) {
classesBuilder.append(sortableStyle);
}
if (isSorted) {
classesBuilder.append(sortedStyle);
}
appendExtraStyles(header, classesBuilder);
TableCellBuilder th = tr.startTH().colSpan(prevColspan).className(classesBuilder.toString());
enableColumnHandlers(th, column);
if (header != null) {
// Build the header.
Context context = new Context(0, curColumn - prevColspan, header.getKey());
if (isSortable) {
// TODO: Figure out aria-label and translation of label text
th.attribute("role", "button");
th.tabIndex(-1);
}
renderSortableHeader(th, context, header, isSorted, isSortAscending);
}
th.endTH();
}
use of org.gwtproject.cell.client.Cell.Context in project gwtproject by treblereel.
the class CellList method renderRowValues.
@Override
protected void renderRowValues(SafeHtmlBuilder sb, List<T> values, int start, SelectionModel<? super T> selectionModel) {
String keyboardSelectedItem = " " + style.cellListKeyboardSelectedItem();
String selectedItem = " " + style.cellListSelectedItem();
String evenItem = style.cellListEvenItem();
String oddItem = style.cellListOddItem();
int keyboardSelectedRow = getKeyboardSelectedRow() + getPageStart();
int length = values.size();
int end = start + length;
for (int i = start; i < end; i++) {
T value = values.get(i - start);
boolean isSelected = selectionModel == null ? false : selectionModel.isSelected(value);
StringBuilder classesBuilder = new StringBuilder();
classesBuilder.append(i % 2 == 0 ? evenItem : oddItem);
if (isSelected) {
classesBuilder.append(selectedItem);
}
if (i == keyboardSelectedRow) {
classesBuilder.append(keyboardSelectedItem);
}
SafeHtmlBuilder cellBuilder = new SafeHtmlBuilder();
Context context = new Context(i, 0, getValueKey(value));
cell.render(context, value, cellBuilder);
sb.append(Template.INSTANCE.div(i, classesBuilder.toString(), cellBuilder.toSafeHtml()));
}
}
Aggregations