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, double width, Unit unit) 

Source Link

Document

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

Usage

From source file:com.codenvy.ide.client.propertiespanel.common.namespace.NameSpaceEditorViewImpl.java

License:Open Source License

private CellTable<NameSpace> createTable(@Nonnull CellTableResources resource) {
    CellTable<NameSpace> table = new CellTable<>(0, resource);

    Column<NameSpace, String> nameSpace = new Column<NameSpace, String>(new TextCell()) {
        @Override/*from   w w  w .  j  av  a 2  s.  com*/
        public String getValue(NameSpace object) {
            return object.toString();
        }
    };

    table.setLoadingIndicator(null);

    table.addColumn(nameSpace);
    table.setColumnWidth(nameSpace, 570, Style.Unit.PX);

    final SingleSelectionModel<NameSpace> selectionModel = new SingleSelectionModel<>();
    selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
        @Override
        public void onSelectionChange(SelectionChangeEvent event) {
            delegate.onSelectedNameSpace(selectionModel.getSelectedObject());
        }
    });
    table.setSelectionModel(selectionModel);

    return table;
}

From source file:com.codenvy.ide.client.propertiespanel.common.propertyconfig.PropertyConfigViewImpl.java

License:Open Source License

/**
 * Returns cell table entity. Adds column names and values to table. Sets selection model to table.
 *
 * @param localizationConstant//from   www  .  j  a v  a2 s .c o m
 *         localization constant which contains special names of element in current table
 */
private CellTable<Property> createTable(@Nonnull final WSO2EditorLocalizationConstant localizationConstant,
        @Nonnull CellTableResources resource) {

    final CellTable<Property> table = new CellTable<>(0, resource);

    final SingleSelectionModel<Property> selectionModel = new SingleSelectionModel<>();
    selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
        @Override
        public void onSelectionChange(SelectionChangeEvent event) {
            delegate.onSelectedProperty(selectionModel.getSelectedObject());
        }
    });
    table.setSelectionModel(selectionModel);

    TextColumn<Property> name = new TextColumn<Property>() {
        @Override
        public String getValue(Property property) {
            String name = property.getProperty(NAME);

            return name == null ? "" : name;
        }
    };

    TextColumn<Property> expression = new TextColumn<Property>() {
        @Override
        public String getValue(Property property) {
            String value = property.getProperty(VALUE);

            return value == null ? "" : value;
        }
    };

    TextColumn<Property> type = new TextColumn<Property>() {
        @Override
        public String getValue(Property property) {
            ValueType type = property.getProperty(TYPE);

            return type == null ? "" : type.name();
        }
    };

    table.addColumn(name, localizationConstant.columnName());
    table.addColumn(type, localizationConstant.columnType());
    table.addColumn(expression, localizationConstant.columnExpression());

    table.setColumnWidth(name, 210, Style.Unit.PX);
    table.setColumnWidth(type, 120, Style.Unit.PX);
    table.setColumnWidth(expression, 210, Style.Unit.PX);

    table.setLoadingIndicator(null);

    return table;
}

From source file:com.codenvy.ide.client.propertiespanel.endpoints.address.property.PropertyViewImpl.java

License:Open Source License

