Example usage for com.google.gwt.user.client.ui Grid resizeRows

List of usage examples for com.google.gwt.user.client.ui Grid resizeRows

Introduction

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

Prototype

public void resizeRows(int rows) 

Source Link

Document

Resizes the grid to the specified number of rows.

Usage

From source file:co.fxl.gui.gwt.GWTGridPanel.java

License:Open Source License

private void resize() {
    Grid grid = (Grid) container.widget;
    if (gridCell.column >= grid.getColumnCount()) {
        grid.resizeColumns(gridCell.column + 1);
    }/*from   www.  j a v a2  s  .  co m*/
    if (gridCell.row >= grid.getRowCount()) {
        grid.resizeRows(gridCell.row + 1);
    }
}

From source file:com.google.gerrit.client.account.ContactPanelShort.java

License:Apache License

protected void onInitUI() {
    if (LocaleInfo.getCurrentLocale().isRTL()) {
        labelIdx = 1;//from ww w .ja  v  a2  s.co  m
        fieldIdx = 0;
    } else {
        labelIdx = 0;
        fieldIdx = 1;
    }

    nameTxt = new NpTextBox();
    nameTxt.setVisibleLength(60);
    nameTxt.setReadOnly(!canEditFullName());

    emailPick = new ListBox();

    final Grid infoPlainText = new Grid(2, 2);
    infoPlainText.setStyleName(Gerrit.RESOURCES.css().infoBlock());
    infoPlainText.addStyleName(Gerrit.RESOURCES.css().accountInfoBlock());

    body.add(infoPlainText);

    registerNewEmail = new Button(Util.C.buttonOpenRegisterNewEmail());
    registerNewEmail.setEnabled(false);
    registerNewEmail.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(final ClickEvent event) {
            doRegisterNewEmail();
        }
    });
    final FlowPanel emailLine = new FlowPanel();
    emailLine.add(emailPick);
    if (canRegisterNewEmail()) {
        emailLine.add(registerNewEmail);
    }

    int row = 0;
    if (!Gerrit.getConfig().canEdit(FieldName.USER_NAME) && Gerrit.getConfig().siteHasUsernames()) {
        infoPlainText.resizeRows(infoPlainText.getRowCount() + 1);
        row(infoPlainText, row++, Util.C.userName(), new UsernameField());
    }

    if (!canEditFullName()) {
        FlowPanel nameLine = new FlowPanel();
        nameLine.add(nameTxt);
        if (Gerrit.getConfig().getEditFullNameUrl() != null) {
            Button edit = new Button(Util.C.linkEditFullName());
            edit.addClickHandler(new ClickHandler() {
                @Override
                public void onClick(ClickEvent event) {
                    Window.open(Gerrit.getConfig().getEditFullNameUrl(), "_blank", null);
                }
            });
            nameLine.add(edit);
        }
        Button reload = new Button(Util.C.linkReloadContact());
        reload.addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {
                Window.Location.replace(Gerrit.loginRedirect(PageLinks.SETTINGS_CONTACT));
            }
        });
        nameLine.add(reload);
        row(infoPlainText, row++, Util.C.contactFieldFullName(), nameLine);
    } else {
        row(infoPlainText, row++, Util.C.contactFieldFullName(), nameTxt);
    }
    row(infoPlainText, row++, Util.C.contactFieldEmail(), emailLine);

    infoPlainText.getCellFormatter().addStyleName(0, 0, Gerrit.RESOURCES.css().topmost());
    infoPlainText.getCellFormatter().addStyleName(0, 1, Gerrit.RESOURCES.css().topmost());
    infoPlainText.getCellFormatter().addStyleName(row - 1, 0, Gerrit.RESOURCES.css().bottomheader());

    save = new Button(Util.C.buttonSaveChanges());
    save.setEnabled(false);
    save.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(final ClickEvent event) {
            doSave(null);
        }
    });
    new OnEditEnabler(save, nameTxt);

    emailPick.addChangeHandler(new ChangeHandler() {
        @Override
        public void onChange(final ChangeEvent event) {
            final int idx = emailPick.getSelectedIndex();
            final String v = 0 <= idx ? emailPick.getValue(idx) : null;
            if (Util.C.buttonOpenRegisterNewEmail().equals(v)) {
                for (int i = 0; i < emailPick.getItemCount(); i++) {
                    if (currentEmail.equals(emailPick.getValue(i))) {
                        emailPick.setSelectedIndex(i);
                        break;
                    }
                }
                doRegisterNewEmail();
            } else {
                save.setEnabled(true);
            }
        }
    });
}

