001package org.gwtbootstrap3.extras.select.client.ui.constants;
002
003/*
004 * #%L
005 * GwtBootstrap3
006 * %%
007 * Copyright (C) 2016 GwtBootstrap3
008 * %%
009 * Licensed under the Apache License, Version 2.0 (the "License");
010 * you may not use this file except in compliance with the License.
011 * You may obtain a copy of the License at
012 * 
013 *      http://www.apache.org/licenses/LICENSE-2.0
014 * 
015 * Unless required by applicable law or agreed to in writing, software
016 * distributed under the License is distributed on an "AS IS" BASIS,
017 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018 * See the License for the specific language governing permissions and
019 * limitations under the License.
020 * #L%
021 */
022
023/**
024 * Selected text format.
025 *
026 * @author Xiaodong Sun
027 */
028public enum SelectedTextFormat {
029
030    /**
031     * A comma delimited list of selected values (default)
032     */
033    VALUES("values"),
034
035    /**
036     * Always show the select title (placeholder), regardless of selection
037     */
038    STATIC("static"),
039
040    /**
041     * If one item is selected, then the option value is shown. If more than
042     * one is selected then the number of selected items is displayed, e.g.
043     * <code># items selected</code>
044     */
045    COUNT("count"),
046    ;
047
048    private String format;
049
050    private SelectedTextFormat(String format) {
051        this.format = format;
052    }
053
054    /**
055     * Returns the basic format.
056     *
057     * @return
058     */
059    public String getFormat() {
060        return format;
061    }
062
063    /**
064     * Returns <code>count > x</code> if the format is
065     * {@link SelectedTextFormat#COUNT}, or the basic format otherwise.
066     *
067     * @param minCount
068     * @return
069     */
070    public String getFormat(int minCount) {
071        return getFormat() + (this == COUNT ? " > " + minCount : "");
072    }
073
074}