⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 usermgreditui.java

📁 《j2ee开发全程实录》随书源码
💻 JAVA
字号:
package com.cownew.PIS.base.permission.client;

import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import javax.swing.DefaultListModel;
import javax.swing.Icon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JScrollPane;
import javax.swing.JTextField;

import com.cownew.PIS.base.permission.common.IPermissionService;
import com.cownew.PIS.base.permission.common.IUserDAO;
import com.cownew.PIS.base.permission.common.UserInfo;
import com.cownew.PIS.base.permission.common.UserPermissionItemInfo;
import com.cownew.PIS.basedata.common.IPersonDAO;
import com.cownew.PIS.framework.client.RemoteServiceLocator;
import com.cownew.PIS.framework.common.db.Selectors;
import com.cownew.PIS.framework.common.exception.PISException;

import com.cownew.PIS.ui.base.ExceptionHandler;
import com.cownew.PIS.ui.commonUI.EditUI;
import com.cownew.PIS.ui.ctrl.prompt.OVPicker.PopupValueObjectPicker;
import com.cownew.PIS.ui.utils.PISAbstractAction;
import com.cownew.ctk.ui.swing.BeanListCellRenderer;
import com.cownew.ctk.ui.swing.MsgBox;

public class UserMgrEditUI extends EditUI
{

	private JLabel jLabel;

	private JTextField txtNumber;

	private JLabel jLabel2 = null;

	private PopupValueObjectPicker dpPerson;

	private JList listPermission;

	private JLabel jLabel3;

	private JButton btnDistribute;

	private JButton btnUnDistribute;

	private JList listOtherPerm;

	private JLabel jLabel4;

	private ActionDistribute actionDistribute;

	private ActionUnDistribute actionUnDistribute;

	private JScrollPane jScrollPane;

	private JScrollPane jScrollPane1;

	public UserMgrEditUI() throws Exception
	{
		super();

	}

	protected void initAction()
	{
		super.initAction();
		actionDistribute = new ActionDistribute("<");
		actionUnDistribute = new ActionUnDistribute(">");
	}

	protected void initDataBind()
	{
		super.initDataBind();
		dataBinder.registerBind(txtNumber, "number");
		dataBinder.registerBind(dpPerson, "person");
	}

	/**
	 * This method initializes this
	 * 
	 */
	protected void initialize()
	{
		super.initialize();
		jLabel4 = new JLabel();
		jLabel4.setBounds(new Rectangle(274, 105, 91, 16));
		jLabel4.setText("未分配权限");
		jLabel3 = new JLabel();
		jLabel3.setBounds(new Rectangle(17, 107, 53, 16));
		jLabel3.setText("权限");
		jLabel2 = new JLabel();
		jLabel2.setBounds(new Rectangle(16, 83, 51, 16));
		jLabel2.setText("对应人员");
		jLabel = new JLabel();
		jLabel.setBounds(new Rectangle(17, 21, 48, 16));
		jLabel.setText("用户名");
		this.setLayout(null);
		this.setSize(new Dimension(476, 221));
		this.add(jLabel, null);
		this.add(getTxtNumber(), null);
		this.add(jLabel2, null);
		this.add(getDpPerson(), null);
		this.add(jLabel3, null);
		this.add(getBtnDistribute(), null);
		this.add(getBtnUnDistribute(), null);
		this.add(jLabel4, null);
		this.add(getJScrollPane(), null);
		this.add(getJScrollPane1(), null);

		getBtnDistribute().setAction(actionDistribute);
		getBtnUnDistribute().setAction(actionUnDistribute);

	}

	public void loadToUI()
	{
		try
		{
			IPermissionService ps = (IPermissionService) RemoteServiceLocator
					.getRemoteService(IPermissionService.class);
			Set permSet = ((UserInfo) modelVO).getPermissions();

			if (permSet == null)
			{
				permSet = new HashSet();
			}

			fillPermList(permSet);
			fillOtherPermList(permSet, ps.getAllPermissionItem());
		} catch (PISException e)
		{
			ExceptionHandler.handle(e);
		}
		super.loadToUI();

	}

