package com.vci.client.workflow.editor.user; import java.awt.BorderLayout; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.List; import javax.swing.BoxLayout; import javax.swing.DefaultListModel; import javax.swing.JButton; import javax.swing.JComponent; import javax.swing.JList; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.ListSelectionModel; 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.swing.VCIOptionPane; import com.vci.common.resource.CommonProperties; import com.vci.corba.common.VCIError; public class FowardUserComponent extends UserPanel { private static final long serialVersionUID = -990618910839831914L; private JPanel userComponent; private JList list; private DefaultListModel listModel; public FowardUserComponent() { setLayout(new BorderLayout(0, 0)); userComponent = new JPanel(); add(userComponent); GridBagLayout gbl_panel_3 = new GridBagLayout(); userComponent.setLayout(gbl_panel_3); JScrollPane scrollPane = new JScrollPane(); GridBagConstraints gbc_scrollPane = new GridBagConstraints(); gbc_scrollPane.weighty = 1.0; gbc_scrollPane.weightx = 1.0; gbc_scrollPane.fill = GridBagConstraints.BOTH; gbc_scrollPane.anchor = GridBagConstraints.CENTER; gbc_scrollPane.insets = new Insets(0, 0, 0, 5); gbc_scrollPane.gridx = 0; gbc_scrollPane.gridy = 0; userComponent.add(scrollPane, gbc_scrollPane); listModel = new DefaultListModel(); list = new JList(listModel); scrollPane.setViewportView(list); JPanel panel = new JPanel(); GridBagConstraints gbc_panel = new GridBagConstraints(); gbc_panel.fill = GridBagConstraints.BOTH; gbc_panel.gridx = 1; gbc_panel.gridy = 0; userComponent.add(panel, gbc_panel); panel.setLayout(new BorderLayout(0, 0)); JPanel panel_1 = new JPanel(); panel.add(panel_1, BorderLayout.WEST); panel_1.setLayout(new BoxLayout(panel_1, BoxLayout.Y_AXIS)); JButton btnNewButton = new JButton("添加"); btnNewButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionevent) { selectUser(); } }); panel_1.add(btnNewButton); JButton btnNewButton_1 = new JButton("删除"); btnNewButton_1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionevent) { int selectedIndex = list.getSelectedIndex(); if (selectedIndex == -1) { VCIOptionPane.showMessage(LogonApplication.frame, "请选择记录"); return; } Object elementAt = listModel.getElementAt(selectedIndex); // idList.remove(elementAt.getId()); listModel.remove(selectedIndex); list.setSelectedIndex(selectedIndex - 1); list.updateUI(); } }); panel_1.add(btnNewButton_1); } private void selectUser() { String userDialogControl = CommonProperties.getStringProperty("workflow.UserDialog"); if(userDialogControl!=null&&!"".equals(userDialogControl)){ Class cls; try { cls = Class.forName(userDialogControl); CustomUserDialog res = (CustomUserDialog) cls.getConstructor(UserPanel.class).newInstance(this); res.setLocationRelativeTo(null); res.setVisible(true); if(interFaceResult!=null&&!"".equals(interFaceResult)){ listModel.removeAllElements(); listModel.addElement(interFaceResult); } } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (SecurityException e) { e.printStackTrace(); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } catch (NoSuchMethodException e) { e.printStackTrace(); } }else{ FowardUser fowardUser = new FowardUser(); fowardUser.getList().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); fowardUser.setLocationRelativeTo(null); fowardUser.setVisible(true); List userObjectlist = fowardUser.getUserObjectlist(); if (userObjectlist != null) { for (UserObject userObject : userObjectlist) { listModel.removeAllElements(); if(!listModel.contains(userObject)) { listModel.addElement(userObject); } } } } } public JComponent getUserComponent() { return userComponent; } /* * 获取已选择的用户信息 * @see com.vci.rmip.workflow.client.editor.user.IUserComponent#getSelectedUsers() */ public List getSelectedUsers() { List list = new ArrayList(); int size = listModel.size(); for (int i = 0; i < size; i++) { Object elementAt = listModel.getElementAt(i); if(elementAt instanceof String){ list.add((String) elementAt); }else if(elementAt instanceof UserObject){ UserObject userObject = (UserObject) elementAt; list.add(userObject.getUserName()); } } return list; } public void setSelectedUsers(List users) { listModel.removeAllElements(); try { for (String userName : users) { UserObject user = new RightManagementClientDelegate(LogonApplication.getUserEntityObject()).fetchUserInfoByName(userName); if (!"".equals(user.getUserName())){ listModel.addElement(user); } } } catch (VCIException e) { e.printStackTrace(); } } public List getSelectedRoles() { // TODO Auto-generated method stub return null; } public List getSelectedDepts() { // TODO Auto-generated method stub return null; } public String getSelectedCust() { // TODO Auto-generated method stub return null; } public void setSelectedRoles(List roles) { // TODO Auto-generated method stub } public void setSelectedDepts(List depts) { // TODO Auto-generated method stub } public void setSelectedCust(String cust) { // TODO Auto-generated method stub } public JComponent getUserComponent(CustomEditPanel customUserPanel) { return getUserComponent(); } public List getSelectedUserDepartment() { // TODO Auto-generated method stub return null; } public List getSelectedUserRole() { // TODO Auto-generated method stub return null; } public List getSelectedUserOrg() { // TODO Auto-generated method stub return null; } public List getSelectedUserLine() { // TODO Auto-generated method stub return null; } public List getSelectedDeptAddUser() { // TODO Auto-generated method stub return null; } public void setSelectedUserDepartment(List users) { // TODO Auto-generated method stub } public void setSelectedUserRole(List users) { // TODO Auto-generated method stub } public void setSelectedUserDept(List users) { // TODO Auto-generated method stub } public void setSelectedUserLine(List users) { // TODO Auto-generated method stub } public void setSelectedDeptAndUser(List users) { // TODO Auto-generated method stub } }