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.sitemap.client.ui;
029
030import org.opencms.ade.sitemap.client.control.CmsSitemapController;
031import org.opencms.ade.sitemap.shared.CmsGalleryType;
032import org.opencms.gwt.client.Messages;
033import org.opencms.gwt.client.ui.CmsPopup;
034import org.opencms.gwt.client.ui.CmsPushButton;
035import org.opencms.gwt.client.ui.I_CmsButton.ButtonColor;
036import org.opencms.gwt.client.ui.I_CmsButton.ButtonStyle;
037import org.opencms.gwt.client.ui.css.I_CmsInputLayoutBundle;
038import org.opencms.gwt.client.ui.css.I_CmsLayoutBundle;
039import org.opencms.gwt.client.ui.input.CmsLabel;
040import org.opencms.gwt.client.ui.input.CmsTextBox;
041import org.opencms.gwt.client.ui.input.form.CmsFieldsetFormFieldPanel;
042import org.opencms.util.CmsStringUtil;
043import org.opencms.util.CmsUUID;
044
045import com.google.gwt.dom.client.Style;
046import com.google.gwt.event.dom.client.ClickEvent;
047import com.google.gwt.event.dom.client.ClickHandler;
048import com.google.gwt.event.logical.shared.ValueChangeEvent;
049import com.google.gwt.event.logical.shared.ValueChangeHandler;
050import com.google.gwt.user.client.ui.FlowPanel;
051import com.google.gwt.user.client.ui.Widget;
052
053/**
054 * The create new gallery folder dialog.<p>
055 */
056public class CmsCreateGalleryDialog extends CmsPopup {
057
058    /** The text metrics key. */
059    private static final String METRICS_KEY = "CREATE_NEW_GALLERY_DIALOG";
060
061    /** The controller. */
062    private CmsSitemapController m_controller;
063
064    /** The dialog content panel. */
065    private CmsFieldsetFormFieldPanel m_dialogContent;
066
067    /** The OK button. */
068    private CmsPushButton m_okButton;
069
070    /** The parent folder id. */
071    private CmsUUID m_parentId;
072
073    /** The resource type id. */
074    private int m_resourceTypeId;
075
076    /** The title input. */
077    private CmsTextBox m_titleInput;
078
079    /**
080     * Constructor.<p>
081     *
082     * @param controller the controller
083     * @param resourceTypeId the gallery type id
084     * @param parentId the parent folder id
085     */
086    public CmsCreateGalleryDialog(CmsSitemapController controller, int resourceTypeId, CmsUUID parentId) {
087
088        super(
089            org.opencms.ade.sitemap.client.Messages.get().key(
090                org.opencms.ade.sitemap.client.Messages.GUI_GALLERIES_CREATE_0));
091        m_resourceTypeId = resourceTypeId;
092        m_parentId = parentId;
093        m_controller = controller;
094        CmsGalleryType type = m_controller.getGalleryType(Integer.valueOf(resourceTypeId));
095        m_dialogContent = new CmsFieldsetFormFieldPanel(type, null);
096        m_dialogContent.addStyleName(I_CmsInputLayoutBundle.INSTANCE.inputCss().highTextBoxes());
097        m_dialogContent.getFieldSet().setOpenerVisible(false);
098        m_dialogContent.getFieldSet().getElement().getStyle().setMarginTop(4, Style.Unit.PX);
099        setMainContent(m_dialogContent);
100        m_titleInput = new CmsTextBox();
101        m_titleInput.setTriggerChangeOnKeyPress(true);
102        m_titleInput.addValueChangeHandler(new ValueChangeHandler<String>() {
103
104            public void onValueChange(ValueChangeEvent<String> event) {
105
106                setOkEnabled(CmsStringUtil.isNotEmptyOrWhitespaceOnly(event.getValue()));
107            }
108        });
109        addInputRow(
110            org.opencms.ade.sitemap.client.Messages.get().key(
111                org.opencms.ade.sitemap.client.Messages.GUI_GALLERIES_LABEL_TITLE_0),
112            m_titleInput);
113        addDialogClose(null);
114
115        CmsPushButton closeButton = new CmsPushButton();
116        closeButton.setText(Messages.get().key(Messages.GUI_CANCEL_0));
117        closeButton.setUseMinWidth(true);
118        closeButton.setButtonStyle(ButtonStyle.TEXT, ButtonColor.BLUE);
119        closeButton.addClickHandler(new ClickHandler() {
120
121            /**
122             * @see com.google.gwt.event.dom.client.ClickHandler#onClick(com.google.gwt.event.dom.client.ClickEvent)
123             */
124            public void onClick(ClickEvent event) {
125
126                hide();
127            }
128        });
129        addButton(closeButton);
130
131        m_okButton = new CmsPushButton();
132        m_okButton.setText(Messages.get().key(Messages.GUI_OK_0));
133        m_okButton.setUseMinWidth(true);
134        m_okButton.setButtonStyle(ButtonStyle.TEXT, ButtonColor.RED);
135        m_okButton.addClickHandler(new ClickHandler() {
136
137            /**
138             * @see com.google.gwt.event.dom.client.ClickHandler#onClick(com.google.gwt.event.dom.client.ClickEvent)
139             */
140            public void onClick(ClickEvent event) {
141
142                onOk();
143            }
144        });
145        addButton(m_okButton);
146        setOkEnabled(false);
147    }
148
149    /**
150     * Creates the new gallery folder.<p>
151     */
152    protected void onOk() {
153
154        m_controller.createNewGallery(m_parentId, m_resourceTypeId, m_titleInput.getFormValueAsString());
155        hide();
156    }
157
158    /**
159     * Enables or disables the OK button.<p>
160     *
161     * @param enabled <code>true</code> to enable the button
162     */
163    protected void setOkEnabled(boolean enabled) {
164
165        if (enabled) {
166            m_okButton.enable();
167        } else {
168            m_okButton.disable(
169                org.opencms.ade.sitemap.client.Messages.get().key(
170                    org.opencms.ade.sitemap.client.Messages.GUI_NEW_GALLERY_VALIDATION_0));
171        }
172    }
173
174    /**
175     * Adds a row to the form.<p>
176     *
177     * @param label the label
178     * @param inputWidget the input widget
179     */
180    private void addInputRow(String label, Widget inputWidget) {
181
182        FlowPanel row = new FlowPanel();
183        row.setStyleName(I_CmsLayoutBundle.INSTANCE.generalCss().simpleFormRow());
184        CmsLabel labelWidget = new CmsLabel(label);
185        labelWidget.setStyleName(I_CmsLayoutBundle.INSTANCE.generalCss().simpleFormLabel());
186        row.add(labelWidget);
187        inputWidget.addStyleName(I_CmsLayoutBundle.INSTANCE.generalCss().simpleFormInputBox());
188        row.add(inputWidget);
189        m_dialogContent.getFieldSet().add(row);
190    }
191
192}