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.containerpage.client.ui; 029 030import org.opencms.ade.containerpage.shared.CmsDialogOptions; 031import org.opencms.ade.containerpage.shared.CmsDialogOptions.Option; 032import org.opencms.gwt.client.ui.CmsListItemWidget; 033import org.opencms.gwt.client.ui.CmsPopup; 034import org.opencms.gwt.client.ui.CmsPushButton; 035import org.opencms.gwt.client.ui.css.I_CmsLayoutBundle; 036import org.opencms.gwt.client.ui.input.CmsRadioButton; 037import org.opencms.gwt.client.ui.input.CmsRadioButtonGroup; 038import org.opencms.gwt.client.util.I_CmsSimpleCallback; 039import org.opencms.gwt.shared.CmsListInfoBean; 040import org.opencms.util.CmsStringUtil; 041 042import com.google.gwt.dom.client.Style.Unit; 043import com.google.gwt.event.dom.client.ClickEvent; 044import com.google.gwt.event.dom.client.ClickHandler; 045import com.google.gwt.user.client.ui.FlowPanel; 046import com.google.gwt.user.client.ui.HTML; 047import com.google.gwt.user.client.ui.VerticalPanel; 048 049/** 050 * Dialog to show different options to select.<p> 051 */ 052public class CmsOptionDialog extends CmsPopup { 053 054 /** The radio button group. */ 055 CmsRadioButtonGroup m_buttonGroup; 056 057 /** 058 * Constructor.<p> 059 * 060 * @param caption the default dialog caption 061 * @param options the available options 062 * @param resourceInfo the resource info if available 063 * @param onSelect the on select callback 064 */ 065 public CmsOptionDialog( 066 String caption, 067 CmsDialogOptions options, 068 CmsListInfoBean resourceInfo, 069 final I_CmsSimpleCallback<String> onSelect) { 070 071 super(CmsStringUtil.isNotEmptyOrWhitespaceOnly(options.getTitle()) ? options.getTitle() : caption); 072 setModal(true); 073 setGlassEnabled(true); 074 FlowPanel panel = new FlowPanel(); 075 if (resourceInfo != null) { 076 CmsListItemWidget resourceInfoWidget = new CmsListItemWidget(resourceInfo); 077 panel.add(resourceInfoWidget); 078 } 079 VerticalPanel innerContent = new VerticalPanel(); 080 innerContent.setStyleName(I_CmsLayoutBundle.INSTANCE.generalCss().border()); 081 innerContent.addStyleName(I_CmsLayoutBundle.INSTANCE.generalCss().cornerAll()); 082 innerContent.getElement().getStyle().setProperty( 083 "marginTop", 084 I_CmsLayoutBundle.INSTANCE.constants().css().defaultSpace()); 085 innerContent.getElement().getStyle().setPadding(10, Unit.PX); 086 innerContent.setWidth("100%"); 087 panel.add(innerContent); 088 if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(options.getInfo())) { 089 HTML infoHTML = new HTML(options.getInfo()); 090 infoHTML.getElement().getStyle().setMarginBottom(10, Unit.PX); 091 innerContent.add(infoHTML); 092 } 093 m_buttonGroup = new CmsRadioButtonGroup(); 094 boolean valueSet = false; 095 for (Option option : options.getOptions()) { 096 CmsRadioButton radioButton = new CmsRadioButton(option.getValue(), option.getLabel()); 097 radioButton.setGroup(m_buttonGroup); 098 innerContent.add(radioButton); 099 if (option.isDisabled()) { 100 radioButton.setEnabled(false); 101 } else if (!valueSet) { 102 radioButton.setChecked(true); 103 valueSet = true; 104 } 105 if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(option.getDescription())) { 106 radioButton.setTitle(option.getDescription()); 107 } 108 109 } 110 setMainContent(panel); 111 CmsPushButton ok = new CmsPushButton(); 112 ok.setText(org.opencms.gwt.client.Messages.get().key(org.opencms.gwt.client.Messages.GUI_OK_0)); 113 ok.addClickHandler(new ClickHandler() { 114 115 public void onClick(ClickEvent event) { 116 117 onSelect.execute(m_buttonGroup.getSelectedButton().getName()); 118 close(); 119 } 120 }); 121 CmsPushButton cancel = new CmsPushButton(); 122 cancel.setText(org.opencms.gwt.client.Messages.get().key(org.opencms.gwt.client.Messages.GUI_CANCEL_0)); 123 cancel.addClickHandler(new ClickHandler() { 124 125 public void onClick(ClickEvent event) { 126 127 close(); 128 } 129 }); 130 addButton(cancel); 131 addButton(ok); 132 addDialogClose(null); 133 } 134 135 /** 136 * Closes the dialog.<p> 137 */ 138 void close() { 139 140 if (m_closeCommand != null) { 141 m_closeCommand.execute(); 142 } 143 hide(); 144 } 145}