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

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

Introduction

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

Prototype

@Override
public int insertRow(int beforeRow) 

Source Link

Document

Inserts a row into the FlexTable.

Usage

From source file:ch.eaternity.client.FlexTableUtil.java

License:Apache License

/**
 * Copy an entire FlexTable from one FlexTable to another. Each element is copied by creating a
 * new {@link HTML} widget by calling {@link FlexTable#getHTML(int, int)} on the source table.
 * /*from ww w . jav a  2s  . com*/
 * @param sourceTable the FlexTable to copy a row from
 * @param targetTable the FlexTable to copy a row to
 * @param sourceRow the index of the source row
 * @param targetRow the index before which to insert the copied row
 */
public static void copyRow(FlexTable sourceTable, FlexTable targetTable, int sourceRow, int targetRow) {
    targetTable.insertRow(targetRow);
    for (int col = 0; col < sourceTable.getCellCount(sourceRow); col++) {
        HTML html = new HTML(sourceTable.getHTML(sourceRow, col));
        targetTable.setWidget(targetRow, col, html);
    }
    copyRowStyle(sourceTable, targetTable, sourceRow, targetRow);
}

From source file:ch.eaternity.client.FlexTableUtil.java

License:Apache License

/**
 * Move an entire FlexTable from one FlexTable to another. Elements are moved by attempting to
 * call {@link FlexTable#getWidget(int, int)} on the source table. If no widget is found (because
 * <code>null</code> is returned), a new {@link HTML} is created instead by calling
 * {@link FlexTable#getHTML(int, int)} on the source table.
 * //ww w. j a  va  2  s  .co  m
 * @param sourceTable the FlexTable to move a row from
 * @param targetTable the FlexTable to move a row to
 * @param sourceRow the index of the source row
 * @param targetRow the index before which to insert the moved row
 */
public static void moveRow(FlexTable sourceTable, FlexTable targetTable, int sourceRow, int targetRow) {
    if (sourceTable == targetTable && sourceRow >= targetRow) {
        sourceRow++;
    }
    targetTable.insertRow(targetRow);
    for (int col = 0; col < sourceTable.getCellCount(sourceRow); col++) {
        Widget w = sourceTable.getWidget(sourceRow, col);
        if (w != null) {
            targetTable.setWidget(targetRow, col, w);
        } else {
            HTML html = new HTML(sourceTable.getHTML(sourceRow, col));
            targetTable.setWidget(targetRow, col, html);
        }
    }
    copyRowStyle(sourceTable, targetTable, sourceRow, targetRow);
    sourceTable.removeRow(sourceRow);
}

From source file:com.alkacon.opencms.v8.calendar.client.input.CmsSerialDate.java

License:Open Source License

/**
 * Category field widgets for ADE forms.<p>
 * @param labels a JSON of all needed labels
 *//*  w w  w .j a v  a2  s  .c  om*/