	public Selectors getSelectors()
	{
		Selectors s = new Selectors();
		s.add("person");
		s.add("permissions");
		return s;
	}

	private void fillOtherPermList(Set permSet, List allPermList)
	{
		// 根据用户目前被分配的权限,构造一个权限名set,以优化后边的判断逻辑
		Set permNameSet = new HashSet();
		Iterator permNameIt = permSet.iterator();
		while (permNameIt.hasNext())
		{
			UserPermissionItemInfo permItemInfo = (UserPermissionItemInfo) permNameIt
					.next();
			permNameSet.add(permItemInfo.getPermName());
		}

		DefaultListModel listModel = new DefaultListModel();

		for (int i = 0, n = allPermList.size(); i < n; i++)
		{
			String permName = (String) allPermList.get(i);
			if (!permNameSet.contains(permName))
			{
				//两个列表中储存的都是UserPermissionItemInfo 所以要做一下转换
				UserPermissionItemInfo pItemInfo = new UserPermissionItemInfo();
				pItemInfo.setPermName(permName);
				listModel.addElement(pItemInfo);
			}
		}
		getListOtherPerm().setModel(listModel);
	}

	private void fillPermList(Set permSet)
	{
		DefaultListModel listModel = new DefaultListModel();

		Iterator it = permSet.iterator();
		while (it.hasNext())
		{
			UserPermissionItemInfo permInfo = (UserPermissionItemInfo) it
					.next();
			listModel.addElement(permInfo);
		}
		getListPermission().setModel(listModel);
	}

	public void storeToVO() throws Exception
	{
		super.storeToVO();
		DefaultListModel listModelPerm = (DefaultListModel) listPermission
				.getModel();
		Enumeration en = listModelPerm.elements();
		Set newPItemInfoSet = new HashSet();
		while (en.hasMoreElements())
		{
			UserPermissionItemInfo pItemInfo = (UserPermissionItemInfo) en
					.nextElement();
			pItemInfo.setHead((UserInfo) modelVO);
			newPItemInfoSet.add(pItemInfo);
		}

		((UserInfo) modelVO).setPermissions(newPItemInfoSet);
	}

	protected void actionUnDistribute_actionPerformed(ActionEvent e)
			throws Exception
	{
		Object[] itemToUnDis = listPermission.getSelectedValues();
		if (itemToUnDis.length <= 0)
		{
			MsgBox.showError(this, "请选择要回收的权限!");
			return;
		}

		DefaultListModel listModelOther = (DefaultListModel) listOtherPerm
				.getModel();
		DefaultListModel listModelPerm = (DefaultListModel) listPermission
				.getModel();
		for (int i = 0, n = itemToUnDis.length; i < n; i++)
		{
			UserPermissionItemInfo userItemInfo = (UserPermissionItemInfo) itemToUnDis[i];
			userItemInfo.setHead(null);
			listModelOther.addElement(userItemInfo);
			listModelPerm.removeElement(userItemInfo);
		}

	}

	protected void actionDistribute_actionPerformed(ActionEvent e)
			throws Exception
	{
		Object[] itemToDis = listOtherPerm.getSelectedValues();
		if (itemToDis.length <= 0)
		{
			MsgBox.showError(this, "请选择要分配的权限!");
			return;
		}

		DefaultListModel listModelOther = (DefaultListModel) listOtherPerm
				.getModel();
		DefaultListModel listModelPerm = (DefaultListModel) listPermission
				.getModel();
		for (int i = 0, n = itemToDis.length; i < n; i++)
		{

			Object obj = itemToDis[i];
			listModelPerm.addElement(obj);
			listModelOther.removeElement(obj);
		}
	}

