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

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

Introduction

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

Prototype

public Column(Cell<C> cell) 

Source Link

Document

Construct a new Column with a given Cell .

Usage

From source file:com.gwt2go.dev.client.ui.CellTableViewImpl.java

License:Apache License

/**
 * Add the columns to the table./*from  ww  w.  j a  v  a2s.  c  om*/
 */
private void initTableColumns(final SelectionModel<ContactInfo> selectionModel) {
    // This table will uses a checkbox column for selection.
    // Alternatively, you can call cellTable.setSelectionEnabled(true) to
    // enable mouse selection.
    Column<ContactInfo, Boolean> checkColumn = new Column<ContactInfo, Boolean>(new CheckboxCell(true, true)) {
        @Override
        public Boolean getValue(ContactInfo object) {
            // Get the value from the selection model.
            return selectionModel.isSelected(object);
        }
    };
    checkColumn.setFieldUpdater(new FieldUpdater<ContactInfo, Boolean>() {
        public void update(int index, ContactInfo object, Boolean value) {
            // Called when the user clicks on a checkbox.
            selectionModel.setSelected(object, value);
        }
    });
    cellTable.addColumn(checkColumn, SafeHtmlUtils.fromSafeConstant("<br>"));

    // First name.
    // Column<ContactInfo, String> firstNameColumn = new Column<ContactInfo,
    // String>(
    // new EditTextCell()) {
    // @Override
    // public String getValue(ContactInfo object) {
    // return object.getFirstName();
    // }
    // };

    // TextHeader firstNameHeader = new TextHeader("First name");
    // firstNameHeader.setUpdater(new ValueUpdater<String>() {
    // @Override
    // public void update(String value) {
    // Window.alert("Update the header");
    // }
    // });
    //
    // cellTable.addColumn(firstNameColumn, firstNameHeader);
    //
    // firstNameColumn
    // .setFieldUpdater(new FieldUpdater<ContactInfo, String>() {
    // public void update(int index, ContactInfo object,
    // String value) {
    // // Called when the user changes the value.
    // object.setFirstName(value);
    // ContactDatabase.get().refreshDisplays();
    // }
    // });

    addColumn("First name", new TextCell(), new GetValue<ContactInfo, String>() {
        public String getValue(ContactInfo object) {
            return object.getFirstName();
        }
    });

    // Last name.
    Column<ContactInfo, String> lastNameColumn = new Column<ContactInfo, String>(new EditTextCell()) {
        @Override
        public String getValue(ContactInfo object) {
            return object.getLastName();
        }
    };
    cellTable.addColumn(lastNameColumn, "Last name");
    lastNameColumn.setFieldUpdater(new FieldUpdater<ContactInfo, String>() {
        public void update(int index, ContactInfo object, String value) {
            // Called when the user changes the value.
            object.setLastName(value);
            ContactDatabase.get().refreshDisplays();
        }
    });

    // Category.
    final Category[] categories = ContactDatabase.get().queryCategories();
    List<String> categoryNames = new ArrayList<String>();
    for (Category category : categories) {
        categoryNames.add(category.getDisplayName());
    }
    SelectionCell categoryCell = new SelectionCell(categoryNames);
    Column<ContactInfo, String> categoryColumn = new Column<ContactInfo, String>(categoryCell) {
        @Override
        public String getValue(ContactInfo object) {
            return object.getCategory().getDisplayName();
        }
    };
    cellTable.addColumn(categoryColumn, "Category");
    categoryColumn.setFieldUpdater(new FieldUpdater<ContactInfo, String>() {
        public void update(int index, ContactInfo object, String value) {
            for (Category category : categories) {
                if (category.getDisplayName().equals(value)) {
                    object.setCategory(category);
                }
            }
            ContactDatabase.get().refreshDisplays();
        }
    });

    // Address.
    addColumn("Address", new TextCell(), new GetValue<ContactInfo, String>() {
        public String getValue(ContactInfo object) {
            return object.getAddress();
        }
    });

    // cellTable.addColumn(new Column<ContactInfo, String>(new TextCell()) {
    // @Override
    // public String getValue(ContactInfo object) {
    // return object.getAddress();
    // }
    // }, "Address");
}

