Example usage for com.google.gwt.user.cellview.client Column setHorizontalAlignment

List of usage examples for com.google.gwt.user.cellview.client Column setHorizontalAlignment

Introduction

In this page you can find the example usage for com.google.gwt.user.cellview.client Column setHorizontalAlignment.

Prototype

@Override
public void setHorizontalAlignment(HorizontalAlignmentConstant align) 

Source Link

Document

The new horizontal alignment will apply the next time the table is rendered.

Usage

From source file:org.eclipse.che.ide.ext.openshift.client.service.add.wizard.page.configure.ConfigureServiceViewImpl.java

License:Open Source License

private CellTable<KeyValue> createLabelsTable(CellTableResources tableResources,
        final Predicate<String> labelValidator) {
    labelsTable = new CellTable<>(50, tableResources);
    labelsTable.setTableLayoutFixed(true);
    labelsTable.setKeyboardSelectionPolicy(HasKeyboardSelectionPolicy.KeyboardSelectionPolicy.DISABLED);
    labelsProvider.addDataDisplay(labelsTable);

    final ValidatedInputCell keyTextInputCell = new ValidatedInputCell(labelValidator,
            locale.labelNamePlaceholder());
    final Column<KeyValue, String> keyColumn = new Column<KeyValue, String>(keyTextInputCell) {
        @Override/*  w  w w  .j a  va  2s .  c  o m*/
        public String getCellStyleNames(Cell.Context context, KeyValue keyValue) {
            if (!labelValidator.apply(keyValue.getKey())) {
                return resources.css().applicationTableError();
            }
            return null;
        }

        @Override
        public String getValue(KeyValue keyValue) {
            return keyValue.getKey();
        }
    };
    keyColumn.setFieldUpdater(new FieldUpdater<KeyValue, String>() {
        @Override
        public void update(int index, KeyValue keyValue, String value) {
            keyValue.setKey(value);
            delegate.updateControls();
        }
    });

    ValidatedInputCell valueTextInputCell = new ValidatedInputCell(labelValidator,
            locale.labelValuePlaceholder());
    Column<KeyValue, String> valueColumn = new Column<KeyValue, String>(valueTextInputCell) {
        @Override
        public String getCellStyleNames(Cell.Context context, KeyValue keyValue) {
            if (!labelValidator.apply(keyValue.getValue())) {
                return resources.css().applicationTableError();
            }
            return null;
        }

        @Override
        public String getValue(KeyValue keyValue) {
            return keyValue.getValue();
        }
    };
    valueColumn.setFieldUpdater(new FieldUpdater<KeyValue, String>() {
        @Override
        public void update(int index, KeyValue keyValue, String value) {
            keyValue.setValue(value);
            delegate.updateControls();
        }
    });

    Column<KeyValue, String> removeColumn = new Column<KeyValue, String>(new ButtonCell()) {
        @Override
        public String getValue(KeyValue value) {
            return "-";
        }

        @Override
        public void render(Cell.Context context, KeyValue keyValue, SafeHtmlBuilder sb) {
            Button removeButton = new Button();
            super.render(context, keyValue, sb.appendHtmlConstant(removeButton.getHTML()));
        }
    };
    removeColumn.setFieldUpdater(new FieldUpdater<KeyValue, String>() {
        @Override
        public void update(int index, KeyValue keyValue, String value) {
            labelsProvider.getList().remove(keyValue);
            labelsProvider.refresh();
            delegate.updateControls();
        }
    });

    labelsTable.addColumn(keyColumn);
    labelsTable.setColumnWidth(keyColumn, 20, Style.Unit.PCT);
    labelsTable.addColumn(valueColumn);
    labelsTable.setColumnWidth(valueColumn, 20, Style.Unit.PCT);
    labelsTable.addColumn(removeColumn);
    labelsTable.setColumnWidth(removeColumn, 1, Style.Unit.PCT);
    removeColumn.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);

    return labelsTable;
}

From source file:org.glom.web.client.ui.list.ListTable.java

License:Open Source License

