/* * Isomorphic SmartGWT web presentation layer * Copyright 2000 and beyond Isomorphic Software, Inc. * * OWNERSHIP NOTICE * Isomorphic Software owns and reserves all rights not expressly granted in this source code, * including all intellectual property rights to the structure, sequence, and format of this code * and to all designs, interfaces, algorithms, schema, protocols, and inventions expressed herein. * * If you have any questions, please email
. * * This entire comment must accompany any portion of Isomorphic Software source code that is * copied or moved from this file. */ package com.smartgwt.sample.showcase.client.componentXML; import com.smartgwt.client.core.Function; import com.smartgwt.client.data.DataSource; import com.smartgwt.client.rpc.RPCManager; import com.smartgwt.client.util.SC; import com.smartgwt.client.widgets.Button; import com.smartgwt.client.widgets.Canvas; import com.smartgwt.client.widgets.events.ClickEvent; import com.smartgwt.client.widgets.events.ClickHandler; import com.smartgwt.client.widgets.form.DynamicForm; import com.smartgwt.client.widgets.form.fields.SelectItem; import com.smartgwt.client.widgets.grid.ListGrid; import com.smartgwt.client.widgets.grid.events.RecordClickEvent; import com.smartgwt.client.widgets.grid.events.RecordClickHandler; import com.smartgwt.client.widgets.layout.VLayout; import com.smartgwt.client.widgets.tab.Tab; import com.smartgwt.client.widgets.tab.TabSet; import com.smartgwt.client.widgets.form.fields.ButtonItem; import com.google.gwt.core.client.EntryPoint; public class ScreenReuse implements EntryPoint { TabSet tabSet; @Override public void onModuleLoad() { final DynamicForm selectorForm = new DynamicForm(); selectorForm.setWidth("100%"); SelectItem selector = new SelectItem("selector"); selector.setValueMap("countryDS", "supplyItem", "worldDS"); selector.setTitle("Select a DataSource"); ButtonItem button = new ButtonItem(); button.setTitle("Create Screen"); button.setWidth(120); button.addClickHandler(new com.smartgwt.client.widgets.form.fields.events.ClickHandler() { @Override public void onClick(com.smartgwt.client.widgets.form.fields.events.ClickEvent event) { if (selectorForm.getValueAsString("selector") != null) { switchTo(selectorForm.getValueAsString("selector")); } } }); selectorForm.setFields(selector, button); tabSet = new TabSet(); final VLayout layout = new VLayout(); layout.setWidth("100%"); layout.setHeight("90%"); layout.setMembersMargin(10); layout.setMembers(selectorForm, tabSet); RPCManager.cacheScreens(new String[]{"screenReuse"}, new Function() { @Override public void execute() { switchTo("countryDS"); } }); layout.draw(); } private void switchTo(String dataSource) { // create a new Tab Tab tab = new Tab(dataSource); // create screen Canvas screen = RPCManager.createScreen("screenReuse"); // get the components we want to use by their local ID final Button saveButton = (Button)screen.getByLocalId("saveButton");//new Button(screen.getByLocalId("saveButton").getJsObj()); final DynamicForm editForm = (DynamicForm)screen.getByLocalId("editForm");//new DynamicForm(screen.getByLocalId("editForm").getJsObj()); final ListGrid listGrid = (ListGrid)screen.getByLocalId("listGrid");//new ListGrid(screen.getByLocalId("listGrid").getJsObj()); // set DataSource editForm.setDataSource(DataSource.get(dataSource)); listGrid.setDataSource(DataSource.get(dataSource)); // set handlers listGrid.addRecordClickHandler(new RecordClickHandler() { public void onRecordClick(RecordClickEvent event) { editForm.clearErrors(true); editForm.editRecord(event.getRecord()); saveButton.enable(); } }); saveButton.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { editForm.saveData(); } }); tab.setPane(screen); tabSet.addTab(tab); tabSet.selectTab(tab); } }