1 package hero.client.grapheditor; 2 3 11 12 import java.awt.*; 13 import java.util.*; 14 15 import hero.net.ProjectSession.StrutsNodeValue; 16 import hero.interfaces.Constants; 17 import javax.swing.JComboBox ; 18 import javax.swing.JFrame ; 19 import javax.swing.JLabel ; 20 import javax.swing.JOptionPane ; 21 import javax.swing.JPanel ; 22 import javax.swing.JScrollPane ; 23 import javax.swing.JTextField ; 24 import javax.swing.JTextArea ; 25 import javax.swing.SwingConstants ; 26 import java.text.SimpleDateFormat ; 27 import javax.swing.JCheckBox ; 28 import javax.swing.ImageIcon ; 29 30 public class WFWindowManager implements Constants{ 31 32 static java.util.ResourceBundle resource = java.util.ResourceBundle.getBundle("resources.Traduction"); 33 34 WFManager manager; 35 WFPersistence persistence; 36 public final static String imageBase = "images/"; 37 public final static ImageIcon icon = new ImageIcon (Thread.currentThread().getContextClassLoader().getResource(imageBase + "icon.png")); 38 39 public String newProjectWindow() { 40 try { 41 JPanel jp = new JPanel (); 42 ArrayList types = new ArrayList(); 43 types.add("Model"); 44 types.add("Cooperative"); 45 JComboBox processTypes = new JComboBox (types.toArray()); 46 processTypes.setSelectedItem("Model"); 47 48 JTextField projectName = new JTextField (); 49 jp.add(new JLabel (resource.getString("wfwindowsmanager.newproj"), SwingConstants.LEFT)); 50 jp.add(projectName); 51 52 jp.setLayout(new GridLayout(0, 2)); 53 jp.add(new JLabel (resource.getString("wfwindowsmanager.choosetype"), SwingConstants.LEFT)); 54 jp.add(processTypes); 55 56 int cloneOption =JOptionPane.showConfirmDialog(null,jp,resource.getString("wfwindowsmanager.newproj"),JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE, icon); 57 if (cloneOption != JOptionPane.CANCEL_OPTION) { 58 while ((projectName.getText()).equals("") 59 && cloneOption != JOptionPane.CANCEL_OPTION) { 60 JOptionPane.showMessageDialog(null,resource.getString("wfwindowsmanager.enterproj"),resource.getString("wfwindowsmanager.newproj"),JOptionPane.INFORMATION_MESSAGE, icon); 61 cloneOption =JOptionPane.showConfirmDialog(null,jp,resource.getString("wfwindowsmanager.newproj"),JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE, icon); 62 } 63 if (cloneOption != JOptionPane.CANCEL_OPTION) { 64 boolean ok = false; 65 if (processTypes.getSelectedItem().equals("Model")) 66 ok =persistence.createModel(projectName.getText()); 67 else 68 ok = persistence.createProject(projectName.getText()); 69 if (!ok) { 70 JOptionPane.showMessageDialog(null,resource.getString("wfwindowsmanager.existproj"),resource.getString("wfwindowsmanager.newproj"),JOptionPane.INFORMATION_MESSAGE, icon); 71 72 } else { 73 manager.setTitle(projectName.getText()); 74 return projectName.getText(); 75 } 76 } 77 } 78 } catch (Exception e1) { 79 JOptionPane.showMessageDialog(null,resource.getString("wfwindowsmanager.createerror"),resource.getString("wfwindowsmanager.newproj"),JOptionPane.INFORMATION_MESSAGE, icon); 80 } 81 return null; 82 } 83 84 public WFWindowManager(WFManager manager, WFPersistence persistence) { 85 this.manager = manager; 86 this.persistence = persistence; 87 } 88 89 public boolean cloneProjectWindow() { 90 try { 91 JPanel jp = new JPanel (); 92 Object [] possibleValues = persistence.getProjects(); 93 JComboBox projectNames = new JComboBox (possibleValues); 94 jp.setLayout(new GridLayout(0, 2)); 95 jp.add(new JLabel (resource.getString("wfwindowsmanager.chooseproj"), SwingConstants.LEFT)); 96 jp.add(projectNames); 97 98 JTextField newProject = new JTextField ("", 0); 99 jp.setLayout(new GridLayout(0, 2)); 100 jp.add(new JLabel (resource.getString("wfwindowsmanager.projname"), SwingConstants.LEFT)); 101 jp.add(newProject); 102 103 int cloneOption =JOptionPane.showConfirmDialog(null,jp,resource.getString("wfwindowsmanager.cloneproj"),JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE, icon); 104 if (cloneOption != JOptionPane.CANCEL_OPTION) { 105 while ((newProject.getText()).equals("") 106 && cloneOption != JOptionPane.CANCEL_OPTION) { 107 JOptionPane.showMessageDialog(null,resource.getString("wfwindowsmanager.enterproj"),resource.getString("wfwindowsmanager.cloneproj"),JOptionPane.INFORMATION_MESSAGE, icon); 108 cloneOption =JOptionPane.showConfirmDialog(null,jp,resource.getString("wfwindowsmanager.cloneproj"),JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE, icon); 109 } 110 if (cloneOption != JOptionPane.CANCEL_OPTION) { 111 boolean ok =persistence.cloneProject((String ) projectNames.getSelectedItem(),newProject.getText()); 112 if (!ok) { 113 JOptionPane.showMessageDialog(null,resource.getString("wfwindowsmanager.existproj"),resource.getString("wfwindowsmanager.cloneproj"),JOptionPane.INFORMATION_MESSAGE, icon); 114 } else { 115 manager.openProject(newProject.getText()); 116 return true; 117 } 118 } 119 } 120 } catch (Exception e1) { 121 JOptionPane.showMessageDialog(null,resource.getString("wfwindowsmanager.cloneerror"),resource.getString("wfwindowsmanager.cloneproj"),JOptionPane.INFORMATION_MESSAGE, icon); 122 } 123 return false; 124 } 125 126 public void openProject() { 127 try { 128 Object [] values = persistence.getProjects(); 129 Object selectedValue = JOptionPane.showInputDialog(null,resource.getString("wfwindowsmanager.graphedit"),resource.getString("wfwindowsmanager.openproj"),JOptionPane.INFORMATION_MESSAGE,icon,values,values[0]); 130 if (selectedValue != null) { 131 manager.openProject((String ) selectedValue); 132 } 133 } catch (Exception e1) { 134 JOptionPane.showMessageDialog(null, resource.getString("wfwindowsmanager.openerror"),resource.getString("wfwindowsmanager.openproj"),JOptionPane.INFORMATION_MESSAGE, icon); 135 } 136 } 137 138 public void editNode(String nodeName) { 139 140 String result = null; 141 JPanel jp = new JPanel (); 142 try { 143 persistence.setProjectNodes(); 144 StrutsNodeValue nl = persistence.getProjectNode(nodeName); 145 GridBagLayout gridbag = new GridBagLayout(); 146 GridBagConstraints c = new GridBagConstraints(); 147 jp.setLayout(gridbag); 148 149 c.fill = GridBagConstraints.BOTH; 150 c.weightx = 1.0; 151 152 jp.add(new JLabel (resource.getString("wfwindowsmanager.deadline"))); 153 DateComboBox dcb = new DateComboBox(); 154 SimpleDateFormat df = new SimpleDateFormat ("yyyy-MM-dd"); 155 SimpleDateFormat dateFormat = new SimpleDateFormat ("MMM dd,yyyy"); 156 if (persistence.getDeadline(nodeName) != null) 157 dcb.setSelectedItem(dateFormat.format(df.parse(nl.getDeadline().toString()))); 158 159 dcb.setEditable(true); 160 jp.add(dcb); 161 gridbag.setConstraints(dcb, c); 162 c.gridwidth = GridBagConstraints.REMAINDER; 163 164 c.weightx = 1.0; 165 Object [] possibleRoles = persistence.getRoles(); 166 JComboBox roles = new JComboBox (possibleRoles); 167 roles.setSelectedItem(persistence.getRole(nodeName)); 168 jp.add(new JLabel (resource.getString("wfwindowsmanager.selectrole"), SwingConstants.LEFT)); 169 jp.add(roles); 170 gridbag.setConstraints(roles, c); 171 172 c.gridwidth = GridBagConstraints.REMAINDER; 173 c.weightx = 0.0; 174 175 JTextArea description = new JTextArea (nl.getDescription()); 176 JScrollPane areaScrollPane = new JScrollPane (description); 177 areaScrollPane.setVerticalScrollBarPolicy( 178 JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); 179 areaScrollPane.setPreferredSize(new Dimension(200, 100)); 180 181 jp.add(new JLabel (resource.getString("wfwindowsmanager.description"), SwingConstants.LEFT)); 182 jp.add(areaScrollPane); 183 gridbag.setConstraints(areaScrollPane, c); 184 185 JCheckBox anti = new JCheckBox (resource.getString("wfwindowsmanager.anticipable")); 186 if (persistence.getNodeAnticipable(nodeName) == true) 187 anti.setSelected(true); 188 else 189 anti.setSelected(false); 190 jp.add(anti); 191 gridbag.setConstraints(anti, c); 192 193 int option =JOptionPane.showConfirmDialog(null,jp,resource.getString("wfwindowsmanager.editact"),JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE, icon); 194 195 if (option != JOptionPane.CANCEL_OPTION) { 196 if (dcb.getSelectedItem() != null) { 197 java.util.Date deadline = 198 dateFormat.parse((String ) dcb.getSelectedItem()); 199 200 while (deadline.getTime() <= System.currentTimeMillis() 201 && option != JOptionPane.CANCEL_OPTION) { 202 JOptionPane.showMessageDialog(null,resource.getString("wfwindowsmanager.datedeadline"),resource.getString("wfwindowsmanager.editact"),JOptionPane.INFORMATION_MESSAGE, icon); 203 option =JOptionPane.showConfirmDialog(null,jp,"Edit Activity",JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE, icon); 204 deadline =dateFormat.parse((String ) dcb.getSelectedItem()); 205 } 206 persistence.setEditNode(nodeName,(String ) roles.getSelectedItem(),description.getText(),deadline); 207 } else { 208 persistence.setNodeDescription(nodeName,description.getText()); 209 persistence.setNodeRole(nodeName,(String ) roles.getSelectedItem()); 210 if (!anti.isSelected()) 211 persistence.setNodeTraditional(nodeName); 212 else 213 persistence.setNodeAnticipable(nodeName); 214 } 215 } 216 } catch (Exception e) { 217 JOptionPane.showMessageDialog(null,resource.getString("wfwindowsmanager.editerror") + e.getMessage(),resource.getString("wfwindowsmanager.editact"),JOptionPane.INFORMATION_MESSAGE, icon); 218 } 219 } 220 221 public Vector addInterHook() { 222 Vector result = new Vector(); 223 Vector hookTypes = new Vector(); 224 hookTypes.add(hero.interfaces.Constants.Nd.AFTERSTART); 225 hookTypes.add(hero.interfaces.Constants.Nd.BEFORESTART); 226 hookTypes.add(hero.interfaces.Constants.Nd.AFTERTERMINATE); 227 hookTypes.add(hero.interfaces.Constants.Nd.BEFORETERMINATE); 228 hookTypes.add(hero.interfaces.Constants.Nd.ANTICIPATE); 229 hookTypes.add(hero.interfaces.Constants.Nd.ONCANCEL); 230 hookTypes.add(hero.interfaces.Constants.Nd.ONDEADLINE); 231 hookTypes.add(hero.interfaces.Constants.Nd.ONREADY); 232 233 JPanel jp = new JPanel (); 234 JTextField hook = new JTextField ("", 10); 235 jp.add(new JLabel (resource.getString("wfwindowsmanager.namehook"), SwingConstants.LEFT)); 236 jp.add(hook); 237 238 JComboBox types = new JComboBox (hookTypes); 239 jp.setLayout(new GridLayout(0, 2)); 240 jp.add(new JLabel (resource.getString("wfwindowsmanager.choosetype"), SwingConstants.LEFT)); 241 jp.add(types); 242 243 int option = JOptionPane.showConfirmDialog( null,jp,resource.getString("wfwindowsmanager.newhook"),JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE, icon); 244 245 if (option != JOptionPane.CANCEL_OPTION) { 246 while ((hook.getText()).equals("") 247 && option != JOptionPane.CANCEL_OPTION) { 248 JOptionPane.showMessageDialog(null,hook.getText()+ resource.getString("wfwindowsmanager.nullhook"),resource.getString("wfwindowsmanager.newhook"),JOptionPane.INFORMATION_MESSAGE, icon); 249 option = JOptionPane.showConfirmDialog( null,jp,resource.getString("wfwindowsmanager.newhook"),JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE, icon); 250 } 251 if (option != JOptionPane.CANCEL_OPTION) { 252 result.add(hook.getText()); 253 result.add((String ) types.getSelectedItem()); 254 String value = null; 255 switch (types.getSelectedIndex()) { 256 case 0 : 257 value = hero.interfaces.Constants.AFTERSTART; 258 break; 259 case 1 : 260 value = hero.interfaces.Constants.BEFORESTART; 261 break; 262 case 2 : 263 value = hero.interfaces.Constants.AFTERTERMINATE; 264 break; 265 case 3 : 266 value = hero.interfaces.Constants.BEFORETERMINATE; 267 break; 268 case 4 : 269 value = hero.interfaces.Constants.ANTICIPATE; 270 break; 271 case 5 : 272 value = hero.interfaces.Constants.ONCANCEL; 273 break; 274 case 6 : 275 value = hero.interfaces.Constants.ONDEADLINE; 276 break; 277 case 7 : 278 value = hero.interfaces.Constants.ONREADY; 279 break; 280 } 281 result.add(value); 282 return (result); 283 } 284 } 285 return (result); 286 } 287 288 public String setInterHookValue(String value) { 289 290 String result = null; 291 JPanel jp = new JPanel (); 292 JTextArea hook = new JTextArea (value); 293 JScrollPane areaScrollPane = new JScrollPane (hook); 294 areaScrollPane.setVerticalScrollBarPolicy( 295 JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); 296 areaScrollPane.setPreferredSize(new Dimension(350, 250)); 297 298 jp.add(new JLabel (resource.getString("wfwindowsmanager.hookaction"), SwingConstants.LEFT)); 299 jp.add(areaScrollPane); 300 301 int option =JOptionPane.showConfirmDialog(null,jp,resource.getString("wfwindowsmanager.hookscript"),JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE, icon); 302 303 if (option != JOptionPane.CANCEL_OPTION) { 304 while ((hook.getText()).equals("") 305 && option != JOptionPane.CANCEL_OPTION) { 306 JOptionPane.showMessageDialog(null,hook.getText()+ resource.getString("wfwindowsmanager.nullhook"),resource.getString("wfwindowsmanager.hookscript"),JOptionPane.INFORMATION_MESSAGE, icon); 307 option =JOptionPane.showConfirmDialog(null,jp,resource.getString("wfwindowsmanager.hookscript"),JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE, icon); 308 } 309 if (option != JOptionPane.CANCEL_OPTION) 310 result = hook.getText(); 311 } 312 return (result); 313 } 314 315 public void addNodePropertyWindow(String node) { 316 JPanel jp = new JPanel (); 317 318 JTextField key = new JTextField ("", 0); 319 jp.setLayout(new GridLayout(0, 2)); 320 jp.add(new JLabel (resource.getString("wfwindowsmanager.keyprop"), SwingConstants.LEFT)); 321 jp.add(key); 322 323 JTextField value = new JTextField ("", 0); 324 jp.setLayout(new GridLayout(0, 2)); 325 jp.add(new JLabel (resource.getString("wfwindowsmanager.valprop"), SwingConstants.LEFT)); 326 jp.add(value); 327 328 JCheckBox prop = new JCheckBox (resource.getString("wfwindowsmanager.propagate")); 329 prop.setSelected(true); 330 jp.add(prop); 331 332 int option =JOptionPane.showConfirmDialog(null,jp,resource.getString("wfwindowsmanager.newnodeprop"),JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE, icon); 333 334 if (option != JOptionPane.CANCEL_OPTION) { 335 while ((key.getText()).equals("") 336 && option != JOptionPane.CANCEL_OPTION) { 337 JOptionPane.showMessageDialog(null,resource.getString("wfwindowsmanager.enterprop"),resource.getString("wfwindowsmanager.newnodeprop"),JOptionPane.INFORMATION_MESSAGE, icon); 338 option =JOptionPane.showConfirmDialog(null,jp,resource.getString("wfwindowsmanager.newprop"),JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE, icon); 339 } 340 if (option != JOptionPane.CANCEL_OPTION && !prop.isSelected()) { 341 try { 342 persistence.addNodeProperty(node,key.getText(),value.getText(), false); 343 } catch (Exception e) { 344 JOptionPane.showMessageDialog(null,resource.getString("wfwindowsmanager.existprop"),resource.getString("wfwindowsmanager.newnodeproperty"),JOptionPane.INFORMATION_MESSAGE, icon); 345 } 346 } else if ( 347 option != JOptionPane.CANCEL_OPTION && prop.isSelected()) { 348 try { 349 persistence.addNodeProperty(node,key.getText(),value.getText(),true); 350 } catch (Exception e) { 351 JOptionPane.showMessageDialog(null,resource.getString("wfwindowsmanager.adderrorprop"),resource.getString("wfwindowsmanager.newnodeprop"),JOptionPane.INFORMATION_MESSAGE, icon); 352 } 353 } 354 } 355 } 356 357 public void addProjectPropertyWindow() { 358 JPanel jp = new JPanel (); 359 360 JTextField key = new JTextField ("", 0); 361 jp.setLayout(new GridLayout(0, 2)); 362 jp.add(new JLabel (resource.getString("wfwindowsmanager.keyprop"), SwingConstants.LEFT)); 363 jp.add(key); 364 365 JTextField value = new JTextField ("", 0); 366 jp.setLayout(new GridLayout(0, 2)); 367 jp.add(new JLabel (resource.getString("wfwindowsmanager.valprop"), SwingConstants.LEFT)); 368 jp.add(value); 369 370 int option =JOptionPane.showConfirmDialog(null,jp,resource.getString("wfwindowsmanager.newpropproj"),JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE, icon); 371 372 if (option != JOptionPane.CANCEL_OPTION) { 373 while ((key.getText()).equals("") 374 && option != JOptionPane.CANCEL_OPTION) { 375 JOptionPane.showMessageDialog(null,resource.getString("wfwindowsmanager.enterprop"),resource.getString("wfwindowsmanager.newpropproj"),JOptionPane.INFORMATION_MESSAGE, icon); 376 option =JOptionPane.showConfirmDialog(null,jp,resource.getString("wfwindowsmanager.newprop"),JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE, icon); 377 } 378 if (option != JOptionPane.CANCEL_OPTION) { 379 try { 380 persistence.addProjectProperty(key.getText(),value.getText()); 381 } catch (Exception e) { 382 JOptionPane.showMessageDialog(null,resource.getString("wfwindowsmanager.adderrorprop"),resource.getString("wfwindowsmanager.newpropproj"),JOptionPane.INFORMATION_MESSAGE, icon); 383 } 384 } 385 } 386 } 387 388 public void iterate(String node) { 389 JPanel jp = new JPanel (); 390 391 JTextField from = new JTextField (node, 0); 392 from.setEditable(false); 393 jp.setLayout(new GridLayout(0, 2)); 394 jp.add(new JLabel (resource.getString("wfwindowsmanager.fromnode"), SwingConstants.LEFT)); 395 jp.add(from); 396 397 JTextField to = new JTextField ("", 0); 398 jp.setLayout(new GridLayout(0, 2)); 399 jp.add(new JLabel (resource.getString("wfwindowsmanager.tonode"), SwingConstants.LEFT)); 400 jp.add(to); 401 402 JTextField condition = new JTextField ("", 30); 403 jp.add(new JLabel (resource.getString("wfwindowsmanager.itecond"), SwingConstants.LEFT)); 404 jp.add(condition); 405 406 int option =JOptionPane.showConfirmDialog(null,jp,resource.getString("wfwindowsmanager.iterate"),JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE, icon); 407 408 if (option != JOptionPane.CANCEL_OPTION) { 409 while ((from.getText()).equals("") && (condition.getText()).equals("") 410 && option != JOptionPane.CANCEL_OPTION) { 411 JOptionPane.showMessageDialog(null,resource.getString("wfwindowsmanager.enternode"),resource.getString("wfwindowsmanager.iterate"),JOptionPane.INFORMATION_MESSAGE, icon); 412 option =JOptionPane.showConfirmDialog(null,jp,resource.getString("wfwindowsmanager.iterate"),JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE, icon); 413 } 414 if (option != JOptionPane.CANCEL_OPTION) { 415 try { 416 persistence.addIteration(node,to.getText(), condition.getText()); 417 manager.wfGraph.updateIterationNodes(node,to.getText()); 418 } catch (Exception e) { 419 JOptionPane.showMessageDialog(null,resource.getString("wfwindowsmanager.iterno"),resource.getString("wfwindowsmanager.iterate"),JOptionPane.INFORMATION_MESSAGE, icon); 420 } 421 } 422 } 423 } 424 425 426 427 public Vector addNode() { 428 Vector result = new Vector(); 429 try { 430 JPanel jp = new JPanel (); 431 Vector nodeTypes = new Vector(); 432 nodeTypes.add("AND JOIN"); 433 nodeTypes.add("OR JOIN"); 434 nodeTypes.add("AND JOIN AUTO"); 435 nodeTypes.add("OR JOIN AUTO"); 436 437 JTextField nodeName = new JTextField ("", 10); 438 jp.add(new JLabel (resource.getString("wfwindowsmanager.namenode"), SwingConstants.LEFT)); 439 jp.add(nodeName); 440 441 JComboBox types = new JComboBox (nodeTypes); 442 jp.setLayout(new GridLayout(0, 2)); 443 jp.add(new JLabel (resource.getString("wfwindowsmanager.choosetype"), SwingConstants.LEFT)); 444 jp.add(types); 445 int option = JOptionPane.showConfirmDialog(null,jp,resource.getString("wfwindowsmanager.newnode"),JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE, icon); 446 if (option != JOptionPane.CANCEL_OPTION) { 447 while ((persistence.containsNode(nodeName.getText()) 448 || (nodeName.getText()).equals("")) 449 && option != JOptionPane.CANCEL_OPTION) { 450 JOptionPane.showMessageDialog(null,nodeName.getText()+ resource.getString("wfwindowsmanager.existnode"),resource.getString("wfwindowsmanager.newnode"),JOptionPane.INFORMATION_MESSAGE, icon); 451 option =JOptionPane.showConfirmDialog(null,jp,"New Activity",JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE, icon); 452 } 453 if (option != JOptionPane.CANCEL_OPTION) { 454 result.add(nodeName.getText()); 455 result.add((String ) types.getSelectedItem()); 456 return (result); 457 458 } 459 } 460 } catch (Exception e1) { 461 JOptionPane.showMessageDialog(null, resource.getString("wfwindowsmanager.errornode"),resource.getString("wfwindowsmanager.newnode"),JOptionPane.INFORMATION_MESSAGE, icon); 462 } 463 return (result); 464 } 465 466 public Vector addNodeSubProcess() { 467 Vector result = new Vector(); 468 try { 469 JPanel jp = new JPanel (); 470 471 Object [] possibleValues = persistence.getProjects(); 472 JComboBox projectNames = new JComboBox (possibleValues); 473 jp.setLayout(new GridLayout(0, 2)); 474 jp.add(new JLabel (resource.getString("wfwindowsmanager.choosesub"), SwingConstants.LEFT)); 475 jp.add(projectNames); 476 477 JTextField nodeName = new JTextField ("", 10); 478 jp.add(new JLabel (resource.getString("wfwindowsmanager.namenode"), SwingConstants.LEFT)); 479 jp.add(nodeName); 480 481 int option = JOptionPane.showConfirmDialog(null,jp,resource.getString("wfwindowsmanager.newsub"),JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE, icon); 482 if (option != JOptionPane.CANCEL_OPTION) { 483 while ((persistence.containsNode(nodeName.getText()) || (nodeName.getText()).equals("")) 484 && option != JOptionPane.CANCEL_OPTION) { 485 JOptionPane.showMessageDialog(null,(String ) projectNames.getSelectedItem()+ resource.getString("wfwindowsmanager.existnodesub"),resource.getString("wfwindowsmanager.newsub"),JOptionPane.INFORMATION_MESSAGE, icon); 486 option =JOptionPane.showConfirmDialog(null,jp,resource.getString("wfwindowsmanager.newsub"),JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE, icon); 487 } 488 while (persistence.containsProject(nodeName.getText()) && option != JOptionPane.CANCEL_OPTION) { 489 JOptionPane.showMessageDialog(null,(String ) projectNames.getSelectedItem()+ resource.getString("wfwindowsmanager.existsub"),resource.getString("wfwindowsmanager.newsub"),JOptionPane.INFORMATION_MESSAGE, icon); 490 option =JOptionPane.showConfirmDialog(null,jp,resource.getString("wfwindowsmanager.newsub"),JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE, icon); 491 } 492 if (option != JOptionPane.CANCEL_OPTION) { 493 result.add(nodeName.getText()); 494 result.add((String ) projectNames.getSelectedItem()); 495 return (result); 496 } 497 } 498 } catch (Exception e1) { 499 JOptionPane.showMessageDialog(null, resource.getString("wfwindowsmanager.errorsystem"),resource.getString("wfwindowsmanager.newsub"),JOptionPane.INFORMATION_MESSAGE, icon); 500 } 501 return (result); 502 } 503 504 public String setEdgeCondition(String edgeName) { 505 String result = null; 506 try { 507 JPanel jp = new JPanel (); 508 JTextField condition = new JTextField ("", 30); 509 jp.add(new JLabel (resource.getString("wfwindowsmanager.edgecond"), SwingConstants.LEFT)); 510 jp.add(condition); 511 result = persistence.getEdgeCondition(edgeName); 512 condition.setText(result); 513 514 int option = JOptionPane.showConfirmDialog(null,jp,resource.getString("wfwindowsmanager.setedge"),JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE, icon); 515 516 if (option != JOptionPane.CANCEL_OPTION) { 517 while ((condition.getText()).equals("") 518 && option != JOptionPane.CANCEL_OPTION) { 519 JOptionPane.showMessageDialog(null,condition.getText()+ resource.getString("wfwindowsmanager.entercond"),resource.getString("wfwindowsmanager.setedge"),JOptionPane.INFORMATION_MESSAGE, icon); 520 option =JOptionPane.showConfirmDialog(null,jp,resource.getString("wfwindowsmanager.setedge"),JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE, icon); 521 } 522 if (option != JOptionPane.CANCEL_OPTION) { 523 result = condition.getText(); 524 return (result); 525 526 } 527 } 528 } catch (Exception ec) { 529 JOptionPane.showMessageDialog(null, resource.getString("wfwindowsmanager.erroredge"),resource.getString("wfwindowsmanager.setedge"),JOptionPane.INFORMATION_MESSAGE, icon); 530 } 531 return (result); 532 } 533 534 public void changeRoleWindow(String node) { 535 try { 536 Object [] possibleRoles = persistence.getRoles(); 537 538 JPanel jp = new JPanel (); 539 540 JComboBox roles = new JComboBox (possibleRoles); 541 jp.setLayout(new GridLayout(0, 2)); 542 jp.add(new JLabel (resource.getString("wfwindowsmanager.selectrole"), SwingConstants.LEFT)); 543 jp.add(roles); 544 545 int option =JOptionPane.showConfirmDialog(null,jp,resource.getString("wfwindowsmanager.changerole"),JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE, icon); 546 if (option != JOptionPane.CANCEL_OPTION) { 547 persistence.setNodeRole(node, (String ) roles.getSelectedItem()); 548 } 549 550 } catch (Exception e) { 551 JOptionPane.showMessageDialog(null,resource.getString("wfwindowsmanager.errorchangerole"),resource.getString("wfwindowsmanager.changerole"),JOptionPane.INFORMATION_MESSAGE, icon); 552 } 553 } 554 555 556 557 protected String dialog(String message, int mode) { 558 FileDialog f = new FileDialog(manager.getFrame(), message, mode); 559 f.show(); 560 if (f.getFile() != null) 561 return f.getDirectory() + f.getFile(); 562 else 563 return null; 564 } 565 566 private boolean contains(Object [] data, String elem) { 567 for (int i = 0; i < data.length; i++) { 568 if (((String ) data[i]).equalsIgnoreCase(elem)) 569 return true; 570 } 571 return false; 572 } 573 574 public void newUser() { 575 try { 576 Object [] usersIn = persistence.getUsersInProject(); 577 Object [] allUsers = persistence.getAllUsers(); 578 int size = allUsers.length - usersIn.length; 579 580 if (size == 0) 581 JOptionPane.showMessageDialog(null, resource.getString("wfwindowsmanager.nomoreuser")); 582 else { 583 Object [] possibleUsers = new Object [size]; 584 int j = 0; 585 for (int i = 0; i < allUsers.length; i++) { 586 if (!contains(usersIn, (String ) allUsers[i])) { 587 possibleUsers[j] = allUsers[i]; 588 j++; 589 } 590 } 591 592 JPanel jp = new JPanel (); 593 594 JComboBox users = new JComboBox (possibleUsers); 595 jp.setLayout(new GridLayout(0, 2)); 596 jp.add(new JLabel (resource.getString("wfwindowsmanager.selectuser"), SwingConstants.LEFT)); 597 jp.add(users); 598 599 int option =JOptionPane.showConfirmDialog(null,jp,resource.getString("wfwindowsmanager.newuser"),JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE, icon); 600 601 if (option != JOptionPane.CANCEL_OPTION) { 602 persistence.addUser((String ) users.getSelectedItem()); 603 } 604 } 605 } catch (Exception e) {e.printStackTrace();} 606 } 607 608 public void newRole() { 609 JPanel jp = new JPanel (); 610 611 JTextField roleName = new JTextField ("", 0); 612 jp.setLayout(new GridLayout(0, 2)); 613 jp.add(new JLabel (resource.getString("wfwindowsmanager.namerole"), SwingConstants.LEFT)); 614 jp.add(roleName); 615 616 JTextField description = new JTextField ("", 0); 617 jp.setLayout(new GridLayout(0, 2)); 618 jp.add(new JLabel (resource.getString("wfwindowsmanager.description"), SwingConstants.LEFT)); 619 jp.add(description); 620 621 int option =JOptionPane.showConfirmDialog(null,jp,resource.getString("wfwindowsmanager.newrole"),JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE, icon); 622 623 if (option != JOptionPane.CANCEL_OPTION) { 624 while ((roleName.getText()).equals("") 625 && option != JOptionPane.CANCEL_OPTION) { 626 JOptionPane.showMessageDialog(null,resource.getString("wfwindowsmanager.enterrolename"),resource.getString("wfwindowsmanager.newrole"),JOptionPane.INFORMATION_MESSAGE, icon); 627 option =JOptionPane.showConfirmDialog(null,jp,"New Role",JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE, icon); 628 } 629 if (option != JOptionPane.CANCEL_OPTION) { 630 try { 631 persistence.addRole(roleName.getText(),description.getText()); 632 } catch (Exception e) { 633 JOptionPane.showMessageDialog(null,resource.getString("wfwindowsmanager.existrole"),resource.getString("wfwindowsmanager.newrole"),JOptionPane.INFORMATION_MESSAGE, icon); 634 } 635 } 636 } 637 } 638 639 public void addUserToRole() { 640 try { 641 JPanel jp = new JPanel (); 642 643 Object [] possibleUsers = persistence.getUsersInProject(); 644 645 JComboBox users = new JComboBox (possibleUsers); 646 jp.setLayout(new GridLayout(0, 2)); 647 jp.add(new JLabel (resource.getString("wfwindowsmanager.selectuser"), SwingConstants.LEFT)); 648 jp.add(users); 649 650 Object [] possibleRoles = persistence.getRoles(); 651 652 JComboBox roles = new JComboBox (possibleRoles); 653 jp.setLayout(new GridLayout(0, 2)); 654 jp.add(new JLabel (resource.getString("wfwindowsmanager.selectrole"), SwingConstants.LEFT)); 655 jp.add(roles); 656 int option =JOptionPane.showConfirmDialog(null, jp,resource.getString("wfwindowsmanager.adduserrole"),JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE, icon); 657 658 if (option != JOptionPane.CANCEL_OPTION) { 659 try { 660 persistence.setUserRole((String ) users.getSelectedItem(),(String ) roles.getSelectedItem()); 661 } catch (Exception exx) { 662 JOptionPane.showMessageDialog(null, resource.getString("wfwindowsmanager.existuserrole"),resource.getString("wfwindowsmanager.adduserrole"),JOptionPane.INFORMATION_MESSAGE, icon); 663 } 664 } 665 } catch (Exception ex) { 666 JOptionPane.showMessageDialog(null, resource.getString("wfwindowsmanager.exerole"),resource.getString("wfwindowsmanager.adduserrole"),JOptionPane.INFORMATION_MESSAGE, icon); 667 } 668 } 669 670 public void addMapperToRole() { 671 try { 672 JPanel jp = new JPanel (); 673 674 Vector mapperTypes = new Vector(); 675 mapperTypes.add(Constants.Mapper.LDAPMAPPER); 676 mapperTypes.add(Constants.Mapper.PROPERTIESMAPPER); 677 mapperTypes.add(Constants.Mapper.CUSTOMMAPPER); 678 679 Object [] possibleRoles = persistence.getRoles(); 680 681 JComboBox roles = new JComboBox (possibleRoles); 682 jp.setLayout(new GridLayout(0, 2)); 683 jp.add(new JLabel (resource.getString("wfwindowsmanager.selectrole"), SwingConstants.LEFT)); 684 jp.add(roles); 685 686 JTextField mapperName = new JTextField ("", 0); 687 jp.setLayout(new GridLayout(0, 2)); 688 jp.add(new JLabel (resource.getString("wfwindowsmanager.mapper"), SwingConstants.LEFT)); 689 jp.add(mapperName); 690 691 JComboBox types = new JComboBox (mapperTypes); 692 jp.setLayout(new GridLayout(0, 2)); 693 jp.add(new JLabel (resource.getString("wfwindowsmanager.mappertype"), SwingConstants.LEFT)); 694 jp.add(types); 695 696 int option =JOptionPane.showConfirmDialog(null, jp,resource.getString("wfwindowsmanager.addmapperrole"),JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE, icon); 697 698 if (option != JOptionPane.CANCEL_OPTION) { 699 try { 700 persistence.addRoleMapper((String ) roles.getSelectedItem(), mapperName.getText(),(String )types.getSelectedItem()); 701 } catch (Exception exx) { 702 JOptionPane.showMessageDialog(null, resource.getString("wfwindowsmanager.existmapperrole"),resource.getString("wfwindowsmanager.addmapperrole"),JOptionPane.INFORMATION_MESSAGE, icon); 703 } 704 } 705 } catch (Exception ex) { 706 ex.printStackTrace(); 707 JOptionPane.showMessageDialog(null, resource.getString("wfwindowsmanager.exemapper"),resource.getString("wfwindowsmanager.addmapperrole"),JOptionPane.INFORMATION_MESSAGE, icon); 708 } 709 } 710 711 public void addPerformerAssigment(String nodeName) { 712 JPanel jp = new JPanel (); 713 714 Vector performerTypes = new Vector(); 715 performerTypes.add(Constants.PerformerAssigment.CALLBACKPA); 716 performerTypes.add(Constants.PerformerAssigment.PROPERTIESPA); 717 718 JComboBox types = new JComboBox (performerTypes); 719 jp.setLayout(new GridLayout(0, 2)); 720 jp.add(new JLabel (resource.getString("wfwindowsmanager.performertype"), SwingConstants.LEFT)); 721 jp.add(types); 722 723 JTextField performerName = new JTextField ("", 0); 724 jp.setLayout(new GridLayout(0, 2)); 725 jp.add(new JLabel (resource.getString("wfwindowsmanager.performername"), SwingConstants.LEFT)); 726 jp.add(performerName); 727 728 JTextField property = new JTextField ("", 0); 729 jp.setLayout(new GridLayout(0, 2)); 730 jp.add(new JLabel (resource.getString("wfwindowsmanager.performerprop"), SwingConstants.LEFT)); 731 jp.add(property); 732 733 734 int option =JOptionPane.showConfirmDialog(null, jp,resource.getString("wfwindowsmanager.addperformer"),JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE, icon); 735 if (option != JOptionPane.CANCEL_OPTION) { 736 try { 737 persistence.addPerformerAssigment(nodeName, performerName.getText(), (String ) types.getSelectedItem(),(String )property.getText()); 738 } catch (Exception exx) { 739 JOptionPane.showMessageDialog(null, resource.getString("wfwindowsmanager.existperformer"),resource.getString("wfwindowsmanager.addperformer"),JOptionPane.INFORMATION_MESSAGE, icon); 740 } 741 } 742 } 743 744 public void usersInProject() { 745 try { 746 JPanel jp = new JPanel (); 747 748 Object [] users = persistence.getUsersInProject(); 749 String text = resource.getString("wfwindowsmanager.userhtml"); 750 Object [] nameRoles = persistence.getRoles(); 751 for (int i = 0; i < nameRoles.length; i++) { 752 text = text + "<th>" + (String ) nameRoles[i] + "</th>"; 753 } 754 755 for (int j = 0; j < users.length; j++) { 756 757 text =text+ "<tr bgcolor=white><td>"+ (String ) users[j]+ "</td>"; 758 759 for (int i = 0; i < nameRoles.length; i++) { 760 if (persistence.isInRole((String ) users[j], (String ) nameRoles[i])) { 761 text = text + "<td align=center> X </td>"; 762 } else { 763 text = text + "<td></td>"; 764 } 765 } 766 text = text + "</tr>"; 767 } 768 text = text + "</table></html>"; 769 JLabel jText = new JLabel (text); 770 jp.add(jText); 771 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); 772 773 JScrollPane scroll = new JScrollPane (jp); 774 scroll.setMaximumSize(new Dimension(screenSize.width / 2, screenSize.height / 2)); 775 JFrame fr = new JFrame (resource.getString("wfwindowsmanager.userproj")); 776 fr.getContentPane().add(scroll, BorderLayout.CENTER); 777 fr.pack(); 778 779 Dimension jpDim = scroll.getPreferredSize(); 780 fr.setLocation(screenSize.width / 2 - (jpDim.width / 2),screenSize.height / 2 - (jpDim.height / 2)); 781 fr.setResizable(true); 782 fr.setVisible(true); 783 784 } catch (Exception ex) { 785 JOptionPane.showMessageDialog(null, resource.getString("wfwindowsmanager.exeuserrole"),resource.getString("wfwindowsmanager.userole"),JOptionPane.INFORMATION_MESSAGE, icon); 786 } 787 } 788 789 790 } | Popular Tags |