private void addColumn(final LayoutItemField layoutItemField) {
    // Setup the default alignment of the column.
    HorizontalAlignmentConstant columnAlignment;
    Formatting formatting = layoutItemField.getFormatting();
    if (formatting == null) {
        GWT.log("addColumn(): Formatting is null for field=" + layoutItemField.getLayoutDisplayName());
        formatting = new Formatting(); // Just to avoid null dereferencing later.
    }//from  www  . j a  v a2s . c  o m

    switch (formatting.getHorizontalAlignment()) {
    case HORIZONTAL_ALIGNMENT_LEFT:
        columnAlignment = HasHorizontalAlignment.ALIGN_LEFT;
        break;
    case HORIZONTAL_ALIGNMENT_RIGHT:
        columnAlignment = HasHorizontalAlignment.ALIGN_RIGHT;
        break;
    case HORIZONTAL_ALIGNMENT_AUTO:
    default:
        columnAlignment = HasHorizontalAlignment.ALIGN_DEFAULT;
        break;
    }

    // create a new column
    Column<DataItem[], ?> column = null;
    final int j = cellTable.getColumnCount();
    switch (layoutItemField.getGlomType()) {

    case TYPE_BOOLEAN:
        column = new Column<DataItem[], Boolean>(new BooleanCell()) {
            @Override
            public Boolean getValue(final DataItem[] row) {
                if (row.length == 1 && row[0] == null) {
                    // an empty row
                    return null;
                }

                if (j >= row.length) {
                    GWT.log("addColumn(): j=" + j + " is out of range. length=" + row.length);
                    return null;
                } else {
                    return row[j].getBoolean();
                }
            }
        };
        // override the configured horizontal alignment
        columnAlignment = HasHorizontalAlignment.ALIGN_CENTER;
        break;

    case TYPE_NUMERIC:
        // create a GWT NumberFormat for the column
        final NumericFormat numericFormat = formatting.getNumericFormat();
        final NumberFormat gwtNumberFormat = Utils.getNumberFormat(numericFormat);

        // create the actual column
        column = new Column<DataItem[], Double>(new NumericCell(
                formatting.getTextFormatColorForegroundAsHTMLColor(),
                formatting.getTextFormatColorBackgroundAsHTMLColor(), gwtNumberFormat,
                numericFormat.getUseAltForegroundColorForNegatives(), numericFormat.getCurrencySymbol())) {
            @Override
            public Double getValue(final DataItem[] row) {
                if (row.length == 1 && row[0] == null) {
                    // an empty row
                    return null;
                }

                if (j >= row.length) {
                    GWT.log("addColumn(): j=" + j + " is out of range. length=" + row.length);
                    return null;
                } else {
                    return row[j].getNumber();
                }
            }
        };
        break;
    case TYPE_IMAGE:
        column = new Column<DataItem[], String>(new ImageCell()) {
            @Override
            public String getValue(final DataItem[] row) {
                if (row.length == 1 && row[0] == null) {
                    // an empty row
                    return null;
                }

                if (j >= row.length) {
                    GWT.log("addColumn(): j=" + j + " is out of range. length=" + row.length);
                    return null;
                } else {
                    return row[j].getImageDataUrl();
                }
            }
        };
        // override the configured horizontal alignment
        columnAlignment = HasHorizontalAlignment.ALIGN_CENTER;
        break;

    default:
        // use a text rendering cell for types we don't know about but log an error
        // TODO log error here
    case TYPE_DATE:
    case TYPE_INVALID:
    case TYPE_TIME:
    case TYPE_TEXT:
        column = new Column<DataItem[], String>(
                new TextCell(formatting.getTextFormatColorForegroundAsHTMLColor(),
                        formatting.getTextFormatColorBackgroundAsHTMLColor())) {
            @Override
            public String getValue(final DataItem[] row) {
                if (row.length == 1 && row[0] == null) {
                    // an empty row
                    return null;
                }

                if (j >= row.length) {
                    GWT.log("addColumn(): j=" + j + " is out of range. length=" + row.length);
                    return null;
                } else {
                    return row[j].getText();
                }
            }
        };
        break;
    }

    // set column properties and add to cell cellTable
    column.setHorizontalAlignment(columnAlignment);
    column.setSortable(true);
    cellTable.addColumn(column, new SafeHtmlHeader(SafeHtmlUtils.fromString(layoutItemField.getTitle())));
}

