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.gwt.client.ui.preferences; 029 030import org.opencms.gwt.client.Messages; 031import org.opencms.gwt.client.ui.CmsScrollPanel; 032import org.opencms.gwt.client.ui.CmsTabbedPanel; 033import org.opencms.gwt.client.ui.CmsTabbedPanel.CmsTabbedPanelStyle; 034import org.opencms.gwt.client.ui.input.I_CmsFormField; 035import org.opencms.gwt.client.ui.input.form.A_CmsFormFieldPanel; 036import org.opencms.gwt.client.ui.input.form.CmsFormRow; 037import org.opencms.gwt.client.util.CmsDomUtil; 038import org.opencms.gwt.shared.CmsUserSettingsBean; 039 040import java.util.Collection; 041 042import com.google.gwt.core.client.GWT; 043import com.google.gwt.event.logical.shared.SelectionEvent; 044import com.google.gwt.event.logical.shared.SelectionHandler; 045import com.google.gwt.resources.client.CssResource; 046import com.google.gwt.uibinder.client.UiBinder; 047import com.google.gwt.uibinder.client.UiField; 048import com.google.gwt.user.client.Timer; 049import com.google.gwt.user.client.ui.FlowPanel; 050import com.google.gwt.user.client.ui.Panel; 051import com.google.gwt.user.client.ui.Widget; 052 053/** 054 * Form panel for editing user settings. 055 **/ 056public class CmsUserSettingsFormFieldPanel extends A_CmsFormFieldPanel { 057 058 /** The ui binder interface for this class. */ 059 public interface I_CmsUserSettingsFormFieldPanelUiBinder extends UiBinder<Widget, CmsUserSettingsFormFieldPanel> { 060 //empty 061 } 062 063 /** 064 * Style imported from the ui.xml file. 065 */ 066 interface ExternalStyle extends CssResource { 067 068 /** 069 * CSS class accessor. 070 * 071 * @return the CSS class 072 **/ 073 String titleColumn(); 074 075 } 076 077 /** The ui binder instance for this class. */ 078 public I_CmsUserSettingsFormFieldPanelUiBinder uiBinder = GWT.create(I_CmsUserSettingsFormFieldPanelUiBinder.class); 079 080 /** Form field container. */ 081 @UiField 082 protected FlowPanel m_basicSettingsPanel; 083 084 /** Tab. */ 085 @UiField 086 protected CmsScrollPanel m_basicTab; 087 088 /** Form field container. */ 089 @UiField 090 protected FlowPanel m_extendedSettingsPanel; 091 092 /** Tab. */ 093 @UiField 094 protected CmsScrollPanel m_extendedTab; 095 096 /** 097 * The style from the ui.xml file. (Note: the field needs to 098 */ 099 @UiField 100 protected ExternalStyle style; 101 102 /** The tab panel. */ 103 private CmsTabbedPanel<CmsScrollPanel> m_tabPanel = new CmsTabbedPanel<CmsScrollPanel>( 104 CmsTabbedPanelStyle.buttonTabs); 105 106 /** 107 * Creates a new instance.<p> 108 * 109 * @param userSettings the bean containing the current user settings 110 */ 111 public CmsUserSettingsFormFieldPanel(CmsUserSettingsBean userSettings) { 112 113 uiBinder.createAndBindUi(this); // don't use the return value, since we use the created widgets as tabs for the tab panel 114 m_tabPanel.add(m_basicTab, Messages.get().key(Messages.GUI_USERSETTINGS_TAB_BASIC_0)); 115 m_tabPanel.add(m_extendedTab, Messages.get().key(Messages.GUI_USERSETTINGS_TAB_EXTENDED_0)); 116 117 final FlowPanel[] tabs = {m_basicSettingsPanel, m_extendedSettingsPanel}; 118 119 m_tabPanel.addSelectionHandler(new SelectionHandler<Integer>() { 120 121 public void onSelection(SelectionEvent<Integer> event) { 122 123 final Widget constTarget = tabs[event.getSelectedItem().intValue()]; 124 Timer timer = new Timer() { 125 126 @Override 127 public void run() { 128 129 CmsDomUtil.resizeAncestor(constTarget); 130 131 } 132 }; 133 timer.schedule(1); 134 } 135 }); 136 initWidget(m_tabPanel); 137 } 138 139 /** 140 * @see org.opencms.gwt.client.ui.input.form.A_CmsFormFieldPanel#getDefaultGroup() 141 */ 142 @Override 143 public String getDefaultGroup() { 144 145 return null; 146 } 147 148 /** 149 * Gets the tab panel.<p> 150 * 151 * @return the tab panel 152 */ 153 public CmsTabbedPanel<CmsScrollPanel> getTabPanel() { 154 155 return m_tabPanel; 156 } 157 158 /** 159 * @see org.opencms.gwt.client.ui.input.form.A_CmsFormFieldPanel#renderFields(java.util.Collection) 160 */ 161 @Override 162 public void renderFields(Collection<I_CmsFormField> fields) { 163 164 for (Panel panel : new Panel[] {m_basicSettingsPanel, m_extendedSettingsPanel}) { 165 panel.clear(); 166 } 167 for (I_CmsFormField field : fields) { 168 CmsFormRow row = createRow(field); 169 getContainerForField(field).add(row); 170 } 171 172 } 173 174 /** 175 * Gets the container in which the field should be placed.<p> 176 * 177 * @param field the form field 178 * @return the intended parent widget for the field 179 */ 180 private Panel getContainerForField(I_CmsFormField field) { 181 182 if (field.getLayoutData().containsKey("basic")) { 183 return m_basicSettingsPanel; 184 } else { 185 return m_extendedSettingsPanel; 186 } 187 } 188 189}