DataSourceTextField stateField = new DataSourceTextField("viewState", "View State");
preferencesDS.setFields(pkField, preferenceField, stateField);
preferencesDS.setClientOnly(true);
preferecesGrid.setDataSource(preferencesDS);
ToolStripButton formulaButton = new ToolStripButton("Formula Builder", "crystal/oo/sc_insertformula.png");
formulaButton.setAutoFit(true);
formulaButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
countryGrid.addFormulaField();
}
});
ToolStripButton summaryBuilder = new ToolStripButton("Summary Builder", "crystal/16/apps/tooloptions.png");
summaryBuilder.setAutoFit(true);
summaryBuilder.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
countryGrid.addSummaryField();
}
});
final SelectItem preferenceSelectItem = new SelectItem("name");
preferenceSelectItem.setTitle("Preference");
ListGrid pickListProperties = new ListGrid();
pickListProperties.setEmptyMessage("No Saved Preferences");
preferenceSelectItem.setPickListProperties(pickListProperties);
preferenceSelectItem.setOptionDataSource(preferencesDS);
//apply the selected preference from the SelectItem
preferenceSelectItem.addChangedHandler(new ChangedHandler() {
@Override
public void onChanged(ChangedEvent event) {
String preferenceName = (String) preferenceSelectItem.getValue();
Criteria criteria = new Criteria("name", preferenceName);
preferencesDS.fetchData(criteria, new DSCallback() {
@Override
public void execute(DSResponse response, Object rawData, DSRequest request) {
Record[] data = response.getData();
if (data.length != 0) {
PreferenceRecord record = (PreferenceRecord) data[0];
countryGrid.setViewState(record.getViewState());
}
}
});
}
});
preferenceSelectItem.addClickHandler(new com.smartgwt.client.widgets.form.fields.events.ClickHandler() {
@Override
public void onClick(com.smartgwt.client.widgets.form.fields.events.ClickEvent event) {
String preferenceName = (String) preferenceSelectItem.getValue();
Criteria criteria = new Criteria("name", preferenceName);
preferencesDS.fetchData(criteria, new DSCallback() {
@Override
public void execute(DSResponse response, Object rawData, DSRequest request) {
Record[] data = response.getData();
if (data.length != 0) {
PreferenceRecord record = (PreferenceRecord) data[0];
countryGrid.setViewState(record.getViewState());
}
}
});
}
});
ToolStripButton savePreference = new ToolStripButton("Save Preference", "silk/database_gear.png");
savePreference.setAutoFit(true);
savePreference.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
SC.askforValue("Enter Preference name :", new ValueCallback() {
@Override
public void execute(String value) {
if (value != null && !value.equals("")) {
String viewState = countryGrid.getViewState();
PreferenceRecord record = new PreferenceRecord(PK_COUNTER++, value, viewState);
preferecesGrid.addData(record);
preferenceSelectItem.setValue(value);
}
}
});
}
});
//toolstrip to attach to the country grid
ToolStrip countryGridToolStrip = new ToolStrip();
countryGridToolStrip.setWidth100();
countryGridToolStrip.addFill();
countryGridToolStrip.addButton(formulaButton);
countryGridToolStrip.addButton(summaryBuilder);
countryGridToolStrip.addSeparator();
countryGridToolStrip.addButton(savePreference);
countryGridToolStrip.addSeparator();
countryGridToolStrip.addFormItem(preferenceSelectItem);
VLayout countryGridLayout = new VLayout(0);
countryGridLayout.setWidth(650);
countryGridLayout.addMember(countryGridToolStrip);
countryGridLayout.addMember(countryGrid);
layout.addMember(countryGridLayout);
VLayout preferencesGridLayout = new VLayout(0);
preferencesGridLayout.setWidth(650);
preferencesGridLayout.addMember(preferecesGrid);
//toolstrip to attach to the preferences grid
ToolStrip preferencesToolStrip = new ToolStrip();
preferencesToolStrip.setWidth100();
preferencesToolStrip.addFill();
ToolStripButton restoreButton = new ToolStripButton("Restore State", "silk/database_gear.png");
restoreButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
Record record = preferecesGrid.getSelectedRecord();
if (record != null) {
String viewState = record.getAttribute("viewState");