public CmsSerialDate(JSONObject labels) {

    super();

    m_labels = labels;

    m_dailyPattern = new CmsPatternPanelDaily(m_labels);
    m_weeklyPattern = new CmsPatternPanelWeekly(m_labels);
    m_monthlyPattern = new CmsPatternPanelMonthly(m_labels);
    m_yearlyPattern = new CmsPatternPanelYearly(m_labels);
    m_patterPanel = m_dailyPattern;
    try {
        m_timeFormat = DateTimeFormat.getFormat(Messages.get().key(Messages.GUI_DATEBOX_TIME_PATTERN_0));
    } catch (Exception e) {
        // in case the pattern is not available, fall back to standard en pattern
        m_timeFormat = DateTimeFormat.getFormat("hh:mm aa");
    }
    m_endDate.setValue(m_timeFormat.format(new Date()));
    m_startDate.setValue(m_timeFormat.format(new Date()));
    m_dateboxbegin.setValue(new Date());

    setSelectVaues();
    setTopPanel();
    setLowPanel();

    m_dateboxbegin.getTextField().getTextBoxContainer().addStyleName(
            org.opencms.ade.contenteditor.client.css.I_CmsLayoutBundle.INSTANCE.widgetCss().calendarStyle());
    m_dateboxend.getTextField().getTextBoxContainer().addStyleName(
            org.opencms.ade.contenteditor.client.css.I_CmsLayoutBundle.INSTANCE.widgetCss().calendarStyle());

    m_table.addStyleName(I_CmsLayoutBundle.INSTANCE.widgetCss().serialDataTabel());
    m_table.insertRow(0);

    // Table for top panel
    FlexTable topPanel = new FlexTable();
    topPanel.insertRow(0);
    // add the Time view.
    topPanel.setWidget(0, 0, m_topPanel);
    topPanel.getCellFormatter().getElement(0, 0).getStyle().setWidth(200, Unit.PX);
    // add the date view.
    topPanel.setWidget(0, 1, m_lowPanel);
    m_table.setWidget(0, 0, topPanel);
    m_table.getFlexCellFormatter().setColSpan(0, 0, 3);
    m_table.getCellFormatter().addStyleName(0, 0,
            I_CmsLayoutBundle.INSTANCE.widgetCss().serialDataTabelBorderBottom());

    // the selection view
    m_table.insertRow(1);
    m_table.setWidget(1, 0, m_serialPanel);
    m_table.getCellFormatter().getElement(1, 0).getStyle().setWidth(1, Unit.PX);
    m_table.setWidget(1, 1, new SimplePanel());
    m_table.getCellFormatter().addStyleName(1, 1,
            I_CmsLayoutBundle.INSTANCE.widgetCss().serialDataTabelBorderRight());
    m_table.setWidget(1, 2, m_patterPanel);

    for (int i = 0; i < m_arrayRadiobox.length; i++) {
        m_arrayRadiobox[i].addStyleName(org.opencms.ade.contenteditor.client.css.I_CmsLayoutBundle.INSTANCE
                .widgetCss().radioButtonlabel());
        m_arrayRadiobox[i].addClickHandler(new ClickHandler() {

            public void onClick(ClickEvent event) {

                changePattern();
            }
        });

        m_serialPanel.add(m_arrayRadiobox[i]);
    }
    initWidget(m_panel);
    m_panel.add(m_table);
    m_panel.add(m_error);

}

From source file:com.alkacon.opencms.v8.calendar.client.input.CmsSerialDate.java

License:Open Source License

/**
 * Private function to set all the end selections.<p>
 * *///from w w  w .  ja va2  s.  com
private void setLowPanel() {

    FlexTable table = new FlexTable();
    table.insertRow(0);
    FlowPanel cell1 = new FlowPanel();
    Label startDate = new Label(m_labels.get("GUI_SERIALDATE_TIME_STARTDATE_0").isString().stringValue());
    startDate.addStyleName(I_CmsLayoutBundle.INSTANCE.widgetCss().serialDateLable());
    cell1.add(startDate);
    cell1.getElement().getStyle().setWidth(100, Unit.PCT);
    cell1.add(m_dateboxbegin);
    m_dateboxbegin.setDateOnly(true);
    m_dateboxbegin.getElement().getStyle().setWidth(108, Unit.PX);
    m_dateboxbegin.getElement().getStyle().setFloat(Float.RIGHT);
    m_dateboxbegin.addValueChangeHandler(new ValueChangeHandler<Date>() {

        public void onValueChange(ValueChangeEvent<Date> event) {

            fireValueChange();

        }
    });
    table.setWidget(0, 0, cell1);
    table.getCellFormatter().getElement(0, 0).getStyle().setWidth(185, Unit.PX);
    table.getCellFormatter().getElement(0, 0).getStyle().setVerticalAlign(VerticalAlign.TOP);

    FlowPanel cell2 = new FlowPanel();
    CmsRadioButton sel1 = new CmsRadioButton("1",
            m_labels.get("GUI_SERIALDATE_DURATION_ENDTYPE_NEVER_0").isString().stringValue());
    m_lowRadioButton[0] = sel1;
    sel1.setGroup(m_groupDuration);
    sel1.setChecked(true);
    sel1.addStyleName(I_CmsLayoutBundle.INSTANCE.widgetCss().serialDatelowPanelSelection());
    sel1.addStyleName(
            org.opencms.ade.contenteditor.client.css.I_CmsLayoutBundle.INSTANCE.widgetCss().radioButtonlabel());
    sel1.getElement().getStyle().setMarginLeft(13, Unit.PX);
    sel1.getElement().getStyle().setMarginTop(0, Unit.PX);
    sel1.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {

            fireValueChange();

        }
    });

    CmsRadioButton sel2 = new CmsRadioButton("2",
            m_labels.get("GUI_SERIALDATE_DURATION_ENDTYPE_OCC_0").isString().stringValue());
    m_lowRadioButton[1] = sel2;
    sel2.setGroup(m_groupDuration);
    sel2.addStyleName(I_CmsLayoutBundle.INSTANCE.widgetCss().serialDatelowPanelSelection());
    sel2.addStyleName(
            org.opencms.ade.contenteditor.client.css.I_CmsLayoutBundle.INSTANCE.widgetCss().radioButtonlabel());
    sel2.getElement().setAttribute("style", "clear:left");
    sel2.getElement().getStyle().setMarginLeft(13, Unit.PX);
    sel2.getElement().getStyle().setMarginTop(6, Unit.PX);
    sel2.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {

            if (m_times.getText().isEmpty()) {
                m_times.setValue("1");
            }
            fireValueChange();

        }
    });

    CmsRadioButton sel3 = new CmsRadioButton("3",
            m_labels.get("GUI_SERIALDATE_DURATION_ENDTYPE_DATE_0").isString().stringValue());
    m_lowRadioButton[2] = sel3;
    sel3.setGroup(m_groupDuration);
    sel3.addStyleName(I_CmsLayoutBundle.INSTANCE.widgetCss().serialDatelowPanelSelection());
    sel3.addStyleName(
            org.opencms.ade.contenteditor.client.css.I_CmsLayoutBundle.INSTANCE.widgetCss().radioButtonlabel());
    sel3.getElement().setAttribute("style", "clear:left");
    sel3.getElement().getStyle().setMarginLeft(13, Unit.PX);
    sel3.getElement().getStyle().setMarginTop(6, Unit.PX);
    sel3.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {

            m_dateboxend.setValue(new Date());
            fireValueChange();

        }
    });

    cell2.add(sel1);
    cell2.add(sel2);

    m_times.setStyleName(I_CmsLayoutBundle.INSTANCE.widgetCss().textBoxSerialDate());
    m_times.getElement().getStyle().setMarginTop(5, Unit.PX);
    m_times.getElement().getStyle().setWidth(82, Unit.PX);
    cell2.add(m_times);
    m_times.addKeyPressHandler(new KeyPressHandler() {

        public void onKeyPress(KeyPressEvent event) {

            fireValueChange();

        }
    });
    m_times.addValueChangeHandler(new ValueChangeHandler<String>() {

        public void onValueChange(ValueChangeEvent<String> event) {

            fireValueChange();

        }

    });
    m_times.addFocusHandler(new FocusHandler() {

        public void onFocus(FocusEvent event) {

            selectEnding(1);

        }
    });
    Label times = new Label(
            m_labels.get("GUI_SERIALDATE_DURATION_ENDTYPE_OCC_TIMES_0").isString().stringValue());
    times.addStyleName(I_CmsLayoutBundle.INSTANCE.widgetCss().serialDateLable());
    times.getElement().getStyle().setMarginTop(7, Unit.PX);
    times.getElement().getStyle().setMarginLeft(2, Unit.PX);
    cell2.add(times);
    cell2.add(sel3);

    cell2.add(m_dateboxend);
    m_dateboxend.setDateOnly(true);
    m_dateboxend.getElement().getStyle().setWidth(90, Unit.PX);
    m_dateboxend.getElement().getStyle().setMarginTop(5, Unit.PX);
    m_dateboxend.getElement().getStyle().setMarginLeft(22, Unit.PX);
    m_dateboxend.addValueChangeHandler(new ValueChangeHandler<Date>() {

        public void onValueChange(ValueChangeEvent<Date> event) {

            fireValueChange();

        }
    });
    m_dateboxend.addDomHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {

            selectEnding(2);

        }
    }, ClickEvent.getType());
    table.setWidget(0, 1, cell2);
    m_lowPanel.add(table);
    m_lowPanel.setStyleName(I_CmsLayoutBundle.INSTANCE.widgetCss().serialDatelowPanel());
}

From source file:com.google.caliper.cloud.client.BenchmarkDataViewer.java

License:Apache License

