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