2010-06-25 56 views
3

我已经构建了一个登录组合,它在我的应用程序入口点显示给用户。输入用户名和密码后,我通过RemoteService将用户名和密码发送到服务器,并将接收包含ClientSession的对象。如果ClientSession是一个有效的对象(公认的用户名和密码),我希望显示主应用程序面板,否则我想再次显示登录对话框(带有错误消息)。如何在vanilla GWT中隐藏模式对话框后面的当前页面?

我的问题是,在对服务器的异步调用期间,如何屏蔽屏幕以便用户在从服务器获取会话时不能点击任何内容?

我知道登录应该很快,但Session对象包含大量用于生成主面板的当前用户的客户端缓存值。这可能需要几分之一秒或最多5秒(不幸的是我不能控制底层基础设施的速度),所以我想屏蔽屏幕直到超时,然后允许用户再次尝试。

在使用GWT Ext之前,我已经完成了这个确切的操作,但是不幸的是,vanilla GWT似乎有很少的样本。

感谢

克里斯

回答

6

GWT类PopupPanel有一个可选的“玻璃面板”,阻止与下面的页面的交互。

final PopupPanel popup = new PopupPanel(false, true); // Create a modal dialog box that will not auto-hide 
popup.add(new Label("Please wait")); 
popup.setGlassEnabled(true); // Enable the glass panel 
popup.center(); // Center the popup and make it visible 
1

您也可以为此使用对话框。 以下是如何使用它的代码。

public class NTMaskAlert extends DialogBox { 

private String displayText; 
private String message; 
private static NTMaskAlert alert; 
Label lable; 

private NTMaskAlert(String text) { 
    setText(text); 
    setWidget(new Image(GWT.getModuleBaseURL() 
      + "/images/ajax-loader_1.gif")); 
    setGlassEnabled(true); 
    setAnimationEnabled(true); 
    super.show(); 
    super.center(); 
    WorkFlowSessionFactory.putValue(WorkFlowSesisonKey.MASKING_PANEL, this); 
} 

public static void mask(String text) { 
    if (text != null) 
     new NTMaskAlert(text); 
    else 
     new NTMaskAlert("Processing"); 
} 

public static void unMask() { 
    NTMaskAlert alert = (NTMaskAlert) WorkFlowSessionFactory 
      .getValue(WorkFlowSesisonKey.MASKING_PANEL); 
    if (alert != null) { 
     alert.hide(); 
     alert = null; 
    } 
} 

public void setDisplayText(String displayText) { 
    this.displayText = displayText; 
    alert.setText(displayText); 
} 

public String getDisplayText() { 
    return displayText; 
} 

public void setMessage(String message) { 
    this.message = message; 
    lable.setText(message); 
} 

public String getMessage() { 
    return message; 
} 

}

使用静态的面具,揭露了操作方法。

1

这是我的解决方案:

public class CustomPopupPanel extends PopupPanel { 

    private Label label = new Label(); 

    public CustomPopupPanel() { 
     super(false, true); // Create a modal dialog box that will not auto-hide 
     super.setGlassEnabled(true); // Enable the glass panel 
     super.add(label); // Add the widget label into the panel 
    } 

    public CustomPopupPanel(String text) { 
     this(); 
     this.mask(text); 
    } 

    public final void mask(String text) { 
     label.setText(text); 
     super.center(); // Center the popup and make it visible 
    } 

    public void unmask() { 
     super.hide(); // Hide the popup 
    } 
} 
相关问题