live filtering
i have done the live filtering....
its working correctly
the way i did it by converting the list grid into datasource and applied the filter
but the problem is ..datasource is not supporting the editable columns
we need to save consent by tick/untick but it is locked ..as datasource doent have any editable column methods as the list grid..
:(
package com.gsihealth.dashboard.client.consent.healthhomeorganization;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.gsihealth.dashboard.client.DashBoardApp;
import com.gsihealth.dashboard.client.common.ProgressBarWindow;
import com.gsihealth.dashboard.client.common.RetryActionCallback;
import com.gsihealth.dashboard.client.service.OrganizationPatientConsentService;
import com.gsihealth.dashboard.client.service.OrganizationPatientConsentServiceAsync;
import com.gsihealth.dashboard.client.util.ApplicationContextUtils;
import com.gsihealth.dashboard.client.util.StringUtils;
import com.gsihealth.dashboard.common.ConsentConstants;
import com.gsihealth.dashboard.common.dto.PersonDTO;
import com.gsihealth.dashboard.entity.dto.OrganizationPatientConsentDTO;
import com.smartgwt.client.data.DataSource;
import com.smartgwt.client.data.fields.DataSourceBooleanField;
import com.smartgwt.client.data.fields.DataSourceTextField;
import com.smartgwt.client.types.Alignment;
import com.smartgwt.client.types.FetchMode;
import com.smartgwt.client.types.ListGridEditEvent;
import com.smartgwt.client.types.ListGridFieldType;
import com.smartgwt.client.types.SelectionStyle;
import com.smartgwt.client.util.SC;
import com.smartgwt.client.widgets.Button;
import com.smartgwt.client.widgets.events.ClickEvent;
import com.smartgwt.client.widgets.events.ClickHandler;
import com.smartgwt.client.widgets.grid.ListGrid;
import com.smartgwt.client.widgets.grid.ListGridField;
import com.smartgwt.client.widgets.grid.ListGridRecord;
import com.smartgwt.client.widgets.layout.HLayout;
import com.smartgwt.client.widgets.layout.Layout;
import com.smartgwt.client.widgets.layout.LayoutSpacer;
import com.smartgwt.client.widgets.layout.VLayout;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author Chad Darby
*/
public class OrganizationPatientConsentPanel extends VLayout {
private PersonDTO personDTO;
private OrganizationPatientConsentServiceAsync organizationPatientConsentService = GWT.create(OrganizationPatientConsentService.class);
private Button saveButton;
private ListGrid listGrid;
private static final int CONSENT_COLUMN = 3;
private ProgressBarWindow progressBarWindow;
public OrganizationPatientConsentPanel(PersonDTO thePersonDTO) {
personDTO = thePersonDTO;
buildGui();
DashBoardApp.restartTimer();
loadOrganizationPatientConsentData();
}
private void buildGui() {
setMargin(5);
listGrid = buildListGrid();
setPadding(5);
addMember(listGrid);
// layout spacer b/w layout lables and layout of remover button
LayoutSpacer topSpacer = new LayoutSpacer();
topSpacer.setHeight(20);
addMember(topSpacer);
// layout for remove button
Layout buttonBar = buildButtonBar();
addMember(buttonBar);
progressBarWindow = new ProgressBarWindow("Saving", "Saving...");
}
/** Helper method to build a ListGrid
*
* @return
*/
private ListGrid buildListGrid() {
String[] columnNames = {OrganizationConsentConstants.ORGANIZATION_NAME, OrganizationConsentConstants.CITY, OrganizationConsentConstants.STATE, OrganizationConsentConstants.PERMIT_CONSENT};
ListGrid theListGrid = new ListGrid();
theListGrid.setCanReorderFields(true);
theListGrid.setCanReorderRecords(true);
theListGrid.setWidth100();
theListGrid.setHeight100();
theListGrid.setAlternateRecordStyles(true);
theListGrid.setShowAllRecords(false);
theListGrid.setSelectionType(SelectionStyle.SINGLE);
theListGrid.setCanEdit(true);
theListGrid.setDataFetchMode(FetchMode.LOCAL);
theListGrid.setCanEdit(false);
theListGrid.setAutoFetchData(true);
theListGrid.setShowFilterEditor(true);
theListGrid.setFilterByCell(true);
theListGrid.setFilterOnKeypress(true);
theListGrid.setEditEvent(ListGridEditEvent.CLICK);
theListGrid.setEditByCell(true);
// add fields
ListGridField[] fields = buildListGridFields(columnNames);
theListGrid.setFields(fields);
theListGrid.setEmptyMessage("...");
theListGrid.setCanResizeFields(true);
return theListGrid;
}
private ListGridField[] buildListGridFields(String[] columnNames) {
ListGridField[] fields = new ListGridField[columnNames.length];
for (int i = 0; i < columnNames.length; i++) {
String tempColumnName = columnNames[i];
ListGridField tempField = buildListGridField(tempColumnName);
fields[i] = tempField;
if (i == CONSENT_COLUMN) {
fields[i].setCanEdit(true);
fields[i].setType(ListGridFieldType.BOOLEAN);
}
}
return fields;
}
private ListGridField buildListGridField(String title) {
ListGridField tempField = new ListGridField(title, title);
tempField.setCanEdit(false);
return tempField;
}
private Layout buildButtonBar() {
// layout for button bar
HLayout buttonLayout = new HLayout(10);
buttonLayout.setWidth100();
buttonLayout.setAlign(Alignment.CENTER);
// remove button
saveButton = new Button("Save Consent");
saveButton.setID("SaveConsent");
saveButton.setWidth(140);
saveButton.addClickHandler(new SaveClickHandler());
buttonLayout.addMember(saveButton);
return buttonLayout;
}
private void loadOrganizationPatientConsentData() {
LoadOrganizationPatientConsentDataCallback loadOrganizationPatientConsentDataCallback = new LoadOrganizationPatientConsentDataCallback();
loadOrganizationPatientConsentDataCallback.attempt();
}
public void populateListGrid(ListGridRecord[] data) {
ListGridRecord[] records = listGrid.getRecords();
// scroll to first row
listGrid.scrollToRow(1);
final DataSource dataSource = new DataSource();
dataSource.setID("dataSource");
dataSource.setClientOnly(true);
DataSourceTextField name = new DataSourceTextField("Organization Name", "Organization Name");
DataSourceTextField city = new DataSourceTextField("City", "City");
DataSourceTextField state = new DataSourceTextField("State", "State");
DataSourceBooleanField Permit = new DataSourceBooleanField("Permit Consent", "Permit Consent");
dataSource.setFields(name, city, state, Permit);
dataSource.setCacheData(data);
listGrid.setDataSource(dataSource);
listGrid.setData(data);
listGrid.markForRedraw();
}
class LoadOrganizationPatientConsentDataCallback extends RetryActionCallback<List<OrganizationPatientConsentDTO>> {
@Override
public void attempt() {
long patientId = personDTO.getPatientEnrollment().getPatientId();
long communityId= ApplicationContextUtils.getLoginResult().getCommunityId();
organizationPatientConsentService.getOrganizationPatientConsentList(patientId,communityId, this);
}
@Override
public void onCapture(List<OrganizationPatientConsentDTO> data) {
long patientOrgId = personDTO.getPatientEnrollment().getOrgId();
String programLevelConsentStatus = personDTO.getPatientEnrollment().getProgramLevelConsentStatus();
ListGridRecord[] records = OrganizationPatientConsentUtils.convert(data, patientOrgId, programLevelConsentStatus);
populateListGrid(records);
}
}
class SaveClickHandler implements ClickHandler {
@Override
public void onClick(ClickEvent clickEvent) {
progressBarWindow.show();
ListGridRecord[] records = listGrid.getRecords();
List<OrganizationPatientConsentDTO> dtos = getCheckedItems(records);
long patientId = personDTO.getPatientEnrollment().getPatientId();
long communityId= ApplicationContextUtils.getLoginResult().getCommunityId();
organizationPatientConsentService.saveOrganizationPatientConsentList(patientId, dtos,communityId, new SaveAsyncCallback());
}
private List<OrganizationPatientConsentDTO> getCheckedItems(ListGridRecord[] records) {
List<OrganizationPatientConsentDTO> dtos = new ArrayList<OrganizationPatientConsentDTO>();
for (ListGridRecord tempRecord : records) {
OrganizationPatientConsentRecord tempOrgRecord = (OrganizationPatientConsentRecord) tempRecord;
OrganizationPatientConsentDTO tempDto = tempOrgRecord.getOrganizationPatientConsentDto();
String consentStatus = tempDto.getConsentStatus();
boolean hasPermit = StringUtils.equalsIgnoreCase(consentStatus, ConsentConstants.CONSENT_PERMIT);
if (hasPermit) {
dtos.add(tempDto);
}
}
return dtos;
}
}
class SaveAsyncCallback implements AsyncCallback {
@Override
public void onSuccess(Object t) {
progressBarWindow.hide();
SC.say("Save successful.");
}
@Override
public void onFailure(Throwable thrwbl) {
progressBarWindow.hide();
SC.warn("Error during save. Please try again.");
}
}
}
i have done the live filtering....
its working correctly
the way i did it by converting the list grid into datasource and applied the filter
but the problem is ..datasource is not supporting the editable columns
we need to save consent by tick/untick but it is locked ..as datasource doent have any editable column methods as the list grid..
:(
package com.gsihealth.dashboard.client.consent.healthhomeorganization;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.gsihealth.dashboard.client.DashBoardApp;
import com.gsihealth.dashboard.client.common.ProgressBarWindow;
import com.gsihealth.dashboard.client.common.RetryActionCallback;
import com.gsihealth.dashboard.client.service.OrganizationPatientConsentService;
import com.gsihealth.dashboard.client.service.OrganizationPatientConsentServiceAsync;
import com.gsihealth.dashboard.client.util.ApplicationContextUtils;
import com.gsihealth.dashboard.client.util.StringUtils;
import com.gsihealth.dashboard.common.ConsentConstants;
import com.gsihealth.dashboard.common.dto.PersonDTO;
import com.gsihealth.dashboard.entity.dto.OrganizationPatientConsentDTO;
import com.smartgwt.client.data.DataSource;
import com.smartgwt.client.data.fields.DataSourceBooleanField;
import com.smartgwt.client.data.fields.DataSourceTextField;
import com.smartgwt.client.types.Alignment;
import com.smartgwt.client.types.FetchMode;
import com.smartgwt.client.types.ListGridEditEvent;
import com.smartgwt.client.types.ListGridFieldType;
import com.smartgwt.client.types.SelectionStyle;
import com.smartgwt.client.util.SC;
import com.smartgwt.client.widgets.Button;
import com.smartgwt.client.widgets.events.ClickEvent;
import com.smartgwt.client.widgets.events.ClickHandler;
import com.smartgwt.client.widgets.grid.ListGrid;
import com.smartgwt.client.widgets.grid.ListGridField;
import com.smartgwt.client.widgets.grid.ListGridRecord;
import com.smartgwt.client.widgets.layout.HLayout;
import com.smartgwt.client.widgets.layout.Layout;
import com.smartgwt.client.widgets.layout.LayoutSpacer;
import com.smartgwt.client.widgets.layout.VLayout;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author Chad Darby
*/
public class OrganizationPatientConsentPanel extends VLayout {
private PersonDTO personDTO;
private OrganizationPatientConsentServiceAsync organizationPatientConsentService = GWT.create(OrganizationPatientConsentService.class);
private Button saveButton;
private ListGrid listGrid;
private static final int CONSENT_COLUMN = 3;
private ProgressBarWindow progressBarWindow;
public OrganizationPatientConsentPanel(PersonDTO thePersonDTO) {
personDTO = thePersonDTO;
buildGui();
DashBoardApp.restartTimer();
loadOrganizationPatientConsentData();
}
private void buildGui() {
setMargin(5);
listGrid = buildListGrid();
setPadding(5);
addMember(listGrid);
// layout spacer b/w layout lables and layout of remover button
LayoutSpacer topSpacer = new LayoutSpacer();
topSpacer.setHeight(20);
addMember(topSpacer);
// layout for remove button
Layout buttonBar = buildButtonBar();
addMember(buttonBar);
progressBarWindow = new ProgressBarWindow("Saving", "Saving...");
}
/** Helper method to build a ListGrid
*
* @return
*/
private ListGrid buildListGrid() {
String[] columnNames = {OrganizationConsentConstants.ORGANIZATION_NAME, OrganizationConsentConstants.CITY, OrganizationConsentConstants.STATE, OrganizationConsentConstants.PERMIT_CONSENT};
ListGrid theListGrid = new ListGrid();
theListGrid.setCanReorderFields(true);
theListGrid.setCanReorderRecords(true);
theListGrid.setWidth100();
theListGrid.setHeight100();
theListGrid.setAlternateRecordStyles(true);
theListGrid.setShowAllRecords(false);
theListGrid.setSelectionType(SelectionStyle.SINGLE);
theListGrid.setCanEdit(true);
theListGrid.setDataFetchMode(FetchMode.LOCAL);
theListGrid.setCanEdit(false);
theListGrid.setAutoFetchData(true);
theListGrid.setShowFilterEditor(true);
theListGrid.setFilterByCell(true);
theListGrid.setFilterOnKeypress(true);
theListGrid.setEditEvent(ListGridEditEvent.CLICK);
theListGrid.setEditByCell(true);
// add fields
ListGridField[] fields = buildListGridFields(columnNames);
theListGrid.setFields(fields);
theListGrid.setEmptyMessage("...");
theListGrid.setCanResizeFields(true);
return theListGrid;
}
private ListGridField[] buildListGridFields(String[] columnNames) {
ListGridField[] fields = new ListGridField[columnNames.length];
for (int i = 0; i < columnNames.length; i++) {
String tempColumnName = columnNames[i];
ListGridField tempField = buildListGridField(tempColumnName);
fields[i] = tempField;
if (i == CONSENT_COLUMN) {
fields[i].setCanEdit(true);
fields[i].setType(ListGridFieldType.BOOLEAN);
}
}
return fields;
}
private ListGridField buildListGridField(String title) {
ListGridField tempField = new ListGridField(title, title);
tempField.setCanEdit(false);
return tempField;
}
private Layout buildButtonBar() {
// layout for button bar
HLayout buttonLayout = new HLayout(10);
buttonLayout.setWidth100();
buttonLayout.setAlign(Alignment.CENTER);
// remove button
saveButton = new Button("Save Consent");
saveButton.setID("SaveConsent");
saveButton.setWidth(140);
saveButton.addClickHandler(new SaveClickHandler());
buttonLayout.addMember(saveButton);
return buttonLayout;
}
private void loadOrganizationPatientConsentData() {
LoadOrganizationPatientConsentDataCallback loadOrganizationPatientConsentDataCallback = new LoadOrganizationPatientConsentDataCallback();
loadOrganizationPatientConsentDataCallback.attempt();
}
public void populateListGrid(ListGridRecord[] data) {
ListGridRecord[] records = listGrid.getRecords();
// scroll to first row
listGrid.scrollToRow(1);
final DataSource dataSource = new DataSource();
dataSource.setID("dataSource");
dataSource.setClientOnly(true);
DataSourceTextField name = new DataSourceTextField("Organization Name", "Organization Name");
DataSourceTextField city = new DataSourceTextField("City", "City");
DataSourceTextField state = new DataSourceTextField("State", "State");
DataSourceBooleanField Permit = new DataSourceBooleanField("Permit Consent", "Permit Consent");
dataSource.setFields(name, city, state, Permit);
dataSource.setCacheData(data);
listGrid.setDataSource(dataSource);
listGrid.setData(data);
listGrid.markForRedraw();
}
class LoadOrganizationPatientConsentDataCallback extends RetryActionCallback<List<OrganizationPatientConsentDTO>> {
@Override
public void attempt() {
long patientId = personDTO.getPatientEnrollment().getPatientId();
long communityId= ApplicationContextUtils.getLoginResult().getCommunityId();
organizationPatientConsentService.getOrganizationPatientConsentList(patientId,communityId, this);
}
@Override
public void onCapture(List<OrganizationPatientConsentDTO> data) {
long patientOrgId = personDTO.getPatientEnrollment().getOrgId();
String programLevelConsentStatus = personDTO.getPatientEnrollment().getProgramLevelConsentStatus();
ListGridRecord[] records = OrganizationPatientConsentUtils.convert(data, patientOrgId, programLevelConsentStatus);
populateListGrid(records);
}
}
class SaveClickHandler implements ClickHandler {
@Override
public void onClick(ClickEvent clickEvent) {
progressBarWindow.show();
ListGridRecord[] records = listGrid.getRecords();
List<OrganizationPatientConsentDTO> dtos = getCheckedItems(records);
long patientId = personDTO.getPatientEnrollment().getPatientId();
long communityId= ApplicationContextUtils.getLoginResult().getCommunityId();
organizationPatientConsentService.saveOrganizationPatientConsentList(patientId, dtos,communityId, new SaveAsyncCallback());
}
private List<OrganizationPatientConsentDTO> getCheckedItems(ListGridRecord[] records) {
List<OrganizationPatientConsentDTO> dtos = new ArrayList<OrganizationPatientConsentDTO>();
for (ListGridRecord tempRecord : records) {
OrganizationPatientConsentRecord tempOrgRecord = (OrganizationPatientConsentRecord) tempRecord;
OrganizationPatientConsentDTO tempDto = tempOrgRecord.getOrganizationPatientConsentDto();
String consentStatus = tempDto.getConsentStatus();
boolean hasPermit = StringUtils.equalsIgnoreCase(consentStatus, ConsentConstants.CONSENT_PERMIT);
if (hasPermit) {
dtos.add(tempDto);
}
}
return dtos;
}
}
class SaveAsyncCallback implements AsyncCallback {
@Override
public void onSuccess(Object t) {
progressBarWindow.hide();
SC.say("Save successful.");
}
@Override
public void onFailure(Throwable thrwbl) {
progressBarWindow.hide();
SC.warn("Error during save. Please try again.");
}
}
}