Example usage for com.google.gwt.dom.client TableCellElement addClassName

List of usage examples for com.google.gwt.dom.client TableCellElement addClassName

Introduction

In this page you can find the example usage for com.google.gwt.dom.client TableCellElement addClassName.

Prototype

@Override
    public boolean addClassName(String className) 

Source Link

Usage

From source file:com.haulmont.cuba.web.toolkit.ui.client.aggregation.TableAggregationRow.java

License:Apache License

protected void addCell(String text, char align, String style, boolean sorted) {
    final TableCellElement td = DOM.createTD().cast();

    final Element container = DOM.createDiv();
    container.setClassName(tableWidget.getStylePrimaryName() + "-cell-wrapper");

    td.setClassName(tableWidget.getStylePrimaryName() + "-cell-content");

    td.addClassName(tableWidget.getStylePrimaryName() + "-aggregation-cell");

    if (style != null && !style.equals("")) {
        td.addClassName(tableWidget.getStylePrimaryName() + "-cell-content-" + style);
    }//from   w w  w . j  a va 2  s  .c o  m

    if (sorted) {
        td.addClassName(tableWidget.getStylePrimaryName() + "-cell-content-sorted");
    }

    container.setInnerText(text);

    setAlign(align, container);

    td.appendChild(container);
    tr.appendChild(td);

    Tools.textSelectionEnable(td, tableWidget.isTextSelectionEnabled());
}

From source file:com.jwh.gwt.fasttable.sample.client.FastTableSample.java

License:Open Source License

private CellListener<SampleModel> buildCellListener() {
    return new CellListener<SampleModel>() {

        /**// ww w  .  ja va  2 s .  c  o m
         * @param event
         */
        @Override
        public void handlerCellEvent(final CellEvent<SampleModel> event) {
            final Document document = tablePanel.getElement().getOwnerDocument();
            switch (event.getOnEvent()) {
            case onClick:
                SelectionListener<SampleModel> listener = new SelectionListener<SampleModel>() {
                    @Override
                    public void select(SampleModel object) {
                        try {
                            showDetailPanel(event, document);
                        } catch (NotFound e) {
                        }
                    }

                    @Override
                    public void unselect(SampleModel object) {
                        try {
                            builder.findRowElement(object).getNextSibling().removeFromParent();
                        } catch (NotFound e) {
                        }
                    }
                };
                try {
                    final Element rowElement = event.getRowElement(document);
                    final Element columnElement = rowElement.getFirstChildElement();
                    // Test multi vs single select by changing this flag
                    boolean isMultiSelect = true;
                    isMultiSelect = false;
                    if (isMultiSelect) {
                        builder.multiSelect(columnElement, event.domainObject, listener);
                    } else {
                        builder.singleSelect(columnElement, event.domainObject, listener);
                    }
                } catch (NotFound e) {
                } catch (AbortOperation e) {
                }
                break;
            case onMouseOver:
                try {
                    event.getRowElement(document).addClassName(HIGHLIGHT);
                } catch (final NotFound e1) {
                }
                break;
            case onMouseOut:
                try {
                    event.getRowElement(document).removeClassName(HIGHLIGHT);
                } catch (final NotFound e1) {
                }
                break;
            default:
                break;
            }

        }

        /**
         * Show a panel under the selected item
         * 
         * @param event
         * @param document
         * @throws NotFound
         */
        private void showDetailPanel(CellEvent<SampleModel> event, final Document document) throws NotFound {
            final SampleModel d = event.getDomainObject();
            final TableRowElement newRow = event.insertRowAfter(document);
            final TableCellElement td = document.createTDElement();
            td.addClassName(DROP_PANEL);
            // Note: "colSpan" must have uppercase 'S' for IE
            td.setAttribute("colSpan", "6");
            newRow.appendChild(td);
            try {
                LabelValueUtil util = new LabelValueUtil();
                util.table.setStyle(Style.BORDER_NONE);
                util.labelValue("Name", d.name);
                util.prepareAttribute("rowSpan", "2");
                final String buttonId = util.button("OK");
                util.newRow();
                util.labelValue("Street", d.street);
                util.newRow();
                util.labelValue("City, State ", d.city + ", " + d.state);
                util.newRow();
                util.labelValue("Zip", d.zip);
                util.newRow();
                final String html = util.toHtml();
                td.setInnerHTML(html);
                final Element okButton = document.getElementById(buttonId);
                DOM.setEventListener((com.google.gwt.user.client.Element) okButton, new EventListener() {
                    @Override
                    public void onBrowserEvent(Event event) {
                        switch (event.getTypeInt()) {
                        case Event.ONMOUSEDOWN:
                            Window.alert(
                                    "This demonstrates how to attach events to content created with setInnerHtml()");
                            break;
                        case Event.ONMOUSEOVER:
                            okButton.addClassName(Style.BUTTON_OVER);
                            break;
                        case Event.ONMOUSEOUT:
                            okButton.removeClassName(Style.BUTTON_OVER);
                            break;
                        default:
                            break;
                        }
                    }
                });
                DOM.sinkEvents((com.google.gwt.user.client.Element) okButton,
                        Event.ONMOUSEOUT | Event.ONMOUSEDOWN | Event.ONMOUSEOVER);
            } catch (Exception e) {
            }
        }
    };
}

From source file:org.drools.guvnor.client.widgets.decoratedgrid.VerticalMergableGridWidget.java

License:Apache License

@SuppressWarnings("rawtypes")
private TableCellElement makeTableCellElement(int iCol, DynamicDataRow rowData) {

    TableCellElement tce = null;

    // Column to handle rendering
    DynamicColumn<?> column = columns.get(iCol);

    CellValue<? extends Comparable<?>> cellData = rowData.get(iCol);
    int rowSpan = cellData.getRowSpan();
    if (rowSpan > 0) {

        // Use Elements rather than Templates as it's easier to set attributes that need to be dynamic
        tce = Document.get().createTDElement();
        DivElement div = Document.get().createDivElement();
        DivElement divText = Document.get().createDivElement();
        tce.addClassName(style.cellTableCell());
        div.setClassName(style.cellTableCellDiv());
        divText.addClassName(style.cellTableTextDiv());

        // Set widths
        int colWidth = column.getWidth();
        div.getStyle().setWidth(colWidth, Unit.PX);
        divText.getStyle().setWidth(colWidth, Unit.PX);
        tce.getStyle().setWidth(colWidth, Unit.PX);

        // Set heights, TD includes border, DIV does not
        int divHeight = cellHeightCalculator.calculateHeight(rowSpan);
        div.getStyle().setHeight(divHeight, Unit.PX);
        tce.setRowSpan(rowSpan);//from   ww  w  .  jav  a2  s.  co m

        //Styling depending upon state
        if (cellData.isOtherwise()) {
            tce.addClassName(style.cellTableCellOtherwise());
        }
        if (cellData instanceof GroupedCellValue) {
            GroupedCellValue gcv = (GroupedCellValue) cellData;
            if (gcv.hasMultipleValues()) {
                tce.addClassName(style.cellTableCellMultipleValues());
            }
        }
        if (cellData.isSelected()) {
            tce.removeClassName(style.cellTableCellMultipleValues());
            tce.removeClassName(style.cellTableCellOtherwise());
            tce.addClassName(style.cellTableCellSelected());
        }

        // Render the cell and set inner HTML
        SafeHtmlBuilder cellBuilder = new SafeHtmlBuilder();
        if (!cellData.isOtherwise()) {
            Coordinate c = cellData.getCoordinate();
            Context context = new Context(c.getRow(), c.getCol(), c);
            column.render(context, rowData, cellBuilder);
        } else {
            cellBuilder.appendEscaped("<otherwise>");
        }
        divText.setInnerHTML(cellBuilder.toSafeHtml().asString());

        // Construct the table
        tce.appendChild(div);
        div.appendChild(divText);
        tce.setTabIndex(0);

        //Add on "Grouping" widget, if applicable
        if (rowSpan > 1 || cellData.isGrouped()) {
            Element de = DOM.createDiv();
            DivElement divGroup = DivElement.as(de);
            divGroup.setTitle(messages.groupCells());
            divGroup.addClassName(style.cellTableGroupDiv());
            if (cellData.isGrouped()) {
                divGroup.setInnerHTML(selectorUngroupedCellsHtml);
            } else {
                divGroup.setInnerHTML(selectorGroupedCellsHtml);
            }
            div.appendChild(divGroup);
        }

    }
    return tce;

}

From source file:org.drools.guvnor.client.widgets.decoratedgrid.VerticalMergableGridWidget.java

License:Apache License

