001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.juneau.console.freemarker;
018
019import java.util.*;
020
021/**
022 * A rail section with one text input.
023 *
024 * <p>
025 * Publishes {@code {schemaVersion:1, viewId, search}} on Enter and after a 250 ms pause in typing.
026 * </p>
027 *
028 * <h5 class='section'>Example:</h5>
029 * <p class='bjava'>
030 *    SearchSection.<jsm>create</jsm>().placeholder(<js>"status:open"</js>).publishes(Topics.<jsm>filter</jsm>(<js>"search"</js>));
031 * </p>
032 *
033 * @since 10.0.0
034 */
035public final class SearchSection extends Section {
036
037   private String placeholder;
038
039   private SearchSection() {}
040
041   /** @return A new section. */
042   public static SearchSection create() {
043      return new SearchSection();
044   }
045
046   /**
047    * Sets the input's placeholder text.
048    *
049    * @param value The placeholder.
050    * @return This object.
051    */
052   public SearchSection placeholder(String value) {
053      placeholder = value;
054      return this;
055   }
056
057   @Override /* Section */
058   public SearchSection publishes(String topic) {
059      super.publishes(topic);
060      return this;
061   }
062
063   @Override /* Section */
064   public SearchSection label(String label) {
065      super.label(label);
066      return this;
067   }
068
069   @Override String kind() { return "search"; }
070
071   @Override void body(Map<String,Object> m) {
072      if (placeholder != null)
073         m.put("placeholder", placeholder);
074   }
075}