/** Adds columns names and values to table. Sets selection model to table. */
private CellTable<Property> createTable(@Nonnull CellTableResources resource) {
    CellTable<Property> table = new CellTable<>(0, resource);

    final SingleSelectionModel<Property> selectionModel = new SingleSelectionModel<>();
    selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
        @Override//  www .j  a  v a2 s . co  m
        public void onSelectionChange(SelectionChangeEvent event) {
            delegate.onPropertySelected(selectionModel.getSelectedObject());
        }
    });
    table.setSelectionModel(selectionModel);

    TextColumn<Property> name = new TextColumn<Property>() {
        @Override
        public String getValue(Property property) {
            return property.getProperty(NAME);
        }
    };

    TextColumn<Property> value = new TextColumn<Property>() {
        @Override
        public String getValue(Property property) {
            if (ValueType.LITERAL.equals(property.getProperty(TYPE))) {
                return property.getProperty(VALUE);
            }

            return property.getProperty(EXPRESSION);
        }
    };

    TextColumn<Property> type = new TextColumn<Property>() {
        @Override
        public String getValue(Property property) {
            ValueType type = property.getProperty(TYPE);

            if (type == null) {
                return "";
            }

            return type.name();
        }
    };

    TextColumn<Property> scope = new TextColumn<Property>() {
        @Override
        public String getValue(Property property) {
            Property.Scope scope = property.getProperty(SCOPE);

            if (scope == null) {
                return "";
            }

            return scope.getValue();
        }
    };

    table.addColumn(name, locale.columnName());
    table.addColumn(value, locale.columnValue());
    table.addColumn(type, locale.columnType());
    table.addColumn(scope, locale.columnScope());

    table.setColumnWidth(name, 150, Style.Unit.PX);
    table.setColumnWidth(value, 150, Style.Unit.PX);
    table.setColumnWidth(type, 60, Style.Unit.PX);
    table.setColumnWidth(scope, 100, Style.Unit.PX);

    table.setLoadingIndicator(null);

    return table;
}

From source file:com.codenvy.ide.client.propertiespanel.mediators.arguments.ArgumentsConfigViewImpl.java

License:Open Source License

private CellTable<Arg> createTable(@Nonnull final WSO2EditorLocalizationConstant localizationConstant,
        @Nonnull CellTableResources resource) {

    final CellTable<Arg> table = new CellTable<>(0, resource);

    final SingleSelectionModel<Arg> selectionModel = new SingleSelectionModel<>();
    selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
        @Override//  ww  w .  ja  v  a  2  s  .co  m
        public void onSelectionChange(SelectionChangeEvent event) {
            delegate.onSelectedArg(selectionModel.getSelectedObject());
        }
    });
    table.setSelectionModel(selectionModel);

    TextColumn<Arg> value = new TextColumn<Arg>() {
        @Override
        public String getValue(Arg object) {
            return object.getProperty(ARG_VALUE);
        }
    };

    TextColumn<Arg> type = new TextColumn<Arg>() {
        @Override
        public String getValue(Arg arg) {
            ArgType argType = arg.getProperty(ARG_TYPE);

            return argType == null ? "" : argType.getValue();
        }
    };

    TextColumn<Arg> evaluator = new TextColumn<Arg>() {
        @Override
        public String getValue(Arg arg) {
            Evaluator evaluator = arg.getProperty(ARG_EVALUATOR);

            return evaluator == null ? "" : evaluator.getValue();
        }
    };

    table.addColumn(type, localizationConstant.columnType());
    table.addColumn(value, localizationConstant.columnValue());
    table.addColumn(evaluator, localizationConstant.columnEvaluator());

    table.setColumnWidth(type, 120, PX);
    table.setColumnWidth(value, 210, PX);
    table.setColumnWidth(evaluator, 120, PX);

    table.setLoadingIndicator(null);

    return table;
}

From source file:org.drools.guvnor.client.scorecards.GuidedScorecardWidget.java

License:Apache License