@Override
@SuppressWarnings({ "rawtypes" })
void deselectCell(CellValue<? extends Comparable<?>> cell) {
    if (cell == null) {
        throw new IllegalArgumentException("cell cannot be null");
    }//ww  w.  j  a v a2s  .c o m

    Coordinate hc = cell.getHtmlCoordinate();
    TableRowElement tre = tbody.getRows().getItem(hc.getRow()).<TableRowElement>cast();
    TableCellElement tce = tre.getCells().getItem(hc.getCol()).<TableCellElement>cast();

    //Merging, grouping etc could have led to the selected HTML cell disappearing
    if (tce != null) {
        String cellSelectedStyle = style.cellTableCellSelected();
        String cellMultipleValuesStyle = style.cellTableCellMultipleValues();
        String cellOtherwiseStyle = style.cellTableCellOtherwise();
        tce.removeClassName(cellSelectedStyle);

        //Re-apply applicable styling
        if (cell.isOtherwise()) {
            tce.addClassName(cellOtherwiseStyle);
        }
        if (cell instanceof GroupedCellValue) {
            GroupedCellValue gcv = (GroupedCellValue) cell;
            if (gcv.hasMultipleValues()) {
                tce.addClassName(cellMultipleValuesStyle);
            }
        }
    }
}

From source file:org.drools.guvnor.client.widgets.decoratedgrid.VerticalMergableGridWidget.java

License:Apache License

@Override
void selectCell(CellValue<? extends Comparable<?>> cell) {
    if (cell == null) {
        throw new IllegalArgumentException("cell cannot be null");
    }/*from  w ww  .j ava  2s  .  com*/

    Coordinate hc = cell.getHtmlCoordinate();
    TableRowElement tre = tbody.getRows().getItem(hc.getRow()).<TableRowElement>cast();
    TableCellElement tce = tre.getCells().getItem(hc.getCol()).<TableCellElement>cast();

    //Cell selected style takes precedence
    String cellSelectedStyle = style.cellTableCellSelected();
    String cellOtherwiseStyle = style.cellTableCellOtherwise();
    String cellMultipleValuesStyle = style.cellTableCellMultipleValues();

    tce.removeClassName(cellMultipleValuesStyle);
    tce.removeClassName(cellOtherwiseStyle);
    tce.addClassName(cellSelectedStyle);
    tce.focus();
}

From source file:org.drools.guvnor.client.widgets.drools.decoratedgrid.AbstractVerticalMergableGridWidget.java

License:Apache License

@SuppressWarnings("rawtypes")
private TableCellElement makeTableCellElement(int iCol, DynamicDataRow rowData) {

    TableCellElement tce = null;

    // Column to handle rendering
    DynamicColumn<T> column = columns.get(iCol);

    CellValue<? extends Comparable<?>> cellData = rowData.get(iCol);
    int rowSpan = cellData.getRowSpan();
    if (rowSpan > 0) {

        // Use Elements rather than Templates as it's easier to set attributes that need to be dynamic
        tce = Document.get().createTDElement();
        DivElement div = Document.get().createDivElement();
        DivElement divText = Document.get().createDivElement();
        tce.addClassName(resources.cellTableCell());
        tce.addClassName(resources.cellTableColumn(column.getModelColumn()));
        div.setClassName(resources.cellTableCellDiv());
        divText.addClassName(resources.cellTableTextDiv());

        // Set widths
        int colWidth = column.getWidth();
        div.getStyle().setWidth(colWidth, Unit.PX);
        divText.getStyle().setWidth(colWidth, Unit.PX);
        tce.getStyle().setWidth(colWidth, Unit.PX);

        // Set heights, TD includes border, DIV does not
        int divHeight = cellHeightCalculator.calculateHeight(rowSpan);
        div.getStyle().setHeight(divHeight, Unit.PX);
        tce.setRowSpan(rowSpan);//from w  w  w  .j av a  2 s  .  c  o m

        //Styling depending upon state
        if (cellData.isOtherwise()) {
            tce.addClassName(resources.cellTableCellOtherwise());
        } else {
            tce.removeClassName(resources.cellTableCellOtherwise());
        }
        if (cellData instanceof GroupedCellValue) {
            GroupedCellValue gcv = (GroupedCellValue) cellData;
            if (gcv.hasMultipleValues()) {
                tce.addClassName(resources.cellTableCellMultipleValues());
            }
        } else {
            tce.removeClassName(resources.cellTableCellMultipleValues());
        }
        if (cellData.isSelected()) {
            tce.addClassName(resources.cellTableCellSelected());
        } else {
            tce.removeClassName(resources.cellTableCellSelected());
        }

        // Render the cell and set inner HTML
        SafeHtmlBuilder cellBuilder = new SafeHtmlBuilder();
        if (!cellData.isOtherwise()) {
            Coordinate c = cellData.getCoordinate();
            Context context = new Context(c.getRow(), c.getCol(), c);
            column.render(context, rowData, cellBuilder);
        } else {
            cellBuilder.appendEscaped("<otherwise>");
        }
        divText.setInnerHTML(cellBuilder.toSafeHtml().asString());

        // Construct the table
        tce.appendChild(div);
        div.appendChild(divText);
        tce.setTabIndex(0);

        //Add on "Grouping" widget, if applicable
        if (rowSpan > 1 || cellData.isGrouped()) {
            Element de = DOM.createDiv();
            DivElement divGroup = DivElement.as(de);
            divGroup.setTitle(Constants.INSTANCE.groupCells());
            divGroup.addClassName(resources.cellTableGroupDiv());
            if (cellData.isGrouped()) {
                divGroup.setInnerHTML(selectorUngroupedCellsHtml);
            } else {
                divGroup.setInnerHTML(selectorGroupedCellsHtml);
            }
            div.appendChild(divGroup);
        }

    }
    return tce;

}

