/* * 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.data.DataSource; import com.smartgwt.client.rpc.LoadScreenCallback; import com.smartgwt.client.rpc.RPCManager; import com.smartgwt.client.rpc.RPCResponse; import com.smartgwt.client.widgets.Button; import com.smartgwt.client.widgets.Canvas; import com.smartgwt.client.widgets.Label; 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.CheckboxItem; import com.smartgwt.client.widgets.grid.ListGrid; import com.smartgwt.client.widgets.layout.HStack; import com.smartgwt.client.widgets.layout.VLayout; import com.smartgwt.client.widgets.layout.VStack; import java.util.Map; import com.google.gwt.core.client.EntryPoint; public class ReplacePlaceholder implements EntryPoint { private VLayout xmlLayout; private Label placeholder; @Override public void onModuleLoad() { final Canvas container = new Canvas("container"); container.setBorder("3px solid green"); VStack mainLayout = new VStack(5); mainLayout.setWidth("300"); mainLayout.setBorder("1px solid red"); HStack innerLayout = new HStack(5); innerLayout.setHeight(30); final DynamicForm autoReplacePlaceholderDynamicForm = new DynamicForm(); autoReplacePlaceholderDynamicForm.setItems( new CheckboxItem("autoReplacePlaceholderCheckbox", "Auto-replace Placeholder") ); final Button replacePlaceholderButton = new Button("Replace Placeholder"); replacePlaceholderButton.setWidth(200); replacePlaceholderButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { replacePlaceholderButtonClick(); } }); Button reloadComponentXMLButton = new Button("Reload component XML"); reloadComponentXMLButton.setWidth(200); reloadComponentXMLButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { if (xmlLayout != null) { xmlLayout.markForDestroy(); xmlLayout = null; RPCManager.loadScreen("replacePlaceholder", new LoadScreenCallback() { @Override public void execute() { xmlLayout = (VLayout) this.getScreen(); placeholder = (Label) xmlLayout.getByLocalId("placeholder"); container.addChild(xmlLayout); Boolean autoReplace = (Boolean)autoReplacePlaceholderDynamicForm.getValue("autoReplacePlaceholderCheckbox"); if (autoReplace != null && autoReplace.booleanValue()) { replacePlaceholderButtonClick(); } } }); } } }); innerLayout.setMembers(reloadComponentXMLButton, replacePlaceholderButton, autoReplacePlaceholderDynamicForm); mainLayout.setMembers(innerLayout, container); RPCManager.loadScreen("replacePlaceholder", new LoadScreenCallback() { @Override public void execute() { xmlLayout = (VLayout) this.getScreen(); placeholder = (Label) xmlLayout.getByLocalId("placeholder"); container.addChild(xmlLayout); } }); mainLayout.draw(); } public void replacePlaceholderButtonClick() { if (placeholder != null) { ListGrid grid = new ListGrid(); grid.setDataSource(DataSource.get("supplyItem")); grid.setAutoFetchData(true); grid.setWidth(400); grid.setHeight(200); xmlLayout.removeMember(placeholder); placeholder = null; xmlLayout.addMember(grid); } } }