 |
-- Main.carlavmott - 06 Jun 2007
Main data model page
Menu Data Model
(1) Introduction
This wiki page is dedicated to discussing the jMaki menu data model. This data model will be used for all menu widgets in jMaki regardless
of the underlying toolkit. It is expected that not all toolkits will support all features in the data model however each menu should support all
most of the features. The motivation for specifying a data model for all menus is to enable users to move between toolkits more easily and to
provide a standard way of represent the data required by the widgets.
(1.1) Examples
Below is an example using the new menu data model. Data passed to the menu widgets will be in JSON format as shown here.
{menu: [
{ label:'Must Read',
menu: [
{ label:'Slashdot', href:'http://www.slashdot.org' },
{ label:'dev.java.net', menu: [
{label : 'jMaki',href: 'http://ajax.dev.java.net'},
{label : 'GlassFish', href: 'http://glassfish.dev.java.net'}
] }
]
},
{ label:'Click me for fun!', action:{message: '/fun.jsp'}},
{ label:'Disabled!', disabled:true },
{ label:'Sun Microsystems', href: 'http://www.sun.com',
action:{topic: '/my/topic/setInclude', message: { url : 'http://www.sun.com'} }
},
{ label:'Oracle', href: 'http://www.oracle.com',
action:{topic: '/my/topic/setInclude', message: { url : 'http://www.oracle.com'} }
}
]}
(2) Data Model
Incorporating the feedback from the team here is the latest rev of the data model. We wanted to
add an action property which allows users to specify the message to publish and the topic to publish to.
If no topic is specified then the default topic is used. We want the message to be a string or JavaScript
object literal and this may need additional specification. Also we want to be able to specify CSS which
is passed through to the underlying widget.
menuBar ::= "{" {<menu>} "}"
menu ::= "menu:" "[" {<label>} "]"
label ::= "{" "label:" <string>, [<menu> | <href> [<action>] ] [<disabled>] [<style> ] "},"
href ::= "href:" <string> ,
action ::= "action:" "{" [<topic>] <message> "},"
topic ::= "topic:" <string>,
message ::= "message:" <obj>
obj ::= <string> | <JavaScript object literal>
style ::= "style:" "{" < CSS markup> "}"
disabled ::= "disabled: true"
JSON Schema for mat is:
{
"description" : "jMaki Menu",
"type":"object",
"properties": {
"menu" : {
"type" : "array",
"items" : {
"type" : "object",
"properties" : {
"id" : {"type": "string", "optional":true,},
"label" : {"type": "string"},
"menu" : {"type" : "object","optional":true,
"properties": {
"id" : {"type": "string", "optional":true,},
"label" : {"type": "string"},
"href" : {"type": "string","optional":true},
"action" : {"type" : "object","optional":true,
"properties": {
"topic": {"type" : "string", "optional" : true},
"message": {"type" : "string", "optional" : true}
}
}
}
},
"href" : {"type": "string","optional":true},
"action" : {"type" : "object","optional":true,
"properties": {
"topic": {"type" : "string", "optional" : true},
"message": {"type" : ["string","object"], "optional" : true}
}
}
}
}
}
}
}
(2.2) Property Descriptions
The outermost menu property or properties identify the labels of the menu bar. As you will see below, the label element allows nodes to be nested to an arbitrary level. Note that there are no restrictions on the order of subordinate properties.
The label property defines the text that will be displayed for this particular node. This property is required.
The href property indicates that the string following the property is a URL and that navigation should go to that URL.
The action is the way to override the default event that is published if a menu item is selected.
The topic property overrides the publish arg at the tag level for the particular item identified by label.
(3) Event Handling
There is only one event for that model that causes a message to be published to the communication bus.
Events that trigger a payload to be published are:
| event type | payload contents |
| onclick | widget id, topic name, href or message |
(4) Background and history
'All menus in .9 release should support the following data model. Current example of the menu data model is as follows using JSON format.
{menu: [
{ label:'Must Read',
menu: [
{ label:'Slashdot', url:'http://www.slashdot.org' },
{ label:'dev.java.net', menu: [
{label : 'jMaki',url:'http://ajax.dev.java.net'},
{label : 'Glass',url:'http://glassfish.dev.java.net'}
] }
]
},
{ label:'Click me for fun!',style:{strongemphasis:true} },
{ label:'Disabled!',style:{disabled:true} },
{ label:'Sun Microsystems', url:'http://www.sun.com',style:{checked:true} },
{ label:'Oracle', url:'http://www.oracle.com' }
]}
This however doesn't support the feature where a page can be loaded by the dcontainer. There needs to be a way to publish a URL without navigating to the URL so that
the injector can do the work.
The proposal for doing that is as follows starting from the example above:
{menu: [
{ label:'Must Read',
menu: [
{ label:'Slashdot', url:'http://www.slashdot.org' },
{ label:'dev.java.net', menu: [
{label : 'jMaki',url:'http://ajax.dev.java.net'},
{label : 'Glass',url:'http://glassfish.dev.java.net'}
] }
] },
{ label:'Click me for fun!',style:{strongemphasis:true} },
{ label:'Disabled!',style:{disabled:true} },
{ label:'Google', publish:'http://www.google.com' },
{ label:'Sun Microsystems', url:'http://www.sun.com',style:{checked:true} },
{ label:'Oracle', url:'http://www.oracle.com' }
]}
I tried to specify the model in a BNF like notation to avoid confusion. Here is the first rev of the menu data model in BNF notation.
topMenu ::= "{" <menu> "}"
menu ::= menu: "[" <label> {<label>} "]"
label ::= "{" label: <text>, <menu> | <url>, | <pulbish>, | [style] "},"
url::= url: <text>
publish ::= publish: <text>
style ::= style: "{" <disabled> | <checked> | <strongemphasis> "}"
disabled ::= disabled: true
checked ::= checked: true
strongemphasis ::= strongemphasis: true
Note: text is the topic name to publish to
Comment (ntruchsess):
I'd suggest to allow both the topic and the actual message to be set:
publish ::= publish: <text>
message ::= message: <text>
- message being what is going to be sent to the topic
- publish being the topic name to publish to (if not set, publish to the topic name that is set in the widget-args)
|