Package com.google.gwt.cell.client.Cell

Examples of com.google.gwt.cell.client.Cell.Context


        if (isSelected) {
          classesBuilder.append(selectedItem);
        }

        SafeHtmlBuilder cellBuilder = new SafeHtmlBuilder();
        Context context = new Context(i, 0, getValueKey(value));
        cell.render(context, value, cellBuilder);

        // Figure out which image to use.
        SafeHtml image;
        if (isOpen) {
View Full Code Here


  /**
   * Get the {@link Context} for the cell.
   */
  private Context createContext() {
    return new Context(0, 0, getKey(value));
  }
View Full Code Here

    if (section == thead) {
      Header<?> header = headers.get(col);
      if (header != null) {
        // Fire the event to the header.
        if (cellConsumesEventType(header.getCell(), eventType)) {
          Context context = new Context(0, col, header.getKey());
          header.onBrowserEvent(context, tableCell, event);
        }

        // Sort the header.
        Column<T, ?> column = columns.get(col);
        if (isClick && column.isSortable()) {
          updatingSortList = true;
          sortList.push(column);
          updatingSortList = false;
          ColumnSortEvent.fire(this, sortList);
        }
      }
    } else if (section == tfoot) {
      Header<?> footer = footers.get(col);
      if (footer != null && cellConsumesEventType(footer.getCell(), eventType)) {
        Context context = new Context(0, col, footer.getKey());
        footer.onBrowserEvent(context, tableCell, event);
      }
    } else if (section == tbody) {
      // Update the hover state.
      int row = tr.getSectionRowIndex();
      if ("mouseover".equals(eventType)) {
        // Unstyle the old row if it is still part of the table.
        if (hoveringRow != null && tbody.isOrHasChild(hoveringRow)) {
          setRowStyleName(hoveringRow, style.cellTableHoveredRow(),
              style.cellTableHoveredRowCell(), false);
        }
        hoveringRow = tr;
        setRowStyleName(hoveringRow, style.cellTableHoveredRow(),
            style.cellTableHoveredRowCell(), true);
      } else if ("mouseout".equals(eventType) && hoveringRow != null) {
        setRowStyleName(hoveringRow, style.cellTableHoveredRow(),
            style.cellTableHoveredRowCell(), false);
        hoveringRow = null;
      } else if (isClick
          && ((getPresenter().getKeyboardSelectedRowInView() != row) || (keyboardSelectedColumn != col))) {
        // Move keyboard focus. Since the user clicked, allow focus to go to a
        // non-interactive column.
        boolean isFocusable = CellBasedWidgetImpl.get().isFocusable(target);
        isFocused = isFocused || isFocusable;
        keyboardSelectedColumn = col;
        getPresenter().setKeyboardSelectedRow(row, !isFocusable, true);
      }

      // Update selection. Selection occurs before firing the event to the cell
      // in case the cell operates on the currently selected item.
      if (!isRowWithinBounds(row)) {
        // If the event causes us to page, then the physical index will be out
        // of bounds of the underlying data.
        return;
      }
      boolean isSelectionHandled = handlesSelection
          || KeyboardSelectionPolicy.BOUND_TO_SELECTION == getKeyboardSelectionPolicy();
      T value = getVisibleItem(row);
      Context context = new Context(row + getPageStart(), col,
          getValueKey(value));
      CellPreviewEvent<T> previewEvent = CellPreviewEvent.fire(this, event,
          this, context, value, cellIsEditing, isSelectionHandled);
      if (isClick && !cellIsEditing && !isSelectionHandled) {
        doSelection(event, value, row, col);
View Full Code Here

          tdClasses += lastColumnStyle;
        }

        SafeHtmlBuilder cellBuilder = new SafeHtmlBuilder();
        if (value != null) {
          Context context = new Context(i, curColumn, getValueKey(value));
          column.render(context, value, cellBuilder);
        }

        // Build the contents.
        SafeHtml contents = SafeHtmlUtils.EMPTY_SAFE_HTML;
View Full Code Here

          if (prevHeader != null) {
            hasHeader = true;

            // Build the header.
            SafeHtmlBuilder headerBuilder = new SafeHtmlBuilder();
            Context context = new Context(0, curColumn - prevColspan,
                prevHeader.getKey());
            prevHeader.render(context, headerBuilder);

            // Wrap the header with a sort icon.
            if (isSorted) {
              SafeHtml unwrappedHeader = headerBuilder.toSafeHtml();
              headerBuilder = new SafeHtmlBuilder();
              getSortDecorator(isSortAscending).render(null, unwrappedHeader,
                  headerBuilder);
            }
            headerHtml = headerBuilder.toSafeHtml();
          }
          if (isSortable) {
            classesBuilder.append(sortableStyle);
          }
          if (isSorted) {
            classesBuilder.append(isSortAscending ? sortedAscStyle
                : sortedDescStyle);
          }
            String headerId = isFooter ? (tableId +"_hf_"+(curColumn-1)) : (tableId +"_h_"+(curColumn-1));

          sb.append(template.th(headerId, prevColspan, classesBuilder.toString(),
              headerHtml));

          // Reset the previous header.
          prevHeader = header;
          prevColspan = 1;
          classesBuilder = new StringBuilder(className);
          isSortable = false;
          isSorted = false;
        } else {
          // Increment the colspan if the headers == each other.
          prevColspan++;
        }

        // Update the sorted state.
        column = columns.get(curColumn);
        if (!isFooter && column.isSortable()) {
          isSortable = true;
          isSorted = (column == sortedColumn);
        }
      }

      // Append the last header.
      SafeHtml headerHtml = SafeHtmlUtils.EMPTY_SAFE_HTML;
      if (prevHeader != null) {
        hasHeader = true;

        // Build the header.
        SafeHtmlBuilder headerBuilder = new SafeHtmlBuilder();
        Context context = new Context(0, curColumn - prevColspan,
            prevHeader.getKey());
        prevHeader.render(context, headerBuilder);

        // Wrap the header with a sort icon.
        if (isSorted) {
View Full Code Here

    Element parent = getKeyboardSelectedElement();
    T value = getVisibleItem(row);
    Object key = getValueKey(value);
    C cellValue = column.getValue(value);
    Cell<C> cell = column.getCell();
    Context context = new Context(row + getPageStart(), col, key);
    return cell.resetFocus(context, parent, cellValue);
  }
View Full Code Here

                .getHeader(footerParent);

        if (header != null) {
          int headerIndex = isHeader ? headerBuilder.getRowIndex(targetTableRow) :
              footerBuilder.getRowIndex(targetTableRow);
          Context context = new Context(headerIndex, col, header.getKey());

          if (cellConsumesEventType(header.getCell(), eventType)) {         
            header.onBrowserEvent(context, headerParent, event);
          }

          if (isSelect) {
            // Preview the event, and possibily disable the column sort event. The event preview is
            // forced even if the header cell does not consume click event
            shouldSortColumn = header.onPreviewColumnSortEvent(context, headerParent, event);
          }
        }
      }

      // Sort the header.
      if (isSelect && shouldSortColumn && columnParent != null) {
        Column<T, ?> column =
            isHeader ? headerBuilder.getColumn(columnParent) : footerBuilder
                .getColumn(columnParent);
        if (column != null && column.isSortable()) {
          /*
           * Force the headers to refresh the next time data is pushed so we
           * update the sort icon in the header.
           */
          headersDirty = true;

          updatingSortList = true;
          sortList.push(column);
          updatingSortList = false;
          ColumnSortEvent.fire(this, sortList);
        }
      }
    } else if (targetTableSection == tbody) {
      /*
       * Get the row index of the data value. This may not correspond to the DOM
       * row index if the user specifies multiple table rows per row object.
       */
      int absRow = tableBuilder.getRowValueIndex(targetTableRow);
      int relRow = absRow - getPageStart();
      int subrow = tableBuilder.getSubrowValueIndex(targetTableRow);

      if (!skipRowHoverCheck) {
        boolean isRowChange = hoveringRow != targetTableRow;
        if (BrowserEvents.MOUSEOVER.equals(eventType)) {
          // Unstyle the old row if it is still part of the table.
          if (hoveringRow != null && getTableBodyElement().isOrHasChild(hoveringRow)) {
            setRowHover(hoveringRow, event, false, isRowChange);
          }
          hoveringRow = targetTableRow;
          setRowHover(hoveringRow, event, true, isRowChange);
        } else if (BrowserEvents.MOUSEOUT.equals(eventType) && hoveringRow != null) {
          boolean unhover = true;
          if (!skipRowHoverFloatElementCheck) {
            // Ignore events happening directly over the hovering row. If there are floating element
            // on top of the row, mouseout event should not be triggered. This is to avoid the flickring
            // effect if the floating element is shown/hide based on hover event.
            int clientX = event.getClientX() + Window.getScrollLeft();
            int clientY = event.getClientY() + Window.getScrollTop();
            int rowLeft = hoveringRow.getAbsoluteLeft();
            int rowTop = hoveringRow.getAbsoluteTop();
            int rowWidth = hoveringRow.getOffsetWidth();
            int rowHeight = hoveringRow.getOffsetHeight();
            int rowBottom = rowTop + rowHeight;
            int rowRight = rowLeft + rowWidth;
            unhover = clientX < rowLeft || clientX > rowRight || clientY < rowTop || clientY > rowBottom;
          }
          if (unhover) {
            setRowHover(hoveringRow, event, false, isRowChange);
            hoveringRow = null;
          }
        }
      }

      // If the event causes us to page, then the physical index will be out
      // of bounds of the underlying data.
      if (!isRowWithinBounds(relRow)) {
        return;
      }

      /*
       * Fire a preview event. The preview event is fired even if the TD does
       * not contain a cell so the selection handler and keyboard handler have a
       * chance to act.
       */
      boolean isSelectionHandled =
          handlesSelection
              || KeyboardSelectionPolicy.BOUND_TO_SELECTION == getKeyboardSelectionPolicy();
      T value = getVisibleItem(relRow);

      /*
       * Create a new context based on the dom column index instead of using the
       * user provided one from TableBuilder. We trigger cell preview events for
       * table cells even if there is no associated Cell instance. If we used
       * the user provided context, we could get inconsistent states where the
       * Context is sometimes user provided and sometimes generated based on the
       * DOM column index.
       */
      Context context = new Context(absRow, col, getValueKey(value), subrow);
      CellPreviewEvent<T> previewEvent =
          CellPreviewEvent.fire(this, event, this, context, value, cellIsEditing,
              isSelectionHandled);

      // Pass the event to the cell.
View Full Code Here

        if (curColumn == columnCount - 1) {
          tdClasses += lastColumnStyle;
        }

        // Add class names specific to the cell.
        Context context = new Context(i, curColumn, getValueKey(value));
        String cellStyles = column.getCellStyleNames(context, value);
        if (cellStyles != null) {
          tdClasses += " " + cellStyles;
        }
View Full Code Here

    int row = getKeyboardSelectedRow();
    int col = getKeyboardSelectedColumn();
    T value = getVisibleItem(row);
    Object key = getValueKey(value);
    // TODO(pengzhuang): this doesn't support sub row selection?
    Context context = new Context(row + getPageStart(), col, key);
    HasCell<T, ?> column = tableBuilder.getColumn(context, value, elem);
    if (column == null) {
      // The selected element does not contain a Cell.
      return false;
    }
View Full Code Here

        return columnData;
    }

    @Test
    public void testConstraints() {
        Context context;
        Map<String, String> values;

        //Row 0, Column 2
        context = new Context( 0,
                               2,
                               null );
        values = manager.getCurrentValueMap( context );
        assertNotNull( values );
        assertEquals( 2,
                      values.size() );

        assertTrue( values.containsKey( "c0p0" ) );
        assertNotNull( values.get( "c0p0" ) );
        assertEquals( "r0c2",
                      values.get( "c0p0" ) );

        assertTrue( values.containsKey( "c1p0" ) );
        assertNotNull( values.get( "c1p0" ) );
        assertEquals( "r0c3",
                      values.get( "c1p0" ) );

        //Row 1, Column 2
        context = new Context( 1,
                               2,
                               null );
        values = manager.getCurrentValueMap( context );
        assertNotNull( values );
        assertEquals( 2,
                      values.size() );

        assertTrue( values.containsKey( "c0p0" ) );
        assertNotNull( values.get( "c0p0" ) );
        assertEquals( "r1c2",
                      values.get( "c0p0" ) );

        assertTrue( values.containsKey( "c1p0" ) );
        assertNotNull( values.get( "c1p0" ) );
        assertEquals( "r1c3",
                      values.get( "c1p0" ) );

        //Row 0, Column 3
        context = new Context( 0,
                               3,
                               null );
        values = manager.getCurrentValueMap( context );
        assertNotNull( values );
        assertEquals( 2,
                      values.size() );

        assertTrue( values.containsKey( "c0p0" ) );
        assertNotNull( values.get( "c0p0" ) );
        assertEquals( "r0c2",
                      values.get( "c0p0" ) );

        assertTrue( values.containsKey( "c1p0" ) );
        assertNotNull( values.get( "c1p0" ) );
        assertEquals( "r0c3",
                      values.get( "c1p0" ) );

        //Row 1, Column 3
        context = new Context( 1,
                               3,
                               null );
        values = manager.getCurrentValueMap( context );
        assertNotNull( values );
        assertEquals( 2,
View Full Code Here

TOP

Related Classes of com.google.gwt.cell.client.Cell.Context

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.