📄 application.java
字号:
/* * Copyright 2006-2007 Queplix Corp. * * Licensed under the Queplix Public License, Version 1.1.1 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.queplix.com/solutions/commercial-open-source/queplix-public-license/ * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. */package com.queplix.core.client.app;import com.google.gwt.core.client.EntryPoint;import com.google.gwt.core.client.GWT;import com.google.gwt.user.client.Window;import com.google.gwt.user.client.ui.RootPanel;import com.google.gwt.user.client.ui.Widget;import com.queplix.core.client.app.rpc.RPC;import com.queplix.core.client.app.vo.EntityElement;import com.queplix.core.client.app.vo.FamgMeta;import com.queplix.core.client.app.vo.FieldMeta;import com.queplix.core.client.app.vo.LoadReportResponseObject;import com.queplix.core.client.app.vo.LoginRequestObject;import com.queplix.core.client.app.vo.LoginResult;import com.queplix.core.client.app.vo.MetaData;import com.queplix.core.client.app.vo.TabMeta;import com.queplix.core.client.app.vo.UserProfile;import com.queplix.core.client.common.crossframes.AdhocData;import com.queplix.core.client.common.event.Event;import com.queplix.core.client.common.event.EventListener;import com.queplix.core.client.common.ui.DialogHelper;import com.queplix.core.client.common.ui.WindowHelper;import com.queplix.core.client.controls.QFormElementModel;import com.queplix.core.client.controls.datefield.DateHelper;import com.queplix.core.client.frames.LoginFrame;import com.queplix.core.client.frames.QFrame;import com.queplix.core.client.frames.adhoc.AdhocReportFrame;import com.queplix.core.client.frames.mainframe.IMainFrame;import com.queplix.core.client.frames.mainframe.MainFrameBuilder;import com.queplix.core.client.frames.mainframe.AdhocOperations;import com.queplix.core.client.frames.mainframe.impl.DefaultMainFrameBuilder;import com.queplix.core.client.i18n.I18N;import java.util.ArrayList;import java.util.HashSet;import java.util.List;import java.util.Set;/** * Main application class. * @author Sultan Tezadov * @since 23 Sep 2006 */// TODO: once generics enabled, remove all occurences of '/*]' and '[*/'public class Application implements EntryPoint , RPC.RequestListener , LengthyTaskManager.LengthyTaskListener , EventListener , IApplication { private MainFrameBuilder mainFrameBuilder; private LoginFrame loginFrame;// private IMainFrame mainFrame;// private OperationContext mainFrameContext; private AdhocReportFrame adhocReportFrame; private MetaData appMetaData; public final static String BROWSER_MSIE = "MSIE"; public final static String BROWSER_FIREFOX = "Firefox"; public static final int LOGIN_FRAME = -1; public static final int MAIN_FRAME = 0; public static final int AD_HOC_REPORT_FRAME = 1; private static UserProfile userProfile; public static UserProfile getUserProfile() { return userProfile; } public Application() { } private AdhocReportFrame getAdhocReport() { if(adhocReportFrame == null) { adhocReportFrame = new AdhocReportFrame(appMetaData); adhocReportFrame.getEventSource().addEventListener(this); } return adhocReportFrame; } /** * To be overriden in inheritances. */ protected void displayModuleContent() { WindowHelper.disableContextMenu(); RPC.addRequestListener(this); LengthyTaskManager.addLengthyTaskListener(this); loginFrame = createLoginFrame(); selectFrame(Application.LOGIN_FRAME); loginFrame.getLoginWidget().setFocus(true); loginFrame.getEventSource().addEventListener(this); setStatus("Ready to log in"); IdleUtilizer.onLoginPrompted(); } public void onModuleLoad() { checkAndLoad(); } /** * Check if this module should be loaded, and if it is */ final protected void checkAndLoad() { String thisClassName = getModuleName(); if(getGwtModuleClassName().equalsIgnoreCase(thisClassName)) { displayModuleContent(); } } /** * To be reloaded in all deriving classes. */ protected String getModuleName() { return "com.queplix.core.Core"; } public static String getGwtModuleClassName(){ return GWT.getModuleName(); } /*hand-made implementation public static native String getGwtModuleClassName(){ metas = $doc.getElementsByTagName("META"); ret = ""; for (i = 0; i < metas.length; i++) { if(metas[i].name == 'gwt:module') { ret = metas[i].content; break; } } return ret; };*/ /** * Force login. Useful during development to bypass authentication * @param login login name */ protected void forceLogin(String login) { loginFrame.forceSubmit(login); } private void loginSuccess(final MetaData meta) { UserSessionManager.init(meta.getSessionTimeoutMinutes(), meta.getSessionTimeoutWarnBeforeMinutes()); userProfile = meta.getUserProfile(); DateHelper.timeOffset = meta.getTimeZoneOffset(); appMetaData = meta; loginFrame.displaySuccessMessage(); WindowHelper.setApplicationBusyMouse(true); // let the browser process events and display the success message: LengthyTaskManager.yieldAndRun(new LengthyTaskManager.Runnable() { public void run() { initMainFrameBuilder(meta); selectFrame(Application.MAIN_FRAME); setStatus("Ready"); loginFrame.clearLoginPage(true); WindowHelper.setApplicationBusyMouse(false); } }); } private void loginFailure() { setStatus("Login failed"); loginFrame.setLoginPageEnabled(true); } private void remoteLogin(String login, String password) { LoginRequestObject lro = new LoginRequestObject(login, password); RPC.QAsyncCallback callback = new RPC.QAsyncCallback() { public void onRequestEnded(boolean success, Object result) { if (success) { LoginResult loginResult = (LoginResult) result; MetaData meta = loginResult.getMetaData(); loginSuccess(meta); } } protected void handleError(Throwable error) { loginFailure(); super.handleError(error); } }; RPC.getRPC().login(lro, callback); setStatus("Request sent. Waiting for reply..."); IdleUtilizer.onLoginSubmitted(); } public void onRequestStarted() { WindowHelper.setApplicationProgressMouse(true); } public void onRequestFinished(boolean success) { WindowHelper.setApplicationProgressMouse(false); UserSessionManager.resetTimer(); } public void handleError(Throwable caught) { DialogHelper.showModalErrorDialog(caught); } /** * Displays current status message in the application's status line */ public static native void setStatus(String text) /*-{ $wnd.status = text; }-*/; /**
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -