Example usage for com.google.gwt.user.cellview.client CellTable setColumnWidth

List of usage examples for com.google.gwt.user.cellview.client CellTable setColumnWidth

Introduction

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

Prototype

@Override
public void setColumnWidth(Column<T, ?> column, String width) 

Source Link

Document

The layout behavior depends on whether or not the table is using fixed layout.

Usage

From source file:com.databasepreservation.visualization.client.common.lists.AsyncTableCell.java

private void configure(final CellTable<T> display) {
    if (selectable) {
        selectColumn = new Column<T, Boolean>(new CheckboxCell(true, false)) {
            @Override//w  w  w.j  ava 2 s . c  o  m
            public Boolean getValue(T object) {
                return selected.contains(object);
            }
        };

        selectColumn.setFieldUpdater(new FieldUpdater<T, Boolean>() {
            @Override
            public void update(int index, T object, Boolean isSelected) {
                if (isSelected) {
                    selected.add(object);
                } else {
                    selected.remove(object);
                }

                // update header
                display.redrawHeaders();
                fireOnCheckboxSelectionChanged();
            }
        });

        Header<Boolean> selectHeader = new Header<Boolean>(new CheckboxCell(true, true)) {

            @Override
            public Boolean getValue() {
                Boolean ret;

                if (selected.isEmpty()) {
                    ret = false;
                } else if (selected.containsAll(getVisibleItems())) {
                    ret = true;
                    showSelectAllPanel();
                } else {
                    // some are selected
                    ret = false;
                    hideSelectAllPanel();
                }

                return ret;
            }
        };

        selectHeader.setUpdater(new ValueUpdater<Boolean>() {

            @Override
            public void update(Boolean value) {
                if (value) {
                    selected.addAll(getVisibleItems());
                    showSelectAllPanel();
                } else {
                    selected.clear();
                    hideSelectAllPanel();
                }
                redraw();
                fireOnCheckboxSelectionChanged();
            }
        });

        display.addColumn(selectColumn, selectHeader);
        display.setColumnWidth(selectColumn, "45px");
    }
    configureDisplay(display);
}

From source file:n3phele.client.view.CommandDetailView.java

License:Open Source License

