1 package hero.client.manager; 2 3 24 25 import hero.util.BonitaClient; 26 import hero.client.events.JMSServicesClient; 27 28 import java.awt.Container ; 29 import java.awt.Dimension ; 30 import java.awt.GridLayout ; 31 import java.awt.event.WindowAdapter ; 32 import java.awt.event.WindowEvent ; 33 import java.util.Iterator ; 34 import java.util.Collection ; 35 import java.util.ArrayList ; 36 import java.awt.Color ; 37 38 import javax.swing.JComboBox ; 39 import javax.swing.JFrame ; 40 import javax.swing.JLabel ; 41 import javax.swing.JOptionPane ; 42 import javax.swing.JPanel ; 43 import javax.swing.JPasswordField ; 44 import javax.swing.JTextField ; 45 import javax.swing.SwingConstants ; 46 import javax.swing.ImageIcon ; 47 import java.awt.Toolkit ; 48 49 public class Manager extends JPanel { 50 51 static java.util.ResourceBundle resource = java.util.ResourceBundle.getBundle("resources.Traduction"); 52 53 String url = null, host = null; 54 int port; 55 String userName = null; 56 String userPassword = null; 57 Collection projects = new ArrayList (); 58 JProjectList projectList = null; 59 final JFrame p = new JFrame (); 60 BonitaClient soapclient; 61 public final static String imageBase = "images/"; 62 public final static ImageIcon icon = new ImageIcon (Thread.currentThread().getContextClassLoader().getResource(imageBase + "icon.png")); 63 64 public Manager(String userName, String userPassword) throws Exception { 65 66 this.userName = userName; 67 this.userPassword = userPassword; 68 69 url = System.getProperty("bonita.host"); 71 72 host = url.substring(7); 73 int point = host.indexOf(":"); 74 url = host; 75 this.host = host.substring(0,point); 76 int portPoint = url.indexOf("/"); 77 if (portPoint != -1) 78 this.port = new Integer (url.substring(point+1,portPoint)).intValue(); else 80 this.port = new Integer (url.substring(point+1)).intValue(); 82 BonitaClient soapclient = new BonitaClient(host, port, "/bonita_ws/services/"); 83 soapclient.login(userName, userPassword); 84 this.soapclient = soapclient; 85 buildView(); 86 } 87 88 public void buildView() throws Exception { 89 String subscription = "(event = 'addUserProject' AND userName = '" + this.userName + "')" + " OR"; 90 91 Collection allProjects = soapclient.getProjects(); 92 Iterator i = allProjects.iterator(); 93 while (i.hasNext()) 94 { 95 String name = (String ) i.next(); 96 subscription = subscription + " projectName = '" + name + "' OR"; 97 if (!name.matches(".*_instance.*")) 98 this.projects.add(name); 99 } 100 101 MListener ml = MListener.getInstance(this.userName, this.userPassword, this.host, this.port); 102 ml.subscription(subscription.substring(0, subscription.length() - 3)); 103 projectList = new JProjectList(this.soapclient, ml, this.projects); 104 projectList.setBackground(new Color (177,177,251)); 105 JTodoList todoList = new JTodoList(this.soapclient, ml); 106 todoList.setBackground(new Color (177,177,251)); 107 JActivityList activityList = new JActivityList(this.soapclient, ml); 108 activityList.setBackground(new Color (177,177,251)); 109 110 projectList.addPropertyChangeListener(JProjectList.SELECTED, todoList); 111 projectList.addPropertyChangeListener(JProjectList.SELECTED, activityList); 112 113 java.net.URL iconUrl = Thread.currentThread().getContextClassLoader().getResource(imageBase + "icon.png"); 114 p.setIconImage(Toolkit.getDefaultToolkit().getImage(iconUrl)); 115 116 hero.client.manager.Menubar menubar = new hero.client.manager.Menubar(this); 117 menubar.setBackground(new Color (153, 153, 255)); 118 p.setJMenuBar(menubar); 119 Container c = p.getContentPane(); 120 c.setLayout(new GridLayout (3, 1)); 121 c.add(projectList); 122 c.add(todoList); 123 c.add(activityList); 124 125 p.addWindowListener(new WindowAdapter () { 126 public void windowClosing(WindowEvent e) { 127 try { 128 JMSServicesClient jms = JMSServicesClient.getInstance(); 129 jms.closeConnection(); 130 System.exit(0); 131 } catch (Exception ex) { 132 } 133 } 134 }); 135 136 p.setSize(new Dimension (150, 400)); 137 138 p.setTitle(resource.getString("manager.activity") + userName); 139 p.pack(); 140 p.show(); 141 } 142 143 public void CloneProject() { 144 JPanel jp = new JPanel (); 145 146 Object [] possibleValues = this.projects.toArray(); 147 JComboBox projectNames = new JComboBox (possibleValues); 148 jp.setLayout(new GridLayout (0, 2)); 149 jp.add(new JLabel (resource.getString("manager.choose"), SwingConstants.LEFT)); 150 jp.add(projectNames); 151 152 JTextField newProject = new JTextField ("", 0); 153 jp.setLayout(new GridLayout (0, 2)); 154 jp.add(new JLabel (resource.getString("manager.create.name2"), SwingConstants.LEFT)); 155 jp.add(newProject); 156 157 int cloneOption = JOptionPane.showConfirmDialog(null, jp, resource.getString("manager.create.clone"), JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE,icon); 158 if (cloneOption != JOptionPane.CANCEL_OPTION) { 159 while ((newProject.getText()).equals("") && cloneOption != JOptionPane.CANCEL_OPTION) { 160 JOptionPane.showMessageDialog(null,resource.getString("manager.create.name"),resource.getString("manager.create.clone"),JOptionPane.INFORMATION_MESSAGE,icon); 161 cloneOption = JOptionPane.showConfirmDialog(null, jp, resource.getString("manager.create.clone"), JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE,icon); 162 } 163 if (cloneOption != JOptionPane.CANCEL_OPTION) { 164 try { 165 if (exists(newProject.getText())) { 166 JOptionPane.showMessageDialog(null,resource.getString("manager.create.exist"),resource.getString("manager.create.clone"),JOptionPane.INFORMATION_MESSAGE,icon); 167 } else{ 168 soapclient.cloneProject((String ) projectNames.getSelectedItem(), newProject.getText()); 169 this.projects.clear(); 170 Collection allProjects = soapclient.getProjects(); 171 Iterator i = allProjects.iterator(); 172 while (i.hasNext()) 173 { 174 String name = (String ) i.next(); 175 if (!name.matches(".*_instance.*")) 176 this.projects.add(name); 177 } 178 } 179 } catch (Exception e) { 180 e.printStackTrace(); 181 JOptionPane.showMessageDialog(null,resource.getString("manager.create.exist"),resource.getString("manager.create.clone"),JOptionPane.INFORMATION_MESSAGE,icon); 182 } 183 } 184 } 185 } 186 187 public void InstantiateProject() { 188 JPanel jp = new JPanel (); 189 190 Object [] possibleValues = this.projects.toArray(); 191 JComboBox projectNames = new JComboBox (possibleValues); 192 jp.setLayout(new GridLayout (0, 2)); 193 jp.add(new JLabel (resource.getString("manager.choose"), SwingConstants.LEFT)); 194 jp.add(projectNames); 195 196 int instOption = JOptionPane.showConfirmDialog(null, jp, resource.getString("manager.create.inst"), JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE,icon); 197 if (instOption != JOptionPane.CANCEL_OPTION) { 198 try { 199 soapclient.instantiateProject((String ) projectNames.getSelectedItem()); 200 this.projects.clear(); 201 Collection allProjects = soapclient.getProjects(); 202 Iterator i = allProjects.iterator(); 203 while (i.hasNext()) 204 { 205 String name = (String ) i.next(); 206 if (!name.matches(".*_instance.*")) 207 this.projects.add(name); 208 } 209 } catch (Exception e) { 210 e.printStackTrace(); 211 JOptionPane.showMessageDialog(null,resource.getString("manager.inst.error")+", "+e.getMessage(),resource.getString("manager.create.inst"),JOptionPane.INFORMATION_MESSAGE,icon); 212 } 213 } 214 } 215 216 private boolean exists(String project) { 217 try { 218 Object [] elems = this.projects.toArray(); 219 for (int i = 0; i < elems.length; i++) { 220 if (((String ) elems[i]).equalsIgnoreCase(project)) 221 return true; 222 } 223 return false; 224 } catch (Exception e) { 225 e.printStackTrace(); 226 } 227 return true; 228 } 229 230 public void NewProject() { 231 projectList.newProject(); 232 } 233 234 235 static public void main(String [] args) { 236 boolean exit = false; 237 String userName = null; 238 String userPassword = null; 239 240 if (System.getProperty("user.login") != null && System.getProperty("user.password") != null) { 241 try { 242 userName = System.getProperty("user.login"); 243 char[] password = System.getProperty("user.password").toCharArray(); 244 userPassword = new String (password); 245 new Manager(userName, userPassword); 246 } catch (Exception e) { 247 JOptionPane.showMessageDialog(null,resource.getString("manager.login.failed"),resource.getString("manager.login.login"),JOptionPane.INFORMATION_MESSAGE,icon); 248 System.exit(0); 249 } 250 } else { 251 while (!exit) { 252 JPanel jp = new JPanel (); 253 254 JTextField login = new JTextField ("", 0); 255 jp.setLayout(new GridLayout (0, 2)); 256 jp.add(new JLabel (resource.getString("manager.login.login"), SwingConstants.LEFT)); 257 jp.add(login); 258 259 JPasswordField passwd = new JPasswordField ("", 0); 260 jp.setLayout(new GridLayout (0, 2)); 261 jp.add(new JLabel (resource.getString("manager.login.password"), SwingConstants.LEFT)); 262 jp.add(passwd); 263 264 try { 265 if (System.getProperty("user.login") != null && System.getProperty("user.password") != null) { 266 userName = System.getProperty("user.login"); 267 char[] password = System.getProperty("user.password").toCharArray(); 268 userPassword = new String (password); 269 new Manager(userName, userPassword); 270 exit = true; 271 } else { 272 273 int option = JOptionPane.showConfirmDialog(null, jp, resource.getString("manager.login"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE,icon); 274 if (option != JOptionPane.CANCEL_OPTION) { 275 while (((login.getText()).equals("") || (passwd.getPassword()).length == 0) && option != JOptionPane.CANCEL_OPTION) { 276 JOptionPane.showMessageDialog(null,null,resource.getString("manager.login.relogin"),JOptionPane.QUESTION_MESSAGE,icon); 277 option = JOptionPane.showConfirmDialog(null, jp, resource.getString("manager.login"), JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE,icon); 278 } 279 if (option != JOptionPane.CANCEL_OPTION) { 280 userName = (String ) login.getText(); 281 char[] password = passwd.getPassword(); 282 userPassword = new String (password); 283 new Manager(userName, userPassword); 284 exit = true; 285 } else 286 System.exit(0); 287 } else 288 System.exit(0); 289 } 290 } catch (Exception e) { 291 JOptionPane.showMessageDialog(null,resource.getString("manager.login.failed")+": "+e.getMessage(),resource.getString("manager.login.login"),JOptionPane.QUESTION_MESSAGE,icon); 292 exit = false; 293 } 294 } 295 } 296 } 297 } 298 299 300 | Popular Tags |