View Javadoc

1   package org.appfuse.webapp.components;
2   
3   import org.apache.tapestry5.BindingConstants;
4   import org.apache.tapestry5.Block;
5   import org.apache.tapestry5.ComponentResources;
6   import org.apache.tapestry5.annotations.Import;
7   import org.apache.tapestry5.annotations.Parameter;
8   import org.apache.tapestry5.annotations.Property;
9   import org.apache.tapestry5.ioc.Messages;
10  import org.apache.tapestry5.ioc.annotations.Inject;
11  import org.apache.tapestry5.ioc.services.SymbolSource;
12  import org.apache.tapestry5.services.AssetSource;
13  import org.apache.tapestry5.services.Context;
14  import org.apache.tapestry5.services.Environment;
15  import org.apache.tapestry5.services.PageRenderLinkSource;
16  import org.apache.tapestry5.services.javascript.JavaScriptSupport;
17  import org.appfuse.webapp.services.SecurityContext;
18  
19  
20  /**
21   * Global Layout component
22   *
23   * @author Serge Eby
24   * @version $Id: Layout.java 5 2008-08-30 09:59:21Z serge.eby $
25   */
26  
27  @Import(stack = {"core"}, module = {"bootstrap/collapse", "bootstrap/dropdown", "bootstrap/modal"},
28      stylesheet = {"classpath:/META-INF/resources/webjars/bootswatch-spacelab/3.3.1+2/css/bootstrap.min.css",
29          "app/layout.css", "app/t5-override.css",
30      })
31  public class Layout {
32  
33      @Property
34      @Parameter(required = true, defaultPrefix = BindingConstants.MESSAGE)
35      private String title;
36  
37      @Property
38      @Parameter(defaultPrefix = BindingConstants.MESSAGE)
39      private String heading;
40  
41      @Property
42      @Parameter(defaultPrefix = BindingConstants.LITERAL)
43      private String menu;
44  
45      @Property
46      @Parameter(defaultPrefix = BindingConstants.LITERAL)
47      private String bodyId;
48  
49      @Property
50      @Parameter(defaultPrefix = BindingConstants.LITERAL)
51      private String bodyClass;
52  
53      @Parameter(defaultPrefix = BindingConstants.LITERAL)
54      private Block sidebar;
55  
56      @Inject
57      private Environment environment;
58  
59      @Inject
60      private Context context;
61  
62      @Inject
63      private Messages messages;
64  
65      @Inject
66      private SecurityContext securityContext;
67  
68      @Inject
69      private ComponentResources resources;
70  
71      @Inject
72      private PageRenderLinkSource linkSource;
73  
74      @Inject
75      private JavaScriptSupport jsSupport;
76  
77      @Inject
78      private AssetSource assetSource;
79  
80      @Inject
81      private SymbolSource symbolSource;
82  
83      @Inject
84      private Block adminMenuBlock;
85  
86      public boolean isLoggedIn() {
87          return securityContext.isLoggedIn();
88      }
89  
90      public Block getSidebar() {
91          if ("AdminMenu".equals(menu) && securityContext.isAdmin()) {
92              return adminMenuBlock;
93          }
94          return null;
95      }
96  
97      public boolean isAdminMenu() {
98          return "AdminMenu".equals(menu);
99      }
100 
101     public String getCurrentPage() {
102         return resources.getPageName().toLowerCase();
103     }
104 }