From source file:com.hazelcast.monitor.client.MapEntrySetBrowserPanel.java

License:Open Source License

@Override
protected FlexTable createTable() {
    FlexTable table = new FlexTable();
    table.addStyleName("table");
    table.addStyleName("mapstats");
    table.setWidget(0, 0, new Label(""));
    table.getFlexCellFormatter().setColSpan(0, 0, 2);
    Button button = new Button("Refresh");
    table.setWidget(1, 0, button);/*from   www  .  j a  va2s  .co m*/
    final TextArea value = new TextArea();
    value.setVisible(false);
    table.setWidget(1, 1, value);
    button.addStyleName("map_refresh_button");
    final Grid resultTable = new Grid(2, 4);
    resultTable.setWidth("800px");
    table.setWidget(2, 0, resultTable);
    table.getFlexCellFormatter().setColSpan(2, 0, 2);
    resultTable.setText(0, 0, "Key:");
    resultTable.setText(0, 1, "Key class:");
    resultTable.setText(0, 2, "Value:");
    resultTable.setText(0, 3, "Value class:");
    resultTable.getRowFormatter().addStyleName(0, "mapstatsEvenRow");
    button.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent clickEvent) {
            mapService.getEntries(clusterWidgets.clusterId, name, new AsyncCallback<MapEntry[]>() {
                public void onFailure(Throwable throwable) {
                    if (throwable instanceof ClientDisconnectedException) {
                        clusterWidgets.disconnected();
                    }
                    value.setVisible(true);
                    value.setText(throwable.toString());
                }

                public void onSuccess(MapEntry[] mapEntries) {
                    resultTable.resizeRows(mapEntries.length + 1);
                    value.setVisible(false);
                    int row = 1;
                    for (final MapEntry mapEntry : mapEntries) {
                        resultTable.setText(row, 0, mapEntry.getKey());
                        resultTable.setText(row, 1, mapEntry.getKeyClass());
                        resultTable.setText(row, 2, mapEntry.getValue());
                        resultTable.setText(row, 3, mapEntry.getValueClass());
                        if (row % 2 == 0) {
                            resultTable.getRowFormatter().addStyleName(row, "mapstatsEvenRow");
                        }
                        row++;
                    }
                }
            });
        }
    });
    return table;
}

From source file:org.catchwa.skeetstalker.client.SkeetStalker.java

License:Open Source License

private void refreshAnswerThese() {
    if (answerTheseService == null) {
        answerTheseService = GWT.create(AnswerTheseService.class);
    }/*from   w w w.ja  v  a  2  s  .  co  m*/
    AsyncCallback<String[]> callback = new AsyncCallback<String[]>() {
        public void onFailure(Throwable caught) {
            // TODO: Do something with errors.
        }

        public void onSuccess(String[] result) {
            Grid table = (Grid) RootPanel.get("questionsContainer").getWidget(0);
            for (int i = 0; i < result.length; i++) {
                int splitHere = result[i].lastIndexOf(' ');
                String title = result[i].substring(0, splitHere);
                String id = result[i].substring(splitHere + 1, result[i].length());
                String base = sites.get(siteChoices.getItemText(siteChoices.getSelectedIndex()));
                base = base.replace("api.", "");
                String html = "<a href=\"" + base + "/questions/" + id + "\" target=\"_blank\">" + title
                        + "</a>";
                if (!containsRow(table, html)) {
                    if (table.getRowCount() > 2) {
                        table.insertRow(1);
                        table.setHTML(1, 0, html);
                        while (table
                                .getRowCount() > org.catchwa.skeetstalker.shared.Constants.CLIENT_TABLE_ROW_LIMIT) {
                            table.removeRow(table.getRowCount() - 1);
                        }
                    } else {
                        table.resizeRows(3);
                        table.setHTML(2, 0, table.getHTML(1, 0));
                        table.setHTML(1, 0, html);
                    }
                }
            }
        }
    };
    answerTheseService.getQuestions(id, site, callback);
}

From source file:org.catchwa.skeetstalker.client.SkeetStalker.java

License:Open Source License

private void resetTable() {
    Grid table = (Grid) RootPanel.get("questionsContainer").getWidget(0);
    while (table.getRowCount() > 0) {
        table.removeRow(0);//w w w  .  ja va  2  s  .  c  o m
    }
    table.resizeRows(1);
    table.setHTML(0, 0, "<b>Questions they'll probably answer (unless you get there first!)</b>");
}

From source file:org.eclipse.che.ide.notification.NotificationItem.java

License:Open Source License

/**
 * Create notification item.//from ww w  .j a  v a 2  s.c  o m
 *
 * @param resources
 * @param notification
 * @param delegate
 */
public NotificationItem(@Nonnull Resources resources, @Nonnull Notification notification,
        @Nonnull final ActionDelegate delegate, final Grid container) {
    this.resources = resources;
    this.notification = notification;
    this.prevState = notification.clone();
    this.delegate = delegate;
    this.container = container;
    notification.addObserver(this);

    iconPanel = new SimplePanel();

    time = new Label(DATA_FORMAT.format(notification.getTime()));
    //If notification message is formated HTML - need to display only plain text from it.
    //TODO: need rework this. we need sanitize only messages that comes from server if we do it here we lose possibility for
    // formatting outputs
    title = new HTML(SimpleHtmlSanitizer.sanitizeHtml(notification.getMessage()));

    Image closeIcon = new Image(resources.close());
    closeIcon.addStyleName(resources.notificationCss().close());
    closeIcon.ensureDebugId("notificationItem-close");
    closeIcon.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            delegate.onCloseItemClicked(NotificationItem.this.notification);
        }
    });

    if (!notification.isRead()) {
        addStyleNameToElements(resources.notificationCss().unread());
    }

    if (!notification.isFinished()) {
        changeImage(resources.progress()).getElement().setAttribute("class",
                resources.notificationCss().progress());
    } else if (notification.isWarning()) {
        changeImage(resources.warning());
        addStyleNameToElements(resources.notificationCss().warning());
    } else if (notification.isError()) {
        changeImage(resources.error());
        addStyleNameToElements(resources.notificationCss().error());
    } else {
        changeImage(resources.success()).getElement().setAttribute("class",
                resources.notificationCss().success());
    }

    int index = container.getRowCount();
    container.resizeRows(index + 1);
    container.setWidget(index, 0, iconPanel);
    container.setWidget(index, 1, time);
    container.setWidget(index, 2, title);
    container.setWidget(index, 3, closeIcon);
    container.getCellFormatter().setHorizontalAlignment(index, 1, HasAlignment.ALIGN_CENTER);
    container.getRowFormatter().addStyleName(index, resources.notificationCss().notificationItem());
    container.getRowFormatter().setVerticalAlign(index, HasAlignment.ALIGN_MIDDLE);

}

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

License:Apache License

private void populate(Grid grid) {
    if (this.borderWidth != null && this.borderWidth > 0) {
        grid.setBorderWidth(this.borderWidth);
    }//from www . j a v 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.columns != null && this.columns > 0) {
        grid.resizeColumns(this.columns);
    }
    if (this.rows != null && this.rows > 0) {
        grid.resizeRows(this.rows);
    }
}

From source file:org.openremote.web.console.widget.panel.form.FormPanelComponent.java

License:Open Source License

