本文主要是介绍用友nc手动注册功能节点以及弹窗JDialog并实现其功能(二次登录总结),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
用友nc手动注册功能节点以及弹窗JDialog并实现其功能(二次登录总结)
一、要实现的功能:如下图,点击二次登录,弹窗,可以选择服务中心,选择服务中心后在主面板可以显示不同的信息。
二、实现步骤:
1、首先我们需要在客户端生成一个节点出来,以往是使用元数据生成向导,这个按照需求来说需要手动生成。生成功能节点步骤如下:
1.1 如图找到功能节点注册按钮,我们手动注册一个功能节点。
1.2在进入菜单注册里面进行注册。
1.3功能注册里面要注意的入口类也就是功能类名一定要注意路径。这也是点击节点后最先调用的代码。
1.4:再到职责里面去分配权限 这3步完成后就会出现一个二次登录的功能节点了。接下来我就需要在入口类写源代码了。
2:源代码结构图:
2.1 ClientUI代码
<span style="font-size:18px;">package nc.ui.pr.H30301;import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.SimpleDateFormat;
import java.util.Date;import nc.desktop.ui.WorkbenchEnvironment;
import nc.sfbase.client.ClientToolKit;
import nc.ui.fdc_crmbd.h3h055.refmodel.ManagementsecRefModel;
import nc.ui.ml.NCLangRes;
import nc.ui.pub.beans.MessageDialog;
import nc.ui.pub.beans.UIButton;
import nc.ui.pub.beans.UIDialog;
import nc.ui.pub.beans.UILabel;
import nc.ui.pub.beans.UIPanel;
import nc.ui.pub.beans.UIRefPane;
import nc.vo.ml.IProductCode;
import nc.vo.org.GroupVO;
import nc.vo.pubapp.AppContext;
import nc.vo.sm.UserVO;public class ClientUI extends UIDialog implements ActionListener {/****/private static final long serialVersionUID = 1L;private UIRefPane m_manageunit;private UILabel m_label1;private UIPanel m_uipanel;@SuppressWarnings("unused")private String m_userid;private UIButton m_btnOk;private UIButton m_btnClose;@SuppressWarnings("deprecation")public ClientUI() {}public ClientUI(Container parent) {super(parent);initialize();}public static void main(String[] args) {ClientUI dialog = new ClientUI(ClientToolKit.getApplet());// 标题dialog.setTitle("二次登录界面");// 设置dialog大小Dimension ds = new Dimension(300, 130);dialog.setSize(ds);// 获取屏幕大小Dimension dsScreen = Toolkit.getDefaultToolkit().getScreenSize();// 设置弹窗位置dialog.setLocation((dsScreen.width - ds.width) / 2,(dsScreen.height - ds.height) / 2);// 显示dialogdialog.setVisible(true);}public void actionPerformed(ActionEvent e) {Object oSource = e.getSource();if (oSource instanceof UIButton) {if (oSource == getUIButtonOK()) {onLogon();} else if (oSource == getUIButtonClose()) {closeCancel();}}}/*** * * @功能说明:获取名称 “服务中心”或者“管理处”* @return*/private String getUnitName() {return "服务中心";}private UIRefPane getManageUnit() {if (m_manageunit == null) {m_manageunit = new UIRefPane();m_manageunit.setRefModel(new ManagementsecRefModel());m_manageunit.setBounds(152, 5, 100, 22);}return m_manageunit;}private UIPanel getUIPanel() {if (m_uipanel == null) {m_uipanel = new UIPanel();m_uipanel.setLayout(null);m_uipanel.setSize(294, 81);m_uipanel.add(getUILabel1(), null);m_uipanel.add(getManageUnit(), null);}return m_uipanel;}private void onLogon() {try {if (getManageUnit().getRefPK() == null) {if (LogonBO_Client.getManageUnit() != null) {closeFrame(false);LogonBO_Client.removeManageUnit();closeOK();clearTopBar();} else {MessageDialog.showWarningDlg(getContentPane(), null,"请选择要的服务中心");return;}} else {if (LogonBO_Client.getManageUnit() != null&& !getManageUnit().getRefPK().equals(LogonBO_Client.getManageUnit())) {closeFrame(true);}// 核算单位二次登录LogonBO_Client.setManageUnit(getManageUnit().getRefPK());closeOK();updateTopBar();}} catch (Exception ex) {MessageDialog.showWarningDlg(this, "错误", "登录失败");nc.bs.logging.Logger.error(ex.getMessage(), ex);}}private void closeFrame(boolean isSwatch) {if (!closeOpenMainframe(isSwatch)) {closeOK();MessageDialog.showErrorDlg(this, "错误", "关闭已打开窗口出错,请重试!");return;}}public void clearTopBar() {}public void updateTopBar() {String centerName = getManageUnit().getText();AppContext.getInstance().getPkGroup().toString();String userName = WorkbenchEnvironment.getInstance().getLoginUser().getUser_code();String date = WorkbenchEnvironment.getInstance().getBusiDate().toString();SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");// 拿到当前登录公司名称GroupVO corpName = WorkbenchEnvironment.getInstance().getGroupVO();String msg = corpName+ " ( "+ centerName+ " )"+ userName+ nc.ui.ml.NCLangRes.getInstance().getStrByID("sysframev5","UPPsysframev5-000022")/* @res ", 您好! " */+ sdf.format(new Date());// 0001221000000000002B ( 123 )nc11, 您好!2016-10-09 16:52:20javax.swing.JLabel lab = WorkbenchEnvironment.getInstance().getWorkbench().getWorkbenchTopPanel().getInfoLabel();lab.setText(msg);}private boolean closeOpenMainframe(boolean isSwatch) {return true;}private UILabel getUILabel1() {if (m_label1 == null) {m_label1 = new UILabel(getUnitName());m_label1.setBounds(28, 7, 116, 18);m_label1.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);m_label1.setILabelType(0/** Java默认(自定义) */);}return m_label1;}/*** 初始化类。*//* 警告:此方法将重新生成。 */private void initialize() {UserVO loginUser = WorkbenchEnvironment.getInstance().getLoginUser();// 当前登录用户m_userid = loginUser.getCuserid();getContentPane().setLayout(new BorderLayout());getUIPanel().add(getUILabel1(), "label1");getUIPanel().add(getManageUnit(), "uirefpane1");getContentPane().add(getUIPanel(), "Center");UIPanel panSouth = new UIPanel();panSouth.add(getUIButtonOK());panSouth.add(getUIButtonClose());getContentPane().add(panSouth, "South");getManageUnit().setPK(LogonBO_Client.getManageUnit());}private UIButton getUIButtonOK() {if (m_btnOk == null) {m_btnOk = new UIButton(NCLangRes.getInstance().getStrByID(IProductCode.PRODUCTCODE_COMMON, "UC001-0000044")+ "(O)");// "确定(O)");m_btnOk.addActionListener(this);m_btnOk.setMnemonic('O');m_btnOk.setName("ok");}return m_btnOk;}private UIButton getUIButtonClose() {if (m_btnClose == null) {m_btnClose = new UIButton(NCLangRes.getInstance().getStrByID(IProductCode.PRODUCTCODE_COMMON, "UC001-0000008")+ "(X)");// "取消(X)");m_btnClose.addActionListener(this);m_btnClose.setMnemonic('X');m_btnClose.setName("close");}return m_btnClose;}
}
</span>
2.2 LogonBO_Client代码:
<span style="font-size:18px;">package nc.ui.pr.H30301;import nc.desktop.ui.WorkbenchEnvironment;import org.apache.commons.lang.StringUtils;public class LogonBO_Client {public static String MANAGEUNIT = "MANAGEUNIT";public static void setManageUnit(String pk_manageunit) throws Exception {// 改为用环境变量缓存WorkbenchEnvironment.getInstance().putClientCache(MANAGEUNIT, pk_manageunit);}public static String getManageUnit() {try {String result = (String) WorkbenchEnvironment.getInstance().getClientCache(MANAGEUNIT);return result;} catch (Exception ex) {return "";}}public static void removeManageUnit() throws Exception {// 改为用环境变量缓存WorkbenchEnvironment.getInstance().removeClientCache(MANAGEUNIT);}public static boolean isManageLoad() {boolean isManageLoad = false;if (StringUtils.isEmpty(getManageUnit())) {isManageLoad = true;}return isManageLoad;}
}
</span>
3:至此,点击客户端的二次登录会弹出一个窗口了。接下来看看怎么在客户端主面板上端添加文字。
3.1 在源代码nc.desktop.ui.Workbench这个类里面把add(getWorkbenchSpace(), BorderLayout.CENTER);这句代码注释启动客户端你将会发现客户端变成这样了
3.2能够找到这个面板,那么我们再在他上面加文字就不难了。重写nc.desktop.ui.WorkbenchTopPanel方法:
<span style="font-size:18px;">package nc.desktop.ui;import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.Insets;
import java.text.SimpleDateFormat;
import java.util.Date;import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;import nc.bs.logging.Logger;
import nc.desktop.quickcode.QuickCodePanel;
import nc.ui.format.NCFormater;
import nc.ui.ml.NCLangRes;
import nc.uitheme.ui.ThemeResourceCenter;
import nc.vo.ml.MultiLangContext;
import nc.vo.org.GroupVO;
import nc.vo.pub.format.exception.FormatException;
import nc.vo.pubapp.AppContext;
import nc.vo.sm.UserVO;public class WorkbenchTopPanel extends JPanel {private static final long serialVersionUID = 7391914363822534372L;private ImageIcon logoIcon = null;private ImageIcon bgIcon = null;private WorkbenchSysFuncBtnsPanel sysFuncBtnsPanel = null;private QuickCodePanel quickCodePanel = null;private JLabel welComeLabel = null;private JLabel infoLabel = null;private JPanel contentPanel = null;private Color textColor = new Color(0x8888ff);public WorkbenchTopPanel() {super();initialize();}private void initialize() {setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 10));setPreferredSize(new Dimension(300, 57));logoIcon = ThemeResourceCenter.getInstance().getImage("themeres/control/desktop/logo.png");if (logoIcon == null) {logoIcon = ThemeResourceCenter.getInstance().getImage("themeres/workbench_logo/desktop/logo.png");// SkinManageCenter.getInstance().getImageIcon("workbench","WorkbenchTopPanel.logoIcon");//ClientToolKit.loadImageIcon("images/workbench6x/ufida-nc-logo.png");}bgIcon = ThemeResourceCenter.getInstance().getImage("themeres/control/desktop/title_bg.png");// SkinManageCenter.getInstance().getImageIcon("workbench","WorkbenchTopPanel.bgIcon");//CClientToolKit.loadImageIcon("images/workbench6x/topbar-bg.png");if (WorkbenchEnvironment.getInstance().isSuperAdm()) {add(getSysFuncBtnsPanel());add(getWelComeLabel());}add(getQuickCodePanel());// 搜索框add(getInfoLabel());// 二次登录显示框add(getContentPanel());}public static String getTopString() {WorkbenchEnvironment env = WorkbenchEnvironment.getInstance();StringBuilder sb = new StringBuilder();UserVO user = env.getLoginUser();if (user != null) {String userName = null;if (!env.isSuperAdm()) {int langSeq = MultiLangContext.getInstance().getCurrentLangSeq();switch (langSeq) {case 1:userName = user.getUser_name();break;case 2:userName = user.getUser_name2();break;case 3:userName = user.getUser_name3();break;case 4:userName = user.getUser_name4();break;case 5:userName = user.getUser_name5();break;case 6:userName = user.getUser_name6();break;default:userName = user.getUser_name();break;}}if (userName == null) {userName = user.getUser_name();}sb.append(userName).append(NCLangRes.getInstance().getStrByID("loginui","loginuires-000006")/* ,您好! */);}try {if (env.isSuperAdm()) {SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");sb.append(sdf.format(new Date())).append(" ");} else {sb.append(NCFormater.formatDate(new Date()).getValue()).append(" ");}} catch (FormatException e) {SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");sb.append(sdf.format(new Date())).append(" ");Logger.error(e.getMessage(), e);}return sb.toString();}/*** 位置分配*/@Overridepublic void doLayout() {Insets insets = getInsets();Dimension size = getSize();Dimension qcpSize = getQuickCodePanel().getPreferredSize();int qcpY = 20;if (getSysFuncBtnsPanel().getParent() == this) {Dimension sfbpSize = getSysFuncBtnsPanel().getPreferredSize();int x = size.width - insets.right - sfbpSize.width;int alignY = insets.top + sfbpSize.height / 2;getSysFuncBtnsPanel().setBounds(x, insets.top, sfbpSize.width,sfbpSize.height);Dimension wclblSize = getWelComeLabel().getPreferredSize();int y = alignY - wclblSize.height / 2;x -= wclblSize.width + 20;getWelComeLabel().setBounds(x, y, wclblSize.width, wclblSize.height);qcpY = size.height - insets.bottom - qcpSize.height;}getQuickCodePanel().setBounds(size.width - insets.right - qcpSize.width, qcpY, qcpSize.width,qcpSize.height);// 公司信息位置设置getInfoLabel().setBounds(150, qcpY, 600, 50);int h = getContentPanel().getPreferredSize().height;getContentPanel().setBounds(insets.left,size.height - insets.bottom - h,size.width - insets.left - insets.right - qcpSize.width, h);}public void paintComponent(Graphics g) {super.paintComponent(g);int w = getSize().width;int h = getSize().height;if (bgIcon != null) {g.drawImage(bgIcon.getImage(), 0, 0, w, h, this);}if (logoIcon != null) {int imgH = logoIcon.getIconHeight();int y = (h - imgH) / 2;logoIcon.paintIcon(this, g, 20, y);}}private WorkbenchSysFuncBtnsPanel getSysFuncBtnsPanel() {if (sysFuncBtnsPanel == null) {sysFuncBtnsPanel = new WorkbenchSysFuncBtnsPanel();}return sysFuncBtnsPanel;}private JLabel getWelComeLabel() {if (welComeLabel == null) {welComeLabel = new JLabel(getTopString());Color welcomeLblForegroundColor = textColor;welComeLabel.setForeground(welcomeLblForegroundColor);welComeLabel.setOpaque(false);}return welComeLabel;}/*** zl 公司信息显示框* * @return*/public JLabel getInfoLabel() {if (infoLabel == null) {AppContext.getInstance().getPkGroup().toString();String userName = WorkbenchEnvironment.getInstance().getLoginUser().getUser_code();SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");// 拿到当前登录公司名称String name = AppContext.getInstance().getPkGroup();String name2 = AppContext.getInstance().getPkUser();GroupVO corpName = WorkbenchEnvironment.getInstance().getGroupVO();String msg = corpName+ userName+ nc.ui.ml.NCLangRes.getInstance().getStrByID("sysframev5","UPPsysframev5-000022") + sdf.format(new Date());infoLabel = new JLabel(msg);infoLabel.setForeground(Color.white);infoLabel.setFont(new java.awt.Font("Microsoft YaHei UI Light", 1,12));// Microsoft YaHei UI Light是字体 1代表样式(1是粗体,0是平常的)12是字号}return infoLabel;}private JPanel getContentPanel() {if (contentPanel == null) {contentPanel = new JPanel() {private static final long serialVersionUID = -7461272101443590629L;@Overridepublic Dimension getPreferredSize() {Insets insets = getInsets();Dimension d = super.getPreferredSize();synchronized (getTreeLock()) {Component[] childs = getComponents();int count = childs == null ? 0 : childs.length;int maxH = 0;for (int i = 0; i < count; i++) {Component component = childs[i];Dimension compSize = component.getPreferredSize();if (compSize.height > maxH) {maxH = compSize.height;}}d.height = insets.top + maxH + insets.bottom;}return d;}};contentPanel.setOpaque(false);contentPanel.setLayout(new FlowLayout(FlowLayout.CENTER, 2, 0));}return contentPanel;}private QuickCodePanel getQuickCodePanel() {if (quickCodePanel == null) {quickCodePanel = new QuickCodePanel();}return quickCodePanel;}void addCompToContentPanel(Component comp) {getContentPanel().add(comp);invalidate();validate();}void removeCompFromContentPanel(Component comp) {getContentPanel().remove(comp);invalidate();validate();}
}
</span>
3.3:在源代码中我添加了add(getInfoLabel());然后对其进行位置分配。下图是要显示的内容: 3.4:至此:登录客户端就会出现相关信息。但是需求是要在切换不同服务中心时还要进行改变。这是我们就得回到ClientUI代码中来了:
3.5:这段代码的重点在于红框中的如何拿到WorkbenchTopPanel里面的lable。至此,基本功能就完成。
三、总结:用友的框架还是帮我们做了很多事情,对于新手来说很多时候根本就不知道他为我们做的事情,还是会用很原生的思想去改他。需要的是多了解他的常用类,然后一步一步分解。刚开始追源代码的时候比追女孩子还用心,问题是还没追到。有时候需要换个角度思考问题,多和其他人交流,当局者迷旁观者清。
这篇关于用友nc手动注册功能节点以及弹窗JDialog并实现其功能(二次登录总结)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!