public void rebuildResultsTable() {
    if (plainText) {
        Label label = new Label();
        label.setStyleName("plaintext");
        label.setText(gridToString(toGrid()));

        resultsDiv.clear();/*from ww  w  .  ja  v  a  2s  . c o  m*/
        resultsDiv.add(label);
        resultsDiv.add(new PlainTextEditor().getWidget());
        HTML dash = new HTML(" - ", false);
        dash.setStyleName("inline");
        resultsDiv.add(dash);
        resultsDiv.add(new SnapshotCreator().getWidget());
        return;
    }

    FlexTable table = new FlexTable();
    table.setStyleName("data");
    int r = 0;
    int c = 0;
    int evenRowMod = 0;

    // results header #1: cValue variables
    if (cVariable != null) {
        evenRowMod = 1;
        table.insertRow(r);
        table.getRowFormatter().setStyleName(r, "valueRow");
        table.getRowFormatter().addStyleName(r, "headerRow");

        table.addCell(r);
        table.getFlexCellFormatter().setColSpan(r, 0, rVariables.size());
        c++;
        for (Value cValue : cValues) {
            table.addCell(r);
            table.getFlexCellFormatter().setColSpan(r, c, 3);
            table.getCellFormatter().setStyleName(r, c, "parameterKey");

            Widget contents = newVariableLabel(cVariable, cValue.getLabel(), rVariables.size());
            contents.setStyleName("valueHeader");

            table.setWidget(r, c++, contents);
        }
        r++;
    }

    // results header 2: rValue variables, followed by "nanos/barchart" column pairs
    c = 0;
    table.insertRow(r);
    table.getRowFormatter().setStyleName(r, "evenRow");
    table.getRowFormatter().addStyleName(r, "headerRow");
    for (Variable variable : rVariables) {
        table.addCell(r);
        table.getCellFormatter().setStyleName(r, c, "parameterKey");
        table.setWidget(r, c, newVariableLabel(variable, variable.getName(), c));
        c++;
    }
    for (Value unused : cValues) {
        table.addCell(r);
        table.getCellFormatter().setStyleName(r, c, "parameterKey");
        table.setWidget(r, c++, newUnitLabel(unitMap.get(selectedType).trim()));

        table.addCell(r);
        table.getCellFormatter().setStyleName(r, c, "parameterKey");
        table.setWidget(r, c++, newRuntimeLabel());

        table.addCell(r);
        table.getCellFormatter().setStyleName(r, c, "parameterKey");
        table.setWidget(r, c++, new InlineLabel("%"));
    }
    r++;

    Key key = newDefaultKey();
    for (RowsIterator rows = new RowsIterator(rVariables); rows.nextRow();) {
        rows.updateKey(key);

        table.insertRow(r);
        table.getRowFormatter().setStyleName(r, r % 2 == evenRowMod ? "evenRow" : "oddRow");
        c = 0;
        for (int v = 0, size = rVariables.size(); v < size; v++) {
            table.addCell(r);
            table.setWidget(r, c++, new Label(rows.getRValue(v).getLabel()));
        }

        for (Value value : cValues) {
            table.addCell(r);
            table.addCell(r);

            if (cVariable != null) {
                key.set(cVariable, value);
            }

            final Datapoint datapoint = keysToDatapoints.get(key);
            table.getCellFormatter().setStyleName(r, c, "numericCell");
            table.getCellFormatter().setStyleName(r, c + 1, "bar");
            table.getCellFormatter().setStyleName(r, c + 2, "numericCell");
            MeasurementSet measurementSet;
            if (datapoint != null
                    && (measurementSet = datapoint.scenarioResults.getMeasurementSet(selectedType)) != null) {
                double rawMedian = getMedian(selectedType, measurementSet);
                String displayedValue = numberFormatMap.get(selectedType)
                        .format(rawMedian / divideByMap.get(selectedType));
                Anchor valueAnchor = new Anchor(displayedValue, false);
                valueAnchor.setStyleName("subtleLink");
                valueAnchor.setStyleName("nanos", true);

                final DialogBox eventLogPopup = new DialogBox(true);
                eventLogPopup.setText("");

                valueAnchor.addClickHandler(new ClickHandler() {
                    public void onClick(ClickEvent clickEvent) {
                        // Do this lazily since it takes quite a bit of time to render these popups for all
                        // the scenarios shown, and quite often they won't even be used.
                        if (eventLogPopup.getText().isEmpty()) {
                            eventLogPopup.setText("Event Log");
                            String eventLog = datapoint.scenarioResults.getEventLog(selectedType);
                            if (eventLog == null || eventLog.isEmpty()) {
                                eventLog = "No event log recorded.";
                            }
                            FlowPanel panel = new FlowPanel();
                            for (String line : eventLog.split("\n")) {
                                panel.add(new Label(line));
                            }
                            panel.setStyleName("eventLog");
                            eventLogPopup.add(panel);
                        }
                        eventLogPopup.center();
                        eventLogPopup.show();
                    }
                });

                table.setWidget(r, c, valueAnchor);
                table.setWidget(r, c + 1, newBar(datapoint.style, measurementSet, value));
                table.setWidget(r, c + 2, newPercentOfReferencePointLabel(rawMedian, value));
            } else {
                table.setWidget(r, c, new Label(""));
                table.setWidget(r, c + 1, new Label(""));
                table.setWidget(r, c + 2, new Label(""));
            }
            c += 3;
        }

        r++;
    }
    resultsDiv.clear();
    resultsDiv.add(table);
    resultsDiv.add(new PlainTextEditor().getWidget());
    HTML dash = new HTML(" - ", false);
    dash.setStyleName("inline");
    resultsDiv.add(dash);
    resultsDiv.add(new SnapshotCreator().getWidget());
}