From source file:org.jboss.as.console.client.shared.subsys.elytron.ui.AuthenticationContextMatchRulesEditor.java

License:Open Source License

@SuppressWarnings("unchecked")
public Widget asWidget() {
    VerticalPanel panel = new VerticalPanel();
    panel.addStyleName("fill-popupLayout-width");

    // table/*from w  w  w  .  ja  va2 s. c om*/
    table = new DefaultCellTable<>(5);
    dataProvider = new ListDataProvider<>();
    dataProvider.addDataDisplay(table);
    table.setSelectionModel(selectionModel);

    // columns
    Column<ModelNode, String> matchRuleColumn = new TextColumn<ModelNode>() {
        @Override
        public String getValue(ModelNode node) {
            // as the match-rules attribute is a list of attributes
            // none of them is required, so there is not a unique colum to show, so all defined attributes are
            // displayed, there is a "view" button that shows all attributes nicely formatted in a ModelNodeForm
            StringBuilder content = new StringBuilder();
            for (Property prop : node.asPropertyList()) {
                content.append(prop.getName()).append(": ").append(prop.getValue().asString()).append(", ");
            }
            return StringUtils.shortenStringIfNecessary(content.toString(), 120);
        }
    };

    Column<ModelNode, ModelNode> linkOpenDetailsColumn = new Column<ModelNode, ModelNode>(
            new ViewLinkCell<>(Console.CONSTANTS.common_label_view(),
                    (ActionCell.Delegate<ModelNode>) selection -> showDetailModal(selection))) {
        @Override
        public ModelNode getValue(ModelNode node) {
            return node;
        }
    };

    linkOpenDetailsColumn.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    table.addColumn(matchRuleColumn, "");
    table.addColumn(linkOpenDetailsColumn, "Option");
    table.setColumnWidth(linkOpenDetailsColumn, 8, Style.Unit.PCT);

    panel.add(mainTableTools());
    panel.add(table);

    DefaultPager pager = new DefaultPager();
    pager.setDisplay(table);
    panel.add(pager);

    // ===================== match-rule form popup
    popupLayout.setStyleName("window-content");

    // read-only form to show details of match-rules attribute
    ModelNodeFormBuilder.FormAssets detailForm = new ModelNodeFormBuilder()
            .setResourceDescription(resourceDescription).setCreateMode(false).unsorted()
            .setCreateNameAttribute(false).setSecurityContext(securityContext).build();
    matchRulesForm = detailForm.getForm();

    popupDialogOptions.showCancel(false);
    Widget formWidget = detailForm.getForm().asWidget();
    popupLayout.add(formWidget);

    return panel;
}

From source file:org.jboss.as.console.client.shared.subsys.elytron.ui.factory.ConfigurableHttpServerMechanismFactoryFilterEditor.java

License:Open Source License

