package com.vci.client.workflow.editor.custom; import java.awt.BorderLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.HashMap; import java.util.Map; import javax.swing.ComboBoxModel; import javax.swing.DefaultComboBoxModel; import javax.swing.DefaultListModel; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.JList; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.SwingUtilities; import javax.swing.border.TitledBorder; import com.vci.client.LogonApplication; 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.locale.LocaleDisplay; import com.vci.client.ui.swing.VCIOptionPane; import com.vci.client.workflow.delegate.ProcessCustomClientDelegate; import com.vci.client.workflow.template.object.ProcessCategoryObject; import com.vci.client.workflow.template.object.ProcessDefinitionObject; import com.vci.corba.common.VCIError; /** * This code was edited or generated using CloudGarden's Jigloo * SWT/Swing GUI Builder, which is free for non-commercial * use. If Jigloo is being used commercially (ie, by a corporation, * company or business for any purpose whatever) then you * should purchase a license for each developer using Jigloo. * Please visit www.cloudgarden.com for details. * Use of Jigloo implies acceptance of these licensing terms. * A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR * THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED * LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE. */ public class TaskListDialog extends javax.swing.JDialog { private JPanel taskListPanel; private JPanel userListPanel; private JComboBox taskComb; private JList userList; private JButton addBtn; private JButton removeBtn; private JList choiceUserList; private JScrollPane choceUserListPanel; private JButton cancel; private JButton ok; private JScrollPane jScrollPane; private JPanel btnPanel; private Map tempMap = new HashMap(); public Map getTempMap() { return tempMap; } public void setTempMap(Map tempMap) { this.tempMap = tempMap; } /** * Auto-generated main method to display this JDialog */ public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { JFrame frame = new JFrame(); TaskListDialog inst = new TaskListDialog(frame); inst.setVisible(true); } }); } public TaskListDialog(JFrame frame) { super(frame); initGUI(); } private void initGUI() { try { BorderLayout thisLayout = new BorderLayout(); getContentPane().setLayout(thisLayout); { taskListPanel = new JPanel(); taskListPanel.setBorder(new TitledBorder("任务列表")); getContentPane().add(taskListPanel, BorderLayout.NORTH); taskListPanel.setPreferredSize(new java.awt.Dimension(515, 88)); { ProcessCustomClientDelegate pcd = new ProcessCustomClientDelegate(); //TODO--此位置以后替换为页面选择模板来选择 ProcessCategoryObject[] processCategories = pcd.getProcessCategories("root"); ProcessDefinitionObject[] processDefinitions = pcd.getProcessDefinitions(processCategories[0].getId()); String[] allTaskNames = pcd.getAllTaskNames(processDefinitions[0].getJbpmDeploymentId()); ComboBoxModel taskCombModel = new DefaultComboBoxModel(allTaskNames); taskComb = new JComboBox(); taskListPanel.add(taskComb); taskComb.setModel(taskCombModel); taskComb.setPreferredSize(new java.awt.Dimension(359, 24)); taskComb.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Object selectedItem = taskComb.getSelectedItem(); UserObject[] userList = (UserObject[]) tempMap.get(selectedItem); DefaultListModel selectListModel = (DefaultListModel) choiceUserList.getModel(); selectListModel.removeAllElements(); if(userList!=null){ for (int i = 0; i < userList.length; i++) { selectListModel.addElement(userList[i]); } }else{ try { initUser(); } catch (VCIException e1) { e1.printStackTrace(); } } } }); } } { userListPanel = new JPanel(); userListPanel.setBorder(new TitledBorder("处理人列表")); getContentPane().add(userListPanel, BorderLayout.CENTER); userListPanel.setPreferredSize(new java.awt.Dimension(515, 210)); userListPanel.setLayout(null); { jScrollPane = new JScrollPane(); userListPanel.add(jScrollPane); jScrollPane.setBounds(66, 27, 155, 216); { initUser(); } } { choceUserListPanel = new JScrollPane(); userListPanel.add(choceUserListPanel); choceUserListPanel.setBounds(313, 30, 149, 210); { DefaultListModel choiceUserListModel = new DefaultListModel(); choiceUserList = new JList(); choceUserListPanel.setViewportView(choiceUserList); choiceUserList.setModel(choiceUserListModel); } } { addBtn = new JButton(); userListPanel.add(addBtn); addBtn.setText(">>"); addBtn.setBounds(232, 74, 62, 24); addBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Object[] objs = userList.getSelectedValues(); if ((objs == null) || (objs.length == 0)) { VCIOptionPane.showMessageDialog(LogonApplication.frame, LocaleDisplay.getI18nString("rmip.stafforg.operate.toselectrole", "RMIPFramework", getLocale())); return; } int len = objs.length; UserObject[] addUserInfo = new UserObject[len]; for (int i = 0; i < len; i++) { addUserInfo[i] = (UserObject)objs[i]; } DefaultListModel selectListModel = (DefaultListModel) choiceUserList.getModel(); DefaultListModel allListModel = (DefaultListModel) userList.getModel(); int size = selectListModel.getSize(); for (int i = 0; i < size; i++) { UserObject entity = (UserObject) selectListModel.getElementAt(i); for (int j = 0; j < len; j++) { if (entity.getId().equals(addUserInfo[j].getId())) { VCIOptionPane.showMessageDialog(LogonApplication.frame, LocaleDisplay.getI18nString("rmip.stafforg.operate.toreselectrole", "RMIPFramework", getLocale())); return; } } } for (int i = 0; i < len; i++) { selectListModel.addElement(addUserInfo[i]); allListModel.removeElement(addUserInfo[i]); } Object selectedItem = taskComb.getSelectedItem(); tempMap.put(selectedItem,addUserInfo); } }); } { removeBtn = new JButton(); userListPanel.add(removeBtn); removeBtn.setText("<<"); removeBtn.setBounds(232, 144, 62, 24); removeBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Object[] objs = choiceUserList.getSelectedValues(); if ((objs == null) || (objs.length == 0)) { VCIOptionPane.showMessageDialog(LogonApplication.frame, LocaleDisplay.getI18nString("rmip.stafforg.operate.toremoverole", "RMIPFramework", getLocale())); return; } int len = objs.length; UserObject[] deleteUserInfo = new UserObject[len]; for (int i = 0; i < len; i++) { deleteUserInfo[i] = (UserObject)objs[i]; } DefaultListModel listModel = (DefaultListModel) choiceUserList.getModel(); DefaultListModel allListModel = (DefaultListModel) userList.getModel(); for (int i = 0; i < listModel.size(); i++) { UserObject entity = (UserObject) listModel.getElementAt(i); for (int j = 0; j < len; j++) { if (entity.getId().equals(deleteUserInfo[j].getId())) { listModel.removeElement(entity); allListModel.addElement(entity); i--; break; } } } Object selectedItem = taskComb.getSelectedItem(); tempMap.put(selectedItem,deleteUserInfo); } }); } } { btnPanel = new JPanel(); getContentPane().add(btnPanel, BorderLayout.SOUTH); btnPanel.setPreferredSize(new java.awt.Dimension(515, 53)); { ok = new JButton(); btnPanel.add(ok); ok.setText("确定"); ok.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { } }); } { cancel = new JButton(); btnPanel.add(cancel); cancel.setText("取消"); cancel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { dispose(); } }); } } this.setSize(531, 431); } catch (Exception e) { e.printStackTrace(); } } /** * 初始化用户 * @throws VCIError * @throws VCIException */ private void initUser() throws VCIException { RightManagementClientDelegate rmc = new RightManagementClientDelegate(); UserObject[] fetchUserInfo = rmc.fetchUserInfo(); DefaultListModel userListModel = new DefaultListModel(); for(UserObject uo:fetchUserInfo){ userListModel.addElement(uo); } userList = new JList(); jScrollPane.setViewportView(userList); userList.setModel(userListModel); } }