Math2mat

/home/ythoma/docs/math2mat/svn/wp1/framework/m2mGUI/src/m2m/frontend/ApplicationActionBarAdvisor.java

Go to the documentation of this file.
00001 
00020 package m2m.frontend;
00021 
00022 import org.eclipse.jface.action.GroupMarker;
00023 import org.eclipse.jface.action.ICoolBarManager;
00024 import org.eclipse.jface.action.IMenuManager;
00025 import org.eclipse.jface.action.IToolBarManager;
00026 import org.eclipse.jface.action.MenuManager;
00027 import org.eclipse.jface.action.Separator;
00028 import org.eclipse.jface.action.ToolBarContributionItem;
00029 import org.eclipse.jface.action.ToolBarManager;
00030 import org.eclipse.swt.SWT;
00031 import org.eclipse.ui.IWorkbenchActionConstants;
00032 import org.eclipse.ui.IWorkbenchWindow;
00033 import org.eclipse.ui.actions.ActionFactory;
00034 import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction;
00035 import org.eclipse.ui.application.ActionBarAdvisor;
00036 import org.eclipse.ui.application.IActionBarConfigurer;
00037 
00038 import m2m.frontend.actions.ClearConsoleAction;
00039 import m2m.frontend.actions.ClearProject;
00040 import m2m.frontend.actions.CommentAction;
00041 import m2m.frontend.actions.CommentUncommentAction;
00042 import m2m.frontend.actions.ConfigureExternalToolsAction;
00043 import m2m.frontend.actions.ConfigureOptimisationAction;
00044 import m2m.frontend.actions.ConfigureSimulationAction;
00045 import m2m.frontend.actions.CopyAction;
00046 import m2m.frontend.actions.CutAction;
00047 import m2m.frontend.actions.DeleteAction;
00048 import m2m.frontend.actions.GenerateVHDL;
00049 import m2m.frontend.actions.LaunchOctaveAction;
00050 import m2m.frontend.actions.LaunchOctaveWithRegeneratedFileAction;
00051 import m2m.frontend.actions.LaunchOptimisationAction;
00052 import m2m.frontend.actions.LaunchRunAllUbiduleAction;
00053 import m2m.frontend.actions.LaunchUbiduleVerification;
00054 import m2m.frontend.actions.LaunchVerifAction;
00055 import m2m.frontend.actions.LaunchXilinxUbiduleAction;
00056 import m2m.frontend.actions.NewProjectAction;
00057 import m2m.frontend.actions.OpenFileAction;
00058 import m2m.frontend.actions.PasteAction;
00059 import m2m.frontend.actions.ReOpenFile;
00060 import m2m.frontend.actions.RedoAction;
00061 import m2m.frontend.actions.RunAll;
00062 import m2m.frontend.actions.SaveAsFileAction;
00063 import m2m.frontend.actions.SaveFileAction;
00064 import m2m.frontend.actions.SelectAllAction;
00065 import m2m.frontend.actions.UncommentAction;
00066 import m2m.frontend.actions.UndoAction;
00067 import m2m.frontend.actions.ValidateProjectsAction;
00068 import m2m.frontend.actions.ViewDotFlatFile;
00069 import m2m.frontend.actions.ViewDotTreeFile;
00070 import m2m.frontend.actions.ViewDynamicStructure;
00071 
00077 public class ApplicationActionBarAdvisor extends ActionBarAdvisor 
00078 {
00079         private static ApplicationActionBarAdvisor instance;
00080         
00081     // Actions - important to allocate these only in makeActions, and then use them
00082     // in the fill methods.  This ensures that the actions aren't recreated
00083     // when fillActionBars is called with FILL_PROXY.
00084     private IWorkbenchAction exitAction;
00085     private IWorkbenchAction aboutAction;
00086     private UndoAction undoAction;
00087     private RedoAction redoAction;
00088     private CutAction cutAction;
00089     private CopyAction copyAction;
00090     private PasteAction pasteAction;
00091     private DeleteAction deleteAction;
00092     private SelectAllAction selectAllAction;
00093     private NewProjectAction newProjectAction;
00094     private NewProjectAction newProjectFromFileAction;
00095     private OpenFileAction openFileAction;
00096     private SaveFileAction saveFileAction;
00097     private SaveAsFileAction saveAsFileAction;
00098     private LaunchOctaveAction launchOctaveAction;
00099     private LaunchOptimisationAction launchOptimisationAction;
00100     private LaunchVerifAction launchVerifAction;
00101     private LaunchUbiduleVerification launchUbiduleVerification;
00102     private LaunchXilinxUbiduleAction launchXilinxUbiduleAction;
00103     private LaunchRunAllUbiduleAction launchRunAllUbiduleAction;
00104  //   private LaunchDotGeneration launchDotGeneration;
00105     private ViewDotTreeFile viewDotTreeFile;
00106     private ViewDotFlatFile viewDotFlatFile;
00107     private GenerateVHDL generateVHDL;
00108     private ClearProject clearProject;
00109     private ClearConsoleAction clearConsole;
00110     private ConfigureOptimisationAction configureOptimisationAction;
00111     private ConfigureSimulationAction configureSimulationAction;
00112     private ConfigureExternalToolsAction configureExternalToolsAction;
00113     private RunAll runAllAction;
00114     private CommentUncommentAction commentUncommentAction;
00115     private CommentAction commentAction;
00116     private UncommentAction uncommentAction;
00117  //   private GenerateMath2MatCode generateM2MCodeAction;
00118     private LaunchOctaveWithRegeneratedFileAction launchOctaveWithRegenAction;
00119  //   private CompareOctaveResults compareOctaveResults;
00120     private ViewDynamicStructure viewDynamicStructure;
00121     private ValidateProjectsAction validateProjectsAction;
00122     private ReOpenFile[] reOpenFile = new ReOpenFile[5];
00123     private MenuManager commentMenu = new MenuManager("&Comment/Uncomment", IWorkbenchActionConstants.M_WINDOW);
00124     private MenuManager ubiduleMenu = new MenuManager("&Ubidule test", IWorkbenchActionConstants.M_WINDOW);
00125     
00126     private MenuManager fileMenu;
00127 
00128     private ApplicationActionBarAdvisor(IActionBarConfigurer configurer) {
00129         super(configurer);
00130         configurer.getWindowConfigurer( ).getWindow();
00131     }
00132     
00133     public UndoAction getUndoAction () {
00134         return undoAction;
00135     }
00136     
00137     protected void makeActions(final IWorkbenchWindow window) {
00138 
00139         // Creates the actions and registers them.
00140         // Registering is needed to ensure that key bindings work.
00141         // The corresponding commands keybindings are defined in the plugin.xml file.
00142         // Registering also provides automatic disposal of the actions when
00143         // the window is closed.
00144 
00145                 exitAction = ActionFactory.QUIT.create(window);
00146         register(exitAction);
00147         
00148         aboutAction = ActionFactory.ABOUT.create(window);
00149         register(aboutAction);
00150         
00151         undoAction = new UndoAction(window, "Undo");
00152         register(undoAction);
00153         
00154         redoAction = new RedoAction(window, "Redo");
00155         register(redoAction);
00156         
00157         cutAction = new CutAction(window, "Cut");
00158         register(cutAction);
00159         
00160         copyAction = new CopyAction(window, "Copy");
00161         register(copyAction);
00162         
00163         pasteAction = new PasteAction(window, "Paste");
00164         register(pasteAction);
00165         
00166         deleteAction = new DeleteAction(window, "Delete");
00167         register(deleteAction);
00168         
00169         selectAllAction = new SelectAllAction(window, "Select All");
00170         register(selectAllAction);
00171         
00172         commentUncommentAction = new CommentUncommentAction(window, "Toggle Comment");
00173         register(commentUncommentAction);
00174         
00175         commentAction = new CommentAction(window, "Comment");
00176         register(commentAction);
00177         
00178         uncommentAction = new UncommentAction(window, "Uncomment");
00179         register(uncommentAction);
00180 
00181         newProjectAction = new NewProjectAction(window, "New empty project",true);
00182         register(newProjectAction);
00183 
00184         newProjectFromFileAction = new NewProjectAction(window, "New project from .m file",false);
00185         register(newProjectFromFileAction);
00186         
00187         openFileAction = new OpenFileAction(window, "Open");
00188         register(openFileAction);
00189         
00190         saveFileAction = new SaveFileAction(window, "Save");
00191         register(saveFileAction);
00192         
00193         saveAsFileAction = new SaveAsFileAction(window, "Save As...");
00194         register(saveFileAction);
00195         
00196         validateProjectsAction = new ValidateProjectsAction(window, "Validate Projects");
00197         register(validateProjectsAction);
00198         
00199         launchOptimisationAction = new LaunchOptimisationAction(window, "Launch Optimization");
00200         register(launchOptimisationAction);
00201         
00202         launchOctaveAction = new LaunchOctaveAction(window, "Launch test generation (with Octave)");
00203         register(launchOctaveAction);
00204         
00205         launchVerifAction = new LaunchVerifAction(window, "Launch Verification");
00206         register(launchVerifAction);
00207         
00208         launchUbiduleVerification = new LaunchUbiduleVerification(window, "Launch ubidule verification");
00209         register(launchUbiduleVerification);
00210         
00211         launchXilinxUbiduleAction = new  LaunchXilinxUbiduleAction(window, "Launch ubidule files generation");
00212         register(launchXilinxUbiduleAction);
00213         
00214         launchRunAllUbiduleAction = new LaunchRunAllUbiduleAction(window, "Launch entire ubidule process");
00215         register(launchRunAllUbiduleAction);
00216         
00217      //   launchDotGeneration = new LaunchDotGeneration(window, "Launch dot file generation");
00218      //   register(launchDotGeneration);
00219         
00220         viewDotTreeFile = new ViewDotTreeFile(window, "Show the tree view");
00221         register(viewDotTreeFile);
00222         
00223         viewDotFlatFile = new ViewDotFlatFile(window, "Show the flat view");
00224         register(viewDotFlatFile);
00225         
00226         viewDynamicStructure = new ViewDynamicStructure(window, "Show dynamic view"); 
00227         register(viewDynamicStructure);
00228         
00229         clearConsole = new ClearConsoleAction(window,"Clear the console");
00230         register(clearConsole);
00231         
00232         generateVHDL = new GenerateVHDL(window, "Generate VHDL");
00233         register(generateVHDL);
00234         
00235         clearProject = new ClearProject(window, "Clear project");
00236         register(clearProject);
00237         
00238         configureOptimisationAction = new ConfigureOptimisationAction(window, "Optimization");
00239         register(configureOptimisationAction);
00240         
00241         configureSimulationAction = new ConfigureSimulationAction(window, "Simulation");
00242         register(configureSimulationAction);
00243         
00244         configureExternalToolsAction = new ConfigureExternalToolsAction(window, "External tools");
00245         register(configureExternalToolsAction);
00246         
00247         runAllAction = new RunAll(window, "Run all");
00248         register(runAllAction);
00249         
00250      //   generateM2MCodeAction = new GenerateMath2MatCode(window, "Generate new Octave Code");
00251      //   register(generateM2MCodeAction);
00252         
00253         launchOctaveWithRegenAction = new LaunchOctaveWithRegeneratedFileAction(window, "Test regenerated Octave code");
00254         register(launchOctaveWithRegenAction);
00255         
00256   //      compareOctaveResults = new CompareOctaveResults(window, "Compare the results given by the original file and the regenerated file");
00257    //     register(compareOctaveResults);
00258 
00259         for(int i = 0; i < reOpenFile.length; i++) {
00260                 reOpenFile[i] = new ReOpenFile(window, "No file");
00261                 register(reOpenFile[i]);
00262         }
00263         
00264         showOpenMenu(false);
00265     }
00266     
00267     public void repopulateFileMenu() {
00268 
00269         fileMenu.removeAll();
00270         
00271         // File
00272         fileMenu.add(newProjectAction);
00273         fileMenu.add(newProjectFromFileAction);
00274         fileMenu.add(new Separator());
00275         fileMenu.add(openFileAction);
00276         fileMenu.add(saveFileAction);
00277         fileMenu.add(saveAsFileAction);
00278         
00279         fileMenu.add(new Separator());
00280         
00281         GUIProperties GUIProps = GUIProperties.getReference();
00282         String[] rof = GUIProps.getReOpenFile();
00283         
00284                 for(int i = 0; i < reOpenFile.length; i++) 
00285                         if (!(rof[i].equalsIgnoreCase("null") || rof[i].equalsIgnoreCase("No file"))){
00286                                 reOpenFile[i].setPath(rof[i].equalsIgnoreCase("null") ? "No File": rof[i]);     
00287                                 fileMenu.add(reOpenFile[i]);
00288                 }
00289         
00290         fileMenu.add(new Separator());
00291         fileMenu.add(exitAction);
00292         
00293     }
00294     
00295     
00296     protected void fillMenuBar(IMenuManager menuBar) {
00297 
00298         MenuManager helpMenu = new MenuManager("&Help", IWorkbenchActionConstants.M_HELP);
00299         MenuManager configMenu = new MenuManager("&Configure...", IWorkbenchActionConstants.M_WINDOW);
00300         fileMenu = new MenuManager("&File", IWorkbenchActionConstants.M_WINDOW);
00301         MenuManager editMenu = new MenuManager("&Edit", IWorkbenchActionConstants.M_EDIT); //.M_FILE);
00302         MenuManager toolMenu = new MenuManager("&Tools", IWorkbenchActionConstants.M_WINDOW);
00303         MenuManager viewMenu = new MenuManager("&View", IWorkbenchActionConstants.M_WINDOW);
00304         
00305         menuBar.add(fileMenu);
00306         // Add a group marker indicating where action set menus will appear.
00307         menuBar.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
00308         menuBar.add(editMenu);
00309         menuBar.add(viewMenu);
00310         menuBar.add(toolMenu);
00311         menuBar.add(configMenu);
00312         menuBar.add(helpMenu);
00313         
00314         repopulateFileMenu();
00315         
00316 
00317        // viewMenu.add(launchDotGeneration);
00318         viewMenu.add(viewDotTreeFile);
00319         viewMenu.add(viewDotFlatFile);
00320         viewMenu.add(viewDynamicStructure);
00321         viewMenu.add(new Separator());
00322         viewMenu.add(clearConsole);
00323        
00324         // Tools
00325     //    toolMenu.add(launchOptimisationAction);
00326         toolMenu.add(generateVHDL);
00327         toolMenu.add(launchOctaveAction);
00328         toolMenu.add(launchOctaveWithRegenAction);
00329         toolMenu.add(launchVerifAction);
00330         toolMenu.add(runAllAction);
00331         toolMenu.add(new Separator());
00332         toolMenu.add(clearProject);
00333      //   toolMenu.add(generateM2MCodeAction);
00334      //   toolMenu.add(compareOctaveResults);
00335         toolMenu.add(new Separator());
00336         toolMenu.add(ubiduleMenu);
00337         ubiduleMenu.add(launchXilinxUbiduleAction);
00338         ubiduleMenu.add(launchUbiduleVerification);
00339         ubiduleMenu.add(launchRunAllUbiduleAction);
00340 
00341         toolMenu.add(new Separator());
00342         toolMenu.add(validateProjectsAction);
00343         
00344         // Edit
00345         editMenu.add(undoAction);
00346         editMenu.add(redoAction);
00347         editMenu.add(new Separator());
00348         editMenu.add(cutAction);
00349         editMenu.add(copyAction);
00350         editMenu.add(pasteAction);
00351         editMenu.add(deleteAction);
00352         editMenu.add(new Separator());
00353         editMenu.add(selectAllAction);
00354         editMenu.add(new Separator());
00355         editMenu.add(commentMenu);
00356         
00357         commentMenu.add(commentUncommentAction);
00358         commentMenu.add(commentAction);
00359         commentMenu.add(uncommentAction);
00360         
00361         // Help
00362         helpMenu.add(aboutAction);
00363         
00364         // Configuration
00365         configMenu.add(configureExternalToolsAction);
00366         configMenu.add(configureOptimisationAction);
00367         configMenu.add(configureSimulationAction);
00368         
00369     }
00370     
00371     protected void fillCoolBar(ICoolBarManager coolBar) {
00372         IToolBarManager toolbar = new ToolBarManager(SWT.FLAT | SWT.RIGHT);
00373         coolBar.add(new ToolBarContributionItem(toolbar, "main"));
00374         toolbar.add(newProjectAction);
00375         toolbar.add(openFileAction);
00376         toolbar.add(saveFileAction);
00377         toolbar.add(new Separator());
00378         toolbar.add(generateVHDL);
00379         toolbar.add(launchOptimisationAction);
00380         toolbar.add(launchOctaveAction);
00381         toolbar.add(launchVerifAction);
00382         toolbar.add(runAllAction);
00383         toolbar.add(launchRunAllUbiduleAction);
00384     }
00385     
00386     
00393     public static ApplicationActionBarAdvisor getInstance(IActionBarConfigurer configurer) {
00394         if (instance == null) 
00395             instance = new ApplicationActionBarAdvisor(configurer);
00396         return instance;
00397     }
00398     
00399     
00405     public static ApplicationActionBarAdvisor getInstance() {
00406         return instance;
00407     }    
00408     
00409     
00415         public ReOpenFile[] getReOpenFile() {
00416                 return reOpenFile;
00417         }
00418         
00419         
00425         public void setEnabledConfigureOptimisationAction(boolean value) {
00426                 runAllAction.setEnabled(value);
00427         }
00428         
00429         
00435         public void setEnableConfigureSimulationAction(boolean value) {
00436                 configureSimulationAction.setEnabled(value);
00437         }
00438         
00439         public ConfigureSimulationAction getConfigureSimulationAction() {
00440                 return configureSimulationAction;
00441         }
00442         
00443         
00449         public void showOpenMenu(boolean value)
00450         {
00451                 /* Show/Hide toolMenu actions */
00452         launchOptimisationAction.setEnabled(value);
00453         launchOctaveAction.setEnabled(value);
00454         launchVerifAction.setEnabled(value);
00455         runAllAction.setEnabled(value);
00456       //  launchDotGeneration.setEnabled(value);
00457         viewDotTreeFile.setEnabled(value);
00458         viewDotFlatFile.setEnabled(value);
00459         viewDynamicStructure.setEnabled(value);
00460         generateVHDL.setEnabled(value);
00461         clearProject.setEnabled(value);
00462      //   generateM2MCodeAction.setEnabled(value);
00463         launchOctaveWithRegenAction.setEnabled(value);
00464      //   compareOctaveResults.setEnabled(value);
00465         launchUbiduleVerification.setEnabled(value);
00466         launchXilinxUbiduleAction.setEnabled(value);
00467         launchRunAllUbiduleAction.setEnabled(value);
00468         
00469         /* Show/Hide editMenu actions */
00470         undoAction.setEnabled(value);
00471         redoAction.setEnabled(value);
00472         cutAction.setEnabled(value);
00473         copyAction.setEnabled(value);
00474         pasteAction.setEnabled(value);
00475         deleteAction.setEnabled(value);
00476         selectAllAction.setEnabled(value);
00477         commentUncommentAction.setEnabled(value);
00478         commentAction.setEnabled(value);
00479         uncommentAction.setEnabled(value);
00480         
00481         /* Show/Hide general actions */
00482         configureSimulationAction.setEnabled(value);
00483         configureOptimisationAction.setEnabled(value);
00484         saveFileAction.setEnabled(value);
00485         saveAsFileAction.setEnabled(value);
00486         }
00487         
00488 }
 All Classes Namespaces Files Functions Variables Enumerations