package com.vci.client.uif.engine.client; import java.awt.BorderLayout; import java.awt.Component; import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.LinkedHashMap; import java.util.LinkedList; 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.ui.exception.VCIException; import com.vci.client.ui.swing.VCIOptionPane; import com.vci.client.ui.swing.VCISwingUtil; import com.vci.client.ui.swing.components.VCIJButton; import com.vci.client.ui.swing.components.VCIJDialog; import com.vci.client.ui.swing.components.VCIJPanel; import com.vci.client.ui.swing.components.table.AbstractVCIJTableDataProvider; import com.vci.client.ui.swing.components.table.VCIJTableNode; import com.vci.client.ui.swing.components.table.VCIJTablePanel; import com.vci.mw.ClientContextVariable; public class SelectorUserDialog extends VCIJDialog{ private VCIJButton btnOk = VCISwingUtil.createVCIJButton("ok", "确定", "确定", "accept.png"); private VCIJButton btnCancel = VCISwingUtil.createVCIJButton("cancel", "取消", "取消", "cancel.png"); private String gprnode; private UserObject userObject; public UserObject getUserObject() { return userObject; } public void setUserObject(UserObject userObject) { this.userObject = userObject; } private UserEntityObject userEntityObj = null; private Component parentComponent = null; public SelectorUserDialog(Component parentComponent,String gprnode){ super(ClientContextVariable.getFrame(), true); this.gprnode = gprnode; this.userEntityObj = new UserEntityObject( ClientContextVariable.getInvocationInfo().userName, ClientContextVariable.getInvocationInfo().clientIPInfo); init(); setSize(UIHelper.DIALOG_DEFAULT_WIDTH, UIHelper.DIALOG_DEFAULT_HEIGHT); this.parentComponent = parentComponent; setLocationRelativeTo(parentComponent); setVisible(true); } public void init(){ setLayout(new BorderLayout()); this.setTitle("选择负责人"); add(tablePanel(), BorderLayout.CENTER); initAction();//初始化按钮点击事件 } private LinkedList selfCustomButtons = new LinkedList(); { selfCustomButtons.add(btnOk); selfCustomButtons.add(btnCancel); } MyDataProvider dataProvider = new MyDataProvider(); VCIJTablePanel tablePanel = new VCIJTablePanel(dataProvider); private VCIJPanel tablePanel(){ int startIndex = dataProvider.getDataColumnStartIndex()+5; LinkedHashMap widthMaps = new LinkedHashMap(); widthMaps.put(startIndex++, 250);widthMaps.put(startIndex++, 250);widthMaps.put(startIndex++, 250); widthMaps.put(startIndex++, 250);widthMaps.put(startIndex++, 250); tablePanel.setColumnWidthMaps(widthMaps); tablePanel.setCustomButtons(selfCustomButtons); tablePanel.setShowPaging(true); tablePanel.setCustomButtonFlowAlign(FlowLayout.CENTER); tablePanel.setPageButtonFlowAlign(FlowLayout.CENTER); tablePanel.setShowExport(false); tablePanel.buildTablePanel(); tablePanel.refreshTableData(); return tablePanel; } class MyDataProvider extends AbstractVCIJTableDataProvider{ UserObject[] selectUserObjs = null; @Override public UserObject[] getDatas(int arg0, int arg1) { if(gprnode == null || gprnode.trim().equals("")){ try { selectUserObjs = new RightManagementClientDelegate(userEntityObj).fetchUserInfoWithOutSanYuan(); } catch (VCIException e) { e.printStackTrace(); VCIOptionPane.showError(parentComponent, "RMIPFramework", e); return null; } } else { try { selectUserObjs = new RightManagementClientDelegate(userEntityObj).getUserByDeptId(gprnode); } catch (VCIException e) { // TODO Auto-generated catch block e.printStackTrace(); VCIOptionPane.showError(parentComponent,"RMIPFramework", e); } } // TODO Auto-generated method stub return selectUserObjs; } @Override public VCIJTableNode getNewRowNode(UserObject dataObj) { // TODO Auto-generated method stub VCIJTableNode node = new VCIJTableNode(dataObj); node.setPropertyValue(getSpecialColumns()[0], dataObj.getTrueName()); node.setPropertyValue(getSpecialColumns()[1], dataObj.getUserName()); node.setPropertyValue(getSpecialColumns()[2], dataObj.getStatus()==1 ? "停用":"启用"); node.setPropertyValue(getSpecialColumns()[3], dataObj.getDesc()); return node; } @Override public String[] getSpecialColumns() { // TODO Auto-generated method stub return "姓名, 账号, 状态, 描述".split(","); } @Override public int getTotal() { // TODO Auto-generated method stub return selectUserObjs.length; } } private void initAction(){ btnCancel.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub cancelButton_ActionPerformed(e); } }); btnOk.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub addButton_ActionPerformed(); } }); } /** * 确认按钮事件 *

Description:

* @author heyj * @time 2014-3-25 */ private void addButton_ActionPerformed(){ int len = tablePanel.getSelectedRowIndexs().length; if(len == 0){ VCIOptionPane.showMessage(this, "请选择人员再进行操作!"); return; } if (len > 1){ VCIOptionPane.showMessage(this, "一次只能选择一个人员进行操作"); return; } UserObject obj = tablePanel.getSelectedRowObjects().get(0); setDialogResult(DialogResult.OK); this.setUserObject(obj); this.dispose(); } /** * 取消按钮事件 * @param e */ private void cancelButton_ActionPerformed(ActionEvent e) { setDialogResult(DialogResult.CANCEL); this.userObject = null; this.dispose(); } }