From source file:org.drools.guvnor.client.widgets.drools.decoratedgrid.AbstractVerticalMergableGridWidget.java

License:Apache License

@Override
@SuppressWarnings({ "rawtypes" })
void deselectCell(CellValue<? extends Comparable<?>> cell) {
    if (cell == null) {
        throw new IllegalArgumentException("cell cannot be null");
    }//ww w .j a  v a2 s  . c  om

    Coordinate hc = cell.getHtmlCoordinate();
    TableRowElement tre = tbody.getRows().getItem(hc.getRow()).<TableRowElement>cast();
    TableCellElement tce = tre.getCells().getItem(hc.getCol()).<TableCellElement>cast();

    //Merging, grouping etc could have led to the selected HTML cell disappearing
    if (tce != null) {
        String cellSelectedStyle = resources.cellTableCellSelected();
        String cellMultipleValuesStyle = resources.cellTableCellMultipleValues();
        String cellOtherwiseStyle = resources.cellTableCellOtherwise();
        tce.removeClassName(cellSelectedStyle);

        //Re-apply applicable styling
        if (cell.isOtherwise()) {
            tce.addClassName(cellOtherwiseStyle);
        }
        if (cell instanceof GroupedCellValue) {
            GroupedCellValue gcv = (GroupedCellValue) cell;
            if (gcv.hasMultipleValues()) {
                tce.addClassName(cellMultipleValuesStyle);
            }
        }
    }
}

From source file:org.drools.guvnor.client.widgets.drools.decoratedgrid.AbstractVerticalMergableGridWidget.java

License:Apache License

@Override
void selectCell(CellValue<? extends Comparable<?>> cell) {
    if (cell == null) {
        throw new IllegalArgumentException("cell cannot be null");
    }/*  w w w . j a v  a 2  s  . com*/

    Coordinate hc = cell.getHtmlCoordinate();
    TableRowElement tre = tbody.getRows().getItem(hc.getRow()).<TableRowElement>cast();
    TableCellElement tce = tre.getCells().getItem(hc.getCol()).<TableCellElement>cast();

    //Cell selected style takes precedence
    String cellSelectedStyle = resources.cellTableCellSelected();
    String cellOtherwiseStyle = resources.cellTableCellOtherwise();
    String cellMultipleValuesStyle = resources.cellTableCellMultipleValues();

    tce.removeClassName(cellMultipleValuesStyle);
    tce.removeClassName(cellOtherwiseStyle);
    tce.addClassName(cellSelectedStyle);
    tce.focus();
}

From source file:org.kie.guvnor.decoratedgrid.client.widget.AbstractVerticalMergableGridWidget.java

License:Apache License

