1 package org.enhydra.shark.swingclient.workflowadmin.worklist; 2 3 import java.awt.*; 4 import java.awt.event.*; 5 import java.util.*; 6 7 import javax.swing.*; 8 9 10 11 import org.enhydra.shark.api.client.wfmodel.*; 12 import org.enhydra.shark.swingclient.*; 13 import org.enhydra.shark.swingclient.workflowadmin.*; 14 import org.enhydra.shark.swingclient.workflowadmin.user.*; 15 import org.enhydra.shark.swingclient.workflowadmin.worklist.actions.*; 16 import org.enhydra.shark.swingclient.worklist.*; 17 18 25 public class WorklistManagement extends ActionPanel { 26 private static Dimension comboFieldDimension=new Dimension(200,20); 27 28 private SharkAdmin workflowAdmin; 29 private Worklist worklist; 30 private JComboBox users; 31 private JLabel isLogged=new JLabel(); 32 private ActionListener usersAL; 34 35 private ArrayList existingUsers=new ArrayList(); 36 37 public WorklistManagement (SharkAdmin wa) { 38 super(); 39 this.workflowAdmin=wa; 41 42 super.init(); 43 44 add(createControlPanel(),BorderLayout.NORTH,0); 45 } 46 47 protected void createActions () { 48 defaultActions=new Action[] { 49 new ReassignWorkitem(this) 50 }; 51 } 52 53 protected Component createCenterComponent () { 54 worklist=new Worklist(workflowAdmin,false); 55 return worklist; 56 } 57 58 public SharkAdmin getWorkflowAdmin () { 59 return workflowAdmin; 60 } 61 62 public Worklist getWorklist () { 63 return worklist; 64 } 65 66 private Component createControlPanel () { 67 JPanel p=new JPanel(); 68 p.setBorder(BorderFactory.createEmptyBorder(10,10,10,10)); 69 p.setLayout(new BoxLayout(p,BoxLayout.X_AXIS)); 70 71 p.add(new JLabel(ResourceManager.getLanguageDependentString("SelectUserKey")+": ")); 72 73 users=new JComboBox(); 74 users.setMinimumSize(new Dimension(comboFieldDimension)); 75 users.setMaximumSize(new Dimension(comboFieldDimension)); 76 users.setPreferredSize(new Dimension(comboFieldDimension)); 77 usersAL=new ActionListener() { 78 public void actionPerformed(ActionEvent ae) { 79 WfResource choosen=getResource(users.getSelectedItem()); 80 worklist.setResource(choosen); 81 92 if (choosen==null) { 93 isLogged.setText(""); 94 } else { 95 LoggedUsersManagement lum=workflowAdmin. 96 getUserManagement().getLoggedUsersManagement(); 97 String uname=null; 98 try { 99 uname=choosen.resource_key(); 100 } catch (Exception ex) {} 101 if (lum.isLogged(uname)) { 102 isLogged.setText(" ---> "+ 103 ResourceManager.getLanguageDependentString("LoggedKey")); 104 } else { 105 isLogged.setText(" ---> "+ 106 ResourceManager.getLanguageDependentString("NotLoggedKey")); 107 } 108 } 109 } 110 }; 111 users.addActionListener(usersAL); 112 p.add(users); 113 114 p.add(isLogged); 115 116 JButton reassign=(JButton)BarFactory. 117 createButton(Utils.getUnqualifiedClassName(ReassignWorkitem.class),commands,true); 118 JPanel bp=new JPanel(); 119 bp.setLayout(new BorderLayout()); 120 bp.add(reassign,BorderLayout.EAST); 121 122 p.add(bp); 123 124 return p; 125 } 126 127 public void clear () { 128 existingUsers.clear(); 129 users.removeActionListener(usersAL); 130 users.removeAllItems(); 131 users.addActionListener(usersAL); 132 isLogged.setText(""); 133 worklist.clear(); 134 } 135 136 public synchronized void refresh (boolean mandatoryRefreshing) { 137 if (!(mandatoryRefreshing || isShowing())) return; 138 ArrayList oldEU=new ArrayList(existingUsers); 139 existingUsers.clear(); 140 try { 141 existingUsers=new ArrayList(Arrays.asList(SharkAdmin.getExecAmin().get_sequence_resource(0))); 142 } catch (Exception ex) { 143 ex.printStackTrace(); 144 } 145 146 ArrayList toAdd=new ArrayList(existingUsers); 147 toAdd.removeAll(oldEU); 148 ArrayList toRemove=new ArrayList(oldEU); 149 toRemove.removeAll(existingUsers); 150 151 if (toAdd.size()>0 || toRemove.size()>0) { 152 String toSelectId=null; 154 try { 155 toSelectId=worklist.getResource().resource_key(); 156 } catch (Exception ex) {} 157 158 users.removeActionListener(usersAL); 160 users.removeAllItems(); 162 Iterator it=existingUsers.iterator(); 163 while (it.hasNext()) { 164 WfResource res=(WfResource)it.next(); 165 try { 166 users.addItem(res.resource_key()); 167 } catch (Exception ex) {} 168 } 169 users.setSelectedItem(toSelectId); 170 Object selItem=users.getSelectedItem(); 171 if ((selItem!=null) && (!selItem.equals(toSelectId))) { 172 worklist.setResource(getResource(selItem)); 173 } else { 174 worklist.refresh(); 175 } 176 185 users.addActionListener(usersAL); 187 } else { 188 worklist.refresh(); 189 } 190 } 191 192 private WfResource getResource (Object key) { 193 if (key==null) return null; 194 String un=(String )key; 195 Iterator it=existingUsers.iterator(); 196 while (it.hasNext()) { 197 WfResource res=(WfResource)it.next(); 198 try { 199 if (res.resource_key().equals(un)) { 200 return res; 201 } 202 } catch (Exception ex) {} 203 } 204 return null; 205 } 206 207 } 208 | Popular Tags |