From source file:com.google.caliper.cloud.client.BenchmarkDataViewer.java

License:Apache License

public void rebuildVariablesTable() {
    FlexTable table = new FlexTable();
    table.setStyleName("data");

    int r = 0;/*ww  w  .  j a  v a2s.  c o m*/
    for (Variable variable : variables) {
        table.insertRow(r);

        table.addCell(r);
        table.getRowFormatter().setStyleName(r, r % 2 == 0 ? "evenRow" : "oddrow");
        table.getCellFormatter().setStyleName(r, 0, "fixedParameterKey");
        table.setWidget(r, 0, new Label(variable.getName()));

        table.addCell(r);
        FlowPanel checkBoxes = new FlowPanel();
        if (variable.hasMultipleValues()) {
            for (Value value : variable.getValues()) {
                checkBoxes.add(newShownCheckbox(value));
            }
        } else {
            checkBoxes.add(new Label(variable.getOnlyValue().getName()));
        }
        table.setWidget(r, 1, checkBoxes);

        r++;
    }

    fixedVariablesDiv.clear();
    fixedVariablesDiv.add(table);
}

From source file:com.google.gwt.gears.sample.workerpool.client.WorkerPoolDemo.java

License:Apache License

/**
 * Utility routine to construct one row of the user interface control panel.
 * //from ww w. j  a  v a 2  s .  c om
 * @param table the table to add to.
 * @param text HTML text to add in the first column
 * @param w a widget in the control panel to add in the second column.
 */
private void buildControlPanelRow(FlexTable table, String text, Widget w) {
    table.insertRow(currentRow);
    table.insertCell(currentRow, 0);
    table.setWidget(currentRow, 0, new HTML(text));
    table.insertCell(currentRow, 1);
    table.setWidget(currentRow, 1, w);
    currentRow++;
}

From source file:com.google.gwt.sample.healthyeatingapp.client.FoodLog.FoodLog.java

