Source code: javax/ide/menu/ActionRegistry.java
1 package javax.ide.menu;
2
3 import javax.ide.Service;
4 import javax.ide.extension.ExtensionRegistry;
5 import javax.ide.menu.spi.MenuHook;
6 import javax.ide.menu.spi.MenuModel;
7 import javax.ide.spi.ProviderNotFoundException;
8
9 /**
10 * Action lookup service. Extensions use this class to lookup
11 * {@link IDEAction}s.
12 */
13 public class ActionRegistry extends Service
14 {
15 /**
16 * Find the {@link IDEAction} identified by the given <code>id</code>.<p>
17 *
18 * This implementation retrieves the action from the menu model and returns
19 * it.
20 *
21 * @param id A unique string name identifying the action. Standard
22 * action identifiers are defined in the class {javax.ide.IDEConstants}.
23 * @return An existing action if one is found, <code>null</code> otherwise.
24 */
25 public IDEAction findAction( String id )
26 {
27 return (IDEAction) getModel().getActions().get( id );
28 }
29
30 /**
31 * Initialize the action registry.<p>
32 *
33 * This implementation does nothing. IDE implementations may override this
34 * method to do additional work when the action registry is initialized.
35 */
36 protected void initialize()
37 {
38
39 }
40
41 /**
42 * Convenience method that obtains the menu model from the MenuHook.
43 *
44 * @return the menu model.
45 */
46 protected final MenuModel getModel()
47 {
48 MenuHook menuHook = (MenuHook)
49 ExtensionRegistry.getExtensionRegistry().getHook(
50 MenuHook.ELEMENT );
51 return menuHook.getModel();
52 }
53
54 /**
55 * Get the ActionRegistry implementation for this IDE.
56 *
57 * @return the ActionRegistry implementation for this IDE.
58 */
59 public static ActionRegistry getActionRegistry()
60 {
61 try
62 {
63 return (ActionRegistry) getService( ActionRegistry.class );
64 }
65 catch ( ProviderNotFoundException nse )
66 {
67 nse.printStackTrace();
68 throw new IllegalStateException( "No action registry" );
69 }
70 }
71 }