001: /**
002: * Copyright 2007 Webmedia Group Ltd.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: **/package org.araneaframework.jsp.tag.presentation;
016:
017: import java.io.Writer;
018: import java.util.List;
019: import javax.servlet.jsp.JspException;
020: import org.araneaframework.http.util.JsonObject;
021: import org.araneaframework.jsp.tag.uilib.WidgetTag;
022: import org.araneaframework.jsp.util.JspUpdateRegionUtil;
023: import org.araneaframework.jsp.util.JspUtil;
024: import org.araneaframework.jsp.util.JspWidgetUtil;
025: import org.araneaframework.uilib.menu.ContextMenuItem;
026: import org.araneaframework.uilib.menu.ContextMenuWidget;
027: import org.araneaframework.uilib.util.NameUtil;
028:
029: /**
030: * @author Taimo Peelo (taimo@araneaframework.org)
031: *
032: * @jsp.tag
033: * name = "contextMenu"
034: * body-content = "empty"
035: * description = "Registers context menu with given identifier. Context menu will be rendered in supported browsers
036: * (IE & Mozilla based browsers) when mouse right-click is made on widget associated with particular context menu widget."
037: *
038: * @since 1.1
039: */
040: public class ContextMenuHtmlTag extends WidgetTag {
041: protected String updateRegions;
042: protected String globalUpdateRegions;
043: protected List updateRegionNames;
044:
045: public int doStartTag(Writer out) throws Exception {
046: super .doStartTag(out);
047:
048: updateRegionNames = JspUpdateRegionUtil.getUpdateRegionNames(
049: pageContext, updateRegions, globalUpdateRegions);
050:
051: ContextMenuWidget widget = (ContextMenuWidget) JspWidgetUtil
052: .traverseToSubWidget(getContextWidget(), id);
053: ContextMenuItem menu = widget.getMenu();
054:
055: JspUtil.writeOpenStartTag(out, "script");
056: JspUtil.writeAttribute(out, "type", "text/javascript");
057: JspUtil.writeCloseStartTag(out);
058:
059: out.write("araneaContextMenuHolder.addMenu('");
060: out.write(NameUtil.getLongestPrefix(widget.getScope()
061: .toString()));
062: out.write("',");
063:
064: writeContextMenu(out, menu);
065:
066: out.write(",");
067: out.write(getOptions(menu).toString());
068: out.write(");");
069:
070: JspUtil.writeEndTag(out, "script");
071:
072: return SKIP_BODY;
073: }
074:
075: protected JsonObject getOptions(ContextMenuItem menu) {
076: JsonObject obj = new JsonObject();
077: if (!updateRegionNames.isEmpty())
078: obj
079: .setStringProperty(
080: "updateRegions",
081: "function() { return '"
082: + JspUpdateRegionUtil
083: .formatUpdateRegionsJS(updateRegionNames)
084: + "'; }");
085: return obj;
086: }
087:
088: protected void writeContextMenu(Writer out, ContextMenuItem menu)
089: throws Exception {
090: out.write(menu.toJSON().toString());
091: }
092:
093: /**
094: * @jsp.attribute
095: * type = "java.lang.String"
096: * required = "false"
097: * description = "Enumerates the regions of markup to be updated in this widget scope. Please see <code><ui:updateRegion></code> for details."
098: */
099: public void setUpdateRegions(String updateRegions)
100: throws JspException {
101: this .updateRegions = (String) evaluate("updateRegions",
102: updateRegions, String.class);
103: }
104:
105: /**
106: * @jsp.attribute
107: * type = "java.lang.String"
108: * required = "false"
109: * description = "Enumerates the regions of markup to be updated globally. Please see <code><ui:updateRegion></code> for details."
110: */
111: public void setGlobalUpdateRegions(String globalUpdateRegions)
112: throws JspException {
113: this .globalUpdateRegions = (String) evaluate(
114: "globalUpdateRegions", globalUpdateRegions,
115: String.class);
116: }
117: }
|