public FlowPanel onModuleLoad() {

    rpcUserNameCall();/*from w w  w.j  a v a2  s  . com*/
    rpcCall();

    // Create a Flex Table
    final FlexTable flexTable = new FlexTable();
    FlexCellFormatter cellFormatter = flexTable.getFlexCellFormatter();
    flexTable.addStyleName("flexTable");
    flexTable.setCellSpacing(2);
    flexTable.setCellPadding(2);

    lbFG = new ListBox();
    lbFN = new ListBox();
    submit = new Button("Submit");
    cancel = new Button("Pick a New Date");

    fp = new FlowPanel();
    // Add some text
    cellFormatter.setHorizontalAlignment(0, 1, HasHorizontalAlignment.ALIGN_CENTER);
    flexTable.setHTML(0, 0, "This table allows you to log your food entries:");
    cellFormatter.setColSpan(0, 0, 2);

    lbFG.setVisibleItemCount(1);

    lbFN.setVisible(false);
    lbFG.addChangeHandler(new ChangeHandler() {

        @Override
        public void onChange(ChangeEvent event) {
            fp.remove(SuccessLabel);
            int selectedIndex = lbFG.getSelectedIndex();
            int numRows = 0;

            if (selectedIndex > 0) {

                numRows = flexTable.getRowCount();
                flexTable.setWidget(numRows - 1, 0, lbFG);
                lbFN.clear();
                caloriesText.setText("", Direction.DEFAULT);

                String test = lbFG.getValue(lbFG.getSelectedIndex());
                String[] str = getFoodNames(ret, test);
                lbFN.addItem("");
                for (String s : str) {
                    lbFN.addItem(s);
                }
                lbFN.setSelectedIndex(0);
                lbFN.setVisible(true);

                flexTable.setWidget(numRows - 1, 1, lbFN);
            }

        }
    });

    lbFN.addChangeHandler(new ChangeHandler() {

        @Override
        public void onChange(ChangeEvent event) {
            int selectedIndex = lbFN.getSelectedIndex();
            int numRows = 0;
            if (selectedIndex > 0)

                numRows = flexTable.getRowCount();
            flexTable.setWidget(numRows - 1, 1, lbFN);

            String test = lbFN.getValue(lbFN.getSelectedIndex());
            String str = "" + getCalories(ret, test);
            caloriesText.setText(str, Direction.DEFAULT);
            flexTable.setWidget(numRows - 1, 2, caloriesText);

        }
    });

    // Add a button that will add more rows to the table
    final Button addRowButton = new Button("Add a Row");
    Button btn2 = new Button("Update");
    addRowButton.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            fp.remove(SuccessLabel);
            addRow(flexTable);
        }
    });

    addRowButton.addStyleName("fixedWidthButton");

    VerticalPanel buttonPanel = new VerticalPanel();
    buttonPanel.setStyleName("flexTable-buttonPanel");
    buttonPanel.add(addRowButton);
    flexTable.setWidget(0, 1, buttonPanel);
    cellFormatter.setVerticalAlignment(0, 1, HasVerticalAlignment.ALIGN_TOP);

    // Add two rows to start
    // addRow(flexTable);

    final DatePicker datePicker = new DatePicker();

    // Set the value in the text box when the user selects a date
    datePicker.addValueChangeHandler(new ValueChangeHandler<Date>() {

        public void onValueChange(ValueChangeEvent<Date> event) {

            Date date = event.getValue();
            DateFormat dfm = new SimpleDateFormat("yyyy-MM-dd");
            dateString = dfm.format(date);
            dateLabel.setText(dateString, Direction.DEFAULT);
            selectedDate = dateLabel.getText();
            queryRpcCall(userNameTyped, selectedDate);

        }
    });
    final Button Btn2 = new Button();
    ret = new ArrayList<FoodLogItems>();
    Btn2.setSize("100px", "30px");
    Btn2.setText("View/Update");
    Btn2.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            Btn2.setVisible(false);
            datePicker.setVisible(false);

            selectedDate = dateLabel.getText();
            String[] dbRows;
            String[] dbElements;

            // Window.alert(prevFoodData);
            if (!(prevFoodData.equals(""))) {

                dbRows = prevFoodData.split(";");
                for (String s : dbRows)

                {
                    dbElements = s.split(":");
                    FoodLogData e = new FoodLogData(userNameTyped, dbElements[2],
                            Integer.parseInt(dbElements[1]), dbElements[0], selectedDate);
                    foodEntries.add(e);
                }

            }

            String[] temp;
            if (foodLogItems != null) {
                array = foodLogItems.split(";");
                // String s="";
                for (String s : array)

                {
                    temp = s.split(":");
                    FoodLogItems e = new FoodLogItems(temp[0], Integer.parseInt(temp[1]), temp[2]);
                    ret.add(e);
                }
                lbFG.addItem("");

                String[] input = new String[ret.size()];
                int i = 0;
                for (FoodLogItems e : ret) {

                    input[i] = e.FoodGroup();
                    i++;

                }

                Set<String> tmp = new LinkedHashSet<String>();
                for (String each : input) {
                    tmp.add(each);
                }
                String[] output = new String[tmp.size()];
                int j = 0;
                for (String each : tmp) {
                    output[j++] = each;
                }

                for (String s : output) {
                    lbFG.addItem(s);
                }

                lbFG.setSelectedIndex(0);

            }

            int numRows = flexTable.getRowCount();
            // Window.alert(""+numRows);
            flexTable.removeAllRows();
            flexTable.insertRow(0);

            int i = 0;
            for (FoodLogData j : foodEntries) {

                flexTable.insertRow(i + 1);
                numRows = flexTable.getRowCount();

                flexTable.setText(numRows - 1, 0, j.getFoodGroup());
                flexTable.setText(numRows - 1, 1, j.getFoodName());
                flexTable.setText(numRows - 1, 2, j.getCalories() + "");

                flexTable.getFlexCellFormatter().setRowSpan(0, 1, numRows + 1);

                i++;

            }
            numRows = flexTable.getRowCount();
            lbFG.setSelectedIndex(0);
            flexTable.setWidget(numRows, 0, lbFG);
            flexTable.getFlexCellFormatter().setRowSpan(0, 1, numRows + 1);

            fp.add(flexTable);
            fp.add(addRowButton);
            fp.add(submit);
            fp.add(cancel);

        }
    });

    InlineLabel dateMessageLabel = new InlineLabel();
    dateMessageLabel.setText("Pick a date: ");

    submit.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            System.out.println("Submitting these items");
            for (FoodLogData e : foodEntries) {
                System.out.println("Food name is " + e.getFoodName());
                insertRpcCall(e.getUserName(), e.getFoodName(), e.getDate(), e.getCalories());
            }
            fp.add(SuccessLabel);
            foodEntries.clear();
        }

    });
    cancel.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {

            // TODO Auto-generated method stub
            fp.remove(SuccessLabel);
            Window.Location.reload();
        }

    });

    fp.add(dateMessageLabel);
    fp.add(dateLabel);
    fp.add(datePicker);
    fp.add(Btn2);

    return fp;

}

