List of usage examples for com.google.gwt.user.cellview.client Column Column
public Column(Cell<C> cell)
From source file:com.google.gwt.examples.cellview.CellTableFieldUpdaterExample.java
License:Apache License
@Override public void onModuleLoad() { // Create a CellTable with a key provider. final CellTable<Contact> table = new CellTable<Contact>(KEY_PROVIDER); // Add a text input column to edit the name. final TextInputCell nameCell = new TextInputCell(); Column<Contact, String> nameColumn = new Column<Contact, String>(nameCell) { @Override//from w w w .ja v a 2s .c o m public String getValue(Contact object) { // Return the name as the value of this column. return object.name; } }; table.addColumn(nameColumn, "Name"); // Add a field updater to be notified when the user enters a new name. nameColumn.setFieldUpdater(new FieldUpdater<Contact, String>() { @Override public void update(int index, Contact object, String value) { // Inform the user of the change. Window.alert("You changed the name of " + object.name + " to " + value); // Push the changes into the Contact. At this point, you could send an // asynchronous request to the server to update the database. object.name = value; // Redraw the table with the new data. table.redraw(); } }); // Push the data into the widget. table.setRowData(CONTACTS); // Add it to the root panel. RootPanel.get().add(table); }
From source file:com.google.gwt.examples.cellview.CellTableFieldUpdaterExampleComplex.java
License:Apache License
@Override public void onModuleLoad() { // Create a CellTable with a key provider. final CellTable<Contact> table = new CellTable<Contact>(KEY_PROVIDER); table.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED); // Add a text input column to edit the name. final TextInputCell nameCell = new TextInputCell(); Column<Contact, String> nameColumn = new Column<Contact, String>(nameCell) { @Override/*from ww w .j a v a 2 s . c o m*/ public String getValue(Contact object) { return object.name; } }; table.addColumn(nameColumn, "Name"); // Add a field updater to be notified when the user enters a new name. nameColumn.setFieldUpdater(new FieldUpdater<Contact, String>() { @Override public void update(int index, Contact object, String value) { // Validate the data. if (value.length() < 3) { Window.alert("Names must be at least three characters long."); /* * Clear the view data. The view data contains the pending change and * allows the table to render with the pending value until the data is * committed. If the data is committed into the object, the view data * is automatically cleared out. If the data is not committed because * it is invalid, you must delete. */ nameCell.clearViewData(KEY_PROVIDER.getKey(object)); // Redraw the table. table.redraw(); return; } // Inform the user of the change. Window.alert("You changed the name of " + object.name + " to " + value); // Push the changes into the Contact. At this point, you could send an // asynchronous request to the server to update the database. object.name = value; // Redraw the table with the new data. table.redraw(); } }); // Add a date column to show the birthday. Column<Contact, Date> dateColumn = new Column<Contact, Date>(new DatePickerCell()) { @Override public Date getValue(Contact object) { return object.birthday; } }; table.addColumn(dateColumn, "Birthday"); // Add a field updater to be notified when the user enters a new birthday. dateColumn.setFieldUpdater(new FieldUpdater<Contact, Date>() { @Override public void update(int index, Contact object, Date value) { Window.alert("You changed the birthday of " + object.name + " to " + DateTimeFormat.getFormat(PredefinedFormat.DATE_LONG).format(value)); // Push the changes into the Contact. object.birthday = value; // Redraw the table with the new data. table.redraw(); } }); // 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"); // 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); // Add it to the root panel. RootPanel.get().add(table); }
From source file:com.google.gwt.sample.expenses.client.ExpenseDetails.java
License:Apache License
/** * Add a column with the specified comparators. * * @param <C> the column type//from w ww. j ava 2s .c om * @param table the table * @param text the header text * @param cell the cell used to render values * @param getter the {@link GetValue} used to retrieve cell values * @param ascComparator the comparator used to sort ascending * @param descComparator the comparator used to sort ascending * @return the new column */ private <C> Column<ExpenseProxy, C> addColumn(final CellTable<ExpenseProxy> table, final String text, final Cell<C> cell, final GetValue<ExpenseProxy, C> getter, final Comparator<ExpenseProxy> ascComparator, final Comparator<ExpenseProxy> descComparator) { // Create the column. final Column<ExpenseProxy, C> column = new Column<ExpenseProxy, C>(cell) { @Override public C getValue(ExpenseProxy object) { return getter.getValue(object); } }; final SortableHeader header = new SortableHeader(text); allHeaders.add(header); // Hook up sorting. header.setUpdater(new ValueUpdater<String>() { public void update(String value) { header.setSorted(true); header.toggleReverseSort(); for (SortableHeader otherHeader : allHeaders) { if (otherHeader != header) { otherHeader.setSorted(false); otherHeader.setReverseSort(true); } } sortExpenses(items.getList(), header.getReverseSort() ? descComparator : ascComparator); table.redrawHeaders(); } }); table.addColumn(column, header); return column; }
From source file:com.google.gwt.sample.expenses.client.ExpenseList.java
License:Apache License
/** * Add a sortable column to the table.//w w w . ja va 2 s . co 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 * @return the column */ private <C> Column<ReportProxy, C> addColumn(final String text, final Cell<C> cell, final GetValue<ReportProxy, C> getter, final String property) { final Column<ReportProxy, C> column = new Column<ReportProxy, C>(cell) { @Override public C getValue(ReportProxy object) { return getter.getValue(object); } }; final SortableHeader header = new SortableHeader(text); allHeaders.add(header); // Sort created by default. if ("created".equals(property)) { header.setSorted(true); header.setReverseSort(true); orderBy = "created" + " DESC"; } header.setUpdater(new ValueUpdater<String>() { public void update(String value) { header.setSorted(true); header.toggleReverseSort(); for (SortableHeader otherHeader : allHeaders) { if (otherHeader != header) { otherHeader.setSorted(false); otherHeader.setReverseSort(true); } } table.redrawHeaders(); // Request sorted rows. orderBy = property; if (header.getReverseSort()) { orderBy += " DESC"; } searchBox.resetDefaultText(); searchRegExp = null; // Go to the first page of the newly-sorted results pager.firstPage(); requestReports(false); } }); table.addColumn(column, header); return column; }
From source file:com.google.gwt.sample.mobilewebapp.client.desktop.DesktopTaskListView.java
License:Apache License
/** * Construct a new {@link DesktopTaskListView}. *//* www . j a v a2s . c om*/ public DesktopTaskListView() { // Create the CellTable. taskList = new DataGrid<TaskProxy>(); taskList.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.DISABLED); taskList.setWidth("100%"); // Add the task name column. Column<TaskProxy, String> nameColumn = new TextColumn<TaskProxy>() { @Override public String getValue(TaskProxy object) { return (object == null) ? null : object.getName(); } }; taskList.addColumn(nameColumn, "Task"); // Add the task notes column. Column<TaskProxy, String> notesColumn = new TextColumn<TaskProxy>() { @Override public String getValue(TaskProxy object) { return (object == null) ? "" : object.getNotes(); } }; taskList.addColumn(notesColumn, "Description"); // Add the task due date column. Column<TaskProxy, Date> dateColumn = new Column<TaskProxy, Date>(new DateCell()) { @Override public Date getValue(TaskProxy object) { return (object == null) ? null : object.getDueDate(); } }; taskList.addColumn(dateColumn, "Due Date"); /* * Inform the presenter when the user selects a task from the task list. */ final NoSelectionModel<TaskProxy> selectionModel = new NoSelectionModel<TaskProxy>(); taskList.setSelectionModel(selectionModel); selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() { @Override public void onSelectionChange(SelectionChangeEvent event) { // Edit the task. if (presenter != null) { presenter.selectTask(selectionModel.getLastSelectedObject()); } } }); // Initialize the widget. initWidget(taskList); }
From source file:com.google.gwt.sample.showcase.client.content.cell.CwCellSampler.java
License:Apache License
/** * Add a column with a header./*from w ww .j ava 2s.com*/ * * @param <C> the cell type * @param cell the cell used to render the column * @param headerText the header string * @param getter the value getter for the cell */ @ShowcaseSource private <C> Column<ContactInfo, C> addColumn(Cell<C> cell, String headerText, final GetValue<C> getter, FieldUpdater<ContactInfo, C> fieldUpdater) { Column<ContactInfo, C> column = new Column<ContactInfo, C>(cell) { @Override public C getValue(ContactInfo object) { return getter.getValue(object); } }; column.setFieldUpdater(fieldUpdater); if (cell instanceof AbstractEditableCell<?, ?>) { editableCells.add((AbstractEditableCell<?, ?>) cell); } contactList.addColumn(column, headerText); return column; }
From source file:com.google.gwt.sample.showcase.client.content.cell.CwCellTable.java
License:Apache License
/** * Add the columns to the table.//from w ww. jav a 2s . com */ @ShowcaseSource private void initTableColumns(final SelectionModel<ContactInfo> selectionModel, ListHandler<ContactInfo> sortHandler) { // Checkbox column. 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, false)) { @Override public Boolean getValue(ContactInfo object) { // Get the value from the selection model. return selectionModel.isSelected(object); } }; cellTable.addColumn(checkColumn, SafeHtmlUtils.fromSafeConstant("<br/>")); cellTable.setColumnWidth(checkColumn, 40, Unit.PX); // First name. Column<ContactInfo, String> firstNameColumn = new Column<ContactInfo, String>(new EditTextCell()) { @Override public String getValue(ContactInfo object) { return object.getFirstName(); } }; firstNameColumn.setSortable(true); sortHandler.setComparator(firstNameColumn, new Comparator<ContactInfo>() { public int compare(ContactInfo o1, ContactInfo o2) { return o1.getFirstName().compareTo(o2.getFirstName()); } }); cellTable.addColumn(firstNameColumn, constants.cwCellTableColumnFirstName()); 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(); } }); cellTable.setColumnWidth(firstNameColumn, 20, Unit.PCT); // Last name. Column<ContactInfo, String> lastNameColumn = new Column<ContactInfo, String>(new EditTextCell()) { @Override public String getValue(ContactInfo object) { return object.getLastName(); } }; lastNameColumn.setSortable(true); sortHandler.setComparator(lastNameColumn, new Comparator<ContactInfo>() { public int compare(ContactInfo o1, ContactInfo o2) { return o1.getLastName().compareTo(o2.getLastName()); } }); cellTable.addColumn(lastNameColumn, constants.cwCellTableColumnLastName()); 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(); } }); cellTable.setColumnWidth(lastNameColumn, 20, Unit.PCT); // 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, constants.cwCellTableColumnCategory()); 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(); } }); cellTable.setColumnWidth(categoryColumn, 130, Unit.PX); // Address. Column<ContactInfo, String> addressColumn = new Column<ContactInfo, String>(new TextCell()) { @Override public String getValue(ContactInfo object) { return object.getAddress(); } }; addressColumn.setSortable(true); addressColumn.setDefaultSortAscending(false); sortHandler.setComparator(addressColumn, new Comparator<ContactInfo>() { public int compare(ContactInfo o1, ContactInfo o2) { return o1.getAddress().compareTo(o2.getAddress()); } }); cellTable.addColumn(addressColumn, constants.cwCellTableColumnAddress()); cellTable.setColumnWidth(addressColumn, 60, Unit.PCT); }
From source file:com.google.gwt.sample.showcase.client.content.cell.CwCellValidation.java
License:Apache License
/** * Initialize this example.//w ww. j av a 2s . c o m */ @ShowcaseSource @Override public Widget onInitialize() { // Create a table. final CellTable<ContactInfo> table = new CellTable<ContactInfo>(10, ContactInfo.KEY_PROVIDER); // Add the Name column. table.addColumn(new Column<ContactInfo, String>(new TextCell()) { @Override public String getValue(ContactInfo object) { return object.getFullName(); } }, constants.cwCellValidationColumnName()); // Add an editable address column. final ValidatableInputCell addressCell = new ValidatableInputCell(constants.cwCellValidationError()); Column<ContactInfo, String> addressColumn = new Column<ContactInfo, String>(addressCell) { @Override public String getValue(ContactInfo object) { return object.getAddress(); } }; table.addColumn(addressColumn, constants.cwCellValidationColumnAddress()); addressColumn.setFieldUpdater(new FieldUpdater<ContactInfo, String>() { public void update(int index, final ContactInfo object, final String value) { // Perform validation after 2 seconds to simulate network delay. new Timer() { @Override public void run() { if (isAddressValid(value)) { // The cell will clear the view data when it sees the updated // value. object.setAddress(value); // Push the change to the views. ContactDatabase.get().refreshDisplays(); } else { // Update the view data to mark the pending value as invalid. ValidationData viewData = addressCell .getViewData(ContactInfo.KEY_PROVIDER.getKey(object)); viewData.setInvalid(true); // We only modified the cell, so do a local redraw. table.redraw(); } } }.schedule(1000); } }); // Add the table to the database. ContactDatabase.get().addDataDisplay(table); return table; }
From source file:com.google.gwt.sample.showcase.client.content.cell.CwDataGrid.java
License:Apache License
/** * Add the columns to the table./* w w w .jav a 2 s .c o m*/ */ @ShowcaseSource private void initTableColumns(final SelectionModel<ContactInfo> selectionModel, ListHandler<ContactInfo> sortHandler) { // Checkbox column. This table will uses a checkbox column for selection. // Alternatively, you can call dataGrid.setSelectionEnabled(true) to enable // mouse selection. Column<ContactInfo, Boolean> checkColumn = new Column<ContactInfo, Boolean>(new CheckboxCell(true, false)) { @Override public Boolean getValue(ContactInfo object) { // Get the value from the selection model. return selectionModel.isSelected(object); } }; dataGrid.addColumn(checkColumn, SafeHtmlUtils.fromSafeConstant("<br/>")); dataGrid.setColumnWidth(checkColumn, 40, Unit.PX); // First name. Column<ContactInfo, String> firstNameColumn = new Column<ContactInfo, String>(new EditTextCell()) { @Override public String getValue(ContactInfo object) { return object.getFirstName(); } }; firstNameColumn.setSortable(true); sortHandler.setComparator(firstNameColumn, new Comparator<ContactInfo>() { public int compare(ContactInfo o1, ContactInfo o2) { return o1.getFirstName().compareTo(o2.getFirstName()); } }); dataGrid.addColumn(firstNameColumn, constants.cwDataGridColumnFirstName()); 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(); } }); dataGrid.setColumnWidth(firstNameColumn, 20, Unit.PCT); // Last name. Column<ContactInfo, String> lastNameColumn = new Column<ContactInfo, String>(new EditTextCell()) { @Override public String getValue(ContactInfo object) { return object.getLastName(); } }; lastNameColumn.setSortable(true); sortHandler.setComparator(lastNameColumn, new Comparator<ContactInfo>() { public int compare(ContactInfo o1, ContactInfo o2) { return o1.getLastName().compareTo(o2.getLastName()); } }); dataGrid.addColumn(lastNameColumn, constants.cwDataGridColumnLastName()); 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(); } }); dataGrid.setColumnWidth(lastNameColumn, 20, Unit.PCT); // Age. Column<ContactInfo, Number> ageColumn = new Column<ContactInfo, Number>(new NumberCell()) { @Override public Number getValue(ContactInfo object) { return object.getAge(); } }; lastNameColumn.setSortable(true); sortHandler.setComparator(ageColumn, new Comparator<ContactInfo>() { public int compare(ContactInfo o1, ContactInfo o2) { return o1.getBirthday().compareTo(o2.getBirthday()); } }); Header<String> ageFooter = new Header<String>(new TextCell()) { @Override public String getValue() { List<ContactInfo> items = dataGrid.getVisibleItems(); if (items.size() == 0) { return ""; } else { int totalAge = 0; for (ContactInfo item : items) { totalAge += item.getAge(); } return "Avg: " + totalAge / items.size(); } } }; dataGrid.addColumn(ageColumn, new SafeHtmlHeader(SafeHtmlUtils.fromSafeConstant(constants.cwDataGridColumnAge())), ageFooter); dataGrid.setColumnWidth(ageColumn, 7, Unit.EM); // 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(); } }; dataGrid.addColumn(categoryColumn, constants.cwDataGridColumnCategory()); 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(); } }); dataGrid.setColumnWidth(categoryColumn, 130, Unit.PX); // Address. Column<ContactInfo, String> addressColumn = new Column<ContactInfo, String>(new TextCell()) { @Override public String getValue(ContactInfo object) { return object.getAddress(); } }; addressColumn.setSortable(true); sortHandler.setComparator(addressColumn, new Comparator<ContactInfo>() { public int compare(ContactInfo o1, ContactInfo o2) { return o1.getAddress().compareTo(o2.getAddress()); } }); dataGrid.addColumn(addressColumn, constants.cwDataGridColumnAddress()); dataGrid.setColumnWidth(addressColumn, 60, Unit.PCT); }
From source file:com.gsr.myschool.back.client.web.application.affectation.AffectationView.java
License:Apache License
private void initDataGrid() { TextColumn<DossierProxy> refColumn = new TextColumn<DossierProxy>() { @Override/* w w w . j av a 2 s .c o m*/ public String getValue(DossierProxy object) { return object.getGeneratedNumDossier(); } }; refColumn.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER); preInscriptionsTable.addColumn(refColumn, "N Dossier"); preInscriptionsTable.setColumnWidth(refColumn, 10, Style.Unit.PCT); TextColumn<DossierProxy> nomColumn = new TextColumn<DossierProxy>() { @Override public String getValue(DossierProxy object) { if (object.getCandidat() == null) return ""; return object.getCandidat().getLastname() + " " + object.getCandidat().getFirstname(); } }; nomColumn.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER); preInscriptionsTable.addColumn(nomColumn, "Nom prnom"); preInscriptionsTable.setColumnWidth(nomColumn, 15, Style.Unit.PCT); TextColumn<DossierProxy> dateColumn = new TextColumn<DossierProxy>() { @Override public String getValue(DossierProxy object) { if (object.getCandidat().getBirthDate() == null) return ""; return dateFormat.format(object.getCandidat().getBirthDate()); } }; dateColumn.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER); preInscriptionsTable.addColumn(dateColumn, "Date de naissance"); preInscriptionsTable.setColumnWidth(dateColumn, 10, Style.Unit.PCT); TextColumn<DossierProxy> cFiliereColumn = new TextColumn<DossierProxy>() { @Override public String getValue(DossierProxy object) { if (object.getFiliere() == null) { return ""; } else { return object.getFiliere().getNom(); } } }; cFiliereColumn.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT); preInscriptionsTable.addColumn(cFiliereColumn, "Formation"); preInscriptionsTable.setColumnWidth(cFiliereColumn, 10, Style.Unit.PCT); TextColumn<DossierProxy> cLevelColumn = new TextColumn<DossierProxy>() { @Override public String getValue(DossierProxy object) { if (object.getNiveauEtude() == null) { return ""; } else { return object.getNiveauEtude().getNom(); } } }; cLevelColumn.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT); preInscriptionsTable.addColumn(cLevelColumn, "Niveau demand"); preInscriptionsTable.setColumnWidth(cLevelColumn, 15, Style.Unit.PCT); TextColumn<DossierProxy> statusColumn = new TextColumn<DossierProxy>() { @Override public String getValue(DossierProxy object) { if (object.getStatus() == null) return ""; return object.getStatus().toString(); } }; statusColumn.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT); preInscriptionsTable.addColumn(statusColumn, "Statut"); preInscriptionsTable.setColumnWidth(statusColumn, 10, Style.Unit.PCT); Delegate<DossierProxy> viewDetailsAction = new Delegate<DossierProxy>() { @Override public void execute(DossierProxy dossier) { getUiHandlers().viewDetails(dossier); } }; Delegate<DossierProxy> affectAction = new Delegate<DossierProxy>() { @Override public void execute(DossierProxy inscription) { getUiHandlers().affecter(inscription); } }; Delegate<DossierProxy> desaffectAction = new Delegate<DossierProxy>() { @Override public void execute(DossierProxy inscription) { getUiHandlers().desaffecter(inscription); } }; Delegate<DossierProxy> imprimer = new Delegate<DossierProxy>() { @Override public void execute(DossierProxy inscription) { getUiHandlers().imprimer(inscription); } }; AffectationActionCell actionsCell = actionCellFactory.create(viewDetailsAction, affectAction, desaffectAction, imprimer); Column<DossierProxy, DossierProxy> actionsColumn = new Column<DossierProxy, DossierProxy>(actionsCell) { @Override public DossierProxy getValue(DossierProxy object) { return object; } }; actionsColumn.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER); preInscriptionsTable.addColumn(actionsColumn, "Action"); preInscriptionsTable.setColumnWidth(actionsColumn, 10, Style.Unit.PCT); }