public CellTable<TypedParameter> createParameterTable() {
    final ProvidesKey<TypedParameter> KEY_PROVIDER = new ProvidesKey<TypedParameter>() {
        public Object getKey(TypedParameter item) {
            return item.getName();
        }// w w w. ja va2s.  co m
    };
    final CellTable<TypedParameter> table;
    table = new CellTable<TypedParameter>(KEY_PROVIDER);
    table.setWidth("100%");
    table.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.DISABLED);
    TextColumn<TypedParameter> descriptionColumn = new TextColumn<TypedParameter>() {
        @Override
        public String getValue(TypedParameter command) {
            String result = "";
            if (command != null)
                return command.getDescription();
            return result;
        }
    };
    table.addColumn(descriptionColumn);

    this.parameterTextInputCell = new DisappearingTextInputCell();
    this.parameterCheckboxCell = new DisappearingCheckBoxCell();
    final ValidInputIndicatorCell valid = new ValidInputIndicatorCell(N3phele.n3pheleResource.inputErrorIcon());

    HasCell<TypedParameter, ?> valueHasCell = new HasCell<TypedParameter, String>() {

        @Override
        public Cell<String> getCell() {
            return CommandDetailView.this.parameterTextInputCell;
        }

        @Override
        public FieldUpdater<TypedParameter, String> getFieldUpdater() {
            return new FieldUpdater<TypedParameter, String>() { // Needs to exist so that the cell level updater is invoked
                @Override
                public void update(int index, TypedParameter object, String value) {
                }

            };
        }

        @Override
        public String getValue(TypedParameter object) {
            if (object != null) {
                if (!object.getType().equalsIgnoreCase("boolean")) {
                    String result = object.getValue();
                    if (isNullOrBlank(result))
                        result = object.getDefaultValue();
                    if (result == null)
                        result = "";
                    return result;
                }
            }
            return null;
        }

    };
    HasCell<TypedParameter, ?> validHasCell = new HasCell<TypedParameter, String>() {

        @Override
        public Cell<String> getCell() {
            return valid;
        }

        @Override
        public FieldUpdater<TypedParameter, String> getFieldUpdater() {
            return null;
        }

        @Override
        public String getValue(TypedParameter object) {
            String errTooltip;
            errTooltip = errorMessageMap().get(object.getType());
            if (checkParameterValue(object)) {
                return "-" + errTooltip;
            } else {
                return "+" + errTooltip;
            }
        }

    };

    HasCell<TypedParameter, ?> booleanHasCell = new HasCell<TypedParameter, Boolean>() {

        @Override
        public Cell<Boolean> getCell() {
            return parameterCheckboxCell;
        }

        @Override
        public FieldUpdater<TypedParameter, Boolean> getFieldUpdater() {
            return new FieldUpdater<TypedParameter, Boolean>() { // Needs to exist so that the cell level updater is invoked
                @Override
                public void update(int index, TypedParameter object, Boolean value) {
                }

            };
        }

        @Override
        public Boolean getValue(TypedParameter object) {
            if (object != null) {
                if (object.getType().equalsIgnoreCase("boolean")) {
                    String result = object.getValue();
                    if (isNullOrBlank(result))
                        result = object.getDefaultValue();
                    return Boolean.valueOf(result);
                }
            }
            return null;
        }

    };
    List<HasCell<TypedParameter, ?>> arg = new ArrayList<HasCell<TypedParameter, ?>>(2);
    arg.add(validHasCell);
    arg.add(valueHasCell);
    arg.add(booleanHasCell);

    Column<TypedParameter, TypedParameter> valueColumn = new Column<TypedParameter, TypedParameter>(
            new TypedPropertyComposite(arg)) {
        @Override
        public TypedParameter getValue(TypedParameter parameter) {
            return parameter;
        }
    };
    valueColumn.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
    table.addColumn(valueColumn);
    table.setWidth("100%", true);
    table.setColumnWidth(valueColumn, "210px");
    valueColumn.setFieldUpdater(new FieldUpdater<TypedParameter, TypedParameter>() {
        public void update(int index, final TypedParameter object, final TypedParameter value) {
            GWT.runAsync(new RunAsyncCallback() {

                @Override
                public void onSuccess() {
                    updateRunButton(true);
                }

                @Override
                public void onFailure(Throwable reason) {
                    //
                }
            });

        }
    });
    return table;
}

From source file:n3phele.client.view.CreateServiceView.java

License:Open Source License

public CellTable<CommandCloudAccount> createAccountTable() {
    final SensitiveCheckBoxCell checkbox = new SensitiveCheckBoxCell(true, true);
    final ProvidesKey<CommandCloudAccount> KEY_PROVIDER = new ProvidesKey<CommandCloudAccount>() {

        public Object getKey(CommandCloudAccount item) {
            return item.getAccountUri();
        }//from   w  w  w .ja va  2 s  . c om
    };
    final CellTable<CommandCloudAccount> table = new CellTable<CommandCloudAccount>(KEY_PROVIDER);
    table.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.DISABLED);
    Column<CommandCloudAccount, Boolean> checkColumn = new Column<CommandCloudAccount, Boolean>(checkbox) {
        @Override
        public Boolean getValue(CommandCloudAccount profile) {
            return (profile.getAccountUri().equals(CreateServiceView.this.selectedAccountURI));
        }

    };
    checkColumn.setFieldUpdater(new FieldUpdater<CommandCloudAccount, Boolean>() {

        @Override
        public void update(int index, CommandCloudAccount profile, Boolean value) {
            if (profile != null) {
                if (value) {
                    CreateServiceView.this.selectedImplementation = profile.getImplementation();
                    CreateServiceView.this.selectedAccountURI = profile.getAccountUri().toString();
                } else {
                    if (profile.getImplementation().equals(CreateServiceView.this.selectedImplementation)) {

                        CreateServiceView.this.selectedImplementation = null;
                        CreateServiceView.this.selectedAccountURI = null;
                    }
                }
                table.redraw();
                String visible = value ? "-" : "+";
                CreateServiceView.this.gotExecutionSelection.setValue(
                        visible + CreateServiceView.this.gotExecutionSelection.getValue().substring(1));
                updateRunButton(true);
                validateAccount(true);
            } else {
                checkbox.clearViewData(KEY_PROVIDER.getKey(profile));
                table.redraw();
                updateRunButton(false);
                validateAccount(false);
                GWT.log("update account");
                CreateServiceView.this.gotExecutionSelection
                        .setValue("+" + CreateServiceView.this.gotExecutionSelection.getValue().substring(1));
            }

        }

    });
    table.addColumn(checkColumn);
    table.setColumnWidth(checkColumn, "40px");
    TextColumn<CommandCloudAccount> accountColumn = new TextColumn<CommandCloudAccount>() {
        @Override
        public String getValue(CommandCloudAccount profile) {
            String result = "";
            if (profile != null)
                return profile.getAccountName();
            return result;
        }
    };
    table.addColumn(accountColumn);
    TextColumn<CommandCloudAccount> nameColumn = new TextColumn<CommandCloudAccount>() {
        @Override
        public String getValue(CommandCloudAccount profile) {
            String result = "";
            if (profile != null) {
                return profile.getImplementation();
            }
            return result;
        }
    };
    table.addColumn(nameColumn);
    table.setWidth("400px");
    table.addStyleName(N3phele.n3pheleResource.css().lineBreakStyle());
    table.setTableLayoutFixed(true);
    return table;
}

