Friday, December 21, 2012

Re: CellTable Filtering on client-side Based On ListBox Selection

What's the problem or did I just miss it between the code? :)

Am Donnerstag, 20. Dezember 2012 17:09:12 UTC+1 schrieb VB:
I have a CellTable with 3 columns, and 1 ListBox that is supposed to provide a drop down of possible filter values.
i want to drive the filtering of the celltable rows, based from a selection in a ListBox (that contains all possible values) of one of the columns in the CellTable
I am using a ListDataProvider and just want to filter on the client side.

The ListBox is populated with String values...
                final ListBox supportCaseStatusListBox = new ListBox();
supportCaseStatusListBox.addItem("In Progress", "1");
supportCaseStatusListBox.addItem("Closed", "5");
                ..............

The statusColumn in CellTable is defined as:
TextColumn<SupportCaseDTO> statusColumn = new TextColumn<SupportCaseDTO>() {
@Override
public String getValue(SupportCaseDTO supportCase) {
return supportCase.getStatus();
}
};


----------

import java.util.ArrayList;
import java.util.List;

import org.dozer.DozerBeanMapper;

import com.google.common.collect.Lists;
import com.google.gwt.core.client.Scheduler;
import com.google.gwt.core.client.Scheduler.ScheduledCommand;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.cellview.client.CellTable;
import com.google.gwt.user.cellview.client.SimplePager;
import com.google.gwt.user.cellview.client.TextColumn;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.Panel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.view.client.ListDataProvider;

public class ViewSupportCasesPanel extends BasePanel{

static final String TITLE = "View Support Case";

private SupportCaseDTO supportCaseDTO = new SupportCaseDTO();
private final Button backButton = new RpButton("Back");
private final HorizontalPanel buttonPanel = new HorizontalPanel();
private final RegistrationBean registrationBean;

public ViewSupportCasesPanel(AppControl appControl,
RegistrationBean registrationBean) {
super(appControl);

this.registrationBean = registrationBean;

VerticalPanel mainVerticalPanel = new VerticalPanel();
initWidget(mainVerticalPanel);

final HTML header = new HTML(Messages.SUPPORT_CASE_VIEW_CASES_HEADER);
mainVerticalPanel.add(header);

final Label supportCaseStatusListLabel = new Label("Support Case Status:");
final ListBox supportCaseStatusListBox = new ListBox();
supportCaseStatusListBox.addItem("In Progress", "1");
supportCaseStatusListBox.addItem("Closed", "5");
supportCaseStatusListBox.addItem("Awaiting Customer Reply", "2");
supportCaseStatusListBox.addItem("RMA", "3");
supportCaseStatusListBox.addItem("Escalated to QA/Dev", "8");
supportCaseStatusListBox.addItem("Software Upgrade Needed", "6");
supportCaseStatusListBox.addItem("Product Replacement Needed", "7");
supportCaseStatusListBox.addItem("Awaiting Customer Confirmation", "4");
// create CellTable
final CellTable<SupportCaseDTO> cellTable = new CellTable<SupportCaseDTO>();

// Create case number column.
TextColumn<SupportCaseDTO> numberColumn = new TextColumn<SupportCaseDTO>() {
@Override
public String getValue(SupportCaseDTO supportCase) {
return supportCase.getCaseNumber();
}
};

// Make the name column sortable.
numberColumn.setSortable(false);

// Create subject column.
TextColumn<SupportCaseDTO> subjectColumn = new TextColumn<SupportCaseDTO>() {
@Override
public String getValue(SupportCaseDTO supportCase) {
return supportCase.getTitle();
}
};

// Create status column.
TextColumn<SupportCaseDTO> statusColumn = new TextColumn<SupportCaseDTO>() {
@Override
public String getValue(SupportCaseDTO supportCase) {
return supportCase.getStatus();
}
};
/* // Create product column.
TextColumn<SupportCaseDTO> productColumn = new TextColumn<SupportCaseDTO>() {
@Override
public String getValue(SupportCaseDTO supportCase) {
return supportCase.getProduct();
}
};*/

// Add the columns.
cellTable.addColumn(numberColumn, "Case #");
cellTable.addColumn(subjectColumn, "Subject");
cellTable.addColumn(statusColumn, "Status");
// cellTable.addColumn(productColumn, "Product");

cellTable.setWidth("100%", true);
cellTable.setColumnWidth(numberColumn, 10, Unit.PCT);
cellTable.setColumnWidth(subjectColumn, 60, Unit.PCT);
cellTable.setColumnWidth(statusColumn, 15, Unit.PCT);
// cellTable.setColumnWidth(productColumn, 15, Unit.PCT);
// Create a data provider.
ListDataProvider<SupportCaseDTO> listDataProvider = new ListDataProvider<SupportCaseDTO>();

// Connect the table to the data provider.
listDataProvider.addDataDisplay(cellTable);

DrSimplePager pager = new DrSimplePager();
pager.setDisplay(cellTable);
pager.setPageSize(20);

// Add the data to the data provider, which automatically pushes it to
// the widget
final List<SupportCaseDTO> listSupportCaseDTO = listDataProvider
.getList();

BusyDialog.show(Messages.PLEASE_WAIT);
MainService.Util.getInstance().getContactSupportCases(
ViewSupportCasesPanel.this.registrationBean,
new DefaultCallback<List<SupportCaseDTO>>() {
@Override
public void onFailure(Throwable ex) {
BusyDialog.hide();
super.onFailure(ex);
}

@Override
public void onSuccess(
final List<SupportCaseDTO> result) {
BusyDialog.hide();

for (SupportCaseDTO supportCase : result) {
listSupportCaseDTO.add(supportCase);
}

super.onSuccess(result);
}
});

mainVerticalPanel.add(UIHelpers.createBreak());
mainVerticalPanel.add(supportCaseStatusListLabel);
mainVerticalPanel.add(supportCaseStatusListBox);
mainVerticalPanel.add(UIHelpers.createBreak());
mainVerticalPanel.add(cellTable);
mainVerticalPanel.add(pager);

mainVerticalPanel.add(createButtonPanel());
mainVerticalPanel.setCellHorizontalAlignment(buttonPanel,
HasHorizontalAlignment.ALIGN_CENTER);

}

Panel createButtonPanel() {
buttonPanel.setSpacing(10);
buttonPanel.add(backButton);

backButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
appControl.onSupportRegister(registrationBean);
}

});

return buttonPanel;
}
   
}

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-web-toolkit/-/kn2DmWlw43QJ.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

No comments:

Post a Comment