org.apache.juneau.rest.widget.MenuItemWidget Maven / Gradle / Ivy
// ***************************************************************************************************************************
// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file *
// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file *
// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance *
// * with the License. You may obtain a copy of the License at *
// * *
// * http://www.apache.org/licenses/LICENSE-2.0 *
// * *
// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an *
// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the *
// * specific language governing permissions and limitations under the License. *
// ***************************************************************************************************************************
package org.apache.juneau.rest.widget;
import java.io.*;
import org.apache.juneau.html.*;
import org.apache.juneau.internal.*;
import org.apache.juneau.rest.*;
import org.apache.juneau.serializer.*;
/**
* A subclass of widgets for rendering menu items with drop-down windows.
*
*
* Defines some simple CSS and Javascript for enabling drop-down menus in the nav section of the page (although
* nothing keeps you from using it in an arbitrary location in the page).
*
*
* The script specifies a "menuClick(element)" function that toggles the visibility of the next sibling of the
* element.
*
*
* Subclasses should implement the following two methods:
*
* - {@link #getLabel(RestRequest)} - The menu item label.
*
- {@link #getContent(RestRequest)} - The menu item content.
*
*
* For example, to render a link that brings up a simple dialog in a div tag:
*
* @Override
* public String getLabel() {
* return "my-menu-item" ;
* };
*
* @Override
* public Div getLabel() {
* return Html5Builder.div ("Surprise!" ).style("color:red" );
* };
*
*
*
* The HTML content returned by the {@link #getHtml(RestRequest)} method is added where the "$W{...}" is
* referenced in the page.
*/
public abstract class MenuItemWidget extends Widget {
/**
* Returns the Javascript needed for the show and hide actions of the menu item.
*/
@Override /* Widget */
public String getScript(RestRequest req) throws Exception {
return loadScript("MenuItemWidget.js");
}
/**
* Defines a "menu-item" class that needs to be used on the outer element of the HTML returned by the
* {@link #getHtml(RestRequest)} method.
*/
@Override /* Widget */
public String getStyle(RestRequest req) throws Exception {
return loadStyle("MenuItemWidget.css");
}
@Override /* Widget */
public String getHtml(RestRequest req) throws Exception {
StringBuilder sb = new StringBuilder();
sb.append(""
+ "
"
);
return sb.toString();
}
/**
* The label for the menu item as it's rendered in the menu bar.
*
* @param req The HTTP request object.
* @return The menu item label.
* @throws Exception
*/
public abstract String getLabel(RestRequest req) throws Exception;
/**
* The content of the popup.
*
* @param req The HTTP request object.
* @return
* The content of the popup.
*
Can be any of the following types:
*
* - {@link Reader} - Serialized directly to the output.
*
- {@link CharSequence} - Serialized directly to the output.
*
- Other - Serialized as HTML using {@link HtmlSerializer#DEFAULT}.
*
Note that this includes any of the {@link org.apache.juneau.dto.html5} beans.
*
* @throws Exception
*/
public abstract Object getContent(RestRequest req) throws Exception;
}