	/**
	 * This method initializes txtNumber	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getTxtNumber()
	{
		if (txtNumber == null)
		{
			txtNumber = new JTextField();
			txtNumber.setBounds(new Rectangle(71, 21, 175, 21));
		}
		return txtNumber;
	}

	public Class getServiceIntfClass()
	{
		return IUserDAO.class;
	}

	/**
	 * This method initializes dpPerson	
	 * 	
	 * @return com.cownew.PIS.ui.ctrl.prompt.OVPicker.PopupValueObjectPicker	
	 */
	private PopupValueObjectPicker getDpPerson()
	{
		if (dpPerson == null)
		{
			dpPerson = new PopupValueObjectPicker(IPersonDAO.class);
			dpPerson.setDisplayProperty("name");
			dpPerson.setBounds(new Rectangle(71, 83, 175, 20));
		}
		return dpPerson;
	}

	/**
	 * This method initializes listPermission	
	 * 	
	 * @return javax.swing.JList	
	 */
	private JList getListPermission()
	{
		if (listPermission == null)
		{
			listPermission = new JList();
			listPermission
					.setCellRenderer(new BeanListCellRenderer("permName"));
		}
		return listPermission;
	}

	/**
	 * This method initializes btnDistribute	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getBtnDistribute()
	{
		if (btnDistribute == null)
		{
			btnDistribute = new JButton();
			btnDistribute.setBounds(new Rectangle(229, 130, 42, 16));
			btnDistribute.setText("<");
		}
		return btnDistribute;
	}

	/**
	 * This method initializes btnUnDistribute	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getBtnUnDistribute()
	{
		if (btnUnDistribute == null)
		{
			btnUnDistribute = new JButton();
			btnUnDistribute.setBounds(new Rectangle(229, 180, 42, 16));
			btnUnDistribute.setText(">");
		}
		return btnUnDistribute;
	}

	/**
	 * This method initializes listOtherPerm	
	 * 	
	 * @return javax.swing.JList	
	 */
	private JList getListOtherPerm()
	{
		if (listOtherPerm == null)
		{
			listOtherPerm = new JList();
			listOtherPerm.setCellRenderer(new BeanListCellRenderer("permName"));
		}
		return listOtherPerm;
	}

	protected class ActionDistribute extends PISAbstractAction
	{

		public ActionDistribute(String name, Icon icon)
		{
			super(name, icon);

		}

		public ActionDistribute(String name)
		{
			super(name);

		}

		public void onActionPerformed(ActionEvent e) throws Exception
		{
			actionDistribute_actionPerformed(e);
		}

	}

	protected class ActionUnDistribute extends PISAbstractAction
	{

		public ActionUnDistribute(String name, Icon icon)
		{
			super(name, icon);

		}

		public ActionUnDistribute(String name)
		{
			super(name);

		}

		public void onActionPerformed(ActionEvent e) throws Exception
		{
			actionUnDistribute_actionPerformed(e);
		}

	}

	/**
	 * This method initializes jScrollPane	
	 * 	
	 * @return javax.swing.JScrollPane	
	 */
	private JScrollPane getJScrollPane()
	{
		if (jScrollPane == null)
		{
			jScrollPane = new JScrollPane();
			jScrollPane.setBounds(new Rectangle(17, 125, 182, 82));
			jScrollPane.setViewportView(getListPermission());
		}
		return jScrollPane;
	}

	/**
	 * This method initializes jScrollPane1	
	 * 	
	 * @return javax.swing.JScrollPane	
	 */
	private JScrollPane getJScrollPane1()
	{
		if (jScrollPane1 == null)
		{
			jScrollPane1 = new JScrollPane();
			jScrollPane1.setBounds(new Rectangle(282, 130, 182, 75));
			jScrollPane1.setViewportView(getListOtherPerm());
		}
		return jScrollPane1;
	}

} //  @jve:decl-index=0:visual-constraint="10,10"

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -