Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: javax/ide/menu/spi/MenuHook.java


1   package javax.ide.menu.spi;
2   
3   import javax.ide.IDEConstants;
4   import javax.ide.extension.ElementName;
5   import javax.ide.extension.ElementStartContext;
6   import javax.ide.extension.ElementVisitor;
7   import javax.ide.extension.ExtensionHook;
8   
9   /**
10   * A <code>MenuHook</code> stores the extension manifest 
11   * information pertaining to actions, menus, and toolbars.
12   */
13  
14  public final class MenuHook extends ExtensionHook
15  {
16    public static final ElementName ELEMENT = 
17      new ElementName( MANIFEST_XMLNS, "menu-hook" );
18      
19    private static final ElementName ACTIONS = new ElementName(
20      MANIFEST_XMLNS, "actions" );
21      
22    private static final ElementName MENUS = new ElementName(
23      MANIFEST_XMLNS, "menus" );
24      
25    private static final ElementName TOOLBARS = new ElementName(
26      MANIFEST_XMLNS, "toolbars" );
27      
28    static final String KEY_MENU_MODEL = "menuModel";
29    static final String KEY_SECTION_CONTAINER = "sectionContainer";
30    
31    
32    private ElementVisitor _actionsVisitor = new ActionsVisitor();
33    private ElementVisitor _toolbarsVisitor = new ToolbarsVisitor();
34    private ElementVisitor _menusVisitor = new MenusVisitor();
35    
36    
37    private final MenuModel _menuModel = createInitialMenuModel();
38    
39    
40    public void start( ElementStartContext context )
41    {
42      context.getScopeData().put( KEY_MENU_MODEL, _menuModel );
43      
44      context.registerChildVisitor( TOOLBARS, _toolbarsVisitor );
45      context.registerChildVisitor( ACTIONS, _actionsVisitor );
46      context.registerChildVisitor( MENUS, _menusVisitor );
47    }
48    
49    public MenuModel getModel()
50    {
51      return _menuModel;
52    }
53  
54    /**
55     * Create the initial menu model. This prepopulates the menu model with the
56     * standard JSR-198 items and sections so that other items can be positioned
57     * in relation to them.
58     * 
59     * IDEs may override this to change the position of the standard items based
60     * on the layout of their own menus and toolbars.
61     * 
62     * @return a pre populated initial menu model.
63     */
64    protected MenuModel createInitialMenuModel()
65    {
66  
67      MenuModel model = new MenuModel();
68      MenuBar mbMain = 
69        model.findOrCreatePullDownMenu( IDEConstants.MAIN_WINDOW_MENUBAR_ID ); 
70      
71      Menu menu = new Menu( IDEConstants.FILE_MENU_ID );
72      
73      Section section = new Section( IDEConstants.NEW_SECTION_ID );
74      menu.addSection( section );
75      
76      section = new Section( IDEConstants.OPEN_SECTION_ID );
77      Item item = new Item( IDEConstants.OPEN_ACTION_ID );
78      section.addItem( item );
79      menu.addSection( section );
80      
81      section = new Section( IDEConstants.CLOSE_SECTION_ID );
82      menu.addSection( section );
83      
84      section = new Section( IDEConstants.PRINT_SECTION_ID );
85      menu.addSection( section );
86      
87      mbMain.addMenu( menu );
88      
89      menu = new Menu( IDEConstants.EDIT_MENU_ID );
90      section = new Section( IDEConstants.COPY_PASTE_SECTION_ID );
91      section.addItem( new Item( IDEConstants.CUT_ACTION_ID ) );
92      section.addItem( new Item( IDEConstants.COPY_ACTION_ID ) );
93      section.addItem( new Item( IDEConstants.PASTE_ACTION_ID ) );
94      menu.addSection( section );
95      mbMain.addMenu( menu );
96      
97      menu = new Menu( IDEConstants.VIEW_MENU_ID );
98      mbMain.addMenu( menu );
99      
100     menu = new Menu( IDEConstants.HELP_MENU_ID );
101     mbMain.addMenu( menu );
102     
103 
104     return model;
105   }
106 
107 }