@Override
public void onRender(int width, int height, List<DataValuePairContainer> data) {
    Grid grid = (Grid) getWidget();
    int rows = fields.size();
    grid.resizeRows(rows + 1);
    int rowHeight = (int) Math.round((double) height / (rows + 1));
    if (!isInitialised) {
        for (int i = 0; i < rows; i++) {
            HTMLTable.CellFormatter formatter = grid.getCellFormatter();
            FormField field = fields.get(i);

            formatter.setHeight(i, 0, rowHeight + "px");
            formatter.setHorizontalAlignment(i, 0, HasHorizontalAlignment.ALIGN_LEFT);
            formatter.setVerticalAlignment(i, 0, HasVerticalAlignment.ALIGN_MIDDLE);

            grid.setWidget(i, 0, field);
        }//w  ww . java2s  .  co m

        // Display buttons
        HorizontalPanel buttonPanel = new HorizontalPanel();
        buttonPanel.setWidth("100%");
        buttonPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
        for (FormButtonComponent button : buttons) {
            buttonPanel.add((Widget) button);
            button.setVisible(true);
            button.initHandlers();
        }
        grid.setWidget(rows, 0, buttonPanel);
    }

    // Get data source if it is defined
    if (dataSource != null && !dataSource.equals("")) {
        inputObject = DataBindingService.getInstance().getData(dataSource);
        if (inputObject != null) {
            dataMap = AutoBeanCodex.encode(inputObject);
        }

        if (dataMap != null) {
            if (itemBindingObject != null && !itemBindingObject.equals("")) {
                if (!dataMap.isUndefined(itemBindingObject)) {
                    objectMap = dataMap.get(itemBindingObject);
                }
            } else {
                objectMap = dataMap;
            }

            // If object map is an indexed object then we need to know which index to use for binding
            // this has to be specified by a DataValuePair called bindingItem
            if (objectMap != null && objectMap.isIndexed() && data != null) {
                // Look for BindingItem dvp
                for (DataValuePairContainer dvpContainer : data) {
                    DataValuePair dvp = dvpContainer.getDataValuePair();
                    if (dvp.getName().equalsIgnoreCase("bindingitem")) {
                        String bindingItem = dvp.getValue();
                        String[] bindingItemKvp = bindingItem.split("=");
                        String fieldName = null;
                        String fieldValue = null;
                        if (bindingItemKvp.length == 2) {
                            fieldName = bindingItemKvp[0];
                            fieldValue = bindingItemKvp[1];
                            for (int i = 0; i < objectMap.size(); i++) {
                                Splittable itemMap = objectMap.get(i);
                                String dataMapEntry = itemMap.get(fieldName).asString();
                                if (dataMapEntry != null && dataMapEntry.equalsIgnoreCase(fieldValue)) {
                                    objectIndex = i;
                                    break;
                                }
                            }
                        }
                        break;
                    }
                }
            }
        }
    }

    // Populate fields using binding data
    Splittable itemMap = objectMap;
    if (objectIndex != null) {
        itemMap = objectMap.get(objectIndex);
    }
    for (FormField field : fields) {
        if (itemMap != null && field.getName() != null && !field.getName().equals("")) {
            try {
                Splittable fieldMap = itemMap.get(field.getName());
                field.setDefaultValue(fieldMap.asString());
            } catch (Exception e) {
            }
        }
        field.onAdd(width, rowHeight);
    }
}

From source file:rocket.widget.client.SortableTable.java

License:Apache License

/**
 * This method does the actual translation or painting of the sorted rows.
 * //  w  w  w  .  ja  v  a2 s  .  c o m
 * @param rows
 *            A sorted list ready to be painted.
 */
protected void redraw(final SortedRowList rows) {
    Checker.notNull("parameter:rows", rows);

    final Grid table = this.getGrid();
    final int columnCount = this.getColumnCount();
    int rowIndex = 1;
    final int rowSize = rows.size();
    final int gridRowCount = table.getRowCount();
    final int requiredGridCount = rowSize + 1;

    // update grid to match number of rows...
    table.resizeRows(requiredGridCount);

    // if grid had a few rows added add even/odd styles to them...

    final RowFormatter rowFormatter = table.getRowFormatter();
    final String evenRowStyle = this.getEvenRowStyle();
    final String oddRowStyle = this.getOddRowStyle();
    final String sortableColumnStyle = this.getSortableColumnStyle();
    final String sortedColumnStyle = this.getSortedColumnStyle();

    for (int row = gridRowCount; row < requiredGridCount; row++) {
        final String style = ((row & 1) == 1) ? evenRowStyle : oddRowStyle;
        rowFormatter.addStyleName(row, style);

        final CellFormatter cellFormatter = table.getCellFormatter();
        final int sortedColumn = this.getSortedColumn();

        for (int column = 0; column < columnCount; column++) {
            if (this.isColumnSortable(column)) {
                cellFormatter.setStyleName(row, column, sortableColumnStyle);

                if (sortedColumn == column) {
                    cellFormatter.addStyleName(row, column, sortedColumnStyle);
                }
            }
        }
    }

    for (int row = 0; row < rowSize; row++) {
        final SortedRowListElement rowObject = (SortedRowListElement) rows.getSortedRowListElement(row);
        this.redraw(rowObject, rowIndex);
        rowIndex++;
    }
}

From source file:stroom.widget.xsdbrowser.client.view.XSDDisplay.java

License:Apache License