@SuppressWarnings("unchecked")
public Widget asWidget() {
    VerticalPanel panel = new VerticalPanel();
    panel.addStyleName("fill-layout-width");

    // table/*from   w w w . jav a 2  s.co  m*/
    table = new DefaultCellTable<>(5, nameProvider);
    dataProvider = new ListDataProvider<>(nameProvider);
    dataProvider.addDataDisplay(table);
    table.setSelectionModel(selectionModel);

    // columns
    Column<ModelNode, String> patternColumn = new TextColumn<ModelNode>() {
        @Override
        public String getValue(ModelNode property) {
            return property.get("pattern-filter").asString();
        }
    };
    patternColumn.setSortable(true);
    Column<ModelNode, String> enablingColumn = new TextColumn<ModelNode>() {
        @Override
        public String getValue(ModelNode property) {
            return property.get("enabling").asString();
        }
    };
    enablingColumn.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    table.addColumn(patternColumn, "Pattern Filter");
    table.addColumn(enablingColumn, "Enabling");
    table.setColumnWidth(patternColumn, 70, Style.Unit.PCT);
    table.setColumnWidth(enablingColumn, 30, Style.Unit.PCT);

    // tools
    ToolStrip tools = new ToolStrip();
    ToolButton addButton = new ToolButton(Console.CONSTANTS.common_label_add(), event -> {

        ModelNodeFormBuilder.FormAssets addFormAssets = new ModelNodeFormBuilder()
                .setResourceDescription(resourceDescription).setCreateMode(true)
                .setSecurityContext(securityContext).setCreateNameAttribute(false).build();
        addFormAssets.getForm().setEnabled(true);

        DefaultWindow dialog = new DefaultWindow(Console.MESSAGES.newTitle("Pattern filter"));
        AddResourceDialog.Callback callback = new AddResourceDialog.Callback() {
            @Override
            public void onAdd(ModelNode payload) {
                circuit.dispatch(
                        new AddListAttribute(ElytronStore.CONFIGURABLE_HTTP_SERVER_MECHANISM_FACTORY_ADDRESS,
                                "filters", factoryName, payload));
                dialog.hide();
            }

            @Override
            public void onCancel() {
                dialog.hide();
            }
        };
        AddResourceDialog addDialog = new AddResourceDialog(addFormAssets, resourceDescription, callback);
        dialog.setWidth(480);
        dialog.setHeight(360);
        dialog.setWidget(addDialog);
        dialog.setGlassEnabled(true);
        dialog.center();
    });
    ToolButton removeButton = new ToolButton(Console.CONSTANTS.common_label_delete(), event -> {
        final ModelNode selection = selectionModel.getSelectedObject();
        if (selection != null) {
            Feedback.confirm("Filter",
                    Console.MESSAGES.deleteConfirm("Filter " + selection.get("pattern-filter").asString()),
                    isConfirmed -> {
                        if (isConfirmed) {
                            circuit.dispatch(new RemoveListAttribute(
                                    ElytronStore.CONFIGURABLE_HTTP_SERVER_MECHANISM_FACTORY_ADDRESS,
                                    factoryName, "filters", selection));
                        }
                    });
        }
    });
    tools.addToolButtonRight(addButton);
    tools.addToolButtonRight(removeButton);
    panel.add(tools);

    panel.add(table);
    DefaultPager pager = new DefaultPager();
    pager.setDisplay(table);
    panel.add(pager);
    return panel;
}

From source file:org.jboss.as.console.client.shared.subsys.elytron.ui.factory.ConfigurableSaslServerFactoryFilterEditor.java

License:Open Source License

