001// ***************************************************************************************************************************
002// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.  See the NOTICE file *
003// * distributed with this work for additional information regarding copyright ownership.  The ASF licenses this file        *
004// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance            *
005// * with the License.  You may obtain a copy of the License at                                                              *
006// *                                                                                                                         *
007// *  http://www.apache.org/licenses/LICENSE-2.0                                                                             *
008// *                                                                                                                         *
009// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an  *
010// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the License for the        *
011// * specific language governing permissions and limitations under the License.                                              *
012// ***************************************************************************************************************************
013package org.apache.juneau.rest.widget;
014
015import org.apache.juneau.rest.*;
016import org.apache.juneau.rest.converters.*;
017
018/**
019 * Widget that returns a menu-item drop-down form for entering search/view/sort arguments.
020 * 
021 * <p>
022 * The variable it resolves is <js>"$W{QueryMenuItem}"</js>.
023 * 
024 * <p>
025 * This widget is designed to be used in conjunction with the {@link Queryable} converter, although implementations
026 * can process the query parameters themselves if they wish to do so by using the {@link RequestQuery#getSearchArgs()}
027 * method to retrieve the arguments and process the data themselves.
028 * 
029 * <p>
030 * An example of this widget can be found in the <code>PetStoreResource</code> in the examples that provides
031 * search/view/sort capabilities against the collection of POJOs:
032 * <p class='bcode'>
033 *    <ja>@RestMethod</ja>(
034 *       name=<jsf>GET</jsf>,
035 *       path=<js>"/"</js>,
036 *       widgets={
037 *          QueryMenuItem.<jk>class</jk>,
038 *       },
039 *       htmldoc=<ja>@HtmlDoc</ja>(
040 *          navlinks={
041 *             <js>"up: ..."</js>,
042 *             <js>"options: ..."</js>,
043 *             <js>"$W{QueryMenuItem}"</js>,
044 *             <js>"$W{ContentTypeMenuItem}"</js>,
045 *             <js>"$W{StyleMenuItem}"</js>,
046 *             <js>"source: ..."</js>
047 *          }
048 *       ),
049 *       converters=Queryable.<jk>class</jk>
050 *    )
051 *    <jk>public</jk> Collection&lt;Pet&gt; getPets() {
052 * </p>
053 * 
054 * <p>
055 * It renders the following popup-box:
056 * <br><img class='bordered' src='doc-files/QueryMenuItem_1.png'>
057 * 
058 * <p>
059 * Tooltips are provided by hovering over the field names.
060 * <br><img class='bordered' src='doc-files/QueryMenuItem_2.png'>
061 * 
062 * <p>
063 * When submitted, the form submits a GET request against the current URI with special GET search API query parameters.
064 * <br>(e.g. <js>"?s=column1=Foo*&amp;v=column1,column2&amp;o=column1,column2-&amp;p=100&amp;l=100"</js>).
065 * <br>The {@link Queryable} class knows how to perform these filters against collections of POJOs.
066 * 
067 * <h5 class='section'>See Also:</h5>
068 * <ul>
069 *    <li class='link'><a class="doclink" href="../../../../../overview-summary.html#juneau-rest-server.Widgets">Overview &gt; juneau-rest-server &gt; Widgets</a>
070 * </ul>
071 */
072public class QueryMenuItem extends MenuItemWidget {
073
074   /**
075    * Returns CSS for the tooltips.
076    */
077   @Override
078   public String getStyle(RestRequest req) throws Exception {
079      return super.getStyle(req)
080         + "\n"
081         + loadStyle("QueryMenuItem.css");
082   }
083
084   @Override /* MenuItemWidget */
085   public String getLabel(RestRequest req) throws Exception {
086      return "query";
087   }
088
089   @Override /* MenuItemWidget */
090   public String getContent(RestRequest req) throws Exception {
091      return loadHtml("QueryMenuItem.html");
092   }
093}