private void addChild(final Grid layout, final SelectionMap map, final XSDNode node,
        final boolean showOccurance, final int row, final int col) {
    // Ensure layout size.
    if (layout.getRowCount() < row + 1) {
        layout.resizeRows(row + 1);
    }// ww w  .  j a v a  2  s. c  o m

    final XSDType type = node.getType();
    rowMap.put(node, row);

    // Add the image for the structure element if this is one.
    if (type.isStructural()) {
        final String occurrence = node.getOccurance();

        if (occurrence != null) {
            final SafeHtmlBuilder builder = new SafeHtmlBuilder();
            builder.appendHtmlConstant("<div class=\"occuranceLabel\">");
            builder.appendEscaped(occurrence);
            builder.appendHtmlConstant("</div>");

            final HTML html = new HTML(builder.toSafeHtml());

            final FlowPanel fp = new FlowPanel();
            fp.add(getImage(type));
            fp.add(html);
            fp.getElement().getStyle().setPosition(Position.RELATIVE);

            layout.setWidget(row, col, fp);
        } else {
            layout.setWidget(row, col, getImage(type));
        }

        layout.setWidget(row, col + 1, AbstractImagePrototype.create(resources.xsdTree03()).createImage());

    } else {
        // Otherwise add the element.
        XSDNode refNode = null;

        Image image = null;
        XSDNodeLabel lblName = null;
        Label lblOccurrence = null;
        Label lblType = null;

        String name = node.getName();
        String valueType = null;

        if (type == XSDType.ELEMENT || type == XSDType.ATTRIBUTE) {
            if (name == null) {
                refNode = node.getRefNode();
                if (refNode != null) {
                    name = refNode.getName();
                }
            }

            if (refNode != null) {
                valueType = refNode.getValueType();
                if (valueType == null) {
                    valueType = "(" + name + "Type)";
                }

            } else {
                valueType = node.getValueType();
                if (valueType == null) {
                    valueType = "(" + name + "Type)";
                }
            }

            if (showOccurance) {
                final String occurance = node.getOccurance();
                if (occurance != null) {
                    lblOccurrence = new Label(node.getOccurance(), false);
                }
            }
        }

        // Get the image to use.
        if (refNode != null) {
            image = getImage(XSDType.ELEMENT_REF);
        } else {
            image = getImage(type);
        }
        if (name != null) {
            lblName = new XSDNodeLabel(name, map, model, node, refNode);
        }
        if (valueType != null) {
            lblType = new Label(valueType, false);
        }

        final int colCount = layout.getColumnCount();

        // Add line images to get back to the structure level.
        if (node.getParent() != null && node.getParent().getType().isStructural()) {
            for (int i = col; i < colCount - 6; i++) {
                layout.setWidget(row, i, AbstractImagePrototype.create(resources.xsdTree03()).createImage());
            }
        }

        // Add other images to create the tree lines.
        int pos = col - 1;
        XSDNode parent = node;
        while (pos >= 0 && parent != null && parent.getType().isStructuralOrElement()) {
            if (node == parent || rowMap.get(parent) == row) {
                if (parent.isFirstChild() && parent.isLastChild()) {
                    layout.setWidget(row, pos,
                            AbstractImagePrototype.create(resources.xsdTree03()).createImage());
                } else if (parent.isFirstChild()) {
                    layout.setWidget(row, pos,
                            AbstractImagePrototype.create(resources.xsdTree06()).createImage());
                } else if (parent.isLastChild()) {
                    layout.setWidget(row, pos,
                            AbstractImagePrototype.create(resources.xsdTree09()).createImage());
                } else {
                    layout.setWidget(row, pos,
                            AbstractImagePrototype.create(resources.xsdTree05()).createImage());
                }
            } else if (!parent.isLastChild()) {
                layout.setWidget(row, pos, AbstractImagePrototype.create(resources.xsdTree02()).createImage());
            }

            parent = parent.getParent();
            pos -= 2;
        }

        if (image != null) {
            layout.setWidget(row, colCount - 6, image);
            image.addStyleName("marginRight");
        }
        if (lblName != null) {
            layout.setWidget(row, colCount - 5, lblName);
        }
        if (lblOccurrence != null) {
            layout.setWidget(row, colCount - 4, new Label("[", false));
            layout.setWidget(row, colCount - 3, lblOccurrence);
            layout.setWidget(row, colCount - 2, new Label("]", false));
        }
        if (lblType != null) {
            layout.setWidget(row, colCount - 1, lblType);
            lblType.addStyleName("marginLeft");
        }
    }
}