@SuppressWarnings("unchecked")
public Widget asWidget() {
    VerticalPanel panel = new VerticalPanel();
    panel.addStyleName("fill-layout-width");

    // table// ww w  .  j  av  a 2s .com
    table = new DefaultCellTable<>(5);
    dataProvider = new ListDataProvider<>();
    dataProvider.addDataDisplay(table);
    table.setSelectionModel(selectionModel);

    // columns
    Column<ModelNode, String> predefinedFilter = new TextColumn<ModelNode>() {
        @Override
        public String getValue(ModelNode node) {
            return node.hasDefined("predefined-filter") ? node.get("predefined-filter").asString() : "";
        }
    };
    Column<ModelNode, String> patternFilter = new TextColumn<ModelNode>() {
        @Override
        public String getValue(ModelNode node) {
            return node.hasDefined("pattern-filter") ? node.get("pattern-filter").asString() : "";
        }
    };
    Column<ModelNode, String> enablingColumn = new TextColumn<ModelNode>() {
        @Override
        public String getValue(ModelNode property) {
            return property.hasDefined("enabling") ? property.get("enabling").asString() : "";
        }
    };
    predefinedFilter.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    patternFilter.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    enablingColumn.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    table.addColumn(predefinedFilter, "Pre-defined Filter");
    table.addColumn(patternFilter, "Pattern Filter");
    table.addColumn(enablingColumn, "Enabling");

    // tools
    ToolStrip tools = new ToolStrip();
    ToolButton addButton = new ToolButton(Console.CONSTANTS.common_label_add(), event -> {

        ModelNodeFormBuilder.FormAssets addFormAssets = new ModelNodeFormBuilder()
                .setResourceDescription(resourceDescription).setCreateMode(true).unsorted()
                .setCreateNameAttribute(false).setSecurityContext(securityContext).build();
        addFormAssets.getForm().setEnabled(true);
        addFormAssets.getForm().addFormValidator((list, formValidation) -> {
            // pattern-filter and predefined-filter are mutually exclusive
            FormItem<String> patternFilterFormItem = formItem(list, "pattern-filter");
            FormItem<String> predefinedFilterFormItem = formItem(list, "predefined-filter");
            if ((patternFilterFormItem.isUndefined() && predefinedFilterFormItem.isUndefined())
                    || (!patternFilterFormItem.isUndefined() && !predefinedFilterFormItem.isUndefined())) {
                predefinedFilterFormItem
                        .setErrMessage("Please set either predefined filter or pattern filter.");
                predefinedFilterFormItem.setErroneous(true);
                formValidation.addError("predefined-filter");
            }
        });

        DefaultWindow dialog = new DefaultWindow(Console.MESSAGES.newTitle("Filter"));
        AddResourceDialog.Callback callback = new AddResourceDialog.Callback() {
            @Override
            public void onAdd(ModelNode payload) {
                // pattern-filter and predefined-filter are mutually exclusive attributes
                if (payload.hasDefined("predefined-filter"))
                    payload.remove("pattern-filter");
                else if (payload.hasDefined("pattern-filter"))
                    payload.remove("predefined-filter");

                circuit.dispatch(new AddListAttribute(ElytronStore.CONFIGURABLE_SASL_SERVER_FACTORY_ADDRESS,
                        FILTERS, factoryName, payload));
                dialog.hide();
            }

            @Override
            public void onCancel() {
                dialog.hide();
            }
        };
        AddResourceDialog addDialog = new AddResourceDialog(addFormAssets, resourceDescription, callback);
        dialog.setWidth(480);
        dialog.setHeight(360);
        dialog.setWidget(addDialog);
        dialog.setGlassEnabled(true);
        dialog.center();
    });
    ToolButton removeButton = new ToolButton(Console.CONSTANTS.common_label_delete(), event -> {
        final ModelNode selection = selectionModel.getSelectedObject();
        if (selection != null) {
            Feedback.confirm("Filter",
                    Console.MESSAGES.deleteConfirm("filter " + (selection.hasDefined("predefined-filter")
                            ? selection.get("predefined-filter").asString()
                            : selection.get("pattern-filter").asString())),
                    isConfirmed -> {
                        if (isConfirmed) {
                            circuit.dispatch(new RemoveListAttribute(
                                    ElytronStore.CONFIGURABLE_SASL_SERVER_FACTORY_ADDRESS, factoryName, FILTERS,
                                    selection));
                        }
                    });
        }
    });
    tools.addToolButtonRight(addButton);
    tools.addToolButtonRight(removeButton);
    panel.add(tools);

    panel.add(table);
    DefaultPager pager = new DefaultPager();
    pager.setDisplay(table);
    panel.add(pager);
    return panel;
}

From source file:org.jboss.as.console.client.shared.subsys.elytron.ui.factory.GenericAuthenticationMechanismFactoryEditor.java

License:Open Source License

