package com.vci.client;
|
|
import java.awt.Dimension;
|
import java.awt.Frame;
|
import java.awt.Insets;
|
import java.awt.Point;
|
import java.awt.Toolkit;
|
import java.awt.event.ComponentAdapter;
|
import java.awt.event.ComponentEvent;
|
import java.net.UnknownHostException;
|
import java.util.Date;
|
import java.util.HashMap;
|
import java.util.Locale;
|
import java.util.Map;
|
|
import javax.swing.JDialog;
|
import javax.swing.JFrame;
|
import javax.swing.SwingUtilities;
|
import javax.swing.WindowConstants;
|
|
import com.vci.client.ClientSession;
|
import com.vci.client.common.ConfigUtils;
|
import com.vci.client.common.interfaces.IAppEventManager;
|
import com.vci.client.common.objects.ClientInfo;
|
import com.vci.client.common.objects.UserEntityObject;
|
import com.vci.client.common.objects.UserObject;
|
import com.vci.client.framework.delegate.RightManagementClientDelegate;
|
import com.vci.client.framework.delegate.SystemCfgClientDelegate;
|
import com.vci.client.framework.rightdistribution.object.RoleRightObject;
|
import com.vci.client.logon.client.BaseStyle;
|
import com.vci.client.logon.client.LogonFrame;
|
import com.vci.client.logon.client.VciFrame;
|
import com.vci.client.logon.client.ViewCodeFrame;
|
import com.vci.client.ui.exception.VCIException;
|
import com.vci.client.ui.locale.LocaleDisplay;
|
import com.vci.client.ui.swing.VCIOptionPane;
|
import com.vci.client.ui.swing.VCISwingUtil;
|
import com.vci.client.ui.swing.components.VCIJOptionPane;
|
import com.vci.common.resource.CommonProperties;
|
import com.vci.corba.framework.data.UserInfo;
|
import com.vci.mw.ClientContextVariable;
|
import com.vci.mw.LaunchModeEnum;
|
|
public class LogonApplication extends BaseStyle implements IAppEventManager {
|
|
public static Frame frame = null;
|
boolean packFrame = false;
|
public static UserObject userObject = null;
|
public static String urlBasePath = ".";
|
public static RoleRightObject[] currentUserRoleRights = null;
|
private Date loginTime = null;
|
private int loginovertime = Integer.parseInt(CommonProperties.getStringProperty("logon.loginovertime"));
|
|
public void setUserObject(UserObject userObj) {
|
userObject = userObj;
|
}
|
|
|
@Override
|
public boolean checkExpired() {
|
boolean expired = isExpired();
|
if(expired){
|
VCIOptionPane.showMessageDialog(LogonApplication.frame, "会话过期,请重新登录!!!!");
|
}
|
return expired;
|
}
|
|
|
@Override
|
public void relogin() {
|
if (frame != null){
|
frame.dispose();
|
}
|
show(new String[]{});
|
}
|
|
/**
|
* 检查Client会话是否过期
|
* @return
|
*/
|
private boolean isExpired(){
|
boolean res = false;
|
// add by xchao 2013.08.16 begin 根据选项配置,确定是否需要检查客户端UI是否超时
|
if(!ClientSession.isCheckClientUITimeout())
|
return false;
|
// add by xchao 2013.08.16 end
|
|
long betweenTime = 0;
|
if (loginTime != null){
|
// 当前时间 - 登录时间 -》 转换为分钟
|
betweenTime = (System.currentTimeMillis() - loginTime.getTime()) / (60 * 1000);
|
}
|
|
// 与会话超时阀值进行比较
|
if (betweenTime > loginovertime){
|
betweenTime = 0;
|
loginTime = null;
|
res = true;
|
}else{
|
setLoginTime();
|
res = false;
|
}
|
ClientSession.setTimeOutFlag(res);
|
return res;
|
}
|
|
|
/**
|
* 设置登录时间
|
*/
|
private void setLoginTime(){
|
loginTime = new Date();
|
}
|
|
public static UserObject getUserObject() {
|
return userObject;
|
}
|
|
public static UserEntityObject userEntityObject;
|
|
public static UserEntityObject getUserEntityObject() {
|
return userEntityObject;
|
}
|
|
public void setUserEntityObject(UserEntityObject userEntityObject) {
|
this.userEntityObject = userEntityObject;
|
}
|
|
private void setUserData(UserObject userObj) {
|
this.userObject = userObj;
|
String ip = this.getLocalIP();
|
String userName = userObj.getUserName();
|
UserEntityObject entityObj = new UserEntityObject(userName, ip);
|
this.setUserEntityObject(entityObj);
|
}
|
|
private static String getLocalIP() {
|
String ip = "127.0.0.1";
|
try {
|
ip = java.net.InetAddress.getLocalHost().getHostAddress();
|
} catch (UnknownHostException e) {
|
e.printStackTrace();
|
}
|
return ip;
|
}
|
|
public LogonApplication(final UserObject userObj) {
|
ClientSession.setAppEventManager(this);
|
SwingUtilities.invokeLater(new Runnable() {
|
@Override
|
public void run() {
|
|
ClientSession.setTimeOutFlag(false);
|
setUserData(userObj);
|
VciFrame vciFrame = new VciFrame(userObj);
|
try {
|
vciFrame.init();
|
} catch (Exception e) {
|
e.printStackTrace();
|
VCIOptionPane.showError(vciFrame, LocaleDisplay.getI18nString("100001", "RMIPFramework", Locale.getDefault()));
|
}
|
if (packFrame) {
|
vciFrame.pack();
|
} else {
|
vciFrame.validate();
|
}
|
showMainFrame(vciFrame);
|
}
|
});
|
}
|
|
@Deprecated
|
public static void loadJar() {
|
// nothing
|
}
|
|
/**
|
* 单点登录使用方法
|
* @param userObj
|
* @param message 业务系统传递的信息
|
*/
|
public LogonApplication(final UserObject userObj,final String[] taskMessage) {
|
ClientSession.setAppEventManager(this);
|
SwingUtilities.invokeLater(new Runnable() {
|
@Override
|
public void run() {
|
|
ClientSession.setTimeOutFlag(false);
|
setUserData(userObj);
|
VciFrame vciFrame = new VciFrame(userObj);
|
vciFrame.setTaskMessage(taskMessage);
|
try {
|
vciFrame.init();
|
} catch (Exception e) {
|
VCIOptionPane.showError(vciFrame, LocaleDisplay.getI18nString("100001", "RMIPFramework", Locale.getDefault()));
|
}
|
if (packFrame) {
|
vciFrame.pack();
|
} else {
|
vciFrame.validate();
|
}
|
showMainFrame(vciFrame);
|
}
|
});
|
}
|
|
private void showMainFrame(VciFrame vciFrame){
|
vciFrame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
|
VCISwingUtil.setClientMainFrame(vciFrame);
|
vciFrame.setFocusableWindowState(true);
|
setSizeAndLocation(vciFrame);
|
vciFrame.setVisible(true);
|
frame = vciFrame;
|
|
// 集成(单点)登录或是B/S登录界面登录时,Client启动时,重新ClientContextVariable
|
LogonApplication.frame = vciFrame;
|
ClientContextVariable.setFrame(vciFrame);
|
try {
|
vciFrame.loadTab1(0);
|
} catch (Exception e) {
|
// TODO Auto-generated catch block
|
e.printStackTrace();
|
}
|
}
|
private Dimension getCurrentSizeAndSetLocation(VciFrame frame){
|
Dimension d = new Dimension();
|
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
|
Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(frame.getGraphicsConfiguration());
|
int top = insets.top;
|
int left = insets.left;
|
int right = insets.right;
|
int bottom = insets.bottom;
|
int width = dim.width - left - right;
|
int height = dim.height - top - bottom;
|
int x = insets.left;
|
int y = insets.top;
|
frame.setLocation(x, y);
|
d = new Dimension(width, height);
|
return d;
|
}
|
private boolean manualSetSize = false;
|
private void setSizeAndLocation(final VciFrame frame){
|
Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(frame.getGraphicsConfiguration());
|
Dimension size = getCurrentSizeAndSetLocation(frame);
|
frame.setPreferredSize(size);
|
frame.setSize(size);
|
Point location = new Point(insets.left, insets.top);
|
frame.setLocation(location);
|
frame.setLocationByPlatform(true);
|
frame.setLocationRelativeTo(null);
|
frame.addComponentListener(new ComponentAdapter() {
|
|
@Override
|
public void componentResized(ComponentEvent e) {
|
if(e.getSource() instanceof VciFrame){
|
if(manualSetSize){
|
manualSetSize = false;
|
return;
|
}
|
VciFrame vf = (VciFrame)e.getSource();
|
int extendedState = vf.getExtendedState();
|
if((extendedState & JFrame.MAXIMIZED_BOTH) == JFrame.MAXIMIZED_BOTH){
|
manualSetSize = true;
|
Dimension size = getCurrentSizeAndSetLocation(frame);
|
frame.setPreferredSize(size);
|
frame.setSize(size);
|
return;
|
}
|
//
|
// //paramString -> COMPONENT_RESIZED (0,0 1600x856)
|
// String[] widthXHeights = e.paramString()
|
// .replaceAll("COMPONENT_RESIZED", "").trim()
|
// .replaceAll("\\(", "")
|
// .replaceAll("\\)", "")
|
// .split(" ")[1].split("x");
|
// int widthNew = Integer.valueOf(widthXHeights[0]);
|
// int heightNew = Integer.valueOf(widthXHeights[1]);
|
// Dimension maxSize = vf.getMaximumSize();
|
// if(heightNew > maxSize.height){
|
// heightNew = maxSize.height;
|
// manualSetSize = true;
|
// vf.setSize(widthNew, heightNew);
|
// }
|
}
|
}
|
});
|
}
|
|
public static void main(String[] args) {
|
System.out.println("");
|
System.out.println("\t***************************************************************");
|
System.out.println("\t* VCI-Platform Client V2024 www.vci-tech.com *");
|
System.out.println("\t* (C)Beijing Hongbo Yuanda Sciense and Technology Co. , Ltd. *");
|
System.out.println("\t***************************************************************");
|
System.out.println("");
|
|
|
for(String a : args){
|
System.out.println("args = "+ a);
|
}
|
// args = new String[]{"intUser_xc","taskType_EDIT","taskId_840033", "ViewCode_false"};
|
|
// add by xchao 2013.08.16 begin 设置客户端UI需要检查是否超时
|
ClientSession.setCheckClientUITimeout(true);
|
// add by xchao 2013.08.16 end
|
|
// launchMode_1 -> 此时代表常规模式,如:通过命令行或调试模式 normal
|
// launchMode_2 -> jnlpwebstart 此时代表通过 使用 jnlp 方式启动
|
// webBasePath_http://ip:port/xxx -> http://ip:port/xxx 是 jnlp 方式启动的 .jnlp 主地址
|
for(String arg : args){
|
if(arg.contains("_")){
|
String[] kvs = arg.split("_");
|
if(kvs.length >= 2){
|
if("launchMode".equalsIgnoreCase(kvs[0])){
|
LaunchModeEnum launchMode = LaunchModeEnum.getByIntVal(Integer.valueOf(kvs[1]));
|
ClientContextVariable.setClientLanuchMode(launchMode);
|
} else if("webBasePath".equalsIgnoreCase(kvs[0])){
|
String webBasePath = arg.substring(arg.indexOf("_")+1);
|
if(!"".equals(webBasePath)){
|
ClientContextVariable.setWebBasePath(webBasePath);
|
}
|
}
|
}
|
}
|
}
|
// System.out.println("launchMode:" + ClientContextVariable.getClientLanuchMode().getLabel());
|
// System.out.println("webBasePath:" + ClientContextVariable.getWebBasePath());
|
// if(ClientContextVariable.getClientLanuchMode() == LaunchModeEnum.Normal){
|
// new ClassLoaderUtil().loadNeedLoadJars();
|
// }
|
show(args);
|
}
|
|
public static void show(final String[] argsInput){
|
SwingUtilities.invokeLater(new Runnable() {
|
@Override
|
public void run() {
|
|
try {
|
String sLookFeel = ConfigUtils.getConfigValue("LookAndFeel");
|
if (!sLookFeel.isEmpty() && !sLookFeel.equals("LookAndFeel"))
|
VCISwingUtil.setLookAndFeel(sLookFeel);
|
else
|
VCISwingUtil.setLookAndFeel();
|
|
JFrame.setDefaultLookAndFeelDecorated(true);
|
JDialog.setDefaultLookAndFeelDecorated(true);
|
//设置主题
|
//SubstanceLookAndFeel.setCurrentTheme(new SubstanceEbonyTheme());
|
//设置按钮外观
|
//SubstanceLookAndFeel.setCurrentButtonShaper(new ClassicButtonShaper());
|
|
//VCISwingUtil.setLookAndFeel(VCISwingUtil.LOOK_AND_FEEL_PlasticLookAndFeel);
|
//VCISwingUtil.setLookAndFeel(VCISwingUtil.LOOK_AND_FEEL_WindowsLookAndFeel);
|
//VCISwingUtil.setLookAndFeel(VCISwingUtil.LOOK_AND_FEEL_AlloyLookAndFeel);
|
//VCISwingUtil.setLookAndFeel(VCISwingUtil.LOOK_AND_FEEL_NimbusLookAndFeel);
|
//VCISwingUtil.setLookAndFeel(VCISwingUtil.LOOK_AND_FEEL_MetalLookAndFeel);
|
//VCISwingUtil.setLookAndFeel("org.pushingpixels.substance.api.SubstanceBusinessBlackSteelLookAndFeel");
|
//VCISwingUtil.setLookAndFeel();
|
String intUserName = "";
|
String taskType = "";
|
String taskId = "";
|
String codes = "";
|
if(argsInput.length >0){
|
// 从传入的参数中,解析出集成用户,参数信息 intUser_XXX
|
String[] innerName = argsInput[0].split("_");
|
if(innerName!=null && innerName.length==2){
|
for(int i = 0; i < innerName.length; i++){
|
String arg = innerName[i];
|
if(arg.trim().equals("intUser")){
|
if((i+1)<innerName.length){
|
intUserName = innerName[i+1];
|
}
|
}
|
}
|
}
|
if (argsInput.length >= 2) {
|
urlBasePath = argsInput[1];
|
}
|
}
|
if(argsInput.length > 2){
|
//从传入的参数中,解析出流程任务类型表示,参数信息 taskType_xxx
|
String[] taskTypeArgs = argsInput[1].split("_");
|
if(taskTypeArgs!=null && taskTypeArgs.length==2){
|
for(int i = 0; i < taskTypeArgs.length; i++){
|
String arg = taskTypeArgs[i];
|
if(arg.trim().equals("taskType")){
|
if((i+1)<taskTypeArgs.length){
|
taskType = getTaskTypeByProcessMark(taskTypeArgs[i+1]);
|
}
|
}
|
}
|
}
|
//从传入的参数中,解析出流程任务ID,参数信息taskId_xxx
|
String[] taskIdArgs = argsInput[2].split("_");
|
if(taskIdArgs!=null && taskIdArgs.length==2){
|
for(int i = 0; i < taskIdArgs.length; i++){
|
String task = taskIdArgs[i];
|
if(task.trim().equals("taskId")){
|
if((i+1)<taskIdArgs.length){
|
taskId = taskIdArgs[i+1];
|
}
|
}
|
}
|
}
|
|
// add by xchao 2013.05.20 begin
|
// for 014
|
// 代码申请,最后 的完成事件中会将申请成功的代码发送给申请人员(通过创建待办通知的方式)
|
// 当申请人员查阅了申请到的代码后,需要执行‘已阅知’,将待办任务从协同平台中删除
|
// 以下代码是配合‘向申请人员发送代码’使用的
|
// 以下代码的书写,是建立在‘待办任务回调URL地址中的参数书写是有顺序的’
|
String[] viewCodeArgs = argsInput[3].split("_");
|
if(viewCodeArgs != null && viewCodeArgs.length == 2){
|
String param = viewCodeArgs[0];
|
String value = viewCodeArgs[1];
|
if("ViewCode".equals(param) && "true".equals(value)){
|
// 发送这个待办时,taskId传递的就是全部的CODE,通过逗号分隔
|
codes = taskId;
|
}
|
}
|
// add by xchao 2013.05.20 end
|
|
}
|
//System.out.println("innerName = "+intUserName+" taskType = "+taskType +" taskId = "+taskId);
|
boolean isLoginSecurity = new SystemCfgClientDelegate(new UserEntityObject("", "")).getConfigValue("logon.Security").equalsIgnoreCase("true");
|
|
if(!intUserName.equals("")){
|
UserObject userObj = new RightManagementClientDelegate().getUserObjectByUserName(intUserName);
|
|
if(userObj != null){
|
if(codes != null && !"".equals(codes)){
|
// 查看代码的窗口
|
final String codess = codes;
|
VCISwingUtil.invokeLater(new Runnable() {
|
@Override
|
public void run() {
|
new ViewCodeFrame(codess).setVisible(true);
|
}
|
}, 0);
|
} else if(!(taskType != null && taskType.equals("") && taskId != null && taskId.equals(""))){
|
String[] message = new String[]{"任务箱",taskType,"待办任务",taskId};
|
setContextInfo(userObj);
|
new LogonApplication(userObj,message);
|
}else{
|
setContextInfo(userObj);
|
new LogonApplication(userObj);
|
}
|
}else if (!isLoginSecurity){
|
showLoginFrame();
|
}
|
} else if (!isLoginSecurity){
|
showLoginFrame();
|
}
|
}catch (VCIException e){
|
System.out.println(LocaleDisplay.getI18nString(e.getException_code(), "RMIPFramework", Locale.getDefault()));
|
}catch (Exception e) {
|
e.printStackTrace();
|
}
|
}
|
});
|
}
|
|
private static void setContextInfo(UserObject userObj){
|
RightManagementClientDelegate rmcd = new RightManagementClientDelegate();
|
UserInfo userInfo = rmcd.changeUserObjectToUserInfo(userObj);
|
ClientInfo clientInfo = new ClientInfo();
|
clientInfo.setIp(getLocalIP());
|
try{
|
rmcd.initContextInfo(userInfo, clientInfo);
|
}catch(VCIException e){
|
e.printStackTrace();
|
VCIJOptionPane.showConfirm(null, "设置客户端上下文信息时发生错误!\n" + e.toString());
|
}
|
}
|
|
/**
|
* 根据流程类型确定流程任务类别
|
* <p>Description: </p>
|
*
|
* @time 2013-4-26
|
* @param taskType 流程标示
|
* @return
|
*/
|
private static String getTaskTypeByProcessMark(String taskType){
|
Map<String, String> map = new HashMap<String, String>();
|
map.put("ADD", "申请任务");
|
map.put("BATCHAPPLY", "申请任务");
|
map.put("EDIT", "更改任务");
|
map.put("DELETE", "删除任务");
|
map.put("FREEZE", "停用任务");
|
map.put("UNFREZE", "启用任务");
|
String result= map.get(taskType);
|
return result;
|
}
|
|
/****
|
* 重新登陆时调用该构造
|
*
|
* @param s
|
* 传递一个空的字符串即可
|
*/
|
public LogonApplication() {
|
show(new String[]{});
|
}
|
// public static void setTaskMessage(String[] taskMessage) {
|
// taskMessage = taskMessage;
|
// }
|
|
private static void showLoginFrame() {
|
LogonFrame logonFrame = new LogonFrame();
|
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
|
Dimension dialogSize = logonFrame.getPreferredSize();
|
logonFrame.setLocation((screenSize.width - dialogSize.width) / 2, (screenSize.height - dialogSize.height) / 2);
|
logonFrame.setVisible(true);
|
}
|
}
|