From source file:com.gwt2go.dev.client.ui.CellTableViewImpl.java

License:Apache License

/**
 * Add a sortable column to the table.//from w  w  w.j  av  a  2  s . c  o m
 * 
 * @param <C>
 *            the data type for the column
 * @param text
 *            the header text
 * @param cell
 *            the cell used to render the column
 * @param getter
 *            the getter to retrieve the value for the column
 * @param property
 *            the property to sort by
 * @param ascComparator
 *            ascendent comparator
 * @param descComparator
 *            descendant comparator
 * @return the column
 */
private <C> Column<ContactInfo, C> addColumn(final String text, final Cell<C> cell,
        final GetValue<ContactInfo, C> getter, final Comparator<ContactInfo> ascComparator,
        final Comparator<ContactInfo> descComparator) {

    // gets the cell value
    final Column<ContactInfo, C> column = new Column<ContactInfo, C>(cell) {
        @Override
        public C getValue(ContactInfo object) {
            return getter.getValue(object);
        }
    };

    final SortHeader header = new SortHeader(text);
    allHeaders.add(header);

    // call this everytime headers is clicked
    header.setUpdater(new ValueUpdater<String>() {
        public void update(String value) {
            header.setSorted(true);
            header.toggleReverseSort();

            for (SortHeader otherHeader : allHeaders) {
                if (otherHeader != header) {
                    otherHeader.setSorted(false);
                    otherHeader.setReverseSort(true);
                }
            }

            // sort the clicked column
            sortExpenses(ContactDatabase.get().getDataProvider().getList(),
                    header.getReverseSort() ? descComparator : ascComparator);

            cellTable.redrawHeaders();

            // Go to the first page of the newly-sorted results, if wished
            // pager.firstPage();
        }
    });
    cellTable.addColumn(column, header);
    return column;
}

From source file:com.gwt2go.dev.client.ui.table.DataGridImpl1.java

License:Apache License

public DataGridImpl1() {

    // Create a CellTable.
    DataGrid<Contact> table = new DataGrid<Contact>();
    table.setWidth("100%");
    table.setHeight("100px");

    //      table.setRowStyles(new RowStyles<DataGridImpl1.Contact>() {         
    //         @Override
    //         public String getStyleNames(Contact row, int rowIndex) {
    //            return "headcol";
    //         }// w w w  .  ja v a  2 s .  c o  m
    //      });

    table.setEmptyTableWidget(new Label("No Information to show"));
    table.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED);

    // Add a text column to show the name.
    TextColumn<Contact> nameColumn = new TextColumn<Contact>() {
        @Override
        public String getValue(Contact object) {
            return object.name;
        }
    };
    table.addColumn(nameColumn, "Name");

    // Add a date column to show the birthday.
    DateCell dateCell = new DateCell();
    Column<Contact, Date> dateColumn = new Column<Contact, Date>(dateCell) {
        @Override
        public Date getValue(Contact object) {
            return object.birthday;
        }
    };

    table.addColumn(dateColumn, "Birthday");

    // Add a text column to show the address.
    TextColumn<Contact> addressColumn = new TextColumn<Contact>() {
        @Override
        public String getValue(Contact object) {
            return object.address;
        }
    };
    table.addColumn(addressColumn, "Address");

    // Add a selection model to handle user selection.
    final SingleSelectionModel<Contact> selectionModel = new SingleSelectionModel<Contact>();
    table.setSelectionModel(selectionModel);
    selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
        public void onSelectionChange(SelectionChangeEvent event) {
            Contact selected = selectionModel.getSelectedObject();
            if (selected != null) {
                Window.alert("You selected: " + selected.name);
            }
        }
    });

    // Set the total row count. This isn't strictly necessary, but it
    // affects
    // paging calculations, so its good habit to keep the row count up to
    // date.
    table.setRowCount(CONTACTS.size(), true);

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

    // -- END TABLE

    // viewPanel.getElement().appendChild(nameSpan);

    viewPanel.add(table);
    viewPanel.setSize("30em", "10em");

    initWidget(viewPanel);

}

From source file:com.gwt2go.dev.client.ui.widget.CellTableSorting.java

License:Apache License

