Source code: javax/ide/menu/spi/MenusVisitor.java
1 package javax.ide.menu.spi;
2
3 import javax.ide.extension.ElementName;
4 import javax.ide.extension.ElementStartContext;
5 import javax.ide.extension.ElementVisitor;
6 import javax.ide.extension.ExtensionHook;
7 import java.util.logging.Level;
8
9 /**
10 * Visits the JSR-198 menu hook element.
11 */
12 final class MenusVisitor extends ElementVisitor
13 {
14 private static final ElementName MENUBAR = new ElementName(
15 ExtensionHook.MANIFEST_XMLNS, "menubar" );
16 private static final ElementName POPUP = new ElementName(
17 ExtensionHook.MANIFEST_XMLNS, "popup" );
18
19 static final String KEY_MENU_BAR = "menuBar";
20
21 private ElementVisitor _menubarVisitor = new MenuBarVisitor();
22 private ElementVisitor _menuVisitor = new MenuVisitor();
23 private ElementVisitor _popupVisitor = new PopupVisitor();
24 private ElementVisitor _sectionVisitor = new SectionVisitor();
25
26 /**
27 * Process the start of an XML element.
28 *
29 * @param context the XML processing context.
30 */
31 public void start( ElementStartContext context )
32 {
33 context.registerChildVisitor( MENUBAR, _menubarVisitor );
34 context.registerChildVisitor( POPUP, _popupVisitor );
35 }
36
37 private final class MenuBarVisitor extends ElementVisitor
38 {
39 public void start( ElementStartContext context )
40 {
41 String id = context.getAttributeValue( "id" );
42 if ( id == null || ( id = id.trim() ) == "" )
43 {
44 log( context, Level.SEVERE, "Required attribute 'id' missing" );
45 return;
46 }
47 MenuModel model =
48 (MenuModel) context.getScopeData().get( MenuHook.KEY_MENU_MODEL );
49 MenuBar menuBar = model.findOrCreatePullDownMenu( id );
50 context.getScopeData().put( KEY_MENU_BAR, menuBar );
51
52 context.registerChildVisitor( MenuVisitor.MENU, _menuVisitor );
53 }
54 }
55
56 private final class PopupVisitor extends ElementVisitor
57 {
58 public void start( ElementStartContext context )
59 {
60 String id = context.getAttributeValue( "id" );
61 if ( id == null || ( id = id.trim() ) == "" )
62 {
63 log( context, Level.SEVERE, "Required attribute 'id' missing" );
64 return;
65 }
66 MenuModel model =
67 (MenuModel) context.getScopeData().get( MenuHook.KEY_MENU_MODEL );
68 PopupMenu popup = model.findOrCreatePopupMenu( id );
69 context.getScopeData().put( MenuHook.KEY_SECTION_CONTAINER, popup );
70
71 context.registerChildVisitor( SectionVisitor.SECTION, _sectionVisitor );
72 }
73 }
74
75
76
77
78
79
80
81 }