private Widget addAttributeCellTable(final DirtyableFlexTable cGrid, final Characteristic characteristic) {
    final CellTable<Attribute> attributeCellTable = new CellTable<Attribute>();

    List<String> operators = new ArrayList<String>();
    String dataType;//  w  ww  . j  a  v  a2 s .  c  o m
    if (characteristic == null) {
        dataType = "String";
    } else {
        dataType = characteristic.getDataType();
    }

    if ("String".equalsIgnoreCase(dataType)) {
        operators.addAll(Arrays.asList(stringOperators));
    } else if ("boolean".equalsIgnoreCase(dataType)) {
        operators.addAll(Arrays.asList(booleanOperators));
    } else {
        operators.addAll(Arrays.asList(numericOperators));
    }
    DynamicSelectionCell categoryCell = new DynamicSelectionCell(operators);
    Column<Attribute, String> operatorColumn = new Column<Attribute, String>(categoryCell) {
        public String getValue(Attribute object) {
            return object.getOperator();
        }
    };

    Column<Attribute, String> valueColumn = new Column<Attribute, String>(new CustomEditTextCell()) {
        public String getValue(Attribute attribute) {
            return attribute.getValue();
        }
    };
    final EditTextCell partialScoreCell = new EditTextCell();
    Column<Attribute, String> partialScoreColumn = new Column<Attribute, String>(partialScoreCell) {
        public String getValue(Attribute attribute) {
            return "" + attribute.getPartialScore();
        }
    };

    Column<Attribute, String> reasonCodeColumn = new Column<Attribute, String>(new EditTextCell()) {
        public String getValue(Attribute attribute) {
            return attribute.getReasonCode();
        }
    };

    ActionCell.Delegate<Attribute> delegate = new ActionCell.Delegate<Attribute>() {
        public void execute(Attribute attribute) {
            if (Window.confirm("Remove this attribute?")) {
                List<Attribute> list = characteristicsAttrMap.get(cGrid).getList();
                list.remove(attribute);
                ((EnumDropDown) cGrid.getWidget(2, 0)).setEnabled(list.size() == 0);
                ((EnumDropDown) cGrid.getWidget(2, 1)).setEnabled(list.size() == 0);
                ((Button) cGrid.getWidget(0, 3)).setEnabled(list.size() != 2);
                attributeCellTable.redraw();
            }
        }
    };
    Cell<Attribute> actionCell = new ActionCell<Attribute>("Remove", delegate);
    Column<Attribute, String> actionColumn = new IdentityColumn(actionCell);

    reasonCodeColumn.setFieldUpdater(new FieldUpdater<Attribute, String>() {
        public void update(int index, Attribute object, String value) {
            object.setReasonCode(value);
            attributeCellTable.redraw();
        }
    });
    operatorColumn.setFieldUpdater(new FieldUpdater<Attribute, String>() {
        public void update(int index, Attribute object, String value) {
            object.setOperator(value);
            attributeCellTable.redraw();
        }
    });
    valueColumn.setFieldUpdater(new FieldUpdater<Attribute, String>() {
        public void update(int index, Attribute object, String value) {
            object.setValue(value);
            attributeCellTable.redraw();
        }
    });
    partialScoreColumn.setFieldUpdater(new FieldUpdater<Attribute, String>() {
        public void update(int index, Attribute object, String value) {
            try {
                double d = Double.parseDouble(value);
                object.setPartialScore(d);
            } catch (Exception e1) {
                partialScoreCell.clearViewData(object);
            }
            attributeCellTable.redraw();
        }
    });
    // Add the columns.
    attributeCellTable.addColumn(operatorColumn, "Operator");
    attributeCellTable.addColumn(valueColumn, "Value");
    attributeCellTable.addColumn(partialScoreColumn, "Partial Score");
    attributeCellTable.addColumn(reasonCodeColumn, "Reason Code");
    attributeCellTable.addColumn(actionColumn, "Actions");
    attributeCellTable.setWidth("100%", true);

    attributeCellTable.setColumnWidth(operatorColumn, 5.0, Style.Unit.PCT);
    attributeCellTable.setColumnWidth(valueColumn, 10.0, Style.Unit.PCT);
    attributeCellTable.setColumnWidth(partialScoreColumn, 10.0, Style.Unit.PCT);
    attributeCellTable.setColumnWidth(reasonCodeColumn, 10.0, Style.Unit.PCT);
    attributeCellTable.setColumnWidth(actionColumn, 5.0, Style.Unit.PCT);

    ListDataProvider<Attribute> dataProvider = new ListDataProvider<Attribute>();
    dataProvider.addDataDisplay(attributeCellTable);
    characteristicsAttrMap.put(cGrid, dataProvider);
    return (attributeCellTable);
}

From source file:org.drools.workbench.screens.guided.scorecard.client.widget.GuidedScoreCardEditor.java

License:Apache License