/**
 * Add a sortable column to the table./*ww  w  .  java 2  s  . c o m*/
 * 
 * @param <C>
 *            the data type for the column
 * @param text
 *            the header text
 * @param cell
 *            the cell used to render the column
 * @param getter
 *            the getter to retrieve the value for the column
 * @param property
 *            the property to sort by
 * @param ascComparator
 *            ascendent comparator
 * @param descComparator
 *            descendant comparator
 * @return the column
 */
private <C> Column<T, C> addColumn(final String text, final Cell<C> cell, final GetValue<T, C> getter,
        final Comparator<T> ascComparator, final Comparator<T> descComparator, final SortableHeader header) {

    // gets the cell value
    final Column<T, C> column = new Column<T, C>(cell) {
        @Override
        public C getValue(T object) {
            return getter.getValue(object);
        }
    };

    // TODO: make this external to be able to add separated headers
    // final SortHeader header = new SortHeader(text);
    allHeaders.add(header);

    header.setUpdater(new ValueUpdater<String>() {
        @Override
        public void update(String value) {
            // Window.alert("History changer " + History.getToken());

            // TODO:
            // every time you click here, you can put the vent into a hashmap
            // and then onHistoryChange you can repeat the action!!!

            // put history tocken every time you click here
            //            String historyTocken = History.getToken();

            //            if (!historyTocken.endsWith(":"+header.getValue()+":")) {
            //               History.newItem(historyTocken+":"+header.getValue()+":", true);
            //            }            

            header.setSorted(true);
            header.toggleReverseSort();

            for (SortableHeader otherHeader : allHeaders) {
                if (otherHeader != header) {
                    otherHeader.setSorted(false);
                    otherHeader.setReverseSort(true);
                }
            }

            // sort the clicked column
            sortExpenses(dataProvider.getList(), header.getReverseSort() ? descComparator : ascComparator);

            // cellTable.redrawHeaders();
            redrawHeaders();

            // Go to the first page of the newly-sorted results, if wished
            // pager.firstPage();
        }
    });

    addColumn(column, header);
    return column;
}

From source file:com.gwtmodel.table.view.table.edit.PresentationEditCellFactory.java

License:Apache License

@SuppressWarnings({ "rawtypes", "unchecked" })
private Column constructControlColumn() {
    // return new ImageColumn();

    List<HasCell> ce = new ArrayList<HasCell>();
    // TODO: blocked now, re-think the usage
    // ce.add(new
    // HasCellImage(ImageNameFactory.getImageName(ImageNameFactory.ImageType.CHANGEROW),
    // PersistTypeEnum.MODIF));
    ce.add(new HasCellImage(PersistTypeEnum.REMOVE));
    ce.add(new HasCellImage(PersistTypeEnum.ADD));
    CompositeCell<MutableInteger> cCell = new CompositeCell(ce);
    Column<MutableInteger, MutableInteger> imageColumn = new Column<MutableInteger, MutableInteger>(cCell) {
        @Override/*from w  w  w  . ja  v  a2  s.c o  m*/
        public MutableInteger getValue(MutableInteger object) {
            return object;
        }
    };
    return imageColumn;

}

From source file:com.gwtplatform.carstore.client.application.cars.CarsView.java

License:Apache License

private void initDataColumns() {
    Column<CarDto, Number> idColumn = new Column<CarDto, Number>(new NumberCell()) {
        @Override/*www.  j a  v  a  2 s.  com*/
        public Long getValue(CarDto carDto) {
            return carDto.getId();
        }
    };

    Column<CarDto, String> manufacturerColumn = new Column<CarDto, String>(new TextCell()) {
        @Override
        public String getValue(CarDto carDto) {
            return carDto.getManufacturer().getName();
        }
    };

    Column<CarDto, String> modelColumn = new Column<CarDto, String>(new TextCell()) {
        @Override
        public String getValue(CarDto carDto) {
            return carDto.getModel();
        }
    };

    carGrid.addColumn(idColumn, "ID");
    carGrid.addColumn(manufacturerColumn, "Manufacturer");
    carGrid.addColumn(modelColumn, "Model");
    carGrid.setColumnWidth(idColumn, 50, Unit.PX);
}

From source file:com.gwtplatform.carstore.client.application.manufacturer.ManufacturerView.java

