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.client.Messages; 031import org.opencms.gwt.client.ui.CmsListItem; 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.I_CmsButton; 036import org.opencms.gwt.client.ui.I_CmsButton.ButtonStyle; 037import org.opencms.gwt.client.ui.css.I_CmsLayoutBundle; 038import org.opencms.gwt.shared.CmsListElementCreationDialogData; 039import org.opencms.gwt.shared.CmsListElementCreationOption; 040import org.opencms.gwt.shared.CmsListInfoBean; 041import org.opencms.util.CmsUUID; 042 043import java.util.function.Consumer; 044 045import com.google.gwt.user.client.ui.FlowPanel; 046import com.google.gwt.user.client.ui.Label; 047 048/** 049 * Dialog that allows the user to choose the resource type of a new content to be created. 050 */ 051public class CmsListAddDialog extends CmsPopup { 052 053 /** 054 * Creates a new instance. 055 * 056 * @param elementId the container element id 057 * @param listAddData the data about the creatable resource types 058 * @param optionHandler the handler to call with the selected option 059 */ 060 public CmsListAddDialog( 061 CmsUUID elementId, 062 CmsListElementCreationDialogData listAddData, 063 Consumer<CmsListElementCreationOption> optionHandler) { 064 065 super(); 066 setCaption(listAddData.getCaption()); 067 setGlassEnabled(true); 068 addDialogClose(() -> {}); 069 CmsPushButton cancel = new CmsPushButton(); 070 cancel.setUseMinWidth(true); 071 cancel.setText(Messages.get().key(Messages.GUI_BUTTON_CANCEL_TEXT_0)); 072 cancel.addClickHandler(event -> CmsListAddDialog.this.hide()); 073 addButton(cancel); 074 CmsListItemWidget listConfigInfoWidget = new CmsListItemWidget(listAddData.getListInfo()); 075 add(listConfigInfoWidget); 076 if (listAddData.getOptions().size() == 0) { 077 FlowPanel labelContainer = new FlowPanel(); 078 labelContainer.addStyleName(I_CmsLayoutBundle.INSTANCE.listAddCss().labelContainer()); 079 Label label = new Label(listAddData.getMessage()); 080 labelContainer.add(label); 081 add(labelContainer); 082 } else { 083 final FlowPanel optionContainer = new FlowPanel(); 084 add(optionContainer); 085 086 optionContainer.addStyleName(I_CmsLayoutBundle.INSTANCE.listAddCss().optionContainer()); 087 088 listAddData.getOptions().stream().forEach(option -> { 089 CmsListInfoBean listInfo = option.getInfo(); 090 CmsListItemWidget itemWidget = new CmsListItemWidget(listInfo); 091 itemWidget.addClickHandler(evt -> { 092 CmsListAddDialog.this.hide(); 093 optionHandler.accept(option); 094 }); 095 CmsPushButton plusButton = new CmsPushButton(); 096 plusButton.setImageClass(I_CmsButton.ADD_SMALL); 097 plusButton.setButtonStyle(ButtonStyle.FONT_ICON, null); 098 itemWidget.getButtonPanel().add(plusButton); 099 CmsListItem item = new CmsListItem(itemWidget); 100 optionContainer.add(item); 101 }); 102 } 103 } 104 105}