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

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

Introduction

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

Prototype

@Override
public int getRowCount() 

Source Link

Document

Gets the number of rows.

Usage

From source file:org.ebayopensource.turmeric.monitoring.client.view.ServiceView.java

License:Open Source License

/**
 * Gets the table column.//w  w w.  j a va2  s  .co m
 * 
 * @param metric
 *            the metric
 * @param startRow
 *            the start row
 * @param col
 *            the col
 * @return the table column
 * @see org.ebayopensource.turmeric.monitoring.client.presenter.ServicePresenter.Display#getTableColumn(org.ebayopensource
 *      .turmeric.monitoring.client.model.ServiceMetric, int, int)
 */
public List<HasClickHandlers> getTableColumn(ServiceMetric metric, int startRow, int col) {
    FlexTable table = getTable(metric);
    if (table == null)
        return null;
    List<HasClickHandlers> list = new ArrayList<HasClickHandlers>();
    for (int i = startRow; i < table.getRowCount(); i++) {
        Widget w = table.getWidget(i, col);
        if (w instanceof HasClickHandlers)
            list.add((HasClickHandlers) w);
    }
    return list;
}

From source file:org.ebayopensource.turmeric.policy.adminui.client.view.policy.FlexTableHelper.java

License:Open Source License

/**
 * Fixes problem with {@link FlexCellFormatter#setRowSpan(int, int, int)},
 * see comment for./*from  w  ww.j  a  v a  2s . co  m*/
 * 
 * @param flexTable
 *            the flex table {@link #FlexTableHelper}.
 */
public static void fixRowSpan(final FlexTable flexTable) {
    Set<Element> tdToRemove = new HashSet<Element>();
    {
        int rowCount = flexTable.getRowCount();
        for (int row = 0; row < rowCount; row++) {
            int cellCount = flexTable.getCellCount(row);
            for (int cell = 0; cell < cellCount; cell++) {
                int colSpan = flexTable.getFlexCellFormatter().getColSpan(row, cell);
                int rowSpan = flexTable.getFlexCellFormatter().getRowSpan(row, cell);
                if (rowSpan != 1) {
                    int column = getColumnOfCell(flexTable, row, cell);
                    for (int row2 = row + 1; row2 < row + rowSpan; row2++) {
                        int baseCell2 = getCellOfColumn(flexTable, row2, column);
                        for (int cell2 = baseCell2; cell2 < baseCell2 + colSpan; cell2++) {
                            if (cell2 != -1) {

                                Element td = flexTable.getCellFormatter().getElement(row2, cell2);
                                tdToRemove.add(td);
                            }
                        }
                    }
                }
            }
        }
    }
    // remove TD elements
    for (Element td : tdToRemove) {
        Element tr = DOM.getParent(td);
        DOM.removeChild(tr, td);
    }
}

From source file:org.freemedsoftware.gwt.client.screen.CallInScreen.java

License:Open Source License

public void showCallinInfo(Integer callinId) {
    tabPanel.selectTab(0);// ww w.j  a v a 2  s.c  o  m
    if (Util.getProgramMode() == ProgramMode.STUBBED) {
        // TODO STUBBED MODE STUFF
    } else if (Util.getProgramMode() == ProgramMode.JSONRPC) {
        String[] params = { JsonUtil.jsonify(callinId) };
        RequestBuilder builder = new RequestBuilder(RequestBuilder.POST,
                URL.encode(Util.getJsonRequest("org.freemedsoftware.module.Callin.GetDetailedRecord", params)));
        try {
            builder.sendRequest(null, new RequestCallback() {
                public void onError(Request request, Throwable ex) {
                }

                @SuppressWarnings("unchecked")
                public void onResponseReceived(Request request, Response response) {
                    if (Util.checkValidSessionResponse(response.getText())) {
                        if (200 == response.getStatusCode()) {
                            HashMap<String, String> data = (HashMap<String, String>) JsonUtil.shoehornJson(
                                    JSONParser.parseStrict(response.getText()), "HashMap<String,String>");
                            if (data != null) {
                                Popup callinDetailPopup = new Popup();
                                callinDetailPopup.setPixelSize(500, 20);
                                FlexTable callinPatientDetail = new FlexTable();
                                while (callinPatientDetail.getRowCount() > 0)
                                    callinPatientDetail.removeRow(0);
                                int row = 0;
                                callinPatientDetail.setWidget(row, 0, new Label(_("Name") + ":"));
                                callinPatientDetail.setWidget(row++, 1, new Label(data.get("name")));

                                callinPatientDetail.setWidget(row, 0, new Label(_("Date of Birth") + ":"));
                                callinPatientDetail.setWidget(row++, 1, new Label(data.get("dob")));

                                callinPatientDetail.setWidget(row, 0, new Label(_("Complaint") + ":"));
                                callinPatientDetail.setWidget(row++, 1, new Label(data.get("complaint")));

                                callinPatientDetail.setWidget(row, 0, new Label(_("Home Phone") + ":"));
                                callinPatientDetail.setWidget(row++, 1, new Label(data.get("phone_home")));

                                callinPatientDetail.setWidget(row, 0, new Label(_("Work Phone") + ":"));
                                callinPatientDetail.setWidget(row++, 1, new Label(data.get("phone_work")));

                                callinPatientDetail.setWidget(row, 0, new Label(_("Facility") + ":"));
                                callinPatientDetail.setWidget(row++, 1, new Label(data.get("facility")));

                                callinPatientDetail.setWidget(row, 0, new Label(_("Provider") + ":"));
                                callinPatientDetail.setWidget(row++, 1, new Label(data.get("physician")));

                                callinPatientDetail.setWidget(row, 0, new Label(_("Call Date") + ":"));
                                callinPatientDetail.setWidget(row++, 1, new Label(data.get("call_date")));

                                callinPatientDetail.setWidget(row, 0, new Label(_("Took Call") + ":"));
                                callinPatientDetail.setWidget(row++, 1, new Label(data.get("took_call")));

                                PopupView viewInfo = new PopupView(callinPatientDetail);
                                callinDetailPopup.setNewWidget(viewInfo);
                                callinDetailPopup.initialize();

                            }
                        } else {
                        }
                    }
                }
            });
        } catch (RequestException e) {
        }
    } else {
        // TODO NORMAL MODE STUFF
    }
}

From source file:org.freemedsoftware.gwt.client.widget.EncounterWidget.java

License:Open Source License

public void createBasicInfoPanel() {
    int row = 0;/*w  w  w.j a  v a 2  s  . c  om*/
    int col = 0;
    templateWidget = new SupportModuleWidget("EncounterNotesTemplate");
    eocList = new CustomListBox();
    eocMap = new HashMap<String, String>();
    FlexTable basicInfoTable = new FlexTable();
    // basicInfoTable.setWidth("20%");
    col = 0;
    Label lbType = new Label(_("Type"));
    radType = new CustomRadioButtonGroup("type");
    radType.addItem(_("Encounter Note"), "Encounter Note", new Command() {

        @Override
        public void execute() {
            HashMap<String, String> map = new HashMap<String, String>();
            map.put("pnotesttype", _("Encounter Note"));
            templateWidget.setAdditionalParameters(map);

        }

    });
    radType.addItem(_("Progress Note"), "Progress Note", new Command() {

        @Override
        public void execute() {
            HashMap<String, String> map = new HashMap<String, String>();
            map.put("pnotesttype", _("Progress Note"));
            templateWidget.setAdditionalParameters(map);
        }

    });
    basicInfoTable.setWidget(row, col++, lbType);
    basicInfoTable.setWidget(row++, col++, radType);
    col = 0;

    Label lbEnTemplate = new Label(_("Notes Template"));
    templateWidget.addValueChangeHandler(new ValueChangeHandler<Integer>() {

        @Override
        public void onValueChange(ValueChangeEvent<Integer> arg0) {
            applyTemplate(templateWidget.getStoredValue());
        }

    });

    HTML addTemplateBtn = new HTML("<a href=\"javascript:undefined;\">" + _("Add") + "</a>");

    addTemplateBtn.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent arg0) {
            callback.jsonifiedData(EncounterCommandType.CREATE_TEMPLATE);
            // EncounterTemplateWidget enc=new EncounterTemplateWidget();
            // mainTabPanel.add(enc, "Encounter Template");
            // mainTabPanel.selectTab(mainTabPanel.getWidgetCount()-1);
        }

    });
    HTML editTemplateBtn = new HTML("<a href=\"javascript:undefined;\">" + _("Edit") + "</a>");
    editTemplateBtn.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent arg0) {
            if (templateWidget.getStoredValue() == null || templateWidget.getStoredValue().equals("0"))
                Window.alert(_("No template selected."));
            else
                callback.jsonifiedData(EncounterCommandType.EDIT_TEMPLATE);
            // EncounterTemplateWidget enc=new EncounterTemplateWidget();
            // mainTabPanel.add(enc, "Encounter Template");
            // mainTabPanel.selectTab(mainTabPanel.getWidgetCount()-1);
        }

    });
    HTML listTemplateBtn = new HTML("<a href=\"javascript:undefined;\">" + _("List") + "</a>");
    templateTable = new CustomTable();
    templateTable.setIndexName("id");
    // patientCustomTable.setSize("100%", "100%");
    templateTable.setWidth("100%");
    templateTable.addColumn(_("Template Name"), "tempname");
    templateTable.addColumn(_("Template Type"), "notetype");
    templateTable.setTableRowClickHandler(new TableRowClickHandler() {
        @Override
        public void handleRowClick(HashMap<String, String> data, int col) {
            templateWidget.setValue(new Integer(data.get("id")));
            templatesPopup.hide();
            applyTemplate(data.get("id"));
        }
    });
    listTemplateBtn.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent arg0) {
            templatesPopup = new Popup();
            templatesPopup.setPixelSize(500, 20);
            VerticalPanel vp = new VerticalPanel();
            ScrollPanel sp = new ScrollPanel();
            vp.add(sp);
            templateTable.clearData();
            loadTemplates();
            sp.add(templateTable);
            //sp.setHeight("300px");
            PopupView viewInfo = new PopupView(vp);
            templatesPopup.setNewWidget(viewInfo);
            templatesPopup.initialize();
        }

    });
    if (!CurrentState.isActionAllowed("EncounterNotesTemplate", AppConstants.WRITE)) {
        addTemplateBtn.setVisible(false);
    }
    if (!CurrentState.isActionAllowed("EncounterNotesTemplate", AppConstants.MODIFY)) {
        editTemplateBtn.setVisible(false);
    }
    basicInfoTable.setWidget(row, col++, lbEnTemplate);
    basicInfoTable.setWidget(row, col++, templateWidget);
    if (CurrentState.isActionAllowed("EncounterNotesTemplate", AppConstants.WRITE))
        basicInfoTable.setWidget(row, col++, addTemplateBtn);
    if (CurrentState.isActionAllowed("EncounterNotesTemplate", AppConstants.MODIFY))
        basicInfoTable.setWidget(row, col++, editTemplateBtn);
    basicInfoTable.setWidget(row, col++, listTemplateBtn);
    row++;

    col = 0;
    Label lbProvider = new Label(_("Provider"));
    provWidget = new SupportModuleWidget("ProviderModule");
    basicInfoTable.setWidget(row, col++, lbProvider);
    basicInfoTable.setWidget(row++, col++, provWidget);

    col = 0;
    Label lbDescription = new Label(_("Description"));
    tbDesc = new TextBox();
    basicInfoTable.setWidget(row, col++, lbDescription);
    basicInfoTable.setWidget(row++, col++, tbDesc);

    col = 0;
    Label lbEoc = new Label(_("Related Episode(s)"));
    VerticalPanel eocVPanel = new VerticalPanel();
    loadEOC();
    final FlexTable eocFlexTable = new FlexTable();
    eocVPanel.add(eocFlexTable);
    HTML addAnother = new HTML(
            "<a href=\"javascript:undefined;\" style='color:blue'>" + _("Add Episode of Care") + "</a>");

    addAnother.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            CustomListBox eoc = new CustomListBox();
            eoc.addItem(_("NONE SELECTED"));
            if (eocMap != null && eocMap.size() > 0) {
                Set<String> keys = eocMap.keySet();
                Iterator<String> iter = keys.iterator();

                while (iter.hasNext()) {

                    final String key = (String) iter.next();
                    final String val = (String) eocMap.get(key);
                    JsonUtil.debug(val);
                    eoc.addItem(val, key);
                }
            }
            final CustomButton remove = new CustomButton("X");
            remove.addClickHandler(new ClickHandler() {
                @Override
                public void onClick(ClickEvent event) {
                    Node parentTableBody = null;
                    Node parentTR = null;

                    Node tempNode = remove.getElement();
                    while (!tempNode.getNodeName().equals("TBODY")) {
                        tempNode = tempNode.getParentNode();
                    }
                    parentTableBody = tempNode;

                    tempNode = remove.getElement();
                    while (!tempNode.getNodeName().equals("TR")) {
                        tempNode = tempNode.getParentNode();
                    }
                    parentTR = tempNode;

                    parentTableBody.removeChild(parentTR);
                }
            });
            int rc = eocFlexTable.getRowCount();
            eocFlexTable.setWidget(rc, 0, eoc);
            eocFlexTable.setWidget(rc, 1, remove);
        }

    });
    eocVPanel.add(addAnother);
    basicInfoTable.setWidget(row, col++, lbEoc);
    basicInfoTable.setWidget(row++, col++, eocVPanel);
    col = 0;
    Label lbDate = new Label(_("Date"));
    date = new CustomDatePicker();
    basicInfoTable.setWidget(row, col++, lbDate);
    basicInfoTable.setWidget(row++, col++, date);
    basicInfoPanel.add(basicInfoTable);
    if (formmode == EncounterFormMode.EDIT) {
        if (templateValuesMap.containsKey("pnotestype")) {
            radType.setWidgetValue(templateValuesMap.get("pnotestype"));
        }
        if (templateValuesMap.containsKey("pnotesdt")) {
            date.setValue(templateValuesMap.get("pnotesdt"));
        }
        if (templateValuesMap.containsKey("pnotesdescrip")) {
            tbDesc.setText(templateValuesMap.get("pnotesdescrip"));
        }
        if (templateValuesMap.containsKey("pnotesdoc")) {
            provWidget.setValue(new Integer(templateValuesMap.get("pnotesdoc")));
        }
        if (templateValuesMap.containsKey("pnotestemplate")) {
            templateWidget.setValue(new Integer(templateValuesMap.get("pnotestemplate")));
        }
    }

}