private Widget addAttributeCellTable(final FlexTable cGrid, final Characteristic characteristic,
        final boolean enumColumn, final String dataType, final List<String> operators) {
    String[] enumValues = null;//from   ww  w  .j  a  v  a2  s.c om
    if (characteristic != null) {
        //enum values
        if (enumColumn) {
            String factName = characteristic.getFact();
            String fieldName = characteristic.getField();
            enumValues = oracle.getEnumValues(factName, fieldName);
        }
    }

    final CellTable<Attribute> attributeCellTable = new CellTable<Attribute>();

    //Operators column
    final DynamicSelectionCell categoryCell = new DynamicSelectionCell(operators);
    final Column<Attribute, String> operatorColumn = new Column<Attribute, String>(categoryCell) {
        public String getValue(final Attribute object) {
            return object.getOperator();
        }
    };
    operatorColumn.setFieldUpdater(new FieldUpdater<Attribute, String>() {
        public void update(int index, Attribute object, String value) {
            object.setOperator(value);
            attributeCellTable.redraw();
        }
    });

    //Value column
    Column<Attribute, String> valueColumn = null;
    if (enumValues != null && enumValues.length > 0) {
        valueColumn = new Column<Attribute, String>(new DynamicSelectionCell(Arrays.asList(enumValues))) {
            public String getValue(final Attribute object) {
                return object.getValue();
            }
        };
        valueColumn.setFieldUpdater(new FieldUpdater<Attribute, String>() {
            public void update(int index, Attribute object, String value) {
                object.setValue(value);
                attributeCellTable.redraw();
            }
        });
    }
    if (valueColumn == null) {
        valueColumn = new Column<Attribute, String>(new CustomEditTextCell()) {
            public String getValue(final Attribute attribute) {
                return attribute.getValue();
            }
        };
        valueColumn.setFieldUpdater(new FieldUpdater<Attribute, String>() {
            public void update(int index, Attribute object, String value) {
                object.setValue(value);
                attributeCellTable.redraw();
            }
        });
    }
    //Partial Score column
    final EditTextCell partialScoreCell = new EditTextCell();
    final Column<Attribute, String> partialScoreColumn = new Column<Attribute, String>(partialScoreCell) {
        public String getValue(final Attribute attribute) {
            return "" + attribute.getPartialScore();
        }
    };
    partialScoreColumn.setFieldUpdater(new FieldUpdater<Attribute, String>() {
        public void update(int index, Attribute object, String value) {
            try {
                double d = Double.parseDouble(value);
                object.setPartialScore(d);
            } catch (Exception e1) {
                partialScoreCell.clearViewData(object);
            }
            attributeCellTable.redraw();
        }
    });

    //Reason Code column
    final Column<Attribute, String> reasonCodeColumn = new Column<Attribute, String>(new EditTextCell()) {
        public String getValue(final Attribute attribute) {
            return attribute.getReasonCode();
        }
    };
    reasonCodeColumn.setFieldUpdater(new FieldUpdater<Attribute, String>() {
        public void update(int index, Attribute object, String value) {
            object.setReasonCode(value);
            attributeCellTable.redraw();
        }
    });

    final ActionCell.Delegate<Attribute> delegate = new ActionCell.Delegate<Attribute>() {
        public void execute(final Attribute attribute) {
            if (Window.confirm(GuidedScoreCardConstants.INSTANCE.promptDeleteAttribute())) {
                final List<Attribute> list = characteristicsAttrMap.get(cGrid).getList();
                list.remove(attribute);
                if ("boolean".equalsIgnoreCase(dataType)) {
                    ((Button) cGrid.getWidget(0, 3)).setEnabled(list.size() != 2);
                }
                attributeCellTable.redraw();
            }
        }
    };

    final Cell<Attribute> actionCell = new ActionCell<Attribute>(GuidedScoreCardConstants.INSTANCE.remove(),
            delegate);
    final Column<Attribute, String> actionColumn = new IdentityColumn(actionCell);

    // Add the columns.
    attributeCellTable.addColumn(operatorColumn, GuidedScoreCardConstants.INSTANCE.operator());
    attributeCellTable.addColumn(valueColumn, GuidedScoreCardConstants.INSTANCE.value());
    attributeCellTable.addColumn(partialScoreColumn, GuidedScoreCardConstants.INSTANCE.partialScore());
    attributeCellTable.addColumn(reasonCodeColumn, GuidedScoreCardConstants.INSTANCE.reasonCode());
    attributeCellTable.addColumn(actionColumn, GuidedScoreCardConstants.INSTANCE.actions());
    attributeCellTable.setWidth("100%", true);

    attributeCellTable.setColumnWidth(operatorColumn, 20.0, Style.Unit.PCT);
    attributeCellTable.setColumnWidth(valueColumn, 20.0, Style.Unit.PCT);
    attributeCellTable.setColumnWidth(partialScoreColumn, 20.0, Style.Unit.PCT);
    attributeCellTable.setColumnWidth(reasonCodeColumn, 20.0, Style.Unit.PCT);
    attributeCellTable.setColumnWidth(actionColumn, 20.0, Style.Unit.PCT);

    ListDataProvider<Attribute> dataProvider = new ListDataProvider<Attribute>();
    dataProvider.addDataDisplay(attributeCellTable);
    characteristicsAttrMap.put(cGrid, dataProvider);

    if ("boolean".equalsIgnoreCase(dataType)) {
        CustomEditTextCell etc = (CustomEditTextCell) attributeCellTable.getColumn(1).getCell();
        etc.setEnabled(false);
    }

    return (attributeCellTable);
}