@SuppressWarnings("rawtypes")
private TableCellElement makeTableCellElement(int iCol, DynamicDataRow rowData) {

    TableCellElement tce = null;

    // Column to handle rendering
    DynamicColumn<T> column = columns.get(iCol);

    CellValue<? extends Comparable<?>> cellData = rowData.get(iCol);
    int rowSpan = cellData.getRowSpan();
    if (rowSpan > 0) {

        // Use Elements rather than Templates as it's easier to set attributes that need to be dynamic
        tce = Document.get().createTDElement();
        DivElement div = Document.get().createDivElement();
        DivElement divText = Document.get().createDivElement();
        tce.addClassName(resources.cellTableCell());
        tce.addClassName(resources.cellTableColumn(column.getModelColumn()));
        div.setClassName(resources.cellTableCellDiv());
        divText.addClassName(resources.cellTableTextDiv());

        // Set widths
        int colWidth = column.getWidth();
        div.getStyle().setWidth(colWidth, Unit.PX);
        divText.getStyle().setWidth(colWidth, Unit.PX);
        tce.getStyle().setWidth(colWidth, Unit.PX);

        // Set heights, TD includes border, DIV does not
        int divHeight = cellHeightCalculator.calculateHeight(rowSpan);
        div.getStyle().setHeight(divHeight, Unit.PX);
        tce.setRowSpan(rowSpan);/*from w w w . j a va 2 s .  c om*/

        //Styling depending upon state
        if (cellData.isOtherwise()) {
            tce.addClassName(resources.cellTableCellOtherwise());
        } else {
            tce.removeClassName(resources.cellTableCellOtherwise());
        }
        if (cellData instanceof CellValue.GroupedCellValue) {
            CellValue.GroupedCellValue gcv = (CellValue.GroupedCellValue) cellData;
            if (gcv.hasMultipleValues()) {
                tce.addClassName(resources.cellTableCellMultipleValues());
            }
        } else {
            tce.removeClassName(resources.cellTableCellMultipleValues());
        }
        if (cellData.isSelected()) {
            tce.addClassName(resources.cellTableCellSelected());
        } else {
            tce.removeClassName(resources.cellTableCellSelected());
        }

        // Render the cell and set inner HTML
        SafeHtmlBuilder cellBuilder = new SafeHtmlBuilder();
        if (!cellData.isOtherwise()) {
            Coordinate c = cellData.getCoordinate();
            Context context = new Context(c.getRow(), c.getCol(), c);
            column.render(context, rowData, cellBuilder);
        } else {
            cellBuilder.appendEscaped("<otherwise>");
        }
        divText.setInnerHTML(cellBuilder.toSafeHtml().asString());

        // Construct the table
        tce.appendChild(div);
        div.appendChild(divText);
        tce.setTabIndex(0);

        //Add on "Grouping" widget, if applicable
        if (rowSpan > 1 || cellData.isGrouped()) {
            Element de = DOM.createDiv();
            DivElement divGroup = DivElement.as(de);
            divGroup.setTitle(Constants.INSTANCE.groupCells());
            divGroup.addClassName(resources.cellTableGroupDiv());
            if (cellData.isGrouped()) {
                divGroup.setInnerHTML(selectorUngroupedCellsHtml);
            } else {
                divGroup.setInnerHTML(selectorGroupedCellsHtml);
            }
            div.appendChild(divGroup);
        }

    }
    return tce;

}

From source file:org.kie.guvnor.decoratedgrid.client.widget.AbstractVerticalMergableGridWidget.java

License:Apache License

@Override
@SuppressWarnings({ "rawtypes" })
void deselectCell(CellValue<? extends Comparable<?>> cell) {
    if (cell == null) {
        throw new IllegalArgumentException("cell cannot be null");
    }//from  www  .  j a v  a  2 s.c  o m

    Coordinate hc = cell.getHtmlCoordinate();
    TableRowElement tre = tbody.getRows().getItem(hc.getRow()).<TableRowElement>cast();
    TableCellElement tce = tre.getCells().getItem(hc.getCol()).<TableCellElement>cast();

    //Merging, grouping etc could have led to the selected HTML cell disappearing
    if (tce != null) {
        String cellSelectedStyle = resources.cellTableCellSelected();
        String cellMultipleValuesStyle = resources.cellTableCellMultipleValues();
        String cellOtherwiseStyle = resources.cellTableCellOtherwise();
        tce.removeClassName(cellSelectedStyle);

        //Re-apply applicable styling
        if (cell.isOtherwise()) {
            tce.addClassName(cellOtherwiseStyle);
        }
        if (cell instanceof CellValue.GroupedCellValue) {
            CellValue.GroupedCellValue gcv = (CellValue.GroupedCellValue) cell;
            if (gcv.hasMultipleValues()) {
                tce.addClassName(cellMultipleValuesStyle);
            }
        }
    }
}