From source file:org.freemedsoftware.gwt.client.widget.LedgerPopup.java

License:Open Source License

public LedgerPopup(final String procedureId, final String patientId, final String procCovSrc) {
    super();/* ww w  .j a v  a2  s  .c  om*/
    this.setStylePrimaryName(SchedulerCss.EVENT_DIALOG);

    this.procedureId = procedureId;

    VerticalPanel popupContainer = new VerticalPanel();
    setWidget(popupContainer);

    // ///Top header
    final HorizontalPanel closeButtonContainer = new HorizontalPanel();
    popupContainer.add(closeButtonContainer);
    closeButtonContainer.setWidth("100%");

    Image closeImage = new Image("resources/images/close_x.16x16.png");
    closeImage.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent arg0) {
            getLedgerPopup().hide();
        }
    });
    closeButtonContainer.add(closeImage);
    closeButtonContainer.setCellHorizontalAlignment(closeImage, HasHorizontalAlignment.ALIGN_RIGHT);

    // content panel
    final VerticalPanel contentVPanel = new VerticalPanel();
    popupContainer.add(contentVPanel);

    final VerticalPanel defaultVPanel = new VerticalPanel();
    contentVPanel.add(defaultVPanel);
    // ///View details
    final HorizontalPanel viewDetailHPanel = new HorizontalPanel();
    defaultVPanel.add(viewDetailHPanel);
    final Label procedureLabel = new Label(_("Procedure"));
    viewDetailHPanel.add(procedureLabel);
    CustomButton showDetails = new CustomButton(_("View Details"), AppConstants.ICON_VIEW);
    viewDetailHPanel.add(showDetails);

    showDetails.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent arg0) {
            contentVPanel.clear();
            final VerticalPanel viewDetailsVPanel = new VerticalPanel();
            contentVPanel.add(viewDetailsVPanel);
            final CustomTable viewDetailsTable = new CustomTable();
            viewDetailsTable.removeTableStyle();
            viewDetailsVPanel.add(viewDetailsTable);
            viewDetailsTable.setWidth("100%");
            viewDetailsTable.addColumn(_("Date"), "date");
            viewDetailsTable.addColumn(_("Type"), "type");
            viewDetailsTable.addColumn(_("Description"), "desc");
            viewDetailsTable.addColumn(_("Charges"), "charge");
            viewDetailsTable.addColumn(_("Payments"), "payment");
            viewDetailsTable.addColumn(_("Balance"), "");
            Util.callApiMethod("Ledger", "getLedgerInfo", new Integer(procedureId),
                    new CustomRequestCallback() {
                        @Override
                        public void onError() {

                        }

                        @SuppressWarnings("unchecked")
                        @Override
                        public void jsonifiedData(Object data) {
                            HashMap<String, String>[] result = (HashMap<String, String>[]) data;
                            viewDetailsTable.setMaximumRows(result.length);
                            viewDetailsTable.loadData(result);
                            // HashMap<String, String> totals =
                            // result[result.length-1];
                            Integer totalCharges = new Integer(result[result.length - 1].get("total_charges"));
                            Integer totalPayments = new Integer(
                                    result[result.length - 1].get("total_payments"));

                            FlexTable totalDetailsTable = viewDetailsTable.getFlexTable();
                            int row = totalDetailsTable.getRowCount();
                            totalDetailsTable.setHTML(row, 0, _("Total"));
                            totalDetailsTable.setHTML(row, 3, totalCharges + "");
                            totalDetailsTable.setHTML(row, 4, totalPayments + "");
                            totalDetailsTable.setHTML(row, 5, (totalCharges - totalPayments) + "");
                            totalDetailsTable.getRowFormatter().setStyleName(row,
                                    AppConstants.STYLE_TABLE_HEADER);
                        }
                    }, "HashMap<String,String>[]");
            final CustomButton backBtn = new CustomButton(_("Back"), AppConstants.ICON_PREV);
            contentVPanel.add(backBtn);
            backBtn.addClickHandler(new ClickHandler() {
                @Override
                public void onClick(ClickEvent arg0) {
                    contentVPanel.clear();
                    contentVPanel.add(defaultVPanel);
                }
            });
        }
    });

    // /custom table

    procedureTable = new CustomTable();
    procedureTable.removeTableStyle();
    defaultVPanel.add(procedureTable);
    procedureTable.setMaximumRows(4);
    procedureTable.addColumn(_("Procedure Date"), "proc_date");
    procedureTable.addColumn(_("Procedure Code"), "proc_code");
    procedureTable.addColumn(_("Provider"), "prov_name");
    procedureTable.addColumn(_("Charged"), "proc_obal");
    procedureTable.addColumn(_("Charges"), "proc_charges");
    procedureTable.addColumn(_("Paid"), "proc_paid");
    procedureTable.addColumn(_("Balance"), "proc_currbal");
    procedureTable.addColumn(_("Billed"), "proc_billed");
    procedureTable.setIndexName("Id");

    // //////////action area
    final HorizontalPanel actionHPanel = new HorizontalPanel();
    final Label actionLabel = new Label(_("Action"));
    actionHPanel.add(actionLabel);
    actionList = new CustomListBox();
    actionList.addItem(_("NONE SELECTED"));
    actionList.addItem(REBILL);
    actionList.addItem(PAYMENT);
    actionList.addItem(COPAY);
    actionList.addItem(ADJUSTMENT);
    actionList.addItem(DEDUCTABLE);
    actionList.addItem(WITH_HOLD);
    actionList.addItem(TRANSFER);
    actionList.addItem(ALLOWED_AMOUNT);
    actionList.addItem(DENIAL);
    actionList.addItem(WRITE_OFF);
    actionList.addItem(REFUND);
    actionList.addItem(MISTAKE);
    actionList.addItem(LEDGER);
    actionHPanel.add(actionList);
    final CustomButton proceedButton = new CustomButton(_("Proceed"), AppConstants.ICON_NEXT);
    actionHPanel.add(proceedButton);
    proceedButton.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent arg0) {
            if (actionList.getSelectedIndex() != 0) {
                LedgerWidget pw = null;
                CustomRequestCallback cb = new CustomRequestCallback() {
                    @Override
                    public void onError() {

                    }

                    @Override
                    public void jsonifiedData(Object data) {
                        if (data.toString().equals("update")) {
                            contentVPanel.clear();
                            contentVPanel.add(defaultVPanel);
                            refreshData();
                        } else if (data.toString().equals("close")) {
                            contentVPanel.clear();
                            contentVPanel.add(defaultVPanel);
                            refreshData();
                        } else if (data.toString().equals("cancel")) {
                            contentVPanel.clear();
                            contentVPanel.add(defaultVPanel);
                            refreshData();
                        }
                    }
                };
                boolean hasUI = true;
                if (actionList.getSelectedIndex() == 1) {
                    hasUI = false;
                    pw = new LedgerWidget(procedureId, patientId, procCovSrc, PayCategory.REBILLED, cb);
                } else if (actionList.getSelectedIndex() == 2) {
                    pw = new LedgerWidget(procedureId, patientId, procCovSrc, PayCategory.PAYMENT, cb);
                } else if (actionList.getSelectedIndex() == 3) {
                    pw = new LedgerWidget(procedureId, patientId, procCovSrc, PayCategory.COPAY, cb);
                } else if (actionList.getSelectedIndex() == 4) {
                    pw = new LedgerWidget(procedureId, patientId, procCovSrc, PayCategory.ADJUSTMENT, cb);
                } else if (actionList.getSelectedIndex() == 5) {
                    pw = new LedgerWidget(procedureId, patientId, procCovSrc, PayCategory.DEDUCTABLE, cb);
                } else if (actionList.getSelectedIndex() == 6) {
                    pw = new LedgerWidget(procedureId, patientId, procCovSrc, PayCategory.WITHHOLD, cb);
                } else if (actionList.getSelectedIndex() == 7) {
                    pw = new LedgerWidget(procedureId, patientId, procCovSrc, PayCategory.TRANSFER, cb);
                } else if (actionList.getSelectedIndex() == 8) {
                    pw = new LedgerWidget(procedureId, patientId, procCovSrc, PayCategory.ALLOWEDAMOUNT, cb);
                } else if (actionList.getSelectedIndex() == 9) {
                    pw = new LedgerWidget(procedureId, patientId, procCovSrc, PayCategory.DENIAL, cb);
                } else if (actionList.getSelectedIndex() == 10) {
                    pw = new LedgerWidget(procedureId, patientId, procCovSrc, PayCategory.WRITEOFF, cb);
                } else if (actionList.getSelectedIndex() == 11) {
                    pw = new LedgerWidget(procedureId, patientId, procCovSrc, PayCategory.REFUND, cb);
                } else if (actionList.getSelectedIndex() == 12) {
                    hasUI = false;
                    pw = new LedgerWidget(procedureId, patientId, procCovSrc, PayCategory.MISTAKE, cb);
                } else if (actionList.getSelectedIndex() == 13) {
                    pw = new LedgerWidget(procedureId, patientId, procCovSrc, PayCategory.LEDGER, cb);
                }

                if (pw != null) {
                    if (hasUI) {
                        contentVPanel.clear();
                        contentVPanel.add(pw);
                    }
                }
            } else {
                Window.alert(_("Please select the action type."));
            }
        }
    });
    defaultVPanel.add(actionHPanel);
    defaultVPanel.setCellHorizontalAlignment(actionHPanel, HasHorizontalAlignment.ALIGN_CENTER);
    refreshData();
}