From source file:org.eclipse.che.ide.ext.datasource.client.ssl.SslKeyStoreManagerViewImpl.java

License:Open Source License

protected void addAliasColumn(CellTable<SslKeyStoreEntry> cellTable, String columnHeaderName) {
    Column<SslKeyStoreEntry, String> aliasColumn = new Column<SslKeyStoreEntry, String>(new TextCell()) {
        @Override/*from ww w .j  a  v  a  2 s .  c om*/
        public String getValue(SslKeyStoreEntry keyItem) {
            return keyItem.getAlias();
        }
    };
    aliasColumn.setSortable(true);
    cellTable.addColumn(aliasColumn, columnHeaderName);
    cellTable.setColumnWidth(aliasColumn, 50, Style.Unit.PCT);
}

From source file:org.eclipse.che.ide.ext.datasource.client.ssl.SslKeyStoreManagerViewImpl.java

License:Open Source License

protected void addTypeColumn(CellTable<SslKeyStoreEntry> cellTable, String columnHeaderName) {
    Column<SslKeyStoreEntry, String> typeColumn = new Column<SslKeyStoreEntry, String>(new ButtonCell()) {
        @Override//from   w  ww  .  j  a v  a  2s .  c o m
        public String getValue(SslKeyStoreEntry object) {
            return object.getType();
        }

        /** {@inheritDoc} */
        @Override
        public void render(Context context, SslKeyStoreEntry object, SafeHtmlBuilder sb) {
            if (object != null && object.getType() != null) {
                super.render(context, object, sb);
            }
        }
    };
    cellTable.addColumn(typeColumn, columnHeaderName);
    cellTable.setColumnWidth(typeColumn, 30, Style.Unit.PX);
}

From source file:org.eclipse.che.ide.ext.datasource.client.ssl.SslKeyStoreManagerViewImpl.java

License:Open Source License

protected Column<SslKeyStoreEntry, String> addDeleteColumn(CellTable<SslKeyStoreEntry> cellTable,
        String columnHeaderName) {
    Column<SslKeyStoreEntry, String> deleteKeyColumn = new Column<SslKeyStoreEntry, String>(new ButtonCell()) {
        @Override//ww w . j  ava2s  .  co m
        public String getValue(SslKeyStoreEntry object) {
            return "Delete";
        }
    };
    cellTable.addColumn(deleteKeyColumn, columnHeaderName);
    cellTable.setColumnWidth(deleteKeyColumn, 30, Style.Unit.PX);
    return deleteKeyColumn;
}