@SuppressWarnings("unchecked")
public Widget asWidget() {
    VerticalPanel panel = new VerticalPanel();
    panel.addStyleName("fill-popupLayout-width");

    // table//from  w ww .j ava  2 s  .  c o m
    table = new DefaultCellTable<>(5);
    dataProvider = new ListDataProvider<>();
    dataProvider.addDataDisplay(table);
    table.setSelectionModel(selectionModel);

    // columns
    Column<ModelNode, String> mechanismNameColumn = new TextColumn<ModelNode>() {
        @Override
        public String getValue(ModelNode node) {
            // as the mechanism-configuration  attribute is a list of attributes
            // none of them is required, so there is not a unique colum to show, so all defined attributes are
            // displayed, there is a "view" button that shows all attributes nicely formatted in a ModelNodeForm
            StringBuilder content = new StringBuilder();
            for (Property prop : node.asPropertyList()) {
                content.append(prop.getName()).append(": ").append(prop.getValue().asString()).append(", ");
            }
            return StringUtils.shortenStringIfNecessary(content.toString(), 120);
        }
    };

    Column<ModelNode, ModelNode> linkOpenDetailsColumn = new Column<ModelNode, ModelNode>(
            new ViewLinkCell<>(Console.CONSTANTS.common_label_view(), new ActionCell.Delegate<ModelNode>() {

                @Override
                public void execute(ModelNode selection) {
                    showMechanismConfigurationModal(selection);
                }
            })) {
        @Override
        public ModelNode getValue(ModelNode node) {
            return node;
        }
    };

    linkOpenDetailsColumn.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    table.addColumn(mechanismNameColumn, "");
    table.addColumn(linkOpenDetailsColumn, "Option");
    table.setColumnWidth(linkOpenDetailsColumn, 8, Style.Unit.PCT);

    panel.add(mainTableTools());
    panel.add(table);

    DefaultPager pager = new DefaultPager();
    pager.setDisplay(table);
    panel.add(pager);

    // ===================== mechanism configuration form popup
    popupLayout.setStyleName("window-content");

    // read-only form to show details of mechanism-configuration attribute
    ModelNodeFormBuilder.FormAssets mechanismConfigurationFormView = new ModelNodeFormBuilder()
            .setResourceDescription(resourceDescription).setCreateMode(false).unsorted()
            .setCreateNameAttribute(false).setSecurityContext(securityContext)
            .exclude("mechanism-realm-configurations").build();
    mechanismConfigurationForm = mechanismConfigurationFormView.getForm();

    popupDialogOptions.showCancel(false);
    Widget formWidget = mechanismConfigurationFormView.getForm().asWidget();
    popupLayout.add(formWidget);

    return panel;
}

From source file:org.jboss.as.console.client.shared.subsys.elytron.ui.factory.MechanismProviderFilteringSaslServerFilterEditor.java

License:Open Source License

private void setupTable() {
    table = new DefaultCellTable<>(5, nameProvider);
    table.setSelectionModel(selectionModel);

    // columns/*w w w .  j  ava2 s. c  o  m*/
    Column<ModelNode, String> providerNameColumn = createColumn("provider-name");
    Column<ModelNode, String> mechanismNameColumn = createColumn("mechanism-name");
    Column<ModelNode, String> providerVersionColumn = createColumn("provider-version");
    Column<ModelNode, String> versionComparisonColumn = createColumn("version-comparison");
    providerNameColumn.setSortable(true);
    providerNameColumn.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    mechanismNameColumn.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    providerVersionColumn.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    versionComparisonColumn.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    table.addColumn(providerNameColumn, "Provider Name");
    table.addColumn(mechanismNameColumn, "Mechanism Name");
    table.addColumn(providerVersionColumn, "Provider Version");
    table.addColumn(versionComparisonColumn, "Version Comparison");
    table.setColumnWidth(providerNameColumn, 30, Style.Unit.PCT);
    table.setColumnWidth(mechanismNameColumn, 30, Style.Unit.PCT);
    table.setColumnWidth(providerVersionColumn, 20, Style.Unit.PCT);
    table.setColumnWidth(versionComparisonColumn, 20, Style.Unit.PCT);
}

From source file:org.jboss.as.console.client.shared.subsys.elytron.ui.GenericListComplexAttribute.java

License:Open Source License