From source file:org.drools.guvnor.client.asseteditor.drools.serviceconfig.KBaseConfigPanel.java

License:Apache License

private void initTableColumns(final CellTable<ServiceKSessionConfig> cellTable) {

    // Add new row
    MyClickableImageCell addRowCell = new MyClickableImageCell(
            new MyClickableImageCell.ImageCellClickHandler() {
                public void onClick(final Cell.Context context) {
                    final ServiceKSessionConfig newKsession = new ServiceKSessionConfig(
                            kbase.getNextKSessionName());
                    kbase.addKsession(newKsession);

                    dataProvider.getList().add(newKsession);
                    dataProvider.refresh();
                    pager.lastPage();/*from  w w  w.j  ava 2  s.c o m*/
                }
            });

    final Column<ServiceKSessionConfig, ImageResource> imageColumn = new Column<ServiceKSessionConfig, ImageResource>(
            addRowCell) {
        @Override
        public ImageResource getValue(final ServiceKSessionConfig object) {
            return images.itemImages().newItem();
        }
    };
    cellTable.addColumn(imageColumn, SafeHtmlUtils.fromSafeConstant("<br/>"));
    cellTable.setColumnWidth(imageColumn, "16px");

    // Remove active row
    MyClickableImageCell removeRowCell = new MyClickableImageCell(
            new MyClickableImageCell.ImageCellClickHandler() {
                public void onClick(final Cell.Context context) {
                    if (dataProvider.getList().size() == 1) {
                        Window.alert(Constants.INSTANCE.KBaseNeedsOneKsession());
                    } else {
                        dataProvider.getList().remove(context.getIndex());
                        kbase.removeKsession((String) context.getKey());
                        dataProvider.refresh();
                    }
                }
            });

    final Column<ServiceKSessionConfig, ImageResource> imageColumn2 = new Column<ServiceKSessionConfig, ImageResource>(
            removeRowCell) {
        @Override
        public ImageResource getValue(final ServiceKSessionConfig object) {
            return images.removeItem();
        }
    };
    cellTable.addColumn(imageColumn2, SafeHtmlUtils.fromSafeConstant("<br/>"));
    cellTable.setColumnWidth(imageColumn, "16px");

    // KSession Name
    final EditTextCell textCell = new EditTextCell();
    final Column<ServiceKSessionConfig, String> nameColumn = new Column<ServiceKSessionConfig, String>(
            textCell) {
        @Override
        public String getValue(final ServiceKSessionConfig object) {
            return object.getName();
        }
    };
    cellTable.addColumn(nameColumn, Constants.INSTANCE.Name());
    nameColumn.setFieldUpdater(new FieldUpdater<ServiceKSessionConfig, String>() {
        public void update(int index, ServiceKSessionConfig object, String value) {
            // Called when the user changes the value.
            if (object.getName().equals(value)) {
                return;
            }

            if (kbase.getKsession(value) != null) {
                Window.alert(Constants.INSTANCE.KSessionNameAlreadyExists());
                textCell.clearViewData(KEY_PROVIDER.getKey(object));
                dataProvider.flush();
                dataProvider.refresh();
                cellTable.redraw();
            } else {
                final ServiceKSessionConfig updatedKsession = new ServiceKSessionConfig(value, object);
                kbase.removeKsession(object.getName());
                kbase.addKsession(updatedKsession);
                dataProvider.getList().set(index, updatedKsession);
                dataProvider.refresh();
            }
        }
    });
    cellTable.setColumnWidth(nameColumn, "40%");

    // Type
    final List<String> sessionTypes = new ArrayList<String>(SessionType.values().length);
    for (final SessionType activeType : SessionType.values()) {
        sessionTypes.add(activeType.toString().toLowerCase());
    }

    final SelectionCell typeCell = new SelectionCell(sessionTypes);
    final Column<ServiceKSessionConfig, String> typeColumn = new Column<ServiceKSessionConfig, String>(
            typeCell) {
        @Override
        public String getValue(ServiceKSessionConfig object) {
            return object.getType().toString().toLowerCase();
        }
    };
    cellTable.addColumn(typeColumn, Constants.INSTANCE.Type());
    typeColumn.setFieldUpdater(new FieldUpdater<ServiceKSessionConfig, String>() {
        public void update(int index, ServiceKSessionConfig object, String value) {
            // Called when the user changes the value.
            object.setType(SessionType.valueOf(value.toUpperCase()));
            dataProvider.refresh();
        }
    });
    cellTable.setColumnWidth(typeColumn, "40%");

    //Advanced config
    final Column<ServiceKSessionConfig, String> configAdvanced = new Column<ServiceKSessionConfig, String>(
            new ButtonCell()) {
        @Override
        public String getValue(ServiceKSessionConfig object) {
            return "...";
        }
    };
    cellTable.addColumn(configAdvanced, Constants.INSTANCE.Config());
    configAdvanced.setFieldUpdater(new FieldUpdater<ServiceKSessionConfig, String>() {
        public void update(int index, ServiceKSessionConfig object, String value) {

            final AdvancedKSessionConfigWidget widget = new AdvancedKSessionConfigWidget(object);
            final InternalPopup popup = new InternalPopup(widget.asWidget(),
                    Constants.INSTANCE.KSessionConfiguration());
            popup.addOkButtonClickHandler(new ClickHandler() {

                public void onClick(ClickEvent event) {
                    widget.updateKSession();
                    popup.hide();
                }
            });
            popup.show();
        }
    });
    cellTable.setColumnWidth(configAdvanced, "20%");
}

