List of usage examples for com.google.gwt.user.cellview.client Column setFieldUpdater
public void setFieldUpdater(FieldUpdater<T, C> fieldUpdater)
From source file:com.phideltcmu.recruiter.client.ui.table.RecruitTable.java
License:Creative Commons License
private void defineColumns() { ButtonCell buttonCell = new ButtonCell() { @Override/*from w ww . jav a 2s . c o m*/ public boolean handlesSelection() { return false; } }; Column<Person, String> detailsButton = new Column<Person, String>(buttonCell) { @Override public String getValue(Person person) { return "View"; } }; detailsButton.setFieldUpdater(new FieldUpdater<Person, String>() { @Override public void update(int i, Person person, String s) { new PersonDetails(person).display(); } }); extraColumns.add(new ExtraColumn("Details", detailsButton)); if (DynamicRecruiter.authUser.isAdmin()) { Column<Person, String> deletePersonButton = new Column<Person, String>(buttonCell) { @Override public String getValue(Person person) { return "Delete"; } }; deletePersonButton.setFieldUpdater(new FieldUpdater<Person, String>() { @Override public void update(int i, Person person, String s) { DynamicRecruiter.RECRUIT_SERVICE.removeUser(person.getAndrewID(), DynamicRecruiter.authUser.getAuthToken(), new RemoveUserHandler()); } }); extraColumns.add(new ExtraColumn("Options", deletePersonButton)); } }
From source file:com.phideltcmu.recruiter.client.ui.table.RecruitTable.java
License:Creative Commons License
public RecruitTable() { super();//ww w . ja v a 2s.c o m DynamicRecruiter.GLOBAL_EVENT_BUS.addHandler(RecruitTableFetchedEvent.TYPE, this); // EditTextCell. EditTextCell editTextCell = new EditTextCell(); Column<Person, String> phoneNumberColumn = new Column<Person, String>(editTextCell) { @Override public String getValue(Person person) { String phoneNumber = person.getPhoneNumber(); return phoneNumber.length() == 0 ? "N/A" : phoneNumber; } }; phoneNumberColumn.setFieldUpdater(new FieldUpdater<Person, String>() { @Override public void update(int i, final Person person, String s) { String number = s.replaceAll("\\D+", ""); if (number.length() == 10 || number.length() == 0) { DynamicRecruiter.RECRUIT_SERVICE.setPhoneNumber(person.getAndrewID(), number, DynamicRecruiter.authUser.getAuthToken(), new AsyncCallback<String>() { @Override public void onFailure(Throwable throwable) { throwable.printStackTrace(); } @Override public void onSuccess(String formattedNumber) { person.setPhoneNumber(formattedNumber); } }); } else { Window.alert("That's an invalid number"); } } }); extraColumns.add(new ExtraColumn("Phone Number", phoneNumberColumn)); }
From source file:com.phideltcmu.recruiter.client.ui.table.RecruitTable.java
License:Creative Commons License
public void render(List<Category> categories) { final List<String> categoryNames = new ArrayList<String>(); for (Category category : categories) { categoryNames.add(category.getValue()); }// w w w .ja v a2 s. c o m if (DynamicRecruiter.authUser.isAdmin()) { SelectionCell categoryCell = new SelectionCell(categoryNames); Column<Person, String> categoryColumn = new Column<Person, String>(categoryCell) { @Override public String getValue(Person object) { return categoryNames.get(categoryNames.indexOf(object.getStatus())); } }; categoryColumn.setFieldUpdater(new FieldUpdater<Person, String>() { @Override public void update(int index, Person object, String value) { object.setStatus(value); DynamicRecruiter.RECRUIT_SERVICE.changeCategory(object.getAndrewID(), value, DynamicRecruiter.authUser.getAuthToken(), new AsyncCallback<Void>() { @Override public void onFailure(Throwable throwable) { throwable.printStackTrace(); } @Override public void onSuccess(Void aVoid) { // Window.alert("Status Updated!"); } }); } }); extraColumns.add(new ExtraColumn("Status", categoryColumn)); } else { TextColumn<Person> statusColumn = new TextColumn<Person>() { @Override public String getValue(Person person) { return person.getStatus(); } }; extraColumns.add(new ExtraColumn("Status", statusColumn)); } defineColumns(); this.initColumns(extraColumns); }
From source file:com.phideltcmu.recruiter.client.ui.table.SearchMatchTable.java
License:Creative Commons License
public SearchMatchTable(final Label statusLabel) { ButtonCell buttonCell = new ButtonCell() { @Override//from w w w. j a v a 2 s . com public boolean handlesSelection() { return false; } }; Column<Person, String> addButtonColumn = new Column<Person, String>(buttonCell) { @Override public String getValue(Person person) { return person.getInTable() == true ? "Add Referral" : "Add to list"; } }; addButtonColumn.setFieldUpdater(new FieldUpdater<Person, String>() { @Override public void update(int i, Person person, String s) { statusLabel.setText("Adding " + person.getFullName() + "..."); DynamicRecruiter.RECRUIT_SERVICE.addPerson(person, DynamicRecruiter.authUser, new AddUserHandler(statusLabel)); } }); List<ExtraColumn> extraCols = new ArrayList<ExtraColumn>(); extraCols.add(new ExtraColumn("", addButtonColumn)); this.initColumns(extraCols); }
From source file:com.pronoiahealth.olhie.client.pages.admin.widgets.AuthorRequestWidget.java
License:Open Source License
/** * Build grid/*from w w w. j a v a 2s. c o m*/ */ @PostConstruct protected void postConstruct() { // Data Provider dataProvider = new ListDataProvider<RegistrationForm>(); // Grid configuration authorReqGrid = new CellTable<RegistrationForm>(10, KEY_PROVIDER); authorReqGrid.setWidth("100%"); authorReqGrid.setAutoHeaderRefreshDisabled(true); authorReqGrid.setAutoFooterRefreshDisabled(true); authorReqGrid.setEmptyTableWidget(new Label("Nothing to show")); authorReqGrid.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED); authorReqGrid.setWidth("100%", true); // Selection Model final SelectionModel<RegistrationForm> selectionModel = new SingleSelectionModel<RegistrationForm>( KEY_PROVIDER); authorReqGrid.setSelectionModel(selectionModel, DefaultSelectionEventManager.<RegistrationForm>createCheckboxManager()); // Init columns // Id TextColumn<RegistrationForm> idColumn = new TextColumn<RegistrationForm>() { @Override public String getValue(RegistrationForm object) { return object.getId(); } }; idColumn.setCellStyleNames("ph-Admin-tbl-cell-text-align-left"); authorReqGrid.addColumn(idColumn, "ID"); authorReqGrid.setColumnWidth(idColumn, 5, Unit.PCT); // First Name TextColumn<RegistrationForm> firstColumn = new TextColumn<RegistrationForm>() { @Override public String getValue(RegistrationForm object) { return object.getFirstName(); } }; firstColumn.setCellStyleNames("ph-Admin-tbl-cell-text-align-left"); authorReqGrid.addColumn(firstColumn, "First"); authorReqGrid.setColumnWidth(firstColumn, 7, Unit.PCT); // Last Name TextColumn<RegistrationForm> lastColumn = new TextColumn<RegistrationForm>() { @Override public String getValue(RegistrationForm object) { return object.getLastName(); } }; lastColumn.setCellStyleNames("ph-Admin-tbl-cell-text-align-left"); authorReqGrid.addColumn(lastColumn, "Last"); authorReqGrid.setColumnWidth(lastColumn, 12, Unit.PCT); // userId TextColumn<RegistrationForm> userIdColumn = new TextColumn<RegistrationForm>() { @Override public String getValue(RegistrationForm object) { return object.getUserId(); } }; userIdColumn.setCellStyleNames("ph-Admin-tbl-cell-text-align-left"); authorReqGrid.addColumn(userIdColumn, "UserId"); authorReqGrid.setColumnWidth(userIdColumn, 10, Unit.PCT); // eMail TextColumn<RegistrationForm> eMailColumn = new TextColumn<RegistrationForm>() { @Override public String getValue(RegistrationForm object) { return object.getEmail(); } }; eMailColumn.setCellStyleNames("ph-Admin-tbl-cell-text-align-left"); authorReqGrid.addColumn(eMailColumn, "eMail"); authorReqGrid.setColumnWidth(eMailColumn, 15, Unit.PCT); // Registration Date DateCell dateCell = new DateCell(); Column<RegistrationForm, Date> dateColumn = new Column<RegistrationForm, Date>(dateCell) { @Override public Date getValue(RegistrationForm object) { return object.getRegDate(); } }; dateColumn.setCellStyleNames("ph-Admin-tbl-cell-text-align-left"); authorReqGrid.addColumn(dateColumn, "Reg Date"); authorReqGrid.setColumnWidth(dateColumn, 17, Unit.PCT); // Organization TextColumn<RegistrationForm> orgColumn = new TextColumn<RegistrationForm>() { @Override public String getValue(RegistrationForm object) { return object.getOrganization(); } }; orgColumn.setCellStyleNames("ph-Admin-tbl-cell-text-align-left"); authorReqGrid.addColumn(orgColumn, "Organization"); authorReqGrid.setColumnWidth(orgColumn, 15, Unit.PCT); // Status List<String> statusNames = Arrays.asList(authStatus); SelectionCell statusCell = new SelectionCell(statusNames); Column<RegistrationForm, String> statusColumn = new Column<RegistrationForm, String>(statusCell) { @Override public String getValue(RegistrationForm object) { return object.getAuthorStatus(); } }; statusColumn.setCellStyleNames("ph-Admin-tbl-cell-text-align-left"); authorReqGrid.addColumn(statusColumn, "Status"); // Status column updated statusColumn.setFieldUpdater(new FieldUpdater<RegistrationForm, String>() { @Override public void update(int index, RegistrationForm object, String value) { object.setAuthorStatus(value); dataProvider.refresh(); // Tell the AdminService about the change authorRequestStatusChangeEvent.fire(new AuthorRequestStatusChangeEvent(object.getId(), value)); } }); authorReqGrid.setColumnWidth(statusColumn, 19, Unit.PCT); // Set the dataprovider dataProvider.addDataDisplay(authorReqGrid); // Pager SimplePager.Resources pagerResources = GWT.create(SimplePager.Resources.class); pager = new SimplePager(TextLocation.CENTER, pagerResources, false, 0, true); pager.setDisplay(authorReqGrid); pager.setPageSize(10); pager.getElement().setAttribute("style", "margin: auto;"); // Redraw the grid authorReqGrid.redraw(); authorReqGrid.setVisible(true); // Add to container authorRequestTbl.add(authorReqGrid); pagerContainer.add(pager); }
From source file:com.pronoiahealth.olhie.client.pages.admin.widgets.NewsItemWidget.java
License:Open Source License
/** * Build grid/* w ww . jav a 2 s.c om*/ */ @PostConstruct protected void postConstruct() { // Data Provider dataProvider = new ListDataProvider<NewsItem>(); // Grid configuration newsItemGrid = new CellTable<NewsItem>(10, KEY_PROVIDER); newsItemGrid.setWidth("100%"); newsItemGrid.setAutoHeaderRefreshDisabled(true); newsItemGrid.setAutoFooterRefreshDisabled(true); newsItemGrid.setEmptyTableWidget(new Label("Nothing to show")); newsItemGrid.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED); newsItemGrid.setWidth("100%", true); // Selection Model final SelectionModel<NewsItem> selectionModel = new SingleSelectionModel<NewsItem>(KEY_PROVIDER); newsItemGrid.setSelectionModel(selectionModel, DefaultSelectionEventManager.<NewsItem>createCheckboxManager()); // Init columns // Id TextColumn<NewsItem> idColumn = new TextColumn<NewsItem>() { @Override public String getValue(NewsItem object) { return object.getId(); } }; idColumn.setCellStyleNames("ph-Admin-tbl-cell-text-align-left"); newsItemGrid.addColumn(idColumn, "ID"); newsItemGrid.setColumnWidth(idColumn, 5, Unit.PCT); // Author id TextColumn<NewsItem> authorColumn = new TextColumn<NewsItem>() { @Override public String getValue(NewsItem object) { return object.getAuthorId(); } }; authorColumn.setCellStyleNames("ph-Admin-tbl-cell-text-align-left"); newsItemGrid.addColumn(authorColumn, "Author"); newsItemGrid.setColumnWidth(authorColumn, 10, Unit.PCT); // href TextColumn<NewsItem> hrefColumn = new TextColumn<NewsItem>() { @Override public String getValue(NewsItem object) { return object.getHref(); } }; hrefColumn.setCellStyleNames("ph-Admin-tbl-cell-text-align-left"); newsItemGrid.addColumn(hrefColumn, "Link"); newsItemGrid.setColumnWidth(hrefColumn, 25, Unit.PCT); // Story TextColumn<NewsItem> storyColumn = new TextColumn<NewsItem>() { @Override public String getValue(NewsItem object) { return object.getStory(); } }; storyColumn.setCellStyleNames("ph-Admin-tbl-cell-text-align-left"); newsItemGrid.addColumn(storyColumn, "Story"); newsItemGrid.setColumnWidth(storyColumn, 35, Unit.PCT); // Active List<String> activeNames = Arrays.asList(reset); SelectionCell activeCell = new SelectionCell(activeNames); Column<NewsItem, String> activeColumn = new Column<NewsItem, String>(activeCell) { @Override public String getValue(NewsItem object) { boolean val = object.getActive(); if (val == true) { return "YES"; } else { return "NO"; } } }; activeColumn.setCellStyleNames("ph-Admin-tbl-cell-text-align-left"); newsItemGrid.addColumn(activeColumn, "Active"); // active column updated activeColumn.setFieldUpdater(new FieldUpdater<NewsItem, String>() { @Override public void update(int index, NewsItem object, String value) { boolean retVal = false; if (value.equals("YES")) { retVal = true; object.setActive(true); } else { object.setActive(false); } dataProvider.refresh(); // Tell the AdminService about the change updateNewsItemActiveRequestEvent.fire(new UpdateNewsItemActiveRequestEvent(object.getId(), retVal)); } }); newsItemGrid.setColumnWidth(activeColumn, 18, Unit.PCT); // Delete button Column<NewsItem, String> deleteBtn = new Column<NewsItem, String>(new ButtonCell()) { @Override public String getValue(NewsItem c) { return "x"; } }; newsItemGrid.setColumnWidth(deleteBtn, 5, Unit.PCT); newsItemGrid.addColumn(deleteBtn, ""); // Set the field updater, whenever user clicks on button // row will be removed. deleteBtn.setFieldUpdater(new FieldUpdater<NewsItem, String>() { @Override public void update(int index, NewsItem object, String value) { // Tell the database removeNewsItemRequestEvent.fire(new RemoveNewsItemRequestEvent(object.getId())); // Remove from the data provider and redraw the table dataProvider.getList().remove(object); dataProvider.refresh(); newsItemGrid.redraw(); } }); // Set the dataprovider dataProvider.addDataDisplay(newsItemGrid); // Pager SimplePager.Resources pagerResources = GWT.create(SimplePager.Resources.class); pager = new SimplePager(TextLocation.CENTER, pagerResources, false, 0, true); pager.setDisplay(newsItemGrid); pager.setPageSize(10); pager.getElement().setAttribute("style", "margin: auto;"); // Redraw the grid newsItemGrid.redraw(); newsItemGrid.setVisible(true); // Add to container newsItemTbl.add(newsItemGrid); pagerContainer.add(pager); }
From source file:com.pronoiahealth.olhie.client.pages.admin.widgets.UserManagementWidget.java
License:Open Source License
/** * Build grid/*w w w . ja v a 2s. co m*/ */ @PostConstruct protected void postConstruct() { // Query lable queryLbl.setText("Last Name: "); // Data Provider dataProvider = new ListDataProvider<User>(); // Grid configuration userMgmtGrid = new CellTable<User>(10, KEY_PROVIDER); userMgmtGrid.setWidth("100%"); userMgmtGrid.setAutoHeaderRefreshDisabled(true); userMgmtGrid.setAutoFooterRefreshDisabled(true); userMgmtGrid.setEmptyTableWidget(new Label("Nothing to show")); userMgmtGrid.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED); userMgmtGrid.setWidth("100%", true); // Selection Model // final SelectionModel<User> selectionModel = new // SingleSelectionModel<User>( // KEY_PROVIDER); // userMgmtGrid.setSelectionModel(selectionModel, // DefaultSelectionEventManager.<User> createCheckboxManager()); // Init columns // Id TextColumn<User> idColumn = new TextColumn<User>() { @Override public String getValue(User object) { return object.getId(); } }; idColumn.setCellStyleNames("ph-Admin-tbl-cell-text-align-left"); userMgmtGrid.addColumn(idColumn, "ID"); userMgmtGrid.setColumnWidth(idColumn, 5, Unit.PCT); // First Name TextColumn<User> firstColumn = new TextColumn<User>() { @Override public String getValue(User object) { return object.getFirstName(); } }; firstColumn.setCellStyleNames("ph-Admin-tbl-cell-text-align-left"); userMgmtGrid.addColumn(firstColumn, "First"); userMgmtGrid.setColumnWidth(firstColumn, 7, Unit.PCT); // Last Name TextColumn<User> lastColumn = new TextColumn<User>() { @Override public String getValue(User object) { return object.getLastName(); } }; lastColumn.setCellStyleNames("ph-Admin-tbl-cell-text-align-left"); userMgmtGrid.addColumn(lastColumn, "Last"); userMgmtGrid.setColumnWidth(lastColumn, 12, Unit.PCT); // userId TextColumn<User> userIdColumn = new TextColumn<User>() { @Override public String getValue(User object) { return object.getUserId(); } }; userIdColumn.setCellStyleNames("ph-Admin-tbl-cell-text-align-left"); userMgmtGrid.addColumn(userIdColumn, "UserId"); userMgmtGrid.setColumnWidth(userIdColumn, 10, Unit.PCT); // eMail final EditTextCell eMailEditCell = new EditTextCell(); final Column<User, String> eMailColumn = new Column<User, String>(eMailEditCell) { @Override public String getValue(User object) { return object.getEmail(); } }; eMailColumn.setCellStyleNames("ph-Admin-tbl-cell-text-align-left"); userMgmtGrid.addColumn(eMailColumn, "eMail"); eMailColumn.setFieldUpdater(new FieldUpdater<User, String>() { @Override public void update(int index, User object, String value) { // Validate if (Utils.isValidEmail(value) && value != null && value.length() > 0) { // Set data object.setEmail(value); dataProvider.refresh(); // Tell the database userEmailChangeRequestEvent.fire(new UserEmailChangeRequestEvent(value, object.getUserId())); // Reset style eMailColumn.setCellStyleNames("ph-Admin-tbl-cell-text-align-left"); } else { eMailEditCell.clearViewData(KEY_PROVIDER.getKey(object)); clientErrorEvent.fire(new ClientErrorEvent(value + " is not a valid email address.")); userMgmtGrid.redraw(); } } }); userMgmtGrid.setColumnWidth(eMailColumn, 15, Unit.PCT); // Organization final EditTextCell orgCell = new EditTextCell(); Column<User, String> orgColumn = new Column<User, String>(orgCell) { @Override public String getValue(User object) { return object.getOrganization(); } }; orgColumn.setCellStyleNames("ph-Admin-tbl-cell-text-align-left"); userMgmtGrid.addColumn(orgColumn, "Organization"); orgColumn.setFieldUpdater(new FieldUpdater<User, String>() { @Override public void update(int index, User object, String value) { object.setOrganization(value); dataProvider.refresh(); // Tell the database userOrganizationChangeRequestEvent .fire(new UserOrganizationChangeRequestEvent(value, object.getUserId())); } }); userMgmtGrid.setColumnWidth(orgColumn, 15, Unit.PCT); // Role List<String> roleNames = Arrays.asList(roles); SelectionCell roleCell = new SelectionCell(roleNames); Column<User, String> roleColumn = new Column<User, String>(roleCell) { @Override public String getValue(User object) { return object.getRole(); } }; roleColumn.setCellStyleNames("ph-Admin-tbl-cell-text-align-left"); userMgmtGrid.addColumn(roleColumn, "Role"); // role column updated roleColumn.setFieldUpdater(new FieldUpdater<User, String>() { @Override public void update(int index, User object, String value) { object.setRole(value); dataProvider.refresh(); // Tell the AdminService about the change userChangeRoleEvent.fire(new UserChangeRoleEvent(object.getUserId(), value)); } }); userMgmtGrid.setColumnWidth(roleColumn, 18, Unit.PCT); // Reset password List<String> resetNames = Arrays.asList(reset); SelectionCell resetCell = new SelectionCell(resetNames); Column<User, String> resetColumn = new Column<User, String>(resetCell) { @Override public String getValue(User object) { boolean val = object.isResetPwd(); if (val == true) { return "YES"; } else { return "NO"; } } }; resetColumn.setCellStyleNames("ph-Admin-tbl-cell-text-align-left"); userMgmtGrid.addColumn(resetColumn, "Reset PW"); // role column updated resetColumn.setFieldUpdater(new FieldUpdater<User, String>() { @Override public void update(int index, User object, String value) { boolean retVal = false; if (value.equals("YES")) { retVal = true; object.setResetPwd(true); } else { object.setResetPwd(false); } dataProvider.refresh(); // Tell the AdminService about the change userResetPWEvent.fire(new UserResetPWEvent(object.getUserId(), retVal)); } }); userMgmtGrid.setColumnWidth(resetColumn, 18, Unit.PCT); // Set the dataprovider dataProvider.addDataDisplay(userMgmtGrid); // Pager SimplePager.Resources pagerResources = GWT.create(SimplePager.Resources.class); pager = new SimplePager(TextLocation.CENTER, pagerResources, false, 0, true); pager.setDisplay(userMgmtGrid); pager.setPageSize(5); pager.getElement().setAttribute("style", "margin: auto;"); // Redraw the grid userMgmtGrid.redraw(); userMgmtGrid.setVisible(true); // Add to container userMgmtTbl.add(userMgmtGrid); pagerContainer.add(pager); }
From source file:com.sensia.tools.client.swetools.editors.sensorml.panels.widgets.swe.dataarray.GenericTable.java
License:Open Source License
/** * Populates the table./* ww w . j a v a2 s. c o m*/ * * @param headers the headers to display * @param values the values to set */ public void poupulateTable(final List<String> headers, final Object[][] values) { //clears/creates the list init(); this.originalData = getPropertiesFromValues(values); if (table == null) { //creates the table object createTable(); } else { //remove every columns int nbColumn = table.getColumnCount(); for (int i = 0; i < nbColumn; i++) { table.removeColumn(i); } } int position = 0; //add every column based on header list for (final String colName : headers) { final int currentPosition = position; final Column<Property, String> column = new Column<Property, String>(new TextCell()) { @Override public String getValue(Property object) { return object.properties.get(currentPosition); } }; column.setSortable(false); SafeHtmlHeader colHeader = new SafeHtmlHeader(new SafeHtml() { @Override public String asString() { return "<p style=\"text-align:center;\">" + colName + "</p>"; } }); colHeader.setHeaderStyleNames("data-table-header"); table.addColumn(column, colHeader); position++; } //add extra column if editable if (isEditable) { SafeHtmlHeader removeRowLabelHeader = getRemoveRowLabelHeader(); final Column<Property, String> removeColumn = new Column<Property, String>(new ButtonCell()) { @Override public String getValue(Property c) { return "x"; } }; removeColumn.setSortable(false); //updates when the user remove a row removeColumn.setFieldUpdater(new FieldUpdater<Property, String>() { @Override public void update(int index, Property object, String value) { List<Property> newOriginalData = new ArrayList<Property>(); for (int i = 0; i < originalData.size(); i++) { if (i != index) { newOriginalData.add(originalData.get(i)); } } originalData = newOriginalData; table.setRowCount(originalData.size()); table.setRowData(originalData); dataProvider.setList(originalData); dataProvider.refresh(); deselect(); } }); table.addColumn(removeColumn, removeRowLabelHeader); } table.setRowCount(originalData.size()); table.setRowData(originalData); dataProvider.setList(originalData); dataProvider.refresh(); }
From source file:com.spshop.admin.client.sample.CwCellTable.java
License:Apache License
/** * Add the columns to the table.//www . ja v a2 s . c o m */ 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); 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.stoyanr.todo.client.view.ItemsViewImpl.java
License:Open Source License
private Column<T, String> createTextColumn() { Column<T, String> col = new Column<T, String>(new EditTextCell()) { @Override/*from w w w . j av a 2 s. c om*/ public String getValue(T t) { return presenter.getText(t); } }; col.setFieldUpdater(new FieldUpdater<T, String>() { @Override public void update(int index, T t, String value) { presenter.updateText(t, value); dataProvider.refresh(); } }); return col; }