1 23 package org.objectweb.clif.scenario.util.isac.gui; 24 25 import java.util.Enumeration ; 26 import java.util.Vector ; 27 28 import org.apache.log4j.Category; 29 import org.apache.log4j.PropertyConfigurator; 30 import org.eclipse.jface.action.MenuManager; 31 import org.eclipse.jface.action.Separator; 32 import org.eclipse.jface.action.StatusLineManager; 33 import org.eclipse.jface.action.ToolBarManager; 34 import org.eclipse.jface.dialogs.MessageDialog; 35 import org.eclipse.jface.window.ApplicationWindow; 36 import org.eclipse.swt.SWT; 37 import org.eclipse.swt.custom.SashForm; 38 import org.eclipse.swt.custom.ScrolledComposite; 39 import org.eclipse.swt.custom.StyledText; 40 import org.eclipse.swt.events.FocusEvent; 41 import org.eclipse.swt.events.FocusListener; 42 import org.eclipse.swt.events.ModifyEvent; 43 import org.eclipse.swt.events.ModifyListener; 44 import org.eclipse.swt.events.SelectionEvent; 45 import org.eclipse.swt.events.SelectionListener; 46 import org.eclipse.swt.graphics.Font; 47 import org.eclipse.swt.layout.FillLayout; 48 import org.eclipse.swt.layout.GridData; 49 import org.eclipse.swt.layout.GridLayout; 50 import org.eclipse.swt.widgets.Composite; 51 import org.eclipse.swt.widgets.Control; 52 import org.eclipse.swt.widgets.Display; 53 import org.eclipse.swt.widgets.Label; 54 import org.eclipse.swt.widgets.Menu; 55 import org.eclipse.swt.widgets.MenuItem; 56 import org.eclipse.swt.widgets.Shell; 57 import org.eclipse.swt.widgets.TabFolder; 58 import org.eclipse.swt.widgets.TabItem; 59 import org.objectweb.clif.scenario.util.isac.FileName; 60 import org.objectweb.clif.scenario.util.isac.gui.action.AboutAction; 61 import org.objectweb.clif.scenario.util.isac.gui.action.AddPluginAction; 62 import org.objectweb.clif.scenario.util.isac.gui.action.CollapseCurrentTreeAction; 63 import org.objectweb.clif.scenario.util.isac.gui.action.CopyAction; 64 import org.objectweb.clif.scenario.util.isac.gui.action.CutAction; 65 import org.objectweb.clif.scenario.util.isac.gui.action.DeleteNodeAction; 66 import org.objectweb.clif.scenario.util.isac.gui.action.EditRampDescriptionAction; 67 import org.objectweb.clif.scenario.util.isac.gui.action.ExitAction; 68 import org.objectweb.clif.scenario.util.isac.gui.action.ExpandCurrentTreeAction; 69 import org.objectweb.clif.scenario.util.isac.gui.action.GenerateAction; 70 import org.objectweb.clif.scenario.util.isac.gui.action.NewScenarioAction; 71 import org.objectweb.clif.scenario.util.isac.gui.action.NodeLowerAction; 72 import org.objectweb.clif.scenario.util.isac.gui.action.NodeUpperAction; 73 import org.objectweb.clif.scenario.util.isac.gui.action.OpenScenarioAction; 74 import org.objectweb.clif.scenario.util.isac.gui.action.PasteAction; 75 import org.objectweb.clif.scenario.util.isac.gui.action.SaveScenarioAction; 76 import org.objectweb.clif.scenario.util.isac.gui.action.SaveScenarioAsAction; 77 import org.objectweb.clif.scenario.util.isac.gui.action.ShowHelpAction; 78 import org.objectweb.clif.scenario.util.isac.gui.action.SwitchLoadProfileOrBehaviorsModeAction; 79 import org.objectweb.clif.scenario.util.isac.gui.action.UnSelectAction; 80 import org.objectweb.clif.scenario.util.isac.gui.tree.ScenarioTreeViewer; 81 import org.objectweb.clif.scenario.util.isac.gui.tree.dnd.ScenarioTreeTransfer; 82 import org.objectweb.clif.scenario.util.isac.loadprofile.GroupDescription; 83 import org.objectweb.clif.scenario.util.isac.loadprofile.gui.LoadDrawingEditor; 84 import org.objectweb.clif.scenario.util.isac.plugin.PluginManager; 85 import org.objectweb.clif.scenario.util.isac.plugin.gui.PluginGUIManager; 86 import org.objectweb.clif.scenario.util.isac.util.tree.Node; 87 import org.objectweb.clif.scenario.util.isac.util.tree.NodeDescription; 88 import org.objectweb.clif.scenario.util.isac.util.tree.ScenarioNode; 89 import org.objectweb.clif.scenario.util.isac.util.tree.SyntaxAnalyser; 90 import org.objectweb.clif.scenario.util.isac.util.tree.TreeManager; 91 92 99 public class ScenarioGUIEditor extends ApplicationWindow 100 implements 101 SelectionListener, 102 FocusListener, 103 ModifyListener { 104 105 private String fileName; 106 private ScenarioTreeViewer treeViewer; 107 private PluginGUIManager pluginGUIManager; 108 private TreeManager treeManager; 109 private PluginManager pluginManager; 110 private Composite helpPanel; 111 private ScrolledComposite helpScrolled; 112 private boolean helpVisible; 113 private SashForm formBehaviors; 114 private SashForm formParameters; 115 private Composite parametersPanel; 116 private TabFolder tabFolder; 117 private StyledText styledText; 118 private boolean behaviorsSavedState; 119 private SashForm form; 120 121 private EditRampDescriptionAction editRampDescriptionAction; 123 private SaveScenarioAction saveScenarioAction; 124 private GenerateAction generateXMLAction; 125 private GenerateAction generateTreeAction; 126 private CollapseCurrentTreeAction collapseAction; 127 private ExpandCurrentTreeAction expandAction; 128 private DeleteNodeAction deleteNodeAction; 129 private NodeUpperAction upperAction; 130 private NodeLowerAction lowerAction; 131 private ShowHelpAction showHelpAction; 132 private UnSelectAction unSelectAction; 133 private CutAction cutAction; 134 private CopyAction copyAction; 135 private PasteAction pasteAction; 136 private NewScenarioAction newScenarioAction; 137 private SaveScenarioAsAction saveScenarioAsAction; 138 private OpenScenarioAction openScenarioAction; 139 private SwitchLoadProfileOrBehaviorsModeAction fullBehaviorsModeAction; 140 private SwitchLoadProfileOrBehaviorsModeAction fullLoadProfileModeAction; 141 private SwitchLoadProfileOrBehaviorsModeAction splitModeAction; 142 private ExitAction exitAction; 143 144 private LoadDrawingEditor loadDrawingEditor; 146 147 private MenuItem cutXMLEditorItem; 149 private MenuItem copyXMLEditorItem; 150 private MenuItem pasteXMLEditorItem; 151 private MenuItem generateXMLEditorItem; 152 153 private StatusLineManager statusLine; 155 private int editorShown; 157 static Category cat = Category.getInstance(ScenarioGUIEditor.class 159 .getName()); 160 161 public static final int GUI_EDITOR = 0; 163 public static final int XML_EDITOR = 1; 164 168 171 private ToolBarManager toolBar; 173 174 177 private MenuManager bar; 178 private MenuManager helpMenu; 179 private MenuManager viewMenu; 180 private MenuManager fileMenu; 181 private MenuManager editMenu; 182 private MenuManager addMenu; 183 private MenuManager popupMenu; 184 private MenuManager addMenuPopup; 185 private MenuItem generateTabFolderPopup; 186 private MenuItem generateTabFolderPopup2; 187 188 public static final int FULL_BEHAVIORS_MODE = 0; 189 public static final int FULL_LOAD_PROFILE_MODE = 1; 190 public static final int SPLIT_MODE = 2; 191 192 private int currentSplitMode = -1; 193 private int[] weightSplitMode = new int[]{55, 45}; 194 195 200 public ScenarioGUIEditor() { 201 super(null); 202 cat.debug("-> constructor"); 203 204 this.initManagers(); 206 this.initActions(); 208 this.helpVisible = true; 210 this.fileName = null; 212 this.addMenuBar(); 214 this.addStatusLine(); 216 this.addToolBar(SWT.FLAT | SWT.WRAP); 218 219 setScenarioSavedState(false); 221 } 222 223 227 230 public ScenarioTreeViewer getTreeViewer() { 231 cat.debug("-> getTreeViewer"); 232 return this.treeViewer; 233 } 234 235 238 public ScrolledComposite getHelpScrolled() { 239 cat.debug("-> getHelpScrolled"); 240 return this.helpScrolled; 241 } 242 243 246 public int getEditorShowed() { 247 return editorShown; 248 } 249 253 public void setEditorShowed(int editorShowed) { 254 this.editorShown = editorShowed; 255 if (editorShowed == XML_EDITOR) { 262 this.unSelectAction.run(); 263 this.generateXMLAction.setEnabled(false); 264 this.generateTreeAction.setEnabled(true); 265 this.cutAction.setEnabled(true); 266 this.copyAction.setEnabled(true); 267 this.pasteAction.setEnabled(true); 268 this.fullBehaviorsModeAction.setEnabled(false); 270 this.fullLoadProfileModeAction.setEnabled(false); 271 this.splitModeAction.setEnabled(false); 272 this.collapseAction.setEnabled(false); 273 this.expandAction.setEnabled(false); 274 if (this.generateTabFolderPopup != null 275 && this.generateTabFolderPopup2 != null) { 276 this.generateTabFolderPopup.setEnabled(false); 277 this.generateTabFolderPopup2.setEnabled(true); 278 } 279 return; 280 } 281 if (editorShowed == GUI_EDITOR) { 282 this.notifySelectionChanged(this.treeViewer.getSelectedNode()); 283 this.generateXMLAction.setEnabled(true); 285 this.generateTreeAction.setEnabled(false); 286 this.collapseAction.setEnabled(true); 288 this.expandAction.setEnabled(true); 289 if (this.generateTabFolderPopup != null 290 && this.generateTabFolderPopup2 != null) { 291 this.generateTabFolderPopup.setEnabled(true); 292 this.generateTabFolderPopup2.setEnabled(false); 293 } 294 changeSplitMode(this.getCurrentSplitMode()); 295 return; 296 } 297 } 298 299 304 public String getFileName() { 305 cat.debug("-> getFileName"); 306 return fileName; 307 } 308 309 315 public void setFileName(String string) { 316 cat.debug("-> setFileName"); 317 fileName = string; 318 this.updateWindowTitle(); 319 } 320 321 324 public boolean isBehaviorsSavedState() { 325 return behaviorsSavedState; 326 } 327 331 public void setScenarioSavedState(boolean behaviorsSavedState) { 332 this.behaviorsSavedState = behaviorsSavedState; 333 this.updateWindowTitle(); 335 this.saveScenarioAction.setEnabled(!behaviorsSavedState); 337 } 338 339 343 public boolean getScenarioSavedState() { 344 return this.behaviorsSavedState; 345 } 346 347 352 public boolean getHelpVisibleState() { 353 cat.debug("-> getVisibleState"); 354 return this.helpVisible; 355 } 356 357 363 public void setHelpVisibleState(boolean state) { 364 cat.debug("-> setVisibleState"); 365 this.helpVisible = state; 366 } 367 368 371 private void initManagers() { 372 cat.debug("-> initManagers"); 373 this.pluginGUIManager = PluginGUIManager.getPluginGUIManager(this); 374 this.treeManager = TreeManager.getTreeManager(this); 375 this.pluginManager = PluginManager.getPluginManager(); 376 } 377 378 381 private void initActions() { 382 this.editRampDescriptionAction = new EditRampDescriptionAction(this); 383 this.saveScenarioAction = new SaveScenarioAction(this); 384 this.generateXMLAction = new GenerateAction(this, GUI_EDITOR); 385 this.generateTreeAction = new GenerateAction(this, XML_EDITOR); 386 this.collapseAction = new CollapseCurrentTreeAction(this); 387 this.expandAction = new ExpandCurrentTreeAction(this); 388 this.deleteNodeAction = new DeleteNodeAction(this); 389 this.upperAction = new NodeUpperAction(this); 390 this.lowerAction = new NodeLowerAction(this); 391 this.showHelpAction = new ShowHelpAction(this); 392 this.unSelectAction = new UnSelectAction(this); 393 this.cutAction = new CutAction(this); 394 this.copyAction = new CopyAction(this); 395 this.pasteAction = new PasteAction(this); 396 this.newScenarioAction = new NewScenarioAction(this); 397 this.saveScenarioAsAction = new SaveScenarioAsAction(this); 398 this.openScenarioAction = new OpenScenarioAction(this); 399 this.fullBehaviorsModeAction = new SwitchLoadProfileOrBehaviorsModeAction( 401 this, FULL_BEHAVIORS_MODE); 402 this.fullLoadProfileModeAction = new SwitchLoadProfileOrBehaviorsModeAction( 403 this, FULL_LOAD_PROFILE_MODE); 404 this.splitModeAction = new SwitchLoadProfileOrBehaviorsModeAction(this, 405 SPLIT_MODE); 406 this.exitAction = new ExitAction(this); 407 this.pasteAction.setEnabled(false); 408 } 409 410 416 public void notifySelectionChanged(ScenarioNode node) { 417 cat.debug("-> notifySelectionChanged"); 418 if (this.treeViewer != null) 420 if (this.treeViewer.getClipboard().getContents( 421 ScenarioTreeTransfer.getInstance()) != null) 422 this.pasteAction.setEnabled(true); 423 else 424 this.pasteAction.setEnabled(false); 425 else 426 this.pasteAction.setEnabled(false); 427 428 if (node == null) { 430 this.deleteNodeAction.setEnabled(false); 431 this.upperAction.setEnabled(false); 432 this.lowerAction.setEnabled(false); 433 this.unSelectAction.setEnabled(false); 434 this.cutAction.setEnabled(false); 435 this.copyAction.setEnabled(false); 436 this.updateHelp(null); 437 this.updateAddMenu(null); 438 this.pluginGUIManager.switchPanel(node); 439 return; 440 } 441 this.deleteNodeAction.setEnabled(true); 443 this.upperAction.setEnabled(true); 444 this.lowerAction.setEnabled(true); 445 this.unSelectAction.setEnabled(true); 446 this.cutAction.setEnabled(true); 447 this.copyAction.setEnabled(true); 448 this.updateAddMenu(node); 449 this.pluginGUIManager.switchPanel(node); 450 Vector help = this.treeManager.getNodeHelp(node); 451 this.updateHelp(help); 452 } 453 454 460 public void notifySelectionChangedInLoadProfileEditor(GroupDescription gd) { 461 if (gd == null) { 463 this.deleteNodeAction.setEnabled(false); 464 this.upperAction.setEnabled(false); 465 this.lowerAction.setEnabled(false); 466 this.unSelectAction.setEnabled(false); 467 this.cutAction.setEnabled(false); 468 this.copyAction.setEnabled(false); 469 this.editRampDescriptionAction.setEnabled(false); 470 return; 471 } 472 this.editRampDescriptionAction.setEnabled(true); 473 this.deleteNodeAction.setEnabled(true); 474 this.upperAction.setEnabled(true); 475 this.lowerAction.setEnabled(true); 476 this.unSelectAction.setEnabled(true); 477 this.cutAction.setEnabled(true); 478 this.copyAction.setEnabled(true); 479 } 480 481 485 488 public boolean close() { 489 if (!this.isBehaviorsSavedState() && this.isNotNullTree()) { 491 String [] buttonText = new String []{"Yes", "No", "Cancel"}; 493 String message = "The current scenario is not saved,\n" 494 + "you will loose changes. Would you like to save it ?"; 495 MessageDialog messageBox = new MessageDialog(Display.getCurrent() 496 .getActiveShell(), "Scenario is not saved", null, message, 497 MessageDialog.WARNING, buttonText, 1); 498 messageBox.open(); 499 switch (messageBox.getReturnCode()) { 500 case 0 : 502 SaveScenarioAction.saveScenario(this); 503 return super.close(); 504 case 1 : 506 507 return super.close(); 508 case 2 : 510 return false; 511 } 512 } 513 return super.close(); 514 } 515 516 519 public void widgetDefaultSelected(SelectionEvent event) { 520 cat.warn("-> widgetDefaultSelected : should never append"); 521 } 522 523 526 public void widgetSelected(SelectionEvent event) { 527 cat.debug("-> widgetSelected"); 528 if (event.getSource() == this.generateTabFolderPopup) { 530 this.generateXMLAction.run(); 531 return; 532 533 } else if (event.getSource() == this.generateTabFolderPopup2) { 534 this.generateTreeAction.run(); 535 return; 536 } 537 if (event.getSource() == this.cutXMLEditorItem) { 540 this.cutAction.run(); 542 return; 543 } 544 if (event.getSource() == this.copyXMLEditorItem) { 545 this.copyAction.run(); 547 return; 548 } 549 if (event.getSource() == this.pasteXMLEditorItem) { 550 this.pasteAction.run(); 552 return; 553 } 554 if (event.getSource() == this.generateXMLEditorItem) { 555 this.generateTreeAction.run(); 557 return; 558 } 559 int no = this.tabFolder.getSelectionIndex(); 561 switch (no) { 563 case XML_EDITOR : 564 setEditorShowed(XML_EDITOR); 565 break; 566 case GUI_EDITOR : 568 setEditorShowed(GUI_EDITOR); 569 break; 570 default : 571 } 573 } 574 575 578 public void modifyText(ModifyEvent arg0) { 579 this.setScenarioSavedState(false); 580 } 581 582 585 public void focusGained(FocusEvent arg0) { 586 } 588 589 592 public void focusLost(FocusEvent arg0) { 593 } 595 596 600 606 public boolean isNotNullTree() { 607 cat.debug("-> is not null tree"); 608 if (this.treeViewer.getInput() != null) { 609 if (((ScenarioNode) this.treeViewer.getInput()).getChildren() != null) { 610 if (((ScenarioNode) this.treeViewer.getInput()).getChildren() 611 .size() != 0) { 612 return true; 613 } 614 } 615 } 616 return false; 617 } 618 619 622 private void updateWindowTitle() { 623 String currentName = getFileName(); 624 if (currentName == null) 625 currentName = "NewScenario"; 626 String text = "ScenarioGUIEditor " + FileName.VERSION + " - " 627 + currentName; 628 if (!isBehaviorsSavedState()) 629 text = text.concat("(unsaved)"); 630 Shell shell = this.getShell(); 631 if (shell != null) 632 shell.setText(text); 633 } 634 635 638 public StyledText getStyledText() { 639 return styledText; 640 } 641 642 645 public PasteAction getPasteNodeAction() { 646 return pasteAction; 647 } 648 649 652 public StatusLineManager getStatusLine() { 653 return statusLine; 654 } 655 656 659 public int getCurrentSplitMode() { 660 return currentSplitMode; 661 } 662 666 public void setCurrentSplitMode(int currentSplitMode) { 667 this.currentSplitMode = currentSplitMode; 668 } 669 672 public int[] getWeightSplitMode() { 673 return weightSplitMode; 674 } 675 679 public void setWeightSplitMode(int[] weightSplitMode) { 680 this.weightSplitMode = weightSplitMode; 681 } 682 683 public void changeSplitMode(int typeMode) { 684 if (typeMode == this.getCurrentSplitMode()) 686 ; 687 if (this.getCurrentSplitMode() == ScenarioGUIEditor.SPLIT_MODE) { 689 this.setWeightSplitMode(this.form.getWeights()); 690 } 691 this.fullBehaviorsModeAction.setEnabled(true); 693 this.fullLoadProfileModeAction.setEnabled(true); 694 this.splitModeAction.setEnabled(true); 695 696 switch (typeMode) { 698 case ScenarioGUIEditor.FULL_BEHAVIORS_MODE : 699 this.form.setMaximizedControl(this.formBehaviors); 701 this.fullBehaviorsModeAction.setEnabled(false); 702 this.currentSplitMode = FULL_BEHAVIORS_MODE; 703 break; 704 case ScenarioGUIEditor.FULL_LOAD_PROFILE_MODE : 705 this.form.setMaximizedControl(this.loadDrawingEditor 707 .getParent()); 708 this.fullLoadProfileModeAction.setEnabled(false); 709 this.currentSplitMode = FULL_LOAD_PROFILE_MODE; 710 break; 711 case ScenarioGUIEditor.SPLIT_MODE : 712 this.form.setMaximizedControl(null); 714 this.form.setWeights(this.getWeightSplitMode()); 715 this.splitModeAction.setEnabled(false); 716 this.currentSplitMode = SPLIT_MODE; 717 break; 718 default : 719 } 721 } 722 723 726 public void hideHelpPanel() { 727 cat.debug("-> hideHelpPanel"); 728 this.formParameters.setMaximizedControl(this.parametersPanel); 729 } 730 731 734 public void showHelpPanel() { 735 cat.debug("-> showHelpPanel"); 736 this.formParameters.setMaximizedControl(null); 737 } 738 739 745 public void switchEditorViewer(int editor) { 746 this.tabFolder.setSelection(editor); 747 this.setEditorShowed(editor); 748 } 749 750 753 public MenuManager getEditMenu() { 754 return editMenu; 755 } 756 757 763 public void updateHelp(Vector help) { 764 cat.debug("-> updateHelp"); 765 this.helpPanel = new Composite(this.helpScrolled, SWT.FLAT); 767 this.helpPanel.setBackground(this.getShell().getDisplay() 768 .getSystemColor(SWT.COLOR_WHITE)); 769 GridLayout layout = new GridLayout(); 773 layout.numColumns = 1; 774 this.helpPanel.setLayout(layout); 775 GridData gridTitle = new GridData(); 777 gridTitle.horizontalAlignment = GridData.FILL; 778 gridTitle.verticalAlignment = GridData.FILL; 779 gridTitle.grabExcessHorizontalSpace = true; 780 781 Label title = new Label(this.helpPanel, SWT.BORDER | SWT.CENTER); 782 title.setLayoutData(gridTitle); 783 title.setText("HELP : "); 784 if (help != null) { 786 Font font = new Font(this.getShell().getDisplay(), "Arial", 10, 788 SWT.ITALIC); 789 for (int i = 0; i < help.size(); i++) { 790 Label label = new Label(this.helpPanel, SWT.WRAP | SWT.FLAT 791 | SWT.LEFT); 792 label.setBackground(this.getShell().getDisplay() 793 .getSystemColor(SWT.COLOR_WHITE)); 794 795 label.setFont(font); 798 label.pack(); 799 GridData gridData = new GridData(); 800 gridData.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING; 801 label.setLayoutData(gridData); 803 label.setText((String ) help.elementAt(i)); 804 } 805 font.dispose(); 806 } 807 this.helpScrolled.setMinSize(this.helpPanel.computeSize(SWT.DEFAULT, 809 SWT.DEFAULT)); 810 this.helpScrolled.setContent(this.helpPanel); 811 this.helpScrolled.layout(); 812 } 813 814 818 public void updateAddMenu(ScenarioNode node) { 819 cat.debug("-> updateAddMenu"); 820 this.addMenu.removeAll(); 822 this.addMenuPopup.removeAll(); 823 Vector childrenAllowed = null; 824 if (this.treeViewer == null) 825 childrenAllowed = SyntaxAnalyser.sortByType(this.treeManager 826 .childrenAllowed(null)); 827 else 828 childrenAllowed = SyntaxAnalyser.sortByType(this.treeManager 829 .childrenAllowed(node)); 830 831 Enumeration elements = childrenAllowed.elements(); 833 while (elements.hasMoreElements()) { 834 String type = (String ) elements.nextElement(); 835 cat.warn("TYPE ALLOWED IS : " + type); 836 if (!Node.isPluginNode(type)) { 837 cat.warn("ADD IN THE MENU : " + type); 838 NodeDescription nodeDesc = NodeDescription 839 .createNonePluginNode(type); 840 this.addMenu.add(new AddPluginAction(this, nodeDesc)); 841 this.addMenuPopup.add(new AddPluginAction(this, nodeDesc)); 842 cat.warn("nb elems : (pop)" 843 + this.addMenuPopup.getItems().length + ", (bar)" 844 + this.addMenu.getItems().length); 845 } else { 846 if (type.equals(Node.USE)) { 849 Vector nodesDescs = this.pluginManager 850 .createNodesDescriptions(type); 851 if (nodesDescs != null) { 852 for (int i = 0; i < nodesDescs.size(); i++) { 853 NodeDescription tempDesc = (NodeDescription) nodesDescs 854 .elementAt(i); 855 this.addMenu 856 .add(new AddPluginAction(this, tempDesc)); 857 this.addMenuPopup.add(new AddPluginAction(this, 858 tempDesc)); 859 } 860 } 861 } else { 862 Vector usedPlugins = this.treeManager.getUsedPluginsName(); 863 Vector nodesDescs = this.pluginManager 864 .createNodesDescriptionsByPlugins(usedPlugins, type); 865 if (nodesDescs != null) { 866 for (int i = 0; i < nodesDescs.size(); i++) { 867 NodeDescription tempDesc = (NodeDescription) nodesDescs 868 .elementAt(i); 869 this.addMenu 870 .add(new AddPluginAction(this, tempDesc)); 871 this.addMenuPopup.add(new AddPluginAction(this, 872 tempDesc)); 873 } 874 } 875 } 876 } 877 } 878 if (node != null) { 879 if (!this.addMenu.isEmpty()) { 881 this.addMenu.add(new Separator()); 882 this.addMenuPopup.add(new Separator()); 883 } 884 Vector childrenStructureAllowed = this.treeManager 886 .childrenAllowed(null); 887 Enumeration elementsStructure = childrenStructureAllowed.elements(); 888 while (elementsStructure.hasMoreElements()) { 889 String type = (String ) elementsStructure.nextElement(); 890 cat.warn("ADD to the ADD MENU : " + type); 891 NodeDescription nodeDesc = NodeDescription 892 .createNonePluginNode(type); 893 this.addMenu.add(new AddPluginAction(this, nodeDesc)); 894 this.addMenuPopup.add(new AddPluginAction(this, nodeDesc)); 895 } 896 } 897 } 898 899 900 protected Control createContents(Composite parent) { 901 cat.debug("-> createContents"); 902 Shell shell = this.getShell(); 904 this.updateWindowTitle(); 905 shell.setSize(1024, 768); 906 Display display = shell.getDisplay(); 907 this.tabFolder = new TabFolder(parent, SWT.NONE); 909 tabFolder.addSelectionListener(this); 911 912 form = new SashForm(tabFolder, SWT.VERTICAL | SWT.NULL); 916 this.formBehaviors = new SashForm(form, SWT.HORIZONTAL | SWT.NULL); 918 this.treeViewer = new ScenarioTreeViewer(formBehaviors, SWT.SIMPLE 920 | SWT.BORDER, this); 921 this.createBehaviorsPopup(); 923 this.treeViewer.getTree().setMenu( 925 this.popupMenu.createContextMenu(this.treeViewer.getTree())); 926 this.treeViewer.getTree().addFocusListener(this); 929 930 this.formParameters = new SashForm(formBehaviors, SWT.HORIZONTAL 933 | SWT.NULL); 934 this.parametersPanel = new Composite(formParameters, SWT.FLAT); 936 this.parametersPanel.setLayout(new FillLayout()); 937 pluginGUIManager.setParentComposite(parametersPanel); 939 this.helpScrolled = new ScrolledComposite(formParameters, SWT.BORDER 941 | SWT.H_SCROLL | SWT.V_SCROLL); 942 this.helpScrolled.setExpandHorizontal(true); 943 this.helpScrolled.setExpandVertical(true); 944 this.helpPanel = new Composite(this.helpScrolled, SWT.FLAT); 945 this.helpScrolled.setContent(this.helpPanel); 946 947 955 this.loadDrawingEditor = new LoadDrawingEditor(form, this); 956 957 this.formBehaviors.setWeights(new int[]{30, 70}); 959 960 this.pluginManager.initialisePluginsTable(FileName.PLUGINS_DIR); 962 963 this.updateHelp(null); 965 966 Composite XMLeditor = new Composite(tabFolder, SWT.FLAT); 968 969 XMLeditor.setLayout(new FillLayout()); 970 this.styledText = new StyledText(XMLeditor, SWT.BORDER | SWT.MULTI 971 | SWT.V_SCROLL | SWT.H_SCROLL); 972 this.styledText.addModifyListener(this); 973 974 this.styledText.setMenu(this.createXMLEditorPopup()); 975 Font font = new Font(display, "courier", 12, SWT.ITALIC); 976 styledText.setFont(font); 977 TabItem item1 = new TabItem(tabFolder, SWT.NONE); 979 item1.setText("GUI Editor"); 980 item1.setControl(form); 981 TabItem item2 = new TabItem(tabFolder, SWT.NONE); 982 item2.setText("XML Editor"); 983 item2.setControl(XMLeditor); 984 this.tabFolder.setMenu(this.createTabPopupMenu()); 986 setEditorShowed(GUI_EDITOR); 987 990 changeSplitMode(SPLIT_MODE); 992 993 return form; 994 } 995 1000 private void setMenu() { 1001 bar.removeAll(); 1003 fileMenu.removeAll(); 1004 editMenu.removeAll(); 1005 viewMenu.removeAll(); 1006 helpMenu.removeAll(); 1007 1008 bar.add(fileMenu); 1010 fileMenu.add(this.newScenarioAction); 1011 fileMenu.add(new Separator()); 1012 fileMenu.add(this.saveScenarioAction); 1013 fileMenu.add(this.saveScenarioAsAction); 1014 fileMenu.add(this.openScenarioAction); 1015 fileMenu.add(new Separator()); 1016 fileMenu.add(this.exitAction); 1017 1018 bar.add(editMenu); 1020 this.editMenu.add(this.unSelectAction); 1022 this.editMenu.add(new Separator()); 1023 this.editMenu.add(cutAction); 1025 this.editMenu.add(copyAction); 1026 this.editMenu.add(pasteAction); 1027 this.editMenu.add(new Separator()); 1029 this.editMenu.add(this.deleteNodeAction); 1030 this.editMenu.add(new Separator()); 1031 this.editMenu.add(this.upperAction); 1033 this.editMenu.add(this.lowerAction); 1034 this.editMenu.add(new Separator()); 1035 this.editMenu.add(this.addMenu); 1037 1038 bar.add(viewMenu); 1040 viewMenu.add(this.fullBehaviorsModeAction); 1041 viewMenu.add(this.fullLoadProfileModeAction); 1042 viewMenu.add(this.splitModeAction); 1043 viewMenu.add(new Separator()); 1044 viewMenu.add(this.expandAction); 1045 viewMenu.add(this.collapseAction); 1046 viewMenu.add(new Separator()); 1047 viewMenu.add(this.generateTreeAction); 1048 viewMenu.add(this.generateXMLAction); 1049 1050 helpMenu.add(this.showHelpAction); 1052 helpMenu.add(new Separator()); 1053 helpMenu.add(new AboutAction(this)); 1054 bar.add(helpMenu); 1055 } 1056 1057 private void createBehaviorsPopup() { 1058 this.popupMenu.removeAll(); 1059 this.addMenuPopup = new MenuManager("Add a new"); 1061 this.popupMenu.add(this.addMenuPopup); 1062 this.popupMenu.add(new Separator()); 1063 this.popupMenu.add(this.unSelectAction); 1065 this.popupMenu.add(new Separator()); 1066 this.popupMenu.add(cutAction); 1068 this.popupMenu.add(copyAction); 1069 this.popupMenu.add(pasteAction); 1070 this.popupMenu.add(new Separator()); 1072 this.popupMenu.add(this.deleteNodeAction); 1073 this.popupMenu.add(new Separator()); 1074 this.popupMenu.add(this.upperAction); 1076 this.popupMenu.add(this.lowerAction); 1077 this.popupMenu.add(new Separator()); 1079 this.popupMenu.add(this.expandAction); 1080 this.popupMenu.add(this.collapseAction); 1081 this.popupMenu.add(new Separator()); 1082 this.popupMenu.add(this.generateXMLAction); 1083 } 1084 1085 1090 protected MenuManager createMenuManager() { 1091 cat.debug("-> createMenuManager"); 1092 bar = new MenuManager(); 1093 fileMenu = new MenuManager("&File"); 1095 this.editMenu = new MenuManager("&Edit"); 1097 this.addMenu = new MenuManager("Add a new"); 1099 viewMenu = new MenuManager("&View"); 1101 helpMenu = new MenuManager("&Help"); 1103 this.popupMenu = new MenuManager(); 1105 this.addMenuPopup = new MenuManager(); 1106 1107 this.setMenu(); 1109 this.updateAddMenu(null); 1110 1111 return bar; 1112 } 1113 1114 1117 protected StatusLineManager createStatusLineManager() { 1118 cat.debug("-> createStatusLineManager"); 1119 this.statusLine = new StatusLineManager(); 1120 1121 return statusLine; 1122 } 1123 1124 1127 private void setEditorToolBar() { 1128 cat.warn("SCENARIO EDITOR TOOLBAR {{{{{{{{{{{{{{{"); 1129 toolBar.removeAll(); 1131 toolBar.add(this.newScenarioAction); 1133 toolBar.add(this.saveScenarioAction); 1135 toolBar.add(this.openScenarioAction); 1137 toolBar.add(new Separator()); 1141 toolBar.add(this.cutAction); 1143 toolBar.add(this.copyAction); 1144 toolBar.add(this.pasteAction); 1145 toolBar.add(new Separator()); 1147 1148 toolBar.add(this.deleteNodeAction); 1149 toolBar.add(new Separator()); 1151 toolBar.add(this.upperAction); 1153 toolBar.add(this.lowerAction); 1154 toolBar.add(new Separator()); 1156 toolBar.add(this.fullBehaviorsModeAction); 1157 toolBar.add(this.fullLoadProfileModeAction); 1158 toolBar.add(this.splitModeAction); 1159 toolBar.add(new Separator()); 1161 toolBar.add(this.generateTreeAction); 1163 toolBar.add(this.generateXMLAction); 1164 toolBar.update(true); 1166 } 1167 1168 1173 private Menu createTabPopupMenu() { 1174 this.generateXMLAction.setEnabled(false); 1175 this.generateTreeAction.setEnabled(false); 1176 Menu popup = new Menu(tabFolder); 1177 this.generateTabFolderPopup2 = new MenuItem(popup, SWT.POP_UP); 1178 this.generateTabFolderPopup2.setText(this.generateTreeAction.getText()); 1179 this.generateTabFolderPopup2.setImage(Icons.getImageRegistry().get( 1180 FileName.GENERATE_ICON)); 1181 this.generateTabFolderPopup2.addSelectionListener(this); 1182 this.generateTabFolderPopup = new MenuItem(popup, SWT.POP_UP); 1183 this.generateTabFolderPopup.setText(this.generateXMLAction.getText()); 1184 this.generateTabFolderPopup.setImage(Icons.getImageRegistry().get( 1185 FileName.GENERATE_ICON)); 1186 this.generateTabFolderPopup.addSelectionListener(this); 1187 return popup; 1188 } 1189 1194 private Menu createXMLEditorPopup() { 1195 Menu popupXML = new Menu(this.styledText); 1196 this.cutXMLEditorItem = new MenuItem(popupXML, SWT.POP_UP); 1197 this.cutXMLEditorItem.setText("Cut"); 1198 this.cutXMLEditorItem.setImage(Icons.getImageRegistry().get( 1199 FileName.CUT_ICON)); 1200 this.cutXMLEditorItem.addSelectionListener(this); 1201 this.copyXMLEditorItem = new MenuItem(popupXML, SWT.POP_UP); 1202 this.copyXMLEditorItem.setText("Copy"); 1203 this.copyXMLEditorItem.setImage(Icons.getImageRegistry().get( 1204 FileName.COPY_ICON)); 1205 this.copyXMLEditorItem.addSelectionListener(this); 1206 this.pasteXMLEditorItem = new MenuItem(popupXML, SWT.POP_UP); 1207 this.pasteXMLEditorItem.setText("Paste"); 1208 this.pasteXMLEditorItem.setImage(Icons.getImageRegistry().get( 1209 FileName.PASTE_ICON)); 1210 this.pasteXMLEditorItem.addSelectionListener(this); 1211 new MenuItem(popupXML, SWT.SEPARATOR); 1212 this.generateXMLEditorItem = new MenuItem(popupXML, SWT.POP_UP); 1213 this.generateXMLEditorItem.setText("Generate Tree"); 1214 this.generateXMLEditorItem.setImage(Icons.getImageRegistry().get( 1215 FileName.GENERATE_ICON)); 1216 this.generateXMLEditorItem.addSelectionListener(this); 1217 return popupXML; 1218 } 1219 1220 1223 protected ToolBarManager createToolBarManager(int style) { 1224 cat.debug("-> createToolBarManager"); 1225 toolBar = new ToolBarManager(style); 1226 this.setEditorToolBar(); 1227 1228 return toolBar; 1229 } 1230 1231 1235 1239 private static void printVersion() { 1240 cat.debug("-> printVersion"); 1241 System.out.println("CLIF Scenario GUI Editor v" + FileName.VERSION); 1242 } 1243 1244 1248 private static void printHelp() { 1249 cat.debug("-> printHelp"); 1250 System.out.println("CLIF Scenario GUI Editor : "); 1251 System.out.println("use : ant editor [option]"); 1252 System.out.println("option :"); 1253 System.out.println(" fileName"); 1254 System.out 1255 .println(" --version : Print the version number of the editor"); 1256 System.out.println(" --help : Print this help"); 1257 } 1258 1259 1265 public static void main(String [] args) { 1266 PropertyConfigurator.configure(FileName.LOG4J_PROPERTIES); 1267 for (int i = 0; i < args.length; i++) { 1269 if (args[i].equals("--version")) { 1270 printVersion(); 1271 return; 1272 } else if (args[i].equals("--help")) { 1273 printHelp(); 1274 return; 1275 } 1276 } 1277 ScenarioGUIEditor gui = new ScenarioGUIEditor(); 1279 gui.setBlockOnOpen(true); 1280 gui.open(); 1281 Display.getCurrent().dispose(); 1282 } 1283} | Popular Tags |