I write a class which extends Application. In it,there are two method related to the MainWindow.One is init(), I setMainWindow with a LoginForm class which extends Window. Another is startInit(), I remove the MainWindow by removeWindow(getMainWindow()). The problem is when I setMainWindow with LoginForm, if I want to change it with others, the MainWindow will not change. The detail codes are below:
MainApplication.java:
public class LoginDialog extends Window {
public LoginDialog() {
LoginForm login = new LoginForm();
login.setWidth("100%");
login.setHeight("300px");
login.addListener(new LoginForm.LoginListener() {
public void onLogin(LoginEvent event) {
boolean boo = authenticate(event.getLoginParameter("username"), event.getLoginParameter("password"));
if(boo){
MainApplication app = (MainApplication) getApplication();
app.startInit();
}else
getWindow().showNotification("Error", "Fail to login! Check Username and Password!", Window.Notification.TYPE_ERROR_MESSAGE);
}
});
addComponent(login);
}
public boolean authenticate(String login, String password){
if("admin".equals(login) && "123456".equals(password)){
return true;
}
return false;
}
}
MainApplication.java:
public class MainApplication extends Application {
private TabSheet right = new TabSheet();
private ICEPush pusher = new ICEPush();
public boolean start = false;
@Override
public void init() {
// TODO Auto-generated method stub
setTheme("mainApptheme");
setMainWindow(new LoginDialog());
}
public void startInit(){
removeWindow(getMainWindow());
buildMainFrameWork();
}
class BackgroundThread extends Thread {
@Override
public void run() {
while (start && right.getSelectedTab() != null) {
try {
Thread.sleep(3000);
if(right.getSelectedTab() instanceof MainFrameLogTab){
((MainFrameLogTab)right.getSelectedTab()).addDynamicItem();
pusher.push();
System.out.println("====================push");
}
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
private void buildMainFrameWork() {
setTheme("mainApptheme");
final VerticalLayout root = new VerticalLayout();
root.setSizeFull();
Window main = new Window("Browser title...", root);
setMainWindow(main);
main.addComponent(pusher);
Label title = new Label("EM Testing");
title.addStyleName(Runo.LABEL_H1);
title.setSizeUndefined();
root.addComponent(title);
root.setComponentAlignment(title, Alignment.TOP_CENTER);
right.setSizeFull();
root.addComponent(right);
root.setExpandRatio(title, 0);
root.setExpandRatio(right, 1);
right.addTab(new MainFrameApplistTab(), "ApplistInfo", null);
right.addTab(new MainFrameEmaspUserInfoTab(), "EmaspUserInfo", null);
right.addTab(new MainFrameUserMapTab(), "UserMapInfo", null);
right.addTab(new MainFrameLogTab(), "LogSystem", null);
right.addListener(new TabSheet.SelectedTabChangeListener() {
@Override
public void selectedTabChange(SelectedTabChangeEvent event) {
if (right.getSelectedTab() instanceof AbstractFrameTab) {
if(right.getSelectedTab() instanceof MainFrameLogTab){
start = true;
AbstractFrameTab tab = (AbstractFrameTab) right.getSelectedTab();
tab.refreshTable();
new BackgroundThread().start();
}else{
start = false;
AbstractFrameTab tab = (AbstractFrameTab) right.getSelectedTab();
tab.refreshTable();
}
} else {
start = false;
}
}
});
}
}