License:Apache License

private void initDataColumns() {
    Column<ManufacturerDto, Number> idColumn = new Column<ManufacturerDto, Number>(new NumberCell()) {
        @Override/* w w w.jav a 2 s  . c o m*/
        public Long getValue(ManufacturerDto manufacturerDto) {
            return manufacturerDto.getId();
        }
    };

    Column<ManufacturerDto, String> nameColumn = new Column<ManufacturerDto, String>(new TextCell()) {
        @Override
        public String getValue(ManufacturerDto manufacturerDto) {
            return manufacturerDto.getName();
        }
    };

    manufacturerGrid.addColumn(idColumn, "ID");
    manufacturerGrid.addColumn(nameColumn, "Name");
    manufacturerGrid.setColumnWidth(idColumn, 50, Unit.PX);
}

From source file:com.gwtplatform.carstore.client.application.report.ReportView.java

License:Apache License

private void initDataColumns() {
    Column<ManufacturerRatingDto, String> manufacturerColumn = new Column<ManufacturerRatingDto, String>(
            new TextCell()) {
        @Override//from   w  w w.ja va  2  s  .c om
        public String getValue(ManufacturerRatingDto manufacturerRating) {
            return manufacturerRating.getManufacturer();
        }
    };

    Column<ManufacturerRatingDto, Number> ratingColumn = new Column<ManufacturerRatingDto, Number>(
            new NumberCell()) {
        @Override
        public Double getValue(ManufacturerRatingDto manufacturerRating) {
            return manufacturerRating.getRating();
        }
    };

    reportGrid.addColumn(manufacturerColumn, "Manufacturer");
    reportGrid.addColumn(ratingColumn, "Rating");
    reportGrid.setColumnWidth(ratingColumn, 50, Unit.PX);
}

From source file:com.jitlogic.zico.client.views.traces.MethodAttrsDialog.java

License:Open Source License

private void setupGrid() {
    attrGrid = new DataGrid<String[]>(1024 * 1024, ZicoDataGridResources.INSTANCE, KEY_PROVIDER);
    selectionModel = new SingleSelectionModel<String[]>(KEY_PROVIDER);
    attrGrid.setSelectionModel(selectionModel);

    Column<String[], String> colAttribute = new Column<String[], String>(ATTR_CELL) {
        @Override/*from  ww  w.j a  v  a2s  .c  om*/
        public String getValue(String[] attr) {
            return attr[0];
        }
    };
    attrGrid.addColumn(colAttribute);
    attrGrid.setColumnWidth(colAttribute, 100, Style.Unit.PCT);

    attrStore = new ListDataProvider<String[]>(KEY_PROVIDER);
    attrStore.addDataDisplay(attrGrid);

    selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
        @Override
        public void onSelectionChange(SelectionChangeEvent event) {
            String[] item = selectionModel.getSelectedObject();
            if (item != null) {
                lblAttrName.setText("Selected attribute: " + item[0]);
                txtAttrVal.setText(item[1]);
            }
        }
    });

    attrGrid.setSize("100%", "100%");
}

From source file:com.jitlogic.zico.client.views.traces.MethodRankingPanel.java

License:Open Source License

