001/* 002 * File : $Source$ 003 * Date : $Date$ 004 * Version: $Revision$ 005 * 006 * This library is part of OpenCms - 007 * the Open Source Content Management System 008 * 009 * Copyright (C) 2002 - 2009 Alkacon Software (http://www.alkacon.com) 010 * 011 * This library is free software; you can redistribute it and/or 012 * modify it under the terms of the GNU Lesser General Public 013 * License as published by the Free Software Foundation; either 014 * version 2.1 of the License, or (at our option) any later version. 015 * 016 * This library is distributed in the hope that it will be useful, 017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 019 * Lesser General Public License for more details. 020 * 021 * For further information about Alkacon Software, please see the 022 * company website: http://www.alkacon.com 023 * 024 * For further information about OpenCms, please see the 025 * project website: http://www.opencms.org 026 * 027 * You should have received a copy of the GNU Lesser General Public 028 * License along with this library; if not, write to the Free Software 029 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 030 */ 031 032package org.opencms.ade.postupload.client.ui; 033 034import org.opencms.ade.postupload.shared.CmsPostUploadDialogBean; 035import org.opencms.ade.postupload.shared.CmsPostUploadDialogPanelBean; 036import org.opencms.gwt.client.property.CmsPropertySubmitHandler; 037import org.opencms.gwt.client.property.CmsSimplePropertyEditor; 038import org.opencms.gwt.client.property.I_CmsPropertyEditorHandler; 039import org.opencms.gwt.client.ui.input.form.A_CmsFormFieldPanel; 040import org.opencms.gwt.client.ui.input.form.CmsForm; 041import org.opencms.gwt.client.ui.input.form.I_CmsFormHandler; 042import org.opencms.xml.content.CmsXmlContentProperty; 043 044import java.util.Map; 045 046import com.google.gwt.core.client.Scheduler; 047import com.google.gwt.core.client.Scheduler.ScheduledCommand; 048import com.google.gwt.event.dom.client.ClickEvent; 049import com.google.gwt.event.dom.client.ClickHandler; 050import com.google.gwt.user.client.ui.FlowPanel; 051 052/** 053 * Panel for the property dialog.<p> 054 */ 055public class CmsUploadPropertyPanel extends FlowPanel implements I_CmsFormHandler { 056 057 /** The upload property dialog containing this panel. */ 058 CmsUploadPropertyDialog m_dialog; 059 060 /** The property editor handler instance. */ 061 I_CmsPropertyEditorHandler m_propertyEditorHandler; 062 063 /** The property editor instance. */ 064 private CmsSimplePropertyEditor m_propertyEditor; 065 066 /** The path relative resource path. */ 067 private String m_resourcePath; 068 069 /** The values. */ 070 private CmsPostUploadDialogPanelBean m_values; 071 072 /** 073 * Public constructor.<p> 074 * 075 * @param dialog the dialog which this panel is added to 076 * @param options the data to fill UI component options 077 * @param values the bean with the current values 078 */ 079 public CmsUploadPropertyPanel( 080 CmsUploadPropertyDialog dialog, 081 CmsPostUploadDialogBean options, 082 CmsPostUploadDialogPanelBean values) { 083 084 m_values = values; 085 m_dialog = dialog; 086 m_resourcePath = values.getInfoBean().getSubTitle(); 087 initializePropertyEditor(); 088 // height may change on click 089 addDomHandler(new ClickHandler() { 090 091 public void onClick(ClickEvent event) { 092 093 m_dialog.updateHeight(); 094 } 095 }, ClickEvent.getType()); 096 } 097 098 /** 099 * Gets the property editor instance.<p> 100 * 101 * @return the property editor instance 102 */ 103 public CmsSimplePropertyEditor getPropertyEditor() { 104 105 return m_propertyEditor; 106 } 107 108 /** 109 * Returns the resourcePath.<p> 110 * 111 * @return the resourcePath 112 */ 113 public String getResourcePath() { 114 115 return m_resourcePath; 116 } 117 118 /** 119 * Returns the content bean (values) of the current dialog.<p> 120 * 121 * @return the content bean (values) of the current dialog 122 */ 123 public CmsPostUploadDialogPanelBean getUpdatedValues() { 124 125 CmsPostUploadDialogPanelBean bean = new CmsPostUploadDialogPanelBean( 126 m_values.getStructureId(), 127 m_values.getInfoBean()); 128 129 if (!m_values.equals(bean)) { 130 m_values = bean; 131 } 132 return m_values; 133 } 134 135 /** 136 * @see org.opencms.gwt.client.ui.input.form.I_CmsFormHandler#isSubmitting() 137 */ 138 public boolean isSubmitting() { 139 140 // TODO Auto-generated method stub 141 return false; 142 } 143 144 /** 145 * @see org.opencms.gwt.client.ui.input.form.I_CmsFormHandler#onSubmitValidationResult(org.opencms.gwt.client.ui.input.form.CmsForm, boolean) 146 */ 147 public void onSubmitValidationResult(CmsForm form, boolean ok) { 148 149 if (ok) { 150 form.handleSubmit(new CmsPropertySubmitHandler(m_propertyEditorHandler)); 151 } 152 } 153 154 /** 155 * @see org.opencms.gwt.client.ui.input.form.I_CmsFormHandler#onValidationResult(org.opencms.gwt.client.ui.input.form.CmsForm, boolean) 156 */ 157 public void onValidationResult(CmsForm form, boolean ok) { 158 159 // do nothing for now 160 } 161 162 /** 163 * Sets up the property editor.<p> 164 */ 165 protected void initializePropertyEditor() { 166 167 Map<String, CmsXmlContentProperty> propertyConfig = m_values.getPropertyDefinitions(); 168 m_propertyEditorHandler = new CmsUploadPropertyEditorHandler(m_dialog, m_values); 169 CmsSimplePropertyEditor propertyEditor = new CmsUploadPropertyEditor(propertyConfig, m_propertyEditorHandler); 170 propertyEditor.getForm().setFormHandler(this); 171 m_propertyEditor = propertyEditor; 172 m_propertyEditor.initializeWidgets(null); 173 A_CmsFormFieldPanel propertiesPanel = m_propertyEditor.getForm().getWidget(); 174 add(propertiesPanel); 175 FlowPanel spacer = new FlowPanel(); 176 spacer.getElement().setAttribute("style", "height: 24px"); 177 add(spacer); 178 } 179 180 /** 181 * @see com.google.gwt.user.client.ui.Widget#onLoad() 182 */ 183 @Override 184 protected void onLoad() { 185 186 super.onLoad(); 187 Scheduler.get().scheduleDeferred(new ScheduledCommand() { 188 189 public void execute() { 190 191 if (m_dialog != null) { 192 m_dialog.updateHeight(); 193 } 194 } 195 }); 196 } 197}