001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (C) Alkacon Software (https://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: https://www.alkacon.com 019 * 020 * For further information about OpenCms, please see the 021 * project website: https://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.gwt.client.ui.input.form; 029 030/** 031 * Abstract handler superclass for forms which have their own dialog.<p> 032 */ 033public class CmsDialogFormHandler implements I_CmsFormHandler { 034 035 /** The form dialog. */ 036 protected CmsFormDialog m_dialog; 037 038 /** The form submit handler. */ 039 protected I_CmsFormSubmitHandler m_submitHandler; 040 041 /** Flag indicating whether we are currently submitting the form results. */ 042 private boolean m_submitting = false; 043 044 /** 045 * Creates a new instance.<p> 046 */ 047 public CmsDialogFormHandler() { 048 049 // empty default constructor 050 } 051 052 /** 053 * Returns true if the form results are currently being submitted.<p> 054 * 055 * @return true if the form results are submitted 056 */ 057 public boolean isSubmitting() { 058 059 return m_submitting; 060 } 061 062 /** 063 * @see org.opencms.gwt.client.ui.input.form.I_CmsFormHandler#onSubmitValidationResult(org.opencms.gwt.client.ui.input.form.CmsForm, boolean) 064 */ 065 public void onSubmitValidationResult(CmsForm form, boolean ok) { 066 067 if (ok) { 068 m_submitting = true; 069 m_dialog.hide(); 070 form.handleSubmit(m_submitHandler); 071 } else { 072 m_dialog.setOkButtonEnabled(form.noFieldsInvalid()); 073 } 074 } 075 076 /** 077 * @see org.opencms.gwt.client.ui.input.form.I_CmsFormHandler#onValidationResult(org.opencms.gwt.client.ui.input.form.CmsForm, boolean) 078 */ 079 public void onValidationResult(CmsForm form, boolean ok) { 080 081 m_dialog.setOkButtonEnabled(ok); 082 } 083 084 /** 085 * Sets the dialog.<p> 086 * 087 * @param dialog the form dialog 088 */ 089 public void setDialog(CmsFormDialog dialog) { 090 091 m_dialog = dialog; 092 } 093 094 /** 095 * Sets the form submit handler.<p> 096 * 097 * @param submitHandler the new form submit handler 098 */ 099 public void setSubmitHandler(I_CmsFormSubmitHandler submitHandler) { 100 101 m_submitHandler = submitHandler; 102 } 103}