private void createRankingGrid() {

    rankGrid = new DataGrid<MethodRankInfo>(1024 * 1024, ZicoDataGridResources.INSTANCE, KEY_PROVIDER);
    selectionModel = new SingleSelectionModel<MethodRankInfo>(KEY_PROVIDER);
    rankGrid.setSelectionModel(selectionModel);

    Column<MethodRankInfo, String> colMethod = new Column<MethodRankInfo, String>(new TextCell()) {
        @Override//from w ww.ja  va  2 s  .c o m
        public String getValue(MethodRankInfo m) {
            return m.getMethod();
        }
    };
    rankGrid.addColumn(colMethod, new ResizableHeader<MethodRankInfo>("Method", rankGrid, colMethod));
    rankGrid.setColumnWidth(colMethod, 100, Style.Unit.PCT);

    Column<MethodRankInfo, String> colCalls = new Column<MethodRankInfo, String>(new TextCell()) {
        @Override
        public String getValue(MethodRankInfo m) {
            return "" + m.getCalls();
        }
    };
    rankGrid.addColumn(colCalls, new ResizableHeader<MethodRankInfo>("Calls", rankGrid, colCalls));
    rankGrid.setColumnWidth(colCalls, 50, Style.Unit.PX);

    Column<MethodRankInfo, String> colErrors = new Column<MethodRankInfo, String>(new TextCell()) {
        @Override
        public String getValue(MethodRankInfo m) {
            return "" + m.getErrors();
        }
    };
    rankGrid.addColumn(colErrors, new ResizableHeader<MethodRankInfo>("Errors", rankGrid, colErrors));
    rankGrid.setColumnWidth(colErrors, 50, Style.Unit.PX);

    Column<MethodRankInfo, String> colTime = new Column<MethodRankInfo, String>(new TextCell()) {
        @Override
        public String getValue(MethodRankInfo m) {
            return ClientUtil.formatDuration(m.getTime());
        }
    };
    rankGrid.addColumn(colErrors, new ResizableHeader<MethodRankInfo>("Time", rankGrid, colTime));
    rankGrid.setColumnWidth(colTime, 50, Style.Unit.PX);

    Column<MethodRankInfo, String> colMinTime = new Column<MethodRankInfo, String>(new TextCell()) {
        @Override
        public String getValue(MethodRankInfo m) {
            return ClientUtil.formatDuration(m.getMinTime());
        }
    };
    rankGrid.addColumn(colMinTime, new ResizableHeader<MethodRankInfo>("MinT", rankGrid, colMinTime));
    rankGrid.setColumnWidth(colMinTime, 50, Style.Unit.PX);

    Column<MethodRankInfo, String> colMaxTime = new Column<MethodRankInfo, String>(new TextCell()) {
        @Override
        public String getValue(MethodRankInfo m) {
            return ClientUtil.formatDuration(m.getMaxTime());
        }
    };
    rankGrid.addColumn(colMaxTime, new ResizableHeader<MethodRankInfo>("MaxT", rankGrid, colMaxTime));
    rankGrid.setColumnWidth(colMaxTime, 50, Style.Unit.PX);

    Column<MethodRankInfo, String> colAvgTime = new Column<MethodRankInfo, String>(new TextCell()) {
        @Override
        public String getValue(MethodRankInfo m) {
            return ClientUtil.formatDuration(m.getAvgTime());
        }
    };
    rankGrid.addColumn(colAvgTime, new ResizableHeader<MethodRankInfo>("AvgT", rankGrid, colAvgTime));
    rankGrid.setColumnWidth(colAvgTime, 50, Style.Unit.PX);

    Column<MethodRankInfo, String> colBareTime = new Column<MethodRankInfo, String>(new TextCell()) {
        @Override
        public String getValue(MethodRankInfo m) {
            return ClientUtil.formatDuration(m.getBareTime());
        }
    };
    rankGrid.addColumn(colBareTime, new ResizableHeader<MethodRankInfo>("BT", rankGrid, colBareTime));
    rankGrid.setColumnWidth(colBareTime, 50, Style.Unit.PX);

    Column<MethodRankInfo, String> colMaxBareTime = new Column<MethodRankInfo, String>(new TextCell()) {
        @Override
        public String getValue(MethodRankInfo m) {
            return ClientUtil.formatDuration(m.getMaxBareTime());
        }
    };
    rankGrid.addColumn(colMaxBareTime, new ResizableHeader<MethodRankInfo>("MaxBT", rankGrid, colMaxBareTime));
    rankGrid.setColumnWidth(colMaxBareTime, 50, Style.Unit.PX);

    Column<MethodRankInfo, String> colMinBareTime = new Column<MethodRankInfo, String>(new TextCell()) {
        @Override
        public String getValue(MethodRankInfo m) {
            return ClientUtil.formatDuration(m.getMinBareTime());
        }
    };
    rankGrid.addColumn(colMinBareTime, new ResizableHeader<MethodRankInfo>("MinBT", rankGrid, colMinBareTime));
    rankGrid.setColumnWidth(colMinBareTime, 50, Style.Unit.PX);

    rankStore = new ListDataProvider<MethodRankInfo>(KEY_PROVIDER);
    rankStore.addDataDisplay(rankGrid);

}