Wiki source code of Project WONDER-Frameworks-ERXNavigation
Version 18.1 by David Avendasora on 2010/10/09 11:49
Show last authors
| author | version | line-number | content |
|---|---|---|---|
| 1 | {{toc}}{{/toc}} | ||
| 2 | |||
| 3 | === Quick Getting Started Placeholder === | ||
| 4 | |||
| 5 | ==== 1. Simple example ==== | ||
| 6 | |||
| 7 | To use ERXNavigation you must initialize the ERXNavigationManager in a method such as finishInitialization in Application.java. This requires that a NavigationMenu.plist file already be defined and placed in your project's Resources folder. The Root node's children will be the level 1 navigation items. The Root node can be variable depending on code if you like, but it is not described below. The BugTracker application uses a variable Root (and therefore a different menu structure visible) depending on the type of user that is logged in, so you can refer to that until I get the chance to write it up here. For each of your Children you can define further children up to 3 levels deep. ERXModernNavigationMenu does not have the hierarchical depth limits, but it is not covered here yet. For each menu item you'll want to define an action. I have used Session as my storage for actions, but you may choose to use a navigation controller class for this. Each component must tell the NavigationManager its state in its awake() method. I think that covers the basics with examples below. This document is not terribly complete so don't hesitate to contact me if you have questions in the meantime. | ||
| 8 | |||
| 9 | The Wonder API documentation says "Please read "Documentation/Navigation.html" to find out how to use the navigation components." If you download the source distribution of Wonder, the full path from the top of the source archive is Wonder-Source/Frameworks/Core/ERExtensions/Documentation/Navigation.html. | ||
| 10 | |||
| 11 | {{code title="Application.java" borderStyle="solid"}} | ||
| 12 | |||
| 13 | // initialize the navigation | ||
| 14 | |||
| 15 | public void finishInitialization() { | ||
| 16 | super.finishInitialization(); | ||
| 17 | ERXNavigationManager.manager().configureNavigation(); | ||
| 18 | NSLog.debug.appendln("finishInitialization called."); | ||
| 19 | } | ||
| 20 | |||
| 21 | {{/code}} | ||
| 22 | |||
| 23 | Example actions in Session: | ||
| 24 | |||
| 25 | {{code title="Session.java" borderStyle="solid"}} | ||
| 26 | |||
| 27 | // Don't forget to set the navigation state in your component.java (see below) | ||
| 28 | |||
| 29 | public WOActionResults toUserPage() { | ||
| 30 | return context().page().pageWithName(UserPage.class.getName()); | ||
| 31 | } | ||
| 32 | |||
| 33 | {{/code}} | ||
| 34 | |||
| 35 | Setting the navigation state in the component | ||
| 36 | |||
| 37 | {{code title="UserPage.java" borderStyle="solid"}} | ||
| 38 | |||
| 39 | // Method used to set navigation state for use with the Navigation Menu components | ||
| 40 | // State is pushed from the page level component so that you don't have problems opening | ||
| 41 | // multiple tabs in modern browsers | ||
| 42 | // The code below tells the context that the selected tabs are "my profile" on level 1 and "summary" on level 2 | ||
| 43 | // Add similar code to each of your page level components | ||
| 44 | public void awake() { | ||
| 45 | ERXNavigationManager.manager().navigationStateForSession(session()).setState(new NSArray(new Object[] {"my profile","summmary"})); | ||
| 46 | } | ||
| 47 | |||
| 48 | {{/code}} | ||
| 49 | |||
| 50 | Example NavigationMenu.plist | ||
| 51 | |||
| 52 | {{code title="NavigationMenu.plist" borderStyle="solid"}} | ||
| 53 | |||
| 54 | // there are more options than I am using below. See the docs for more examples | ||
| 55 | // added an example for using "href" | ||
| 56 | // updated an item to show use of displayName | ||
| 57 | ( | ||
| 58 | { | ||
| 59 | name = "Root"; | ||
| 60 | children = ("my profile","my survey","Apple"); | ||
| 61 | }, | ||
| 62 | { | ||
| 63 | name = "my profile"; | ||
| 64 | children = ("summary","details"); | ||
| 65 | action = session.toUserPage; | ||
| 66 | }, | ||
| 67 | { | ||
| 68 | name = "summary"; | ||
| 69 | action = session.toUserPage; | ||
| 70 | }, | ||
| 71 | { | ||
| 72 | name = "details"; | ||
| 73 | displayName "my personal details"; | ||
| 74 | action = session.toUserDetails; | ||
| 75 | }, | ||
| 76 | { | ||
| 77 | name = "my survey"; | ||
| 78 | children = ("instructions","section I"); | ||
| 79 | action = session.toSurvey; | ||
| 80 | }, | ||
| 81 | { | ||
| 82 | name = "instructions"; | ||
| 83 | action = session.toSurvey; | ||
| 84 | }, | ||
| 85 | { | ||
| 86 | name = "section I"; | ||
| 87 | action = session.toSurvey1; | ||
| 88 | }, | ||
| 89 | { name = "Apple"; | ||
| 90 | href = "http://www.apple.com"; | ||
| 91 | }, | ||
| 92 | ) | ||
| 93 | |||
| 94 | {{/code}} | ||
| 95 | |||
| 96 | HTML Source you'll see generated by ERXNavigationMenu when the app is run | ||
| 97 | |||
| 98 | {{code title="Main.html" borderStyle="solid"}} | ||
| 99 | |||
| 100 | <div class="ERXNavigationMenu"> | ||
| 101 | <ul class="Level1Items"> | ||
| 102 | <li nowrap="nowrap" class="Nav1" id="id1"><a href="/cgi-bin/WebObjects/MyApp.woa/wo/49YrOFk9VT0wc2WYDlZ8b0/5.0.11.0.0.1.1.2.1.0.0.1.1.0.0">my profile</a></li> | ||
| 103 | |||
| 104 | <li nowrap="nowrap" class="Nav1Selected" id="id2"><a href="/cgi-bin/WebObjects/MyApp.woa/wo/49YrOFk9VT0wc2WYDlZ8b0/5.0.11.0.0.1.1.2.1.1.0.1.1.0.0">my survey</a></li> | ||
| 105 | </ul> | ||
| 106 | <ul class="Level2Items"> | ||
| 107 | <li nowrap="nowrap" class="Nav2" id="id3"><a href="/cgi-bin/WebObjects/MyApp.woa/wo/49YrOFk9VT0wc2WYDlZ8b0/5.0.11.0.0.1.1.2.3.1.0.0.1.1.0.0">instructions</a></li> | ||
| 108 | |||
| 109 | <li nowrap="nowrap" class="Nav2Selected" id="id4"><a href="/cgi-bin/WebObjects/MyApp.woa/wo/49YrOFk9VT0wc2WYDlZ8b0/5.0.11.0.0.1.1.2.3.1.1.0.1.1.0.0">section I</a></li> | ||
| 110 | </ul> | ||
| 111 | |||
| 112 | |||
| 113 | </div> | ||
| 114 | |||
| 115 | {{/code}} | ||
| 116 | |||
| 117 | CSS items that I defined in my application: | ||
| 118 | |||
| 119 | {{code value="html"}} | ||
| 120 | |||
| 121 | .ERXNavigationMenu { | ||
| 122 | width: 800; | ||
| 123 | margin: auto; | ||
| 124 | border-top: #bdf solid 3px; | ||
| 125 | border-left: #bdf solid 3px; | ||
| 126 | border-right: #bdf solid 3px; | ||
| 127 | border-bottom: #bdf solid 1px; | ||
| 128 | padding-top: .5em; | ||
| 129 | padding-left: 1em; | ||
| 130 | padding-right: 1em; | ||
| 131 | font-family: Helvetica; | ||
| 132 | } | ||
| 133 | |||
| 134 | ul.Level1Items { | ||
| 135 | height: 2em; | ||
| 136 | list-style: none; | ||
| 137 | margin: 0; | ||
| 138 | padding: 0; | ||
| 139 | font-size: 1em; | ||
| 140 | font-weight: bold; | ||
| 141 | } | ||
| 142 | |||
| 143 | ul.Level1Items li { | ||
| 144 | background-color: #48f; | ||
| 145 | float: left; | ||
| 146 | margin: 0 2px 0 0; | ||
| 147 | } | ||
| 148 | |||
| 149 | ul.Level1Items a { | ||
| 150 | background: #48f; | ||
| 151 | color: #fff; | ||
| 152 | display: block; | ||
| 153 | float: left; | ||
| 154 | height: 2em; | ||
| 155 | line-height: 2em; | ||
| 156 | text-decoration: none; | ||
| 157 | padding-left: 10px; | ||
| 158 | padding-right: 10px; | ||
| 159 | } | ||
| 160 | ul.Level1Items li.Nav1 a:hover { | ||
| 161 | background-color: #3af; | ||
| 162 | color: #000; | ||
| 163 | |||
| 164 | } | ||
| 165 | |||
| 166 | ul.Level1Items li.Nav1Selected { | ||
| 167 | background-color: #bdf; | ||
| 168 | } | ||
| 169 | |||
| 170 | ul.Level1Items li.Nav1Selected a { | ||
| 171 | background-color: #bdf; | ||
| 172 | color: #008; | ||
| 173 | font-weight: bold; | ||
| 174 | } | ||
| 175 | |||
| 176 | ul.Level1Items li.Nav1Selected a:hover { | ||
| 177 | color: #008; | ||
| 178 | font-weight: bold; | ||
| 179 | } | ||
| 180 | |||
| 181 | ul.Level2Items { | ||
| 182 | height: 1.5em; | ||
| 183 | list-style: none; | ||
| 184 | margin: 0; | ||
| 185 | padding: 2px 2px 0 2px; | ||
| 186 | font-size: 1em; | ||
| 187 | font-weight: bold; | ||
| 188 | background-color: #bdf; | ||
| 189 | } | ||
| 190 | |||
| 191 | ul.Level2Items li { | ||
| 192 | background-color: #fff; | ||
| 193 | float: left; | ||
| 194 | margin: 2px 2px 0 2px; | ||
| 195 | } | ||
| 196 | |||
| 197 | ul.Level2Items a { | ||
| 198 | background: #bdf; | ||
| 199 | display: block; | ||
| 200 | float: left; | ||
| 201 | height: 1.5em; | ||
| 202 | line-height: 1.5em; | ||
| 203 | font-size: .9em; | ||
| 204 | font-weight: bold; | ||
| 205 | text-decoration: none; | ||
| 206 | padding-left: 10px; | ||
| 207 | padding-right: 10px; | ||
| 208 | } | ||
| 209 | ul.Level2Items li.Nav2 a:hover { | ||
| 210 | background-color: #3af; | ||
| 211 | color: #000; | ||
| 212 | font-weight: bold; | ||
| 213 | } | ||
| 214 | |||
| 215 | ul.Level2Items li.Nav2Selected { | ||
| 216 | background-color: #bdf; | ||
| 217 | font-weight: bold; | ||
| 218 | text-decoration: underline; | ||
| 219 | } | ||
| 220 | |||
| 221 | ul.Level2Items li.Nav2Selected a { | ||
| 222 | color: #008; | ||
| 223 | font-weight: bold; | ||
| 224 | } | ||
| 225 | |||
| 226 | ul.Level2Items li.Nav2Selected a:hover { | ||
| 227 | color: #000; | ||
| 228 | font-weight: bold; | ||
| 229 | } | ||
| 230 | |||
| 231 | {{/code}} | ||
| 232 | |||
| 233 | ==== 2. Using Conditionally Displayed Tabs ==== | ||
| 234 | |||
| 235 | You can do something like: | ||
| 236 | |||
| 237 | {{code title="NavigationMenu.plist" borderStyle="solid"}} | ||
| 238 | |||
| 239 | { | ||
| 240 | action = "session.toItemList"; | ||
| 241 | name = "item list"; | ||
| 242 | displayName = search; | ||
| 243 | children = "session.isItemSelectedForNavigation"; | ||
| 244 | childrenChoices = { | ||
| 245 | itemSelected = ("list","details","history"); | ||
| 246 | noItemSelected = ( "list"); | ||
| 247 | }; | ||
| 248 | }, | ||
| 249 | |||
| 250 | {{/code}} | ||
| 251 | |||
| 252 | {{code title="Session.java" borderStyle="solid"}} | ||
| 253 | |||
| 254 | public String isItemSelectedForNavigation() { | ||
| 255 | Item _selectedItem = (Item) selectedItem(); | ||
| 256 | if(_selectedItem !=null) { | ||
| 257 | return "itemSelected"; | ||
| 258 | } | ||
| 259 | return "noItemSelected"; | ||
| 260 | } | ||
| 261 | |||
| 262 | public WOActionResults toItemList() { | ||
| 263 | ItemList nextPage = (ItemList) pageWithName(ItemList.class.getName()); | ||
| 264 | setSelectedItem(null); | ||
| 265 | return nextPage; | ||
| 266 | } | ||
| 267 | |||
| 268 | public WOActionResults toItemHistory() { | ||
| 269 | ItemHistory nextPage = (ItemHistory) pageWithName(ItemHistory.class.getName()); | ||
| 270 | nextPage.setAnItem(_selectedItem); | ||
| 271 | return nextPage; | ||
| 272 | } | ||
| 273 | |||
| 274 | {{/code}} |