001/*
002 * This library is part of OpenCms -
003 * the Open Source Content Management System
004 *
005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com)
006 *
007 * This library is free software; you can redistribute it and/or
008 * modify it under the terms of the GNU Lesser General Public
009 * License as published by the Free Software Foundation; either
010 * version 2.1 of the License, or (at your option) any later version.
011 *
012 * This library is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015 * Lesser General Public License for more details.
016 *
017 * For further information about Alkacon Software, please see the
018 * company website: http://www.alkacon.com
019 *
020 * For further information about OpenCms, please see the
021 * project website: http://www.opencms.org
022 *
023 * You should have received a copy of the GNU Lesser General Public
024 * License along with this library; if not, write to the Free Software
025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
026 */
027
028package org.opencms.ade.galleries.client.ui;
029
030import org.opencms.gwt.client.ui.CmsPushButton;
031import org.opencms.gwt.client.ui.I_CmsButton;
032import org.opencms.gwt.client.ui.I_CmsButton.ButtonStyle;
033import org.opencms.gwt.client.ui.I_CmsButton.Size;
034
035import com.google.gwt.core.client.GWT;
036import com.google.gwt.event.dom.client.ClickEvent;
037import com.google.gwt.uibinder.client.UiBinder;
038import com.google.gwt.uibinder.client.UiField;
039import com.google.gwt.uibinder.client.UiHandler;
040import com.google.gwt.user.client.ui.Composite;
041import com.google.gwt.user.client.ui.FlowPanel;
042import com.google.gwt.user.client.ui.HTML;
043
044import elemental2.dom.DomGlobal;
045import elemental2.dom.Text;
046import jsinterop.base.Js;
047
048/**
049 * A panel displaying search parameters associated with a gallery tab.<p>
050 * Used in the result tab to display and remove these parameters.<p>
051 *
052 * @since 8.0.0
053 */
054public class CmsSearchParamPanel extends Composite {
055
056    /** The ui-binder to this widget. */
057    interface I_CmsSearchParamPanelUiBinder extends UiBinder<FlowPanel, CmsSearchParamPanel> {
058        // GWT interface, nothing to do here
059    }
060
061    /** The ui-binder instance. */
062    private static I_CmsSearchParamPanelUiBinder uiBinder = GWT.create(I_CmsSearchParamPanelUiBinder.class);
063
064    /** The parameters title. */
065    private String m_title;
066
067    /** The HTML widget to hold the parameters content. */
068    @UiField
069    protected HTML m_text;
070
071    /** The button to remove the parameters. */
072    @UiField
073    protected CmsPushButton m_button;
074
075    /** The result tab. */
076    private A_CmsTab m_tab;
077
078    /** The parameter key. */
079    private String m_paramKey;
080
081    /** The element containing the actual search parameter text. */ 
082    private elemental2.dom.Element m_bElement;
083
084    /**
085     * Constructor.<p>
086     *
087     * @param title the parameters title
088     * @param tab the tab
089     */
090    public CmsSearchParamPanel(String title, A_CmsTab tab) {
091
092        initWidget(uiBinder.createAndBindUi(this));
093        m_button.setButtonStyle(ButtonStyle.FONT_ICON, null);
094        m_button.setImageClass(I_CmsButton.DELETE_SMALL);
095        m_button.setSize(Size.small);
096        m_title = title;
097        elemental2.dom.Element textElem = Js.cast(m_text.getElement());
098        m_bElement = DomGlobal.document.createElement("b");
099        Text nbsp = DomGlobal.document.createTextNode("\u00a0");
100        textElem.append(m_bElement, nbsp);
101        m_tab = tab;
102    }
103
104    /**
105     * Sets the text content of the parameters panel.<p>
106     *
107     * @param content the content
108     * @param paramKey the parameter key
109     */
110    public void setContent(String content, String paramKey) {
111
112        m_bElement.textContent = content;
113        m_paramKey = paramKey;
114    }
115
116    /**
117     * Calls to the result tab to remove parameters. Executed on button click.<p>
118     *
119     * @param event the click event
120     */
121    @UiHandler("m_button")
122    protected void onClick(ClickEvent event) {
123
124        m_tab.removeParam(m_paramKey);
125        m_tab = null;
126        removeFromParent();
127    }
128}