From source file:com.google.gwt.sample.healthyeatingapp.client.FoodLog.FoodLog.java

private void addRow(FlexTable flexTable) {
    int numRows = flexTable.getRowCount();

    if ((lbFG.getSelectedIndex() != 0)) {

        if ((lbFN.getSelectedIndex() != 0)) {

            String str2 = lbFG.getValue(lbFG.getSelectedIndex());
            String str3 = lbFN.getValue(lbFN.getSelectedIndex());
            String str4 = flexTable.getText(numRows - 1, 2);

            FoodLogData e = new FoodLogData(userNameTyped, str3, Integer.parseInt(str4), str2, selectedDate);
            foodEntries.add(e);/*from  w ww.  j a  va2 s . c  o m*/
            //Kevin's code
            flexTable.insertRow(flexTable.getRowCount());
            numRows = flexTable.getRowCount();
            flexTable.setText(numRows - 2, 0, e.getFoodGroup());
            flexTable.setText(numRows - 2, 1, e.getFoodName());
            flexTable.setText(numRows - 2, 2, e.getCalories() + "");
            flexTable.getFlexCellFormatter().setRowSpan(0, 1, numRows + 1);
            //Kevin's code ends
            //Window.alert(""+numRows);

            /*Nadeem's original code
            flexTable.removeAllRows();
            flexTable.insertRow(0);
            numRows = flexTable.getRowCount();
                    
                    
            int i = 0;
            for (FoodLogData j : foodEntries) {               
                       
               flexTable.insertRow(i + 1);
               numRows = flexTable.getRowCount();
                    
               flexTable.setText(numRows - 1, 0, j.getFoodGroup());
               flexTable.setText(numRows - 1, 1, j.getFoodName());
               flexTable.setText(numRows - 1, 2, j.getCalories()+"");
                    
               flexTable.getFlexCellFormatter().setRowSpan(0, 1,
             numRows + 1);
                       
               i++;
                    
            }*/
            //Nadeem's code ends

            numRows = flexTable.getRowCount();
            lbFG.setSelectedIndex(0);
            flexTable.setWidget(numRows, 0, lbFG);
            flexTable.getFlexCellFormatter().setRowSpan(0, 1, numRows + 1);
        } else {
            Window.alert("Food Item Not Selected.");
        }

    } else if (numRows <= 1) {
        lbFG.setSelectedIndex(0);
        flexTable.setWidget(numRows, 0, lbFG);
        flexTable.getFlexCellFormatter().setRowSpan(0, 1, numRows + 1);
    } else {
        Window.alert("Food Item Not Selected.");

    }

}

From source file:com.googlesource.gerrit.plugins.xdocs.client.XDocDiffScreen.java

License:Apache License

protected static int addRow(FlexTable table) {
    int row = table.getRowCount();
    table.insertRow(row);
    return row;// ww  w  . j ava  2 s . c  o  m
}