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

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

Introduction

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

Prototype

public final void setWidth(String width, boolean isFixedLayout) 

Source Link

Document

Set the width of the width and specify whether or not it should use fixed table layout.

Usage

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

License:Open Source License

public CellTable<FileSpecification> createFileTable(Column<FileSpecification, FileSpecification> repoColumn) {
    final ProvidesKey<FileSpecification> KEY_PROVIDER = new ProvidesKey<FileSpecification>() {

        public Object getKey(FileSpecification item) {
            return item.getName();
        }/*www.  ja  va 2 s.c om*/
    };
    final CellTable<FileSpecification> table;
    table = new CellTable<FileSpecification>(KEY_PROVIDER);
    table.setWidth("100%", true);
    table.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.DISABLED);
    TextColumn<FileSpecification> descriptionColumn = new TextColumn<FileSpecification>() {
        @Override
        public String getValue(FileSpecification file) {
            String result = "";
            if (file != null)
                return file.getDescription();
            return result;
        }
    };
    table.addColumn(descriptionColumn);

    table.addColumn(repoColumn);
    repoColumn.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);

    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  w  w. jav  a 2  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   w ww .ja va2  s  .  com*/
    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.kie.guvnor.guided.scorecard.client.editor.GuidedScoreCardEditor.java

License:Apache License

