Search in sources :

Example 21 with Context

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);
}
Also used : Context(org.gwtproject.cell.client.Cell.Context) Timer(org.gwtproject.timer.client.Timer) ValueUpdater(org.gwtproject.cell.client.ValueUpdater) Element(org.gwtproject.dom.client.Element) NativeEvent(org.gwtproject.dom.client.NativeEvent)

Example 22 with Context

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());
}
Also used : Context(org.gwtproject.cell.client.Cell.Context) NativeEvent(org.gwtproject.dom.client.NativeEvent)

Example 23 with Context

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());
}
Also used : Context(org.gwtproject.cell.client.Cell.Context) NativeEvent(org.gwtproject.dom.client.NativeEvent)

Example 24 with Context

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();
}
Also used : Context(org.gwtproject.cell.client.Cell.Context) TableCellBuilder(org.gwtproject.dom.builder.shared.TableCellBuilder)

Example 25 with Context

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()));
    }
}
Also used : Context(org.gwtproject.cell.client.Cell.Context) SafeHtmlBuilder(org.gwtproject.safehtml.shared.SafeHtmlBuilder)

Aggregations

Context (org.gwtproject.cell.client.Cell.Context)33 Element (org.gwtproject.dom.client.Element)14 SafeHtmlBuilder (org.gwtproject.safehtml.shared.SafeHtmlBuilder)13 NativeEvent (org.gwtproject.dom.client.NativeEvent)9 ViewData (org.gwtproject.cell.client.EditTextCell.ViewData)3 ValueUpdater (org.gwtproject.cell.client.ValueUpdater)3 TableCellBuilder (org.gwtproject.dom.builder.shared.TableCellBuilder)2 DivElement (org.gwtproject.dom.client.DivElement)2 EventTarget (org.gwtproject.dom.client.EventTarget)2 ImageElement (org.gwtproject.dom.client.ImageElement)2 TableCellElement (org.gwtproject.dom.client.TableCellElement)2 TableElement (org.gwtproject.dom.client.TableElement)2 TableRowElement (org.gwtproject.dom.client.TableRowElement)2 TableSectionElement (org.gwtproject.dom.client.TableSectionElement)2 HorizontalAlignmentConstant (org.gwtproject.user.client.ui.HasHorizontalAlignment.HorizontalAlignmentConstant)2 VerticalAlignmentConstant (org.gwtproject.user.client.ui.HasVerticalAlignment.VerticalAlignmentConstant)2 HasCell (org.gwtproject.cell.client.HasCell)1 TextCell (org.gwtproject.cell.client.TextCell)1 Scheduler (org.gwtproject.core.client.Scheduler)1 DivBuilder (org.gwtproject.dom.builder.shared.DivBuilder)1