From source file:org.roda.wui.client.common.lists.utils.AsyncTableCell.java

private void configure(final CellTable<T> display) {
    if (selectable) {
        selectColumn = new Column<T, Boolean>(new AcessibleCheckboxCell(true, false)) {
            @Override/*from w ww  . j a v a  2 s .c  om*/
            public Boolean getValue(T object) {
                return selected.contains(object);
            }
        };

        selectColumn.setFieldUpdater(new FieldUpdater<T, Boolean>() {
            @Override
            public void update(int index, T object, Boolean isSelected) {
                if (isSelected) {
                    selected.add(object);
                } else {
                    selected.remove(object);
                }

                // update header
                display.redrawHeaders();
                fireOnCheckboxSelectionChanged();
            }
        });

        Header<Boolean> selectHeader = new Header<Boolean>(new AcessibleCheckboxCell(true, true)) {

            @Override
            public Boolean getValue() {
                Boolean ret;

                if (selected.isEmpty()) {
                    ret = false;
                } else if (selected.containsAll(getVisibleItems())) {
                    ret = true;
                    showSelectAllPanel();
                } else {
                    // some are selected
                    ret = false;
                    hideSelectAllPanel();
                }

                return ret;
            }
        };

        selectHeader.setUpdater(new ValueUpdater<Boolean>() {

            @Override
            public void update(Boolean value) {
                if (value) {
                    selected.addAll(getVisibleItems());
                    showSelectAllPanel();
                } else {
                    selected.clear();
                    hideSelectAllPanel();
                }
                redraw();
                fireOnCheckboxSelectionChanged();
            }
        });

        display.addColumn(selectColumn, selectHeader);
        display.setColumnWidth(selectColumn, "45px");
    }
    configureDisplay(display);
}