private void setupTable() {
    table = new DefaultCellTable<>(10);
    table.setSelectionModel(selectionModel);

    // columns/*from  w w w  . j  av a2s  . c  o m*/
    for (Property propDescription : resourceDescription.get(ATTRIBUTES).asPropertyList()) {
        Column<ModelNode, String> column = createColumn(propDescription.getName());
        column.setSortable(true);
        column.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
        table.addColumn(column, label(propDescription.getName()));
    }
    ;
}

From source file:org.jboss.as.console.client.shared.subsys.elytron.ui.IdentityAttributeMappingView.java

License:Open Source License

@SuppressWarnings("unchecked")
public Widget asWidget() {
    VerticalPanel panel = new VerticalPanel();
    panel.addStyleName("fill-layout-width");

    // table//from w  w  w.ja  v a 2 s .c o  m
    table = new DefaultCellTable<>(5, nameProvider);
    dataProvider = new ListDataProvider<>(nameProvider);
    dataProvider.addDataDisplay(table);
    table.setSelectionModel(selectionModel);

    // columns
    Column<ModelNode, String> fromColumn = new TextColumn<ModelNode>() {
        @Override
        public String getValue(ModelNode node) {
            return node.get("from").asString();
        }
    };
    fromColumn.setSortable(true);
    Column<ModelNode, String> toColumn = new TextColumn<ModelNode>() {
        @Override
        public String getValue(ModelNode node) {
            return node.get("to").asString();
        }
    };
    Column<ModelNode, String> filterColumn = new TextColumn<ModelNode>() {
        @Override
        public String getValue(ModelNode node) {
            return node.get("filter").asString();
        }
    };
    filterColumn.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    toColumn.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    ColumnSortEvent.ListHandler<ModelNode> sortHandler = new ColumnSortEvent.ListHandler<>(
            dataProvider.getList());
    sortHandler.setComparator(fromColumn, (o1, o2) -> o1.get("from").asString().toLowerCase()
            .compareTo(o2.get("from").asString().toLowerCase()));
    table.addColumn(fromColumn, "From");
    table.addColumn(toColumn, "To");
    table.addColumn(filterColumn, "Filter");
    table.setColumnWidth(fromColumn, 30, Style.Unit.PCT);
    table.setColumnWidth(toColumn, 40, Style.Unit.PCT);
    table.setColumnWidth(filterColumn, 20, Style.Unit.PCT);
    table.addColumnSortHandler(sortHandler);
    table.getColumnSortList().push(fromColumn);

    panel.add(table);
    DefaultPager pager = new DefaultPager();
    pager.setDisplay(table);
    panel.add(pager);
    return panel;
}

From source file:org.jboss.as.console.client.shared.subsys.elytron.ui.JdbcRealmPrincipalsQueryView.java

License:Open Source License

@SuppressWarnings("unchecked")
public Widget asWidget() {
    VerticalPanel panel = new VerticalPanel();
    panel.addStyleName("fill-layout-width");

    // table//from   www. jav a  2  s  .c  om
    table = new DefaultCellTable<>(5, nameProvider);
    dataProvider = new ListDataProvider<>(nameProvider);
    dataProvider.addDataDisplay(table);
    table.setSelectionModel(selectionModel);

    // columns
    Column<ModelNode, String> nameColumn = new TextColumn<ModelNode>() {
        @Override
        public String getValue(ModelNode node) {
            return node.get("sql").asString();
        }
    };
    nameColumn.setSortable(true);
    Column<ModelNode, String> datasourceColumn = new TextColumn<ModelNode>() {
        @Override
        public String getValue(ModelNode node) {
            return node.get("data-source").asString();
        }
    };

    table.addColumn(nameColumn, Console.CONSTANTS.common_label_name());
    table.addColumn(datasourceColumn, "Datasource");
    table.setColumnWidth(nameColumn, 85, Style.Unit.PCT);
    table.setColumnWidth(datasourceColumn, 15, Style.Unit.PCT);
    datasourceColumn.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);

    panel.add(setupTableButtons());
    panel.add(table);
    DefaultPager pager = new DefaultPager();
    pager.setDisplay(table);
    panel.add(pager);
    return panel;
}