Using ButtonBar to hold buttons (Ext GWT) : ToolBar « GWT « Java






Using ButtonBar to hold buttons (Ext GWT)

Using ButtonBar to hold buttons (Ext GWT)
 
/*
 * Ext GWT - Ext for GWT
 * Copyright(c) 2007-2009, Ext JS, LLC.
 * licensing@extjs.com
 * 
 * http://extjs.com/license
 */

package com.google.gwt.sample.hello.client;

import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.event.MessageBoxEvent;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.util.Format;
import com.extjs.gxt.ui.client.util.Params;
import com.extjs.gxt.ui.client.widget.Info;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.MessageBox;
import com.extjs.gxt.ui.client.widget.ProgressBar;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.button.ButtonBar;
import com.extjs.gxt.ui.client.widget.layout.FlowData;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.ui.RootPanel;

public class Hello implements EntryPoint {
  public void onModuleLoad() {
    RootPanel.get().add(new MessageBoxExample());
  }
}
class MessageBoxExample extends LayoutContainer {

  @Override
  protected void onRender(Element parent, int pos) {
    super.onRender(parent, pos);
    final Listener<MessageBoxEvent> l = new Listener<MessageBoxEvent>() {
      public void handleEvent(MessageBoxEvent ce) {
        Button btn = ce.getButtonClicked();
        Info.display("MessageBox", "The '{0}' button was pressed", btn.getText());
      }
    };

    final ButtonBar buttonBar = new ButtonBar();
    buttonBar.setMinButtonWidth(75);
    
    buttonBar.add(new Button("Confirm", new SelectionListener<ButtonEvent>() {
      public void componentSelected(ButtonEvent ce) {
        MessageBox.confirm("Confirm", "Are you sure you want to do that?", l);
      }
    }));

    buttonBar.add(new Button("Prompt", new SelectionListener<ButtonEvent>() {
      public void componentSelected(ButtonEvent ce) {
        final MessageBox box = MessageBox.prompt("Name", "Please enter your name:");
        box.addCallback(new Listener<MessageBoxEvent>() {
          public void handleEvent(MessageBoxEvent be) {
            Info.display("MessageBox", "You entered '{0}'", new Params(be.getValue()));
          }
        });
      }
    }));

    buttonBar.add(new Button("Multiline Prompt", new SelectionListener<ButtonEvent>() {
      public void componentSelected(ButtonEvent ce) {
        MessageBox box = MessageBox.prompt("Address", "Please enter your address:", true);
        box.addCallback(new Listener<MessageBoxEvent>() {
          public void handleEvent(MessageBoxEvent be) {
            String v = Format.ellipse(be.getValue(), 80);
            Info.display("MessageBox", "You entered '{0}'", new Params(v));
          }
        });
      }
    }));

    buttonBar.add(new Button("Yes/No/Cancel", new SelectionListener<ButtonEvent>() {
      public void componentSelected(ButtonEvent ce) {
        MessageBox box = new MessageBox();
        box.setButtons(MessageBox.YESNOCANCEL);
        box.setIcon(MessageBox.QUESTION);
        box.setTitle("Save Changes?");
        box.addCallback(l);
        box.setMessage("You are closing a tab that has unsaved changes. Would you like to save your changes?");
        box.show();
      }
    }));

    buttonBar.add(new Button("Progress", new SelectionListener<ButtonEvent>() {
      public void componentSelected(ButtonEvent ce) {
        final MessageBox box = MessageBox.progress("Please wait", "Loading items...",
            "Initializing...");
        final ProgressBar bar = box.getProgressBar();
        final Timer t = new Timer() {
          float i;

          @Override
          public void run() {
            bar.updateProgress(i / 100, (int) i + "% Complete");
            i += 5;
            if (i > 105) {
              cancel();
              box.close();
              Info.display("Message", "Items were loaded", "");
            }
          }
        };
        t.scheduleRepeating(500);
      }
    }));

    buttonBar.add(new Button("Wait", new SelectionListener<ButtonEvent>() {
      public void componentSelected(ButtonEvent ce) {
        final MessageBox box = MessageBox.wait("Progress",
            "Saving your data, please wait...", "Saving...");
        Timer t = new Timer() {
          @Override
          public void run() {
            Info.display("Message", "Your fake data was saved", "");
            box.close();
          }
        };
        t.schedule(5000);
      }
    }));

    buttonBar.add(new Button("Alert", new SelectionListener<ButtonEvent>() {
      public void componentSelected(ButtonEvent ce) {
        MessageBox.alert("Alert", "Access Denied", l);
      }
    }));
    add(buttonBar, new FlowData(10));
  }

}

   
  








Ext-GWT.zip( 4,297 k)

Related examples in the same category

1.Tool Strips Sample (Smart GWT)Tool Strips Sample (Smart GWT)
2.Adding ComboBox to ToolBar (Ext GWT)Adding ComboBox to ToolBar (Ext GWT)
3.ToolBar overflow (Ext GWT)
4.ToolBar with Dropdown menu (Ext GWT)ToolBar with Dropdown menu (Ext GWT)
5.Ribbon like ToolBar (Ext GWT)Ribbon like ToolBar (Ext GWT)
6.Multi-column no-title ToolBar (Ext GWT)Multi-column no-title ToolBar (Ext GWT)
7.ToolBar with grouped buttons (Ext GWT)ToolBar with grouped buttons (Ext GWT)
8.Office 2007 style toolbar (Ext GWT)Office 2007 style toolbar (Ext GWT)
9.Adding menu bar to ContentPanel (Ext GWT)Adding menu bar to ContentPanel (Ext GWT)
10.Adding Status to ToolBar (Ext GWT)Adding Status to ToolBar (Ext GWT)
11.Add ToolBar to the bottom of a FormPanel (Ext GWT)Add ToolBar to the bottom of a FormPanel (Ext GWT)
12.Adding ToolBar to ContentPanel (Ext GWT)Adding ToolBar to ContentPanel (Ext GWT)