From source file:org.jbpm.form.builder.ng.model.client.form.items.MIGLayoutFormItem.java

License:Apache License

private void populate(FlexTable grid) {
    if (this.borderWidth != null && this.borderWidth > 0) {
        grid.setBorderWidth(this.borderWidth);
    }//w  w w  .  jav  a2 s . c  o m
    if (this.cellpadding != null && this.cellpadding >= 0) {
        grid.setCellPadding(this.cellpadding);
    }
    if (this.cellspacing != null && this.cellspacing >= 0) {
        grid.setCellSpacing(this.cellspacing);
    }
    if (getHeight() != null) {
        grid.setHeight(getHeight());
    }
    if (getWidth() != null) {
        grid.setWidth(getWidth());
    }
    if (this.title != null) {
        grid.setTitle(this.title);
    }
    if (this.rows != null && this.rows > 0) {
        while (this.rows > grid.getRowCount()) {
            grid.insertRow(grid.getRowCount());
            int columnCount = 0;
            FlexCellFormatter formatter = grid.getFlexCellFormatter();
            for (int cell = 0; cell < grid.getCellCount(grid.getRowCount() - 1); cell++) {
                columnCount += formatter.getColSpan(grid.getRowCount() - 1, cell);
            }
            while (this.columns > columnCount) {
                grid.addCell(grid.getRowCount() - 1); //at least one cell per column. Modified later by colspans
                columnCount++;
            }
        }
        while (this.rows < grid.getRowCount()) {
            grid.removeRow(grid.getRowCount() - 1);
        }
    }
    if (this.columns != null && this.columns > 0) {
        for (int row = 0; row < grid.getRowCount(); row++) {
            int columnCount = 0;
            FlexCellFormatter formatter = grid.getFlexCellFormatter();
            for (int cell = 0; cell < grid.getCellCount(row); cell++) {
                columnCount += formatter.getColSpan(row, cell);
            }
            while (this.columns > columnCount) {
                grid.addCell(row);
                columnCount++;
            }
            while (this.columns < columnCount) {
                int cellCount = grid.getCellCount(row);
                if (cellCount > 0) {
                    int cellColumns = formatter.getColSpan(row, cellCount - 1);
                    if (cellColumns > 1 && columnCount - cellColumns >= this.columns) {
                        grid.removeCell(row, cellCount - 1);
                    } else {
                        grid.removeCell(row, cellCount - 1);
                    }
                }
                columnCount--;
            }
        }
    }
}

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) {//from w w  w . ja  v  a2  s.  c o 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

public void onEndBuild(GwtMetawidget metawidget) {

    Facet facet = metawidget.getFacet("buttons");

    if (facet != null) {
        State state = getState(metawidget, metawidget);
        FlexTable flexTable = (FlexTable) metawidget.getWidget(0);
        int row = flexTable.getRowCount();

        int numberOfColumns = getEffectiveNumberOfColumns(metawidget);

        if (numberOfColumns > 0) {
            state.formatter.setColSpan(row, 0, numberOfColumns * LABEL_AND_COMPONENT_AND_REQUIRED);
        }/*from w ww . j a  v a2  s.c o  m*/

        if (mFooterStyleName != null) {
            state.formatter.setStyleName(row, 0, mFooterStyleName);
        }

        flexTable.setWidget(row, 0, facet);
    }
}

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  ww . j a  v  a 2s  .  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.onesocialweb.gwt.client.util.FormLayoutHelper.java

License:Apache License

public static void addHTMLLabelRow(FlexTable target, String label, String value) {

    target.insertRow(target.getRowCount());
    target.addCell(target.getRowCount() - 1);
    target.addCell(target.getRowCount() - 1);
    target.setText(target.getRowCount() - 1, 0, label);
    target.setText(target.getRowCount() - 1, 1, value);

    target.addStyleName("fields");

    // add styling
    target.getCellFormatter().addStyleName(target.getRowCount() - 1, 0, "label");
    target.getCellFormatter().addStyleName(target.getRowCount() - 1, 1, "value");

}