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.containerpage.client.ui;
029
030import org.opencms.ade.containerpage.shared.CmsReuseInfo;
031import org.opencms.gwt.client.ui.CmsList;
032import org.opencms.gwt.client.ui.CmsListItem;
033import org.opencms.gwt.client.ui.CmsListItemWidget;
034import org.opencms.gwt.client.ui.CmsPopup;
035import org.opencms.gwt.client.ui.CmsPushButton;
036import org.opencms.gwt.client.ui.FontOpenCms;
037import org.opencms.gwt.client.ui.I_CmsButton.ButtonColor;
038import org.opencms.gwt.client.ui.I_CmsButton.ButtonStyle;
039import org.opencms.gwt.client.ui.contextmenu.CmsContextMenuButton;
040import org.opencms.gwt.client.ui.contextmenu.CmsDialogContextMenuHandler;
041import org.opencms.gwt.client.ui.css.I_CmsConstantsBundle;
042import org.opencms.gwt.shared.CmsCoreData.AdeContext;
043import org.opencms.gwt.shared.CmsListInfoBean;
044import org.opencms.gwt.shared.CmsResourceListInfo;
045
046import java.util.Arrays;
047import java.util.List;
048import java.util.function.Consumer;
049
050import com.google.gwt.core.client.GWT;
051import com.google.gwt.uibinder.client.UiBinder;
052import com.google.gwt.uibinder.client.UiField;
053import com.google.gwt.user.client.ui.FlowPanel;
054import com.google.gwt.user.client.ui.Label;
055import com.google.gwt.user.client.ui.Panel;
056import com.google.gwt.user.client.ui.Widget;
057
058/**
059 * A dialog for showing the usages of a reused element before editing it.
060 */
061public class CmsReuseInfoDialog extends CmsPopup {
062
063    /**
064     * UiBinder interface for this dialog.<p>
065     */
066    interface I_UiBinder extends UiBinder<Panel, CmsReuseInfoDialog> {
067        // empty uibinder interface
068    }
069
070    /** UiBinder instance for this dialog. */
071    private static I_UiBinder uibinder = GWT.create(I_UiBinder.class);
072
073    /** Container for the label. */
074    @UiField
075    protected FlowPanel m_labelBox;
076
077    /** The container for the file info box. */
078    @UiField
079    protected Panel m_infoBoxContainer;
080
081    /** The message label. */
082    @UiField
083    protected Label m_label;
084
085
086    /** The list item container for the element usages. */
087    @UiField
088    protected CmsList<CmsListItem> m_listPanel;
089
090    /** The ok button. */
091    @UiField
092    protected CmsPushButton m_okButton;
093
094    /** The cancel button. */
095    @UiField
096    protected CmsPushButton m_cancelButton;
097
098
099    /** The callback for the dialog. */
100    private Consumer<Boolean> m_callback;
101
102    /**
103     * Creates a new instance.
104     *
105     * @param reuseInfo the reuse info bean
106     * @param callback the callback to call with the dialog result
107     */
108    public CmsReuseInfoDialog(CmsReuseInfo reuseInfo, Consumer<Boolean> callback) {
109
110        super(reuseInfo.getTitle());
111        setModal(true);
112        setGlassEnabled(true);
113        m_callback = callback;
114        CmsListInfoBean elementInfo = reuseInfo.getElementInfo();
115        Panel panel = uibinder.createAndBindUi(this);
116        Widget warnIcon = FontOpenCms.WARNING.getWidget(20, I_CmsConstantsBundle.INSTANCE.css().colorWarning());
117        m_labelBox.insert(warnIcon, 0);
118        CmsListItemWidget infoBox = new CmsListItemWidget(elementInfo);
119        m_infoBoxContainer.add(infoBox);
120        setMainContent(panel);
121        m_okButton.setButtonStyle(ButtonStyle.TEXT, ButtonColor.RED);
122        for (CmsPushButton button : getDialogButtons()) {
123            addButton(button);
124        }
125        CmsDialogContextMenuHandler menuHandler = new CmsDialogContextMenuHandler();
126        m_okButton.setText(org.opencms.gwt.client.Messages.get().key(org.opencms.gwt.client.Messages.GUI_OK_0));
127        m_cancelButton.setText(org.opencms.gwt.client.Messages.get().key(org.opencms.gwt.client.Messages.GUI_CANCEL_0));
128        m_label.setText(reuseInfo.getMessage());
129
130        for (CmsResourceListInfo bean : reuseInfo.getUsageInfos()) {
131            CmsListItemWidget liw = new CmsListItemWidget(bean);
132            CmsListItem li = new CmsListItem(liw);
133            CmsContextMenuButton button = new CmsContextMenuButton(bean.getStructureId(), menuHandler, AdeContext.resourceinfo);
134            liw.addButton(button);
135            m_listPanel.add(li);
136        }
137
138        m_okButton.addClickHandler(event -> {
139            CmsReuseInfoDialog.this.hide();
140            m_callback.accept(Boolean.TRUE);
141        });
142
143        m_cancelButton.addClickHandler(event -> {
144            CmsReuseInfoDialog.this.hide();
145            m_callback.accept(Boolean.FALSE);
146        });
147
148    }
149
150    /**
151     * Gets the dialog buttons.
152     *
153     * @return the dialog buttons
154     */
155    private List<CmsPushButton> getDialogButtons() {
156
157        return Arrays.asList(m_cancelButton, m_okButton);
158    }
159
160}