From source file:org.eclipse.che.ide.ext.openshift.client.deploy._new.NewApplicationViewImpl.java

License:Open Source License

private CellTable<KeyValue> createCellTable(CellTableResources cellTableResources,
        final ListDataProvider<KeyValue> dataProvider, final Predicate<String> keyValidator,
        final Predicate<String> valueValidator) {
    final CellTable<KeyValue> table = new CellTable<>(50, cellTableResources);
    table.setKeyboardSelectionPolicy(HasKeyboardSelectionPolicy.KeyboardSelectionPolicy.DISABLED);
    dataProvider.addDataDisplay(table);/*  www.  jav a  2s .  c o m*/

    TextInputCell keyCell = new TextInputCell() {
        @Override
        public void onBrowserEvent(Context context, com.google.gwt.dom.client.Element parent, String value,
                NativeEvent event, ValueUpdater<String> valueUpdater) {
            super.onBrowserEvent(context, parent, value, event, valueUpdater);
            if (event.getType().equals(BrowserEvents.KEYUP)) {
                String newValue = getInputElement(parent).getValue();
                if (!keyValidator.apply(newValue)) {
                    parent.getParentElement().addClassName(resources.css().deployApplicationTableError());
                } else {
                    parent.getParentElement().removeClassName(resources.css().deployApplicationTableError());
                }
                valueUpdater.update(newValue);
                delegate.updateControls();
            }
        }
    };

    Column<KeyValue, String> nameColumn = new Column<KeyValue, String>(keyCell) {
        @Override
        public String getCellStyleNames(Cell.Context context, KeyValue object) {
            if (!keyValidator.apply(object.getKey())) {
                return resources.css().deployApplicationTableError();
            }
            return null;
        }

        @Override
        public String getValue(KeyValue object) {
            return object.getKey();
        }
    };

    nameColumn.setFieldUpdater(new FieldUpdater<KeyValue, String>() {
        @Override
        public void update(int index, KeyValue object, String value) {
            object.setKey(value);
        }
    });

    TextInputCell valueCell = new TextInputCell() {
        @Override
        public void onBrowserEvent(Cell.Context context, com.google.gwt.dom.client.Element parent, String value,
                NativeEvent event, ValueUpdater<String> valueUpdater) {
            super.onBrowserEvent(context, parent, value, event, valueUpdater);
            if (event.getType().equals(BrowserEvents.KEYUP)) {
                String newValue = getInputElement(parent).getValue();
                if (!valueValidator.apply(newValue)) {
                    parent.getParentElement().addClassName(resources.css().deployApplicationTableError());
                } else {
                    parent.getParentElement().removeClassName(resources.css().deployApplicationTableError());
                }
                valueUpdater.update(newValue);
                delegate.updateControls();
            }
        }
    };

    Column<KeyValue, String> valueColumn = new Column<KeyValue, String>(valueCell) {
        @Override
        public String getCellStyleNames(Cell.Context context, KeyValue object) {
            if (!valueValidator.apply(object.getValue())) {
                return resources.css().deployApplicationTableError();
            }
            return null;
        }

        @Override
        public String getValue(KeyValue object) {
            return object.getValue();
        }
    };

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

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

        @Override
        public void render(Cell.Context context, KeyValue object, SafeHtmlBuilder sb) {
            Button removeButton = new Button();
            super.render(context, object, sb.appendHtmlConstant(removeButton.getHTML()));
        }
    };

    removeColumn.setFieldUpdater(new FieldUpdater<KeyValue, String>() {
        @Override
        public void update(int index, KeyValue object, String value) {
            dataProvider.getList().remove(object);
            delegate.updateControls();
        }
    });

    table.addColumn(nameColumn);
    table.setColumnWidth(nameColumn, 35, Style.Unit.PCT);
    table.addColumn(valueColumn);
    table.setColumnWidth(valueColumn, 55, Style.Unit.PCT);
    table.addColumn(removeColumn);
    table.setColumnWidth(removeColumn, 10, Style.Unit.PCT);
    removeColumn.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);

    return table;
}