KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > clif > scenario > util > isac > gui > ScenarioGUIEditor


1 /*
2  * CLIF is a Load Injection Framework
3  * Copyright (C) 2004 France Telecom R&D
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * CLIF
20  *
21  * Contact: clif@objectweb.org
22  */

23 package org.objectweb.clif.scenario.util.isac.gui;
24
25 import java.util.Enumeration JavaDoc;
26 import java.util.Vector JavaDoc;
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 /**
93  * Main class of the scenario gui editor, this class extends application window,
94  * and will set up all the widgets needed to edit a scenario...
95  *
96  * @author JC Meillaud
97  * @author A Peyrard
98  */

99 public class ScenarioGUIEditor extends ApplicationWindow
100         implements
101             SelectionListener,
102             FocusListener,
103             ModifyListener {
104
105     private String JavaDoc 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     // actions
122
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     // loadProfile editor
145
private LoadDrawingEditor loadDrawingEditor;
146
147     // popup xml editor items
148
private MenuItem cutXMLEditorItem;
149     private MenuItem copyXMLEditorItem;
150     private MenuItem pasteXMLEditorItem;
151     private MenuItem generateXMLEditorItem;
152
153     // status line
154
private StatusLineManager statusLine;
155     // editor shown
156
private int editorShown;
157     // logger
158
static Category cat = Category.getInstance(ScenarioGUIEditor.class
159             .getName());
160
161     // EDitor Mode
162
public static final int GUI_EDITOR = 0;
163     public static final int XML_EDITOR = 1;
164     // TreeMode
165
// public static final int BEHAVIORS_TREE = 2;
166
// public static final int LOAD_PROFILE_TREE = 1;
167

168     // Current tree viewer used
169
// private int currentTreeViewer = 2;
170

171     // define the toolbar
172
private ToolBarManager toolBar;
173
174     /**
175      * Define the menu managers
176      */

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     /**
196      * Build a new Scenario gui editor object, this object is a application
197      * window, which permit the edition of a clif scenario file
198      *
199      */

200     public ScenarioGUIEditor() {
201         super(null);
202         cat.debug("-> constructor");
203
204         // init the managers
205
this.initManagers();
206         // init actions
207
this.initActions();
208         // initialise the state of the help panel
209
this.helpVisible = true;
210         // initialise the current filename
211
this.fileName = null;
212         // add a menu bar
213
this.addMenuBar();
214         // add a status line
215
this.addStatusLine();
216         // add a toolBar
217
this.addToolBar(SWT.FLAT | SWT.WRAP);
218
219         // set the saved state
220
setScenarioSavedState(false);
221     }
222
223     ///////////////////////////////////////////////////////////////////////////////////////
224
// Control method, getter, setter and some others stuffs
225
///////////////////////////////////////////////////////////////////////////////////////
226

227     /**
228      * Get the tree viewer
229      */

230     public ScenarioTreeViewer getTreeViewer() {
231         cat.debug("-> getTreeViewer");
232         return this.treeViewer;
233     }
234
235     /**
236      * Get the scrolled composite which contains the help
237      */

238     public ScrolledComposite getHelpScrolled() {
239         cat.debug("-> getHelpScrolled");
240         return this.helpScrolled;
241     }
242
243     /**
244      * @return Returns the editorShowed.
245      */

246     public int getEditorShowed() {
247         return editorShown;
248     }
249     /**
250      * @param editorShowed
251      * The editorShowed to set.
252      */

253     public void setEditorShowed(int editorShowed) {
254         this.editorShown = editorShowed;
255         //this.generateXMLAction.switchGenerationMethod(editorShowed);
256
//this.generateTreeAction.switchGenerationMethod(editorShowed);
257
// if the tab folder popup is not null
258
// if (this.generateTabFolderPopup != null)
259
// this.generateTabFolderPopup.setText(this.generateXMLAction
260
// .getText());
261
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             // disable the split mode buttons
269
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             // set the menu actions
284
this.generateXMLAction.setEnabled(true);
285             this.generateTreeAction.setEnabled(false);
286             //this.deleteNodeAction.setEnabled(true);
287
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     /**
300      * Attribute fileName getter
301      *
302      * @return The curent fileName
303      */

304     public String JavaDoc getFileName() {
305         cat.debug("-> getFileName");
306         return fileName;
307     }
308
309     /**
310      * Attribute fileName setter
311      *
312      * @param string
313      * The current fileName
314      */

315     public void setFileName(String JavaDoc string) {
316         cat.debug("-> setFileName");
317         fileName = string;
318         this.updateWindowTitle();
319     }
320
321     /**
322      * @return Returns the behaviorsSavedState.
323      */

324     public boolean isBehaviorsSavedState() {
325         return behaviorsSavedState;
326     }
327     /**
328      * @param behaviorsSavedState
329      * The behaviorsSavedState to set.
330      */

331     public void setScenarioSavedState(boolean behaviorsSavedState) {
332         this.behaviorsSavedState = behaviorsSavedState;
333         // update the title
334
this.updateWindowTitle();
335         // update the save action
336
this.saveScenarioAction.setEnabled(!behaviorsSavedState);
337     }
338
339     /**
340      * Method wich return the saved state
341      * @return The saved state
342      */

343     public boolean getScenarioSavedState() {
344         return this.behaviorsSavedState;
345     }
346
347     /**
348      * Get the state of the help panel
349      *
350      * @return The help panel state
351      */

352     public boolean getHelpVisibleState() {
353         cat.debug("-> getVisibleState");
354         return this.helpVisible;
355     }
356
357     /**
358      * Set the state of the help panel
359      *
360      * @param state
361      * The state which will be set to the help panel
362      */

363     public void setHelpVisibleState(boolean state) {
364         cat.debug("-> setVisibleState");
365         this.helpVisible = state;
366     }
367
368     /**
369      * Initialise the managers
370      */

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     /**
379      * Initialise the actions
380      */

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         // change mode actions
400
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     /**
411      * When the selection has changed in the tree viewer, this method is called
412      *
413      * @param node
414      * The node which is selected
415      */

416     public void notifySelectionChanged(ScenarioNode node) {
417         cat.debug("-> notifySelectionChanged");
418         // enable paste action if the clipboard is not null
419
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         // Check if the node is not null
429
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         // enabled actions which need a node selected
442
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 JavaDoc help = this.treeManager.getNodeHelp(node);
451         this.updateHelp(help);
452     }
453
454     /**
455      * Notify that the selection has changed in the load profile editor
456      *
457      * @param gd
458      * the group description
459      */

460     public void notifySelectionChangedInLoadProfileEditor(GroupDescription gd) {
461         // change the action which are allowed
462
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     /////////////////////////////////////////////////////////////////////
482
// Listener Implementation
483
/////////////////////////////////////////////////////////////////////
484

485     /**
486      * @see org.eclipse.jface.window.Window#close()
487      */

488     public boolean close() {
489         // check if the scenario is saved
490
if (!this.isBehaviorsSavedState() && this.isNotNullTree()) {
491             // ask the user if he wants to save the scenario
492
String JavaDoc[] buttonText = new String JavaDoc[]{"Yes", "No", "Cancel"};
493             String JavaDoc 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                 // yes
501
case 0 :
502                     SaveScenarioAction.saveScenario(this);
503                     return super.close();
504                 // No
505
case 1 :
506
507                     return super.close();
508                 // Cancel
509
case 2 :
510                     return false;
511             }
512         }
513         return super.close();
514     }
515
516     /**
517      * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
518      */

519     public void widgetDefaultSelected(SelectionEvent event) {
520         cat.warn("-> widgetDefaultSelected : should never append");
521     }
522
523     /**
524      * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
525      */

526     public void widgetSelected(SelectionEvent event) {
527         cat.debug("-> widgetSelected");
528         // if popup menu is the source event
529
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         ///////////////////////////////
538
// Popup XML Editor items
539
if (event.getSource() == this.cutXMLEditorItem) {
540             // exec cut action
541
this.cutAction.run();
542             return;
543         }
544         if (event.getSource() == this.copyXMLEditorItem) {
545             // exec copy action
546
this.copyAction.run();
547             return;
548         }
549         if (event.getSource() == this.pasteXMLEditorItem) {
550             // exec paste action
551
this.pasteAction.run();
552             return;
553         }
554         if (event.getSource() == this.generateXMLEditorItem) {
555             // exec generate tree action
556
this.generateTreeAction.run();
557             return;
558         }
559         // We click on the tabFolder
560
int no = this.tabFolder.getSelectionIndex();
561         // show XML editor
562
switch (no) {
563             case XML_EDITOR :
564                 setEditorShowed(XML_EDITOR);
565                 break;
566             // show GUI editor
567
case GUI_EDITOR :
568                 setEditorShowed(GUI_EDITOR);
569                 break;
570             default :
571         // there is none others choice
572
}
573     }
574
575     /**
576      * @see org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events.ModifyEvent)
577      */

578     public void modifyText(ModifyEvent arg0) {
579         this.setScenarioSavedState(false);
580     }
581
582     /**
583      * @see org.eclipse.swt.events.FocusListener#focusGained(org.eclipse.swt.events.FocusEvent)
584      */

585     public void focusGained(FocusEvent arg0) {
586         // do nothing
587
}
588
589     /**
590      * @see org.eclipse.swt.events.FocusListener#focusLost(org.eclipse.swt.events.FocusEvent)
591      */

592     public void focusLost(FocusEvent arg0) {
593         // do nothing
594
}
595
596     //////////////////////////////////////////////////////////////////////
597
// Creation of the interfaces methods
598
//////////////////////////////////////////////////////////////////////
599

600     /**
601      * This method check if the tree containing in the treeviewer is not a new
602      * tree without nodes
603      *
604      * @return True if the tree has not been edited
605      */

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     /**
620      * Change window Title
621      */

622     private void updateWindowTitle() {
623         String JavaDoc currentName = getFileName();
624         if (currentName == null)
625             currentName = "NewScenario";
626         String JavaDoc 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     /**
636      * @return Returns the styledText.
637      */

638     public StyledText getStyledText() {
639         return styledText;
640     }
641
642     /**
643      * @return Returns the pasteNodeAction.
644      */

645     public PasteAction getPasteNodeAction() {
646         return pasteAction;
647     }
648
649     /**
650      * @return Returns the statusLine.
651      */

652     public StatusLineManager getStatusLine() {
653         return statusLine;
654     }
655
656     /**
657      * @return Returns the currentSplitMode.
658      */

659     public int getCurrentSplitMode() {
660         return currentSplitMode;
661     }
662     /**
663      * @param currentSplitMode
664      * The currentSplitMode to set.
665      */

666     public void setCurrentSplitMode(int currentSplitMode) {
667         this.currentSplitMode = currentSplitMode;
668     }
669     /**
670      * @return Returns the weightSplitMode.
671      */

672     public int[] getWeightSplitMode() {
673         return weightSplitMode;
674     }
675     /**
676      * @param weightSplitMode
677      * The weightSplitMode to set.
678      */

679     public void setWeightSplitMode(int[] weightSplitMode) {
680         this.weightSplitMode = weightSplitMode;
681     }
682
683     public void changeSplitMode(int typeMode) {
684         // if there is no change
685
if (typeMode == this.getCurrentSplitMode())
686             ;
687         // if we were in split mode set the weight of the two forms
688
if (this.getCurrentSplitMode() == ScenarioGUIEditor.SPLIT_MODE) {
689             this.setWeightSplitMode(this.form.getWeights());
690         }
691         // set all actions to true
692
this.fullBehaviorsModeAction.setEnabled(true);
693         this.fullLoadProfileModeAction.setEnabled(true);
694         this.splitModeAction.setEnabled(true);
695
696         // switch between the type mode
697
switch (typeMode) {
698             case ScenarioGUIEditor.FULL_BEHAVIORS_MODE :
699                 // set the maximized part
700
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                 // set the maximized part
706
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                 // reset the weight previously set
713
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         // no other mode
720
}
721     }
722
723     /**
724      * Method which hide the help panel
725      */

726     public void hideHelpPanel() {
727         cat.debug("-> hideHelpPanel");
728         this.formParameters.setMaximizedControl(this.parametersPanel);
729     }
730
731     /**
732      * Method which show the help panel
733      */

734     public void showHelpPanel() {
735         cat.debug("-> showHelpPanel");
736         this.formParameters.setMaximizedControl(null);
737     }
738
739     /**
740      * Switch editor viewer
741      *
742      * @param editor
743      * The editor
744      */

745     public void switchEditorViewer(int editor) {
746         this.tabFolder.setSelection(editor);
747         this.setEditorShowed(editor);
748     }
749
750     /**
751      * @return Returns the editMenu.
752      */

753     public MenuManager getEditMenu() {
754         return editMenu;
755     }
756
757     /**
758      * Update the help composite with the help lines given in parameter
759      *
760      * @param help
761      * The help lines
762      */

763     public void updateHelp(Vector JavaDoc help) {
764         cat.debug("-> updateHelp");
765         // redefine the panel
766
this.helpPanel = new Composite(this.helpScrolled, SWT.FLAT);
767         this.helpPanel.setBackground(this.getShell().getDisplay()
768                 .getSystemColor(SWT.COLOR_WHITE));
769         //this.helpPanel.setBackground(this.getShell().getDisplay()
770
//.getSystemColor(SWT.COLOR_WHITE));
771
// set the layout
772
GridLayout layout = new GridLayout();
773         layout.numColumns = 1;
774         this.helpPanel.setLayout(layout);
775         // add a title to this panel
776
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         // check if the help vector is not null
785
if (help != null) {
786             // add each help line
787
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(new Font("TimesRoman"));
796
//, Font.handle+Font.ITALIC, 30);
797
label.setFont(font);
798                 label.pack();
799                 GridData gridData = new GridData();
800                 gridData.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING;
801                 //gridData.grabExcessHorizontalSpace = true;
802
label.setLayoutData(gridData);
803                 label.setText((String JavaDoc) help.elementAt(i));
804             }
805             font.dispose();
806         }
807         // set the size of the scrolled composite
808
this.helpScrolled.setMinSize(this.helpPanel.computeSize(SWT.DEFAULT,
809                 SWT.DEFAULT));
810         this.helpScrolled.setContent(this.helpPanel);
811         this.helpScrolled.layout();
812     }
813
814     /**
815      * Update the actions which are contains in the add menu, this menu is used
816      * to add a new node on the behaviors tree
817      */

818     public void updateAddMenu(ScenarioNode node) {
819         cat.debug("-> updateAddMenu");
820         // remove all the previous components in this menu
821
this.addMenu.removeAll();
822         this.addMenuPopup.removeAll();
823         Vector JavaDoc 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         // evaluate each type
832
Enumeration JavaDoc elements = childrenAllowed.elements();
833         while (elements.hasMoreElements()) {
834             String JavaDoc type = (String JavaDoc) 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 we add use type, we verify that the plugin is not already
847
// used
848
if (type.equals(Node.USE)) {
849                     Vector JavaDoc 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 JavaDoc usedPlugins = this.treeManager.getUsedPluginsName();
863                     Vector JavaDoc 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             // add a separator
880
if (!this.addMenu.isEmpty()) {
881                 this.addMenu.add(new Separator());
882                 this.addMenuPopup.add(new Separator());
883             }
884             // add the plugin and behavior
885
Vector JavaDoc childrenStructureAllowed = this.treeManager
886                     .childrenAllowed(null);
887             Enumeration JavaDoc elementsStructure = childrenStructureAllowed.elements();
888             while (elementsStructure.hasMoreElements()) {
889                 String JavaDoc type = (String JavaDoc) 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         // Set the size and the title of the window
903
Shell shell = this.getShell();
904         this.updateWindowTitle();
905         shell.setSize(1024, 768);
906         Display display = shell.getDisplay();
907         // Initialise the tabFolder
908
this.tabFolder = new TabFolder(parent, SWT.NONE);
909         // add a selection listener
910
tabFolder.addSelectionListener(this);
911
912         // Composite which permit to split the window into two parts, one for
913
// the behaviors
914
// and the other one for the loads profiles
915
form = new SashForm(tabFolder, SWT.VERTICAL | SWT.NULL);
916         // Definition of the first part, the behaviors part
917
this.formBehaviors = new SashForm(form, SWT.HORIZONTAL | SWT.NULL);
918         // create the tree viewer for behaviors
919
this.treeViewer = new ScenarioTreeViewer(formBehaviors, SWT.SIMPLE
920                 | SWT.BORDER, this);
921         // init the popu menu
922
this.createBehaviorsPopup();
923         // Set the popu menu of the treeviewer
924
this.treeViewer.getTree().setMenu(
925                 this.popupMenu.createContextMenu(this.treeViewer.getTree()));
926         //this.treeViewer.setPopUpMenu(this.popupMenu);
927
// add a focus listener to the tree
928
this.treeViewer.getTree().addFocusListener(this);
929
930         // Split the top rigth panel into two parts, one for parameters editor,
931
// and one for the help
932
this.formParameters = new SashForm(formBehaviors, SWT.HORIZONTAL
933                 | SWT.NULL);
934         // parameters
935
this.parametersPanel = new Composite(formParameters, SWT.FLAT);
936         this.parametersPanel.setLayout(new FillLayout());
937         // set the parent for the parameters panels
938
pluginGUIManager.setParentComposite(parametersPanel);
939         // help
940
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         // // Definition of the second part, the loads profiles part
948
// formLoad = new SashForm(form, SWT.HORIZONTAL | SWT.NULL);
949
// LoadProfileTreeViewer lptv = new LoadProfileTreeViewer(formLoad,
950
// SWT.SIMPLE | SWT.BORDER, this);
951
// // create a popup for this composite
952
// lptv.getTree()
953
// .setMenu(this.popupMenu.createContextMenu(lptv.getTree()));
954

955         this.loadDrawingEditor = new LoadDrawingEditor(form, this);
956
957         // set the weight of the differents parts
958
this.formBehaviors.setWeights(new int[]{30, 70});
959
960         // initialise the plugins
961
this.pluginManager.initialisePluginsTable(FileName.PLUGINS_DIR);
962
963         // initialise the help panel
964
this.updateHelp(null);
965
966         // initialise the XML Editor
967
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         // set the table items
978
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         // popup menu of the tabfolder
985
this.tabFolder.setMenu(this.createTabPopupMenu());
986         setEditorShowed(GUI_EDITOR);
987         // notify the editor showed
988
//setEditorShowed(GUI_EDITOR);
989

990         // set the split mode
991
changeSplitMode(SPLIT_MODE);
992
993         return form;
994     }
995     /**
996      * Create a menu with the allowed Behaviors actions
997      *
998      * True if the treeviewer is the loadprofile treeviewer
999      */

1000    private void setMenu() {
1001        // remove all items
1002
bar.removeAll();
1003        fileMenu.removeAll();
1004        editMenu.removeAll();
1005        viewMenu.removeAll();
1006        helpMenu.removeAll();
1007
1008        // add filemenu
1009
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        // add editmenu
1019
bar.add(editMenu);
1020        // add unselect action
1021
this.editMenu.add(this.unSelectAction);
1022        this.editMenu.add(new Separator());
1023        // add dnd support
1024
this.editMenu.add(cutAction);
1025        this.editMenu.add(copyAction);
1026        this.editMenu.add(pasteAction);
1027        // separator
1028
this.editMenu.add(new Separator());
1029        this.editMenu.add(this.deleteNodeAction);
1030        this.editMenu.add(new Separator());
1031        // add up and down action
1032
this.editMenu.add(this.upperAction);
1033        this.editMenu.add(this.lowerAction);
1034        this.editMenu.add(new Separator());
1035        // initialise the edit menu
1036
this.editMenu.add(this.addMenu);
1037
1038        // viewMenu
1039
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
1051
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        // initialise the popup menu
1060
this.addMenuPopup = new MenuManager("Add a new");
1061        this.popupMenu.add(this.addMenuPopup);
1062        this.popupMenu.add(new Separator());
1063        // add unselect action
1064
this.popupMenu.add(this.unSelectAction);
1065        this.popupMenu.add(new Separator());
1066        // add dnd support
1067
this.popupMenu.add(cutAction);
1068        this.popupMenu.add(copyAction);
1069        this.popupMenu.add(pasteAction);
1070        // separator
1071
this.popupMenu.add(new Separator());
1072        this.popupMenu.add(this.deleteNodeAction);
1073        this.popupMenu.add(new Separator());
1074        // add up and down action
1075
this.popupMenu.add(this.upperAction);
1076        this.popupMenu.add(this.lowerAction);
1077        // expand collapse actions
1078
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    /**
1086     * Create the menumanager for the scenario editor
1087     *
1088     * @see org.eclipse.jface.window.ApplicationWindow#createMenuManager()
1089     */

1090    protected MenuManager createMenuManager() {
1091        cat.debug("-> createMenuManager");
1092        bar = new MenuManager();
1093        // add a file menu
1094
fileMenu = new MenuManager("&File");
1095        // add a edit menu
1096
this.editMenu = new MenuManager("&Edit");
1097        // initialise the edit menu
1098
this.addMenu = new MenuManager("Add a new");
1099        // add a view menu
1100
viewMenu = new MenuManager("&View");
1101        // add a help menu
1102
helpMenu = new MenuManager("&Help");
1103        // add a popup menu
1104
this.popupMenu = new MenuManager();
1105        this.addMenuPopup = new MenuManager();
1106
1107        // set the default menu
1108
this.setMenu();
1109        this.updateAddMenu(null);
1110
1111        return bar;
1112    }
1113
1114    /**
1115     * @see org.eclipse.jface.window.ApplicationWindow#createStatusLineManager()
1116     */

1117    protected StatusLineManager createStatusLineManager() {
1118        cat.debug("-> createStatusLineManager");
1119        this.statusLine = new StatusLineManager();
1120
1121        return statusLine;
1122    }
1123
1124    /**
1125     * Set the toolbars actions
1126     */

1127    private void setEditorToolBar() {
1128        cat.warn("SCENARIO EDITOR TOOLBAR {{{{{{{{{{{{{{{");
1129        // delete all actions
1130
toolBar.removeAll();
1131        // add new file button
1132
toolBar.add(this.newScenarioAction);
1133        // add save button
1134
toolBar.add(this.saveScenarioAction);
1135        // add load button
1136
toolBar.add(this.openScenarioAction);
1137        // add exit action
1138
//toolBar.add(this.exitAction);
1139
// separator
1140
toolBar.add(new Separator());
1141        // add dnd support
1142
toolBar.add(this.cutAction);
1143        toolBar.add(this.copyAction);
1144        toolBar.add(this.pasteAction);
1145        // separator
1146
toolBar.add(new Separator());
1147
1148        toolBar.add(this.deleteNodeAction);
1149        // separator
1150
toolBar.add(new Separator());
1151        // add and down actions
1152
toolBar.add(this.upperAction);
1153        toolBar.add(this.lowerAction);
1154        // separator
1155
toolBar.add(new Separator());
1156        toolBar.add(this.fullBehaviorsModeAction);
1157        toolBar.add(this.fullLoadProfileModeAction);
1158        toolBar.add(this.splitModeAction);
1159        // separator
1160
toolBar.add(new Separator());
1161        // generate
1162
toolBar.add(this.generateTreeAction);
1163        toolBar.add(this.generateXMLAction);
1164        // update
1165
toolBar.update(true);
1166    }
1167
1168    /**
1169     * Create a popup menu for the Tab part
1170     *
1171     * @return The menu created
1172     */

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    /**
1190     * Create a popup menu for the XML Editor part
1191     *
1192     * @return The menu created
1193     */

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    /**
1221     * @see org.eclipse.jface.window.ApplicationWindow#createToolBarManager(int)
1222     */

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    /////////////////////////////////////////////////////////////////////////////
1232
// Execution Part
1233
/////////////////////////////////////////////////////////////////////////////
1234

1235    /**
1236     * This method is used in the execution process, to print in the terminal
1237     * the version of this application
1238     */

1239    private static void printVersion() {
1240        cat.debug("-> printVersion");
1241        System.out.println("CLIF Scenario GUI Editor v" + FileName.VERSION);
1242    }
1243
1244    /**
1245     * This method is used in the execution process, to print in the terminal
1246     * the help of this application
1247     */

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    /**
1260     * Execute the application
1261     *
1262     * @param args
1263     * The arguments given in command line
1264     */

1265    public static void main(String JavaDoc[] args) {
1266        PropertyConfigurator.configure(FileName.LOG4J_PROPERTIES);
1267        // analyse the command line
1268
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        // create a new instance of the editor
1278
ScenarioGUIEditor gui = new ScenarioGUIEditor();
1279        gui.setBlockOnOpen(true);
1280        gui.open();
1281        Display.getCurrent().dispose();
1282    }
1283}
Popular Tags