Example usage for com.google.gwt.user.client.ui FlexTable getCellCount

List of usage examples for com.google.gwt.user.client.ui FlexTable getCellCount

Introduction

In this page you can find the example usage for com.google.gwt.user.client.ui FlexTable getCellCount.

Prototype

@Override
public int getCellCount(int row) 

Source Link

Document

Gets the number of cells on a given row.

Usage

From source file:org.metawidget.gwt.client.ui.layout.FlexTableLayout.java

License:LGPL

public void layoutWidget(Widget widget, String elementName, Map<String, String> attributes, Panel container,
        GwtMetawidget metawidget) {//  ww w. ja  va 2 s. co m

    // Do not render empty stubs

    if (widget instanceof Stub && ((Stub) widget).getWidgetCount() == 0) {
        return;
    }

    // Calculate row and actualColumn. Note FlexTable doesn't work quite as might be
    // expected. Specifically, it doesn't understand 'colspan' in relation to previous rows. So
    // if you do...
    //
    // layout.setWidget( row, 0, widget1 );
    // layout.setColSpan( row, 0, 2 );
    // layout.setWidget( row, 2, widget2 );
    //
    // ...you'll actually get...
    //
    // <td colspan="2">widget1</td>
    // <td/>
    // <td>widget2</td>
    //
    // ...note FlexTable inserts an extra <td/> because it thinks column 1 is missing. Therefore
    // the actualColumn is always just the next column, regardless of what state.mCurrentColumn
    // is

    int actualColumn;
    FlexTable flexTable = (FlexTable) ((ComplexPanel) container).getWidget(0);
    int row = flexTable.getRowCount();

    int numberOfColumns = getEffectiveNumberOfColumns(container);

    State state = getState(container, metawidget);

    if (state.currentColumn < numberOfColumns && row > 0) {
        row--;
        actualColumn = flexTable.getCellCount(row);
    } else {
        state.currentColumn = 0;
        actualColumn = 0;
    }

    // Special support for large components

    boolean spanAllColumns = willFillHorizontally(widget, attributes);

    if (spanAllColumns && state.currentColumn > 0) {
        state.currentColumn = 0;
        actualColumn = 0;
        row++;
    }

    // Label

    String labelText = metawidget.getLabelString(attributes);

    if (SimpleLayoutUtils.needsLabel(labelText, elementName)) {

        // Note: GWT Labels are not real HTML labels, and have no 'for' attribute

        Label label = new Label(labelText + StringUtils.SEPARATOR_COLON);
        String styleName = getStyleName(state.currentColumn * LABEL_AND_COMPONENT_AND_REQUIRED, metawidget);

        if (styleName != null) {
            state.formatter.setStyleName(row, actualColumn, styleName);
        }

        flexTable.setWidget(row, actualColumn, label);
    }

    // Widget

    // Widget column (null labels get collapsed, blank Strings get preserved)

    if (labelText != null) {
        // Zero-column layouts need an extra row

        if (numberOfColumns == 0) {
            state.currentColumn = 0;
            actualColumn = 0;
            row++;
        } else {
            actualColumn++;
        }
    }

    String styleName = getStyleName((state.currentColumn * LABEL_AND_COMPONENT_AND_REQUIRED) + 1, metawidget);

    if (styleName != null) {
        state.formatter.setStyleName(row, actualColumn, styleName);
    }

    flexTable.setWidget(row, actualColumn, widget);

    // Colspan

    int colspan;

    // Metawidgets and large components span all columns

    if (spanAllColumns) {
        colspan = (numberOfColumns * LABEL_AND_COMPONENT_AND_REQUIRED) - 2;
        state.currentColumn = numberOfColumns;

        if (labelText == null) {
            colspan++;
        }

        // Metawidgets span the required column too

        if (widget instanceof GwtMetawidget) {
            colspan++;
        }
    } else if (labelText == null) {

        // Components without labels span two columns

        colspan = 2;
    } else {

        // Everyone else spans just one

        colspan = 1;
    }

    if (colspan > 1) {
        state.formatter.setColSpan(row, actualColumn, colspan);
    }

    // Required

    if (!(widget instanceof GwtMetawidget)) {
        layoutRequired(attributes, container, metawidget);
    }

    state.currentColumn++;
}

From source file:org.metawidget.gwt.client.ui.layout.FlexTableLayout.java

License:LGPL

protected void layoutRequired(Map<String, String> attributes, Widget container, GwtMetawidget metawidget) {

    State state = getState(container, metawidget);
    FlexTable flexTable = (FlexTable) ((ComplexPanel) container).getWidget(0);
    int row = flexTable.getRowCount() - 1;
    int column = flexTable.getCellCount(row);

    state.formatter.setStyleName(row, column,
            getStyleName((state.currentColumn * LABEL_AND_COMPONENT_AND_REQUIRED) + 2, metawidget));

    if (attributes != null && TRUE.equals(attributes.get(REQUIRED)) && !TRUE.equals(attributes.get(READ_ONLY))
            && !metawidget.isReadOnly()) {
        flexTable.setText(row, column, "*");
        return;/*from  w w w  .ja v  a 2 s .  c o  m*/
    }

    // Render an empty div, so that the CSS can force it to a certain
    // width if desired for the layout (browsers seem to not respect
    // widths set on empty table columns)
    //
    // Note: don't do <div/>, as we may not be XHTML

    flexTable.setHTML(row, column, "<div></div>");
}

