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

Quick Search    Search Deep

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


1   package javax.ide.menu.spi;
2   
3   import java.util.ArrayList;
4   import java.util.Collections;
5   import java.util.HashMap;
6   import java.util.List;
7   import java.util.Map;
8   import java.util.Set;
9   
10  import javax.ide.command.Controller;
11  import javax.ide.menu.IDEAction;
12  
13  /**
14   * The menu model retrieved from extension manifests.
15   */
16  public final class MenuModel 
17  {
18    private final Map _actions = new HashMap();
19    private final Map _pullDownMenus = new HashMap();
20    private final Map _popupMenus = new HashMap();
21    private final Map _toolbars = new HashMap();
22    private final Map _actionControllers = new HashMap();
23  
24    void addAction( IDEAction action )
25    {
26      _actions.put( action.getID(), action );
27    }
28    
29    boolean isUniqueActionId( String id )
30    {
31      return !_actions.containsKey( id );
32    }
33  
34    Toolbar findOrCreateToolbar( String id )
35    {
36      Toolbar toolbar =  (Toolbar) _toolbars.get( id );
37      if ( toolbar == null )
38      {
39        toolbar = new Toolbar( id );
40        _toolbars.put( id, toolbar );
41      }
42      return toolbar;
43    }
44    
45    MenuBar findOrCreatePullDownMenu( String id )
46    {
47      MenuBar mc =  (MenuBar) _pullDownMenus.get( id );
48      if ( mc == null )
49      {
50        mc = new MenuBar( id );
51        _pullDownMenus.put( id, mc );
52      }
53      return mc;
54    }
55    
56    PopupMenu findOrCreatePopupMenu( String id )
57    {
58      PopupMenu mc =  (PopupMenu) _popupMenus.get( id );
59      if ( mc == null )
60      {
61        mc = new PopupMenu( id );
62        _popupMenus.put( id, mc );
63      }
64      return mc;
65    }
66    
67    /**
68     * Get a set of ids of all actions that have registered controllers.
69     * The action ids in this collection may be a superset of the set of all
70     * registered action ids.
71     * 
72     * @return a set of action ids for which there are controllers (or
73     *    overridden controllers).
74     */
75    public Set getActionsWithControllers()
76    {
77      return _actionControllers.keySet();
78    }
79    
80    /**
81     * Get all declaratively registered controllers for the specified action
82     * id.
83     * 
84     * @param actionId an action id.
85     * @return a list of controllers.
86     */
87    public List /*<Controller>*/ getControllers( String actionId )
88    {
89      List list = (List) _actionControllers.get( actionId );
90      if ( list == null )
91      {
92        return Collections.EMPTY_LIST;
93      }
94      return Collections.unmodifiableList( list );
95    }
96    
97    void addController( String actionId, Controller controller )
98    {
99      List controllers = (List) _actionControllers.get( actionId );
100     if ( controllers == null )
101     {
102       controllers = new ArrayList();
103       _actionControllers.put( actionId, controllers );
104     }
105     controllers.add( controller );
106   }
107 
108   /**
109    * Get all actions in the model.
110    * 
111    * @return the map of actions. Keys are action ids, values are IDEAction
112    *    instances.
113    */
114   public Map /*<String,IDEAction> */ getActions()
115   {
116     return _actions;
117   }
118   
119   /**
120    * Get all menu bars in the model
121    * 
122    * @return the map of menu bars. Keys are menu bar ids, values are 
123    *    MenuBar instances.
124    */
125   public Map /*<String,MenuBar> */ getMenuBars()
126   {
127     return _pullDownMenus;
128   }
129   
130   /**
131    * Get all pull down menus in the model.
132    * 
133    * @return the map of menus. Keys are menu ids, values are MenuItemContainer
134    *    instances.
135    */
136   public Map /*<String,PopupMenu> */ getPopupMenus()
137   {
138     return _popupMenus;
139   }
140   
141   
142   /**
143    * Get all toolbars in the model.
144    * 
145    * @return the map of toolbars. Keys are toolbar ids, values are Toolbar
146    *    instances.
147    */
148   public Map /*<String,Toolbar>*/ getToolbars()
149   {
150     return _toolbars;
151   }
152 }