FileDocCategorySizeDatePackage
MessagesExampleController.javaAPI DocExample2799Mon Aug 27 20:11:56 BST 2007com.google.gwt.sample.i18n.client

MessagesExampleController

public class MessagesExampleController extends Object
Demonstrates how to use {@link Messages}.

Fields Summary
private static final ErrorMessages
ERRORS
public final com.google.gwt.user.client.ui.TextBox
txtArg1
public final com.google.gwt.user.client.ui.TextBox
txtArg2
public final com.google.gwt.user.client.ui.TextBox
txtArg3
public final com.google.gwt.user.client.ui.Label
lblFormattedMessage
public final com.google.gwt.user.client.ui.Label
lblMessageTemplate
private String
prevArg1
private String
prevArg2
private String
prevArg3
private final MessagesExampleConstants
constants
Constructors Summary
public MessagesExampleController(MessagesExampleConstants constants)


     
    this.constants = constants;

    String messageTemplate = ERRORS.permissionDenied("{0}", "{1}", "{2}");
    lblMessageTemplate.setText(messageTemplate);

    KeyboardListenerAdapter listener = new KeyboardListenerAdapter() {
      public void onKeyUp(Widget sender, char keyCode, int modifiers) {
        maybeRefreshFormattedMessage();
      }
    };
    txtArg1.addKeyboardListener(listener);
    txtArg2.addKeyboardListener(listener);
    txtArg3.addKeyboardListener(listener);

    txtArg1.setText("amelie");
    txtArg2.setText("guest");
    txtArg3.setText("/secure/blueprints.xml");

    maybeRefreshFormattedMessage();
  
Methods Summary
public MessagesExampleConstantsgetConstants()

    return constants;
  
private voidmaybeRefreshFormattedMessage()

    String arg1 = txtArg1.getText().trim();
    String arg2 = txtArg2.getText().trim();
    String arg3 = txtArg3.getText().trim();

    if (arg1.equals(prevArg1)) {
      if (arg2.equals(prevArg2)) {
        if (arg3.equals(prevArg3)) {
          // Nothing has changed.
          return;
        }
      }
    }

    prevArg1 = arg1;
    prevArg2 = arg2;
    prevArg3 = arg3;

    String formattedMessage = ERRORS.permissionDenied(arg1, arg2, arg3);
    lblFormattedMessage.setText(formattedMessage);