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.views;
018
019import static org.apache.juneau.commons.utils.Shorts.*;
020
021import org.apache.juneau.commons.bean.*;
022
023/**
024 * One labelled value in a {@link CellPopover}, bound to a top-level row-data key.
025 *
026 * <p>
027 * Optional {@link #render} is restricted to the text-shaped built-ins ({@code date}, {@code bool},
028 * {@code decimal}, {@code datetime}, {@code ts-zulu}).  HTML-shaped renderers are rejected at
029 * {@link CellPopover#validate()}.
030 *
031 * @since 10.0.0
032 */
033@BeanType(properties="data,title,render")
034@SuppressWarnings({
035   "java:S1845" // Fluent-builder setters intentionally mirror field names (Juneau DSL convention).
036})
037public class PopoverField {
038
039   /** The key into the DataTables row.  Must not be dotted. */
040   public String data;
041
042   /** Optional label shown beside the value. */
043   public String title;
044
045   /** Optional text-shaped renderer.  <jk>null</jk> paints {@code String(value)} via {@code textContent}. */
046   public Render render;
047
048   /**
049    * Creates a field bound to the specified row-data key.
050    *
051    * @param data The row key.  Must not be <jk>null</jk> or blank.
052    * @return A new {@link PopoverField}.
053    */
054   public static PopoverField of(String data) {
055      if (ib(data))
056         throw iaex("PopoverField data must not be null or blank.");
057      var f = new PopoverField();
058      f.data = data;
059      return f;
060   }
061
062   /**
063    * Sets the label shown beside the value.
064    *
065    * @param value The label.  Can be <jk>null</jk>.
066    * @return This object.
067    */
068   public PopoverField title(String value) {
069      title = value;
070      return this;
071   }
072
073   /**
074    * Sets the named renderer using the <c>"id:field"</c> string sugar (see {@link Render#parse(String)}).
075    *
076    * @param value The render-id string.  Must not be <jk>null</jk> or blank.
077    * @return This object.
078    */
079   public PopoverField render(String value) {
080      render = Render.parse(value);
081      return this;
082   }
083
084   /**
085    * Sets the named renderer to a pre-built {@link Render}.
086    *
087    * @param value The renderer reference.  Can be <jk>null</jk> to unset.
088    * @return This object.
089    */
090   public PopoverField render(Render value) {
091      render = value;
092      return this;
093   }
094}