/* * GWT-Ext Widget Library * Copyright(c) 2007-2008, GWT-Ext. * licensing@gwt-ext.com * * http://www.gwt-ext.com/license */ import com.google.gwt.core.client.EntryPoint; import com.google.gwt.user.client.Timer; import com.google.gwt.user.client.ui.RootPanel; import com.gwtext.client.core.EventObject; import com.gwtext.client.util.Format; import com.gwtext.client.widgets.*; import com.gwtext.client.widgets.event.ButtonListenerAdapter; import com.gwtext.client.widgets.layout.TableLayout; public class MessageBoxSample implements EntryPoint { public void onModuleLoad() { Panel panel = new Panel(); panel.setBorder(false); panel.setPaddings(15); panel.setLayout(new TableLayout(2)); Panel panel1 = new Panel(); panel1.setTitle("Confirm"); panel1.setFrame(true); panel1.setWidth(250); panel1.setHeight(150); panel1.setPaddings(20); Button button1 = new Button("Show Me", new ButtonListenerAdapter() { public void onClick(Button button, EventObject e) { MessageBox.confirm("Confirm", "Are you sure you want to do that?", new MessageBox.ConfirmCallback() { public void execute(String btnID) { System.out.println("Button Click : " + Format.format("You clicked the {0} button", btnID)); } }); } }); panel1.add(new HTMLPanel("A Standard Yes/No Confirm Dialog.", 0, 0, 0, 10)); panel1.addButton(button1); panel.add(new PaddedPanel(panel1, 0, 0, 10, 10)); Panel panel2 = new Panel(); panel2.setTitle("Prompt"); panel2.setFrame(true); panel2.setWidth(250); panel2.setHeight(150); panel2.setPaddings(20); Button button2 = new Button("Show Me", new ButtonListenerAdapter() { public void onClick(Button button, EventObject e) { MessageBox.prompt("Name", "Please enter your name:", new MessageBox.PromptCallback() { public void execute(String btnID, String text) { System.out.println("Button Click : " + Format.format("You clicked the {0} button and " + "entered the text \"{1}\"", btnID, text)); } }); } }); panel2.add(new HTMLPanel("A Standard prompt dialog.", 0, 0, 0, 10)); panel2.addButton(button2); panel.add(new PaddedPanel(panel2, 0, 0, 10, 10)); Panel panel3 = new Panel(); panel3.setTitle("Multi-line Prompt"); panel3.setFrame(true); panel3.setWidth(250); panel3.setHeight(150); panel3.setPaddings(20); Button button3 = new Button("Show Me", new ButtonListenerAdapter() { public void onClick(final Button button, EventObject e) { MessageBox.show(new MessageBoxConfig() { { setTitle("Address"); setMsg("Please enter your address:"); setWidth(300); setButtons(MessageBox.OKCANCEL); setMultiline(true); setCallback(new MessageBox.PromptCallback() { public void execute(String btnID, String text) { System.out.println("Button Click : " + Format.format("You clicked the {0} button and entered " + "the text \"{1}\"", btnID, text)); } }); setAnimEl(button.getId()); } }); } }); panel3.add(new HTMLPanel("A multi-line prompt dialog.", 0, 0, 0, 10)); panel3.addButton(button3); panel.add(new PaddedPanel(panel3, 0, 0, 10, 10)); Panel panel4 = new Panel(); panel4.setTitle("Yes/No/Cancel"); panel4.setFrame(true); panel4.setWidth(250); panel4.setHeight(150); panel4.setPaddings(20); Button button4 = new Button("Show Me", new ButtonListenerAdapter() { public void onClick(final Button button, EventObject e) { MessageBox.show(new MessageBoxConfig() { { setTitle("Save Changes?"); setMsg("Your are closing a tab that has unsaved changes. " + "Would you like to save your changes?"); setButtons(MessageBox.YESNOCANCEL); setCallback(new MessageBox.PromptCallback() { public void execute(String btnID, String text) { System.out.println("Button Click : " + Format.format("You clicked the {0} button", btnID)); } }); setAnimEl(button.getId()); } }); } }); panel4.add(new HTMLPanel("Standard Yes/No/Cancel dialog.", 0, 0, 0, 10)); panel4.addButton(button4); panel.add(new PaddedPanel(panel4, 0, 0, 10, 10)); Panel panel5 = new Panel(); panel5.setTitle("Progress Dialog"); panel5.setFrame(true); panel5.setWidth(250); panel5.setHeight(150); panel5.setPaddings(20); Button button5 = new Button("Show Me", new ButtonListenerAdapter() { public void onClick(final Button button, EventObject e) { MessageBox.show(new MessageBoxConfig() { { setTitle("Please wait..."); setMsg("Initializing..."); setWidth(240); setProgress(true); setClosable(false); setCallback(new MessageBox.PromptCallback() { public void execute(String btnID, String text) { System.out.println("Button Click : " + Format.format("You clicked the {0} button and " + "entered the text {1}", btnID, text)); } }); setAnimEl(button.getId()); } }); //create bogus progress for (int i = 1; i < 12; i++) { final int j = i; Timer timer = new Timer() { public void run() { if (j == 11) { MessageBox.hide(); } else { MessageBox.updateProgress(j * 10, "Loading item " + j + " of 10... "); } } }; timer.schedule(i * 1000); } } }); panel5.add(new HTMLPanel("You can set a progress on a progress MessageBox..", 0, 0, 0, 10)); panel5.addButton(button5); panel.add(new PaddedPanel(panel5, 0, 0, 10, 10)); Panel panel6 = new Panel(); panel6.setTitle("Wait Dialog"); panel6.setFrame(true); panel6.setWidth(250); panel6.setHeight(150); panel6.setPaddings(20); Button button6 = new Button("Show Me", new ButtonListenerAdapter() { public void onClick(final Button button, EventObject e) { MessageBox.show(new MessageBoxConfig() { { setMsg("Saving your data, please wait..."); setProgressText("Saving..."); setWidth(300); setWait(true); setWaitConfig(new WaitConfig() { { setInterval(200); } }); setAnimEl(button.getId()); } }); Timer timer = new Timer() { public void run() { MessageBox.hide(); System.out.println("Done, Your fake data was saved!"); } }; timer.schedule(8000); } }); panel6.add(new HTMLPanel("Dialog with indefinite progress bar (will close after 8 sec).", 0, 0, 0, 10)); panel6.addButton(button6); panel.add(new PaddedPanel(panel6, 0, 0, 10, 10)); Panel panel7 = new Panel(); panel7.setTitle("Alert"); panel7.setFrame(true); panel7.setWidth(250); panel7.setHeight(150); panel7.setPaddings(20); Button button7 = new Button("Show Me", new ButtonListenerAdapter() { public void onClick(Button button, EventObject e) { MessageBox.alert("Changes saved successfully"); } }); panel7.add(new HTMLPanel("Standard Alert dialog.", 0, 0, 0, 10)); panel7.addButton(button7); panel.add(new PaddedPanel(panel7, 0, 0, 10, 10)); RootPanel.get().add(panel); } }