From source file:org.pentaho.pat.client.ui.widgets.DimensionSimplePanel.java

License:Open Source License

private int[] getWidgetRow(Widget widget, FlexTable table) {

    for (int row = 0; row < table.getRowCount(); row++) {
        for (int col = 0; col < table.getCellCount(row); col++) {
            Widget w = table.getWidget(row, col);
            if (w == widget) {
                return new int[] { row, col };
            }/*from  w  ww .j ava 2s.  c o m*/
        }
    }

    return null;
}

From source file:org.pepstock.jem.gwt.client.commons.UITools.java

License:Open Source License

/**
 * Format FlexTable columns in order to make columns easy-readable  
 * @param t the FlexTable/*from   w w w. j  av  a2  s.  c  o m*/
 * @param style Odd column style
 * @param skipFirstRow if <code>true</code> leave the first row as is (for table header)
 */
public static void setColumnKeyValueStyle(FlexTable t, String style, boolean skipFirstRow) {
    FlexCellFormatter cf = t.getFlexCellFormatter();
    int i = skipFirstRow ? 1 : 0;
    for (i = 0; i < t.getRowCount(); i++) {
        for (int j = 0; j < t.getCellCount(i); j++) {
            if (j % 2 == 0) {
                cf.addStyleName(i, j, style);
            }
        }
    }
}

From source file:org.pepstock.jem.gwt.client.commons.UITools.java

License:Open Source License

/**
 * Format FlexTable header in order to make header easy-readable  
 * @param t the FlexTable/* w  ww.j  a  va  2  s .c o m*/
 * @param style Odd column style
 */
public static void setHeaderStyle(FlexTable t, String style) {
    FlexCellFormatter cf = t.getFlexCellFormatter();
    for (int i = 0; i < t.getCellCount(0); i++) {
        cf.addStyleName(0, i, style);
    }
}

From source file:org.sonatype.nexus.gwt.ui.client.repository.RepositoryPage.java

License:Open Source License

protected void addCell(FlexTable table, String string, int span) {
    int row = table.getRowCount() - 1;
    int column = table.getCellCount(row);
    table.setText(row, column, string);//ww  w. j  a  v a2s.c  o m
    if (span > 1) {
        ((FlexTable.FlexCellFormatter) table.getCellFormatter()).setColSpan(row, column, span);
    }
}

From source file:org.sonatype.nexus.gwt.ui.client.repository.RepositoryPage.java

License:Open Source License

protected void addCell(FlexTable table, Widget widget, int span) {
    int row = table.getRowCount() - 1;
    int column = table.getCellCount(row);
    table.setWidget(row, column, widget);
    if (span > 1) {
        ((FlexTable.FlexCellFormatter) table.getCellFormatter()).setColSpan(row, column, span);
    }//from   ww w  .jav  a  2s .  co m
}

From source file:org.zoxweb.client.widget.WidgetUtil.java

License:Apache License

public static NVBaseWidget<?> lookupNVBaseWidgetByNVC(FlexTable flexTable, NVConfig nvc) {
    if (flexTable != null && flexTable.getRowCount() > 0 && nvc != null) {
        for (int row = 0; row < flexTable.getRowCount(); row++) {
            int columnCount = flexTable.getCellCount(row);

            if (columnCount > 0) {
                for (int column = 0; column < columnCount; column++) {
                    Widget widget = flexTable.getWidget(row, column);

                    if (widget != null & widget instanceof NVBaseWidget) {
                        NVBaseWidget<?> nvbw = (NVBaseWidget<?>) widget;

                        if (nvbw.getNVConfig() != null && nvc.getName().equals(nvbw.getNVConfig().getName())) {
                            return nvbw;
                        }/*  w ww.j ava  2s . co  m*/
                    }

                }
            }
        }
    }

    return null;
}

From source file:org.zoxweb.client.widget.WidgetUtil.java

License:Apache License

public static NVBaseWidget<?> lookupNVBaseWidgetByNVC(FlexTable flexTable, NVConfig nvc, int column) {
    if (flexTable != null && nvc != null && column > -1) {
        for (int row = 0; row < flexTable.getRowCount(); row++) {
            if (flexTable.getCellCount(row) > column) {
                Widget widget = flexTable.getWidget(row, column);

                if (widget != null & widget instanceof NVBaseWidget) {
                    NVBaseWidget<?> nvbw = (NVBaseWidget<?>) widget;

                    if (nvbw.getNVConfig() != null && nvc.getName().equals(nvbw.getNVConfig().getName())) {
                        return nvbw;
                    }//  w  w  w.  j  a  va  2  s .  co  m
                }
            }
        }
    }

    return null;
}

From source file:org.zoxweb.client.widget.WidgetUtil.java

License:Apache License

public static List<Integer> getRowsByWidgetName(FlexTable flexTable, String name) {
    if (flexTable != null && name != null) {
        List<Integer> list = new ArrayList<Integer>();

        for (int row = 0; row < flexTable.getRowCount(); row++) {
            if (flexTable.getCellCount(row) > 1) {
                Widget widget = flexTable.getWidget(row, 1);

                if (widget instanceof NVBaseWidget) {
                    NVBaseWidget<?> nvbw = (NVBaseWidget<?>) widget;

                    if (nvbw.getName() != null && name.equals(nvbw.getName())) {
                        list.add(row);/*from w w w. ja  v  a2s. c  om*/
                    }
                }
            }
        }

        return list;
    }

    return null;
}