001: package simpleorm.simplewebapp.core;
002:
003: import simpleorm.simplewebapp.core.WPage;
004: import simpleorm.simplewebapp.core.WPageStructure;
005: import simpleorm.simplewebapp.requestlet.WPageRenderer;
006: import simpleorm.simplewebapp.requestlet.WJspRenderer;
007:
008: /**
009: * An leaf items on a menu, used to both display menus and dispatch calls to jsps.<p>
010: *
011: * WARNING These are generally Global (ie final values), see WGlobalState.
012: * Do not modify them on a per page basis, but do refer to them using
013: * WPageStructure.getPageItem etc. in case there are local coplies.<p>
014: *
015: */
016: public class WMenuItemGlobal extends WMenuAbstractGlobal {
017: Class<? extends WPage> pageClass; // The wPage class that processes this entry
018: String role; // required to access program
019:
020: /**
021: * We make a special case of the successItem to go to when a crud form is successful.
022: * For all other links are encoded within the pages themselves.
023: * We do not want to add a Struts-like extra level of indirection in general.
024: * But for this common case we want to be able to return to the "caller" which may change.
025: * (Maybe this should be changed later?)
026: */
027: WMenuItemGlobal successItem;
028:
029: Class<? extends WPageRenderer> renderer = WJspRenderer.class;
030:
031: public WMenuItemGlobal(WMenuParentGlobal parent) {
032: super (parent);
033: }
034:
035: /** Needed for JSPs to grey out menu items -- geters cannot have parameters.
036: * We also allow for the possibility that Menus are not associated directly with pages. */
037: public boolean isAccessible() {
038: return WPageStructure.getThreadPage().getPageSecurity()
039: .isAccessible(this );
040: }
041:
042: /** Returns the address of the jsp for this, eg. /Simple/manuallist.jsp */
043: public String jspUrl() {
044: return "/" + parent.getName() + "/" + pageClass.getSimpleName()
045: + ".jsp";
046: }
047:
048: /** Sets .pageClass and .name */
049: public void setPageClassName(Class<? extends WPage> page) {
050: pageClass = page;
051: name = pageClass.getSimpleName();
052: }
053:
054: public String toString() {
055: return "{WMenuItemGlobal " + name + " " + swbUrl + "}";
056: }
057:
058: ////// GENERATED ////////
059:
060: public Class<? extends WPage> getPageClass() {
061: return pageClass;
062: }
063:
064: public String getRole() {
065: return role;
066: }
067:
068: public WMenuItemGlobal setRole(String role) {
069: this .role = role;
070: return this ;
071: }
072:
073: public WMenuItemGlobal getSuccessItem() {
074: return successItem;
075: }
076:
077: public WMenuItemGlobal setSuccessItem(WMenuItemGlobal successItem) {
078: this .successItem = successItem;
079: return this ;
080: }
081:
082: /** Creates the WPage for this item and sets its its menu item.*/
083: public <T extends WPage> T newPage() throws Exception {
084: Class<? extends WPage> pageClass = getPageClass();
085: WPage page = pageClass.newInstance(); // Beware that a lot of initialization happens here
086: WPageStructure struct = page.getPageStructure();
087: struct.setPageItem(this ); // Note that this happens AFTER the newInstance().
088: // Note that ObjectInputStream.readObject() (deserialize) somehow does not call constructors -- might be a dirty work around
089: return (T) page;
090: }
091:
092: public Class<? extends WPageRenderer> getRenderer() {
093: return renderer;
094: }
095:
096: public WMenuItemGlobal setRenderer(
097: Class<? extends WPageRenderer> renderer) {
098: this.renderer = renderer;
099: return this;
100: }
101: }
|