private Widget addAttributeCellTable(final DirtyableFlexTable cGrid, final Characteristic characteristic) {
    final CellTable<Attribute> attributeCellTable = new CellTable<Attribute>();
    final List<String> operators = new ArrayList<String>();
    String dataType;/*from w ww  .  j  a va2s . com*/
    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));
    }

    //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
    final Column<Attribute, String> 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(Constants.INSTANCE.promptDeleteAttribute())) {
                final List<Attribute> list = characteristicsAttrMap.get(cGrid).getList();
                list.remove(attribute);
                ((ListBox) cGrid.getWidget(2, 0)).setEnabled(list.size() == 0);
                ((ListBox) cGrid.getWidget(2, 1)).setEnabled(list.size() == 0);
                ((Button) cGrid.getWidget(0, 3)).setEnabled(list.size() != 2);
                attributeCellTable.redraw();
            }
        }
    };

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

    // Add the columns.
    attributeCellTable.addColumn(operatorColumn, Constants.INSTANCE.operator());
    attributeCellTable.addColumn(valueColumn, Constants.INSTANCE.value());
    attributeCellTable.addColumn(partialScoreColumn, Constants.INSTANCE.partialScore());
    attributeCellTable.addColumn(reasonCodeColumn, Constants.INSTANCE.reasonCode());
    attributeCellTable.addColumn(actionColumn, Constants.INSTANCE.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:tn.spindox.client.ui.CellTableFieldUpdaterExample.java

License:Apache License

public CellTable<Person> getTable() {

    // Create a CellTable with a key provider.
    final CellTable<Person> table = new CellTable<Person>(KEY_PROVIDER);
    table.setWidth("100%", false);

    // Add a date column to show the birthday.
    CheckboxCell checkBoxCell = new CheckboxCell();
    Column<Person, Boolean> SelectedColumn = new Column<Person, Boolean>(checkBoxCell) {
        @Override/*from  ww  w  .j  a va 2s  .  c om*/
        public Boolean getValue(Person object) {
            return object.selected;
        }
    };

    TextColumn<Person> firstNameColumn = new TextColumn<Person>() {
        @Override
        public String getValue(Person object) {
            // Return the name as the value of this column.
            return object.firstName;
        }
    };
    TextColumn<Person> lastNameColumn = new TextColumn<Person>() {
        @Override
        public String getValue(Person object) {
            // Return the name as the value of this column.
            return object.lastName;
        }
    };
    TextColumn<Person> birthDateColumn = new TextColumn<Person>() {
        @Override
        public String getValue(Person object) {
            // Return the name as the value of this column.
            return object.birthDate;
        }
    };
    TextColumn<Person> RegionColumn = new TextColumn<Person>() {
        @Override
        public String getValue(Person object) {
            // Return the name as the value of this column.
            return object.region;
        }
    };
    TextColumn<Person> emailColumn = new TextColumn<Person>() {
        @Override
        public String getValue(Person object) {
            // Return the name as the value of this column.
            return object.email;
        }
    };

    // Add a field updater to be notified when the user enters a new name.
    SelectedColumn.setFieldUpdater(new FieldUpdater<Person, Boolean>() {

        @Override
        public void update(int index, Person person, Boolean value) {

            if (value) {
                person.selected = true;
            } else {
                person.selected = false;
            }
        }

    });

    ButtonCell editCell = new ButtonCell();
    Column<Person, String> editColumn = new Column<Person, String>(editCell) {
        @Override
        public String getValue(Person object) {
            return "edit";
        }
    };

    editColumn.setFieldUpdater(new FieldUpdater<Person, String>() {

        @Override
        public void update(int index, Person object, String value) {

            System.out.println("-----------> clicked");

            callLoginDialogBox();
        }

        protected void callLoginDialogBox() {
            EditPersonBox editPersonBox = new EditPersonBox();

            editPersonBox.show();
        }

    });

    ButtonCell deleteCell = new ButtonCell();
    Column<Person, String> deleteColumn = new Column<Person, String>(deleteCell) {
        @Override
        public String getValue(Person object) {
            return "delete";
        }
    };

    deleteColumn.setFieldUpdater(new FieldUpdater<Person, String>() {

        @Override
        public void update(int index, Person person, String value) {

            System.out.println("-----------> delete clicked");

            Employee e = new Employee();
            e.setId_pers(person.id);
            e.setFirstName(person.firstName);
            e.setLastName(person.lastName);
            e.setBirthDate(person.birthDate);
            e.setRegion(person.region);
            e.setEmail(person.email);

            serverPerson.delete(e, new AsyncCallback<Void>() {

                @Override
                public void onFailure(Throwable caught) {
                    System.out.println("---> Error while deleting employee");
                }

                @Override
                public void onSuccess(Void result) {
                    System.out.println("---> deleting success !!! ");
                    table.redraw();
                }

            });

        }

    });

    table.addColumn(SelectedColumn, "");
    table.addColumn(firstNameColumn, "First Name");
    table.addColumn(lastNameColumn, "Last Name");
    table.addColumn(birthDateColumn, "Birth Date");
    table.addColumn(RegionColumn, "Region");
    table.addColumn(emailColumn, "Email");
    table.addColumn(editColumn, "");
    table.addColumn(deleteColumn, "");

    // Push the data into the widget.
    // table.setRowData(CONTACTS);

    final EmployeeServiceAsync server = GWT.create(EmployeeService.class);
    server.getListEmployees(new AsyncCallback<List<Employee>>() {

        @Override
        public void onFailure(Throwable caught) {
            System.out.println("---> Pb in retrieveing persons...");

        }

        @Override
        public void onSuccess(List<Employee> result) {

            List<Person> persons = new ArrayList<Person>();

            for (Employee e : result) {
                Person contact = new Person(false, e.getId_pers(), e.getLastName(), e.getFirstName(),
                        e.getBirthDate(), e.getRegion(), e.getEmail());
                persons.add(contact);
            }
            // Push the data into the widget.
            table.setRowData(persons);
        }

    });

    return table;
}

From source file:uk.ac.ebi.fg.annotare2.web.gwt.editor.client.view.widget.MultiSelectListDialog.java

License:Apache License

private CellTable<String> createCellTable(Map<String, Boolean> items) {
    CellTable<String> cellTable = new CellTable<String>();
    cellTable.setWidth("100%", true);
    cellTable.setEmptyTableWidget(new Label("empty list"));
    cellTable.setVisibleRange(0, items.size());

    selectionModel = new MultiSelectionModel<String>();
    cellTable.setSelectionModel(selectionModel, DefaultSelectionEventManager.<String>createCheckboxManager());

    Column<String, Boolean> checkboxColumn = new Column<String, Boolean>(new CheckboxCell(true, false)) {
        @Override/*  w ww  .ja v a  2  s. c  o m*/
        public Boolean getValue(String object) {
            return selectionModel.isSelected(object);
        }
    };
    cellTable.addColumn(checkboxColumn);
    cellTable.setColumnWidth(checkboxColumn, 40, Style.Unit.PX);

    Column<String, String> valueColumn = new Column<String, String>(new TextCell()) {
        @Override
        public String getValue(String object) {
            return object;
        }
    };
    cellTable.addColumn(valueColumn);

    dataProvider = new ListDataProvider<String>();
    dataProvider.addDataDisplay(cellTable);
    dataProvider.setList(new ArrayList<String>(items.keySet()));

    for (String item : items.keySet()) {
        selectionModel.setSelected(item, items.get(item));
    }
    return cellTable;
}