Java源码示例:com.google.gwt.dom.client.StyleElement

示例1
/**
 * Styles a multi-row selection with the number of elements.
 *
 * @param drag
 *            the current drag event holding the context.
 */
void setMultiRowDragDecoration(final VDragEvent drag) {
    final Widget widget = drag.getTransferable().getDragSource().getWidget();

    if (widget instanceof VScrollTable) {
        final VScrollTable table = (VScrollTable) widget;
        final int rowCount = table.selectedRowKeys.size();

        Element dragCountElement = Document.get().getElementById(SP_DRAG_COUNT);
        if (rowCount > 1 && table.selectedRowKeys.contains(table.focusedRow.getKey())) {
            if (dragCountElement == null) {
                dragCountElement = Document.get().createStyleElement();
                dragCountElement.setId(SP_DRAG_COUNT);
                final HeadElement head = HeadElement
                        .as(Document.get().getElementsByTagName(HeadElement.TAG).getItem(0));
                head.appendChild(dragCountElement);
            }
            final SafeHtml formattedCssStyle = getDraggableTemplate()
                    .multiSelectionStyle(determineActiveTheme(drag), String.valueOf(rowCount));
            final StyleElement dragCountStyleElement = StyleElement.as(dragCountElement);
            dragCountStyleElement.setInnerSafeHtml(formattedCssStyle);
        } else if (dragCountElement != null) {
            dragCountElement.removeFromParent();
        }
    }
}
 
示例2
private static Registration injectCornerStyle(String id, Cell cell) {
  Color borderColor = cell.get(Cell.BORDER_COLOR);
  String border = borderColor == null ? "none" : "1px solid " + borderColor.toCssColor();
  Color backgroundColor = cell.get(Cell.BACKGROUND);
  String background = backgroundColor == null ? Color.WHITE.toCssColor() : backgroundColor.toCssColor();
  final StyleElement styleElement = StyleInjector.injectStylesheet("." + id
      + "::before { border-top: " + border + "; border-left: " + border + "; " +
      "background: linear-gradient(135deg, " + background + " 0%, " + background
      + " 70%, rgba(0,0,0,0) 71%, rgba(0,0,0,0) 100%) }");
  StyleInjector.flush();
  return new Registration() {
    @Override
    protected void doRemove() {
      styleElement.removeFromParent();
    }
  };
}
 
示例3
@Test
@Description("Check multi row drag decoration with a valid multi selection")
public void processMultiRowDragDecorationMultiSelection() {
    final ViewClientCriterion cut = new ViewClientCriterion();

    // prepare table
    final VScrollTable table = Mockito.spy(new VScrollTable());
    table.selectedRowKeys.add("one");
    table.selectedRowKeys.add("two");
    table.focusedRow = Mockito.mock(VScrollTable.VScrollTableBody.VScrollTableRow.class);
    when(table.focusedRow.getKey()).thenReturn("one");

    // prepare drag-event with table widget:
    final VDragEvent dragEvent = CriterionTestHelper.createMockedVDragEvent("thisId", table, "myTheme");
    dragEvent.getTransferable().getDragSource().getConnection().getUIConnector();

    // prepare document
    final Document document = Document.get();
    final StyleElement ele = Mockito.spy(StyleElement.class);
    when(ele.getTagName()).thenReturn(StyleElement.TAG);
    when(document.getElementById(ViewClientCriterion.SP_DRAG_COUNT)).thenReturn(ele);

    try {
        // act
        cut.setMultiRowDragDecoration(dragEvent);

        // assure that multi-row decoration for the table was processed
        verify(document).getElementById(ViewClientCriterion.SP_DRAG_COUNT);

        // assure that no multi selection was detected
        verify(ele).setInnerSafeHtml(any(SafeHtml.class));
    } finally {
        reset(Document.get());
    }
}