001/* 002 * T 003his library is part of OpenCms - 004 * the Open Source Content Management System 005 * 006 * Copyright (c) Alkacon Software GmbH & Co. KG (https://www.alkacon.com) 007 * 008 * This library is free software; you can redistribute it and/or 009 * modify it under the terms of the GNU Lesser General Public 010 * License as published by the Free Software Foundation; either 011 * version 2.1 of the License, or (at your option) any later version. 012 * 013 * This library is distributed in the hope that it will be useful, 014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 016 * Lesser General Public License for more details. 017 * 018 * For further information about Alkacon Software, please see the 019 * company website: https://www.alkacon.com 020 * 021 * For further information about OpenCms, please see the 022 * project website: https://www.opencms.org 023 * 024 * You should have received a copy of the GNU Lesser General Public 025 * License along with this library; if not, write to the Free Software 026 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 027 */ 028 029package org.opencms.ui.apps.modules; 030 031import org.opencms.file.CmsObject; 032import org.opencms.ui.A_CmsUI; 033import org.opencms.ui.CmsVaadinUtils; 034import org.opencms.ui.components.CmsBasicDialog; 035 036import com.vaadin.ui.Button; 037import com.vaadin.ui.Button.ClickEvent; 038import com.vaadin.ui.Button.ClickListener; 039import com.vaadin.ui.Window; 040import com.vaadin.v7.data.util.IndexedContainer; 041import com.vaadin.v7.ui.ComboBox; 042 043/** 044 * The dialog for selecting a site when exporting / deleting a module without a module site.<p> 045 */ 046public class CmsSiteSelectDialog extends CmsBasicDialog { 047 048 /** 049 * Callback for the code using the dialog.<p> 050 */ 051 interface I_Callback { 052 053 /** 054 * Called when the user cancels the site select dialog.<p> 055 */ 056 void onCancel(); 057 058 /** 059 * Called when the user selects a site.<p> 060 * 061 * @param site the selected site root 062 */ 063 void onSiteSelect(String site); 064 } 065 066 /** The property id for the caption. */ 067 private static final String CAPTION_PROP = "caption"; 068 069 /** Serial version id. */ 070 private static final long serialVersionUID = 1L; 071 072 /** The callback to call when the dialog finishes. */ 073 private I_Callback m_callback; 074 075 /** The Cancel button. */ 076 private Button m_cancelButton; 077 078 /** The OK button. */ 079 private Button m_okButton; 080 081 /** The site selector. */ 082 private ComboBox m_siteSelector; 083 084 /** 085 * Creates a new instance.<p> 086 */ 087 public CmsSiteSelectDialog() { 088 089 CmsVaadinUtils.readAndLocalizeDesign(this, CmsVaadinUtils.getWpMessagesForCurrentLocale(), null); 090 CmsObject cms = A_CmsUI.getCmsObject(); 091 IndexedContainer container = CmsVaadinUtils.getAvailableSitesContainer(cms, CAPTION_PROP); 092 093 m_siteSelector.setContainerDataSource(container); 094 m_siteSelector.setItemCaptionPropertyId(CAPTION_PROP); 095 m_siteSelector.setNullSelectionAllowed(false); 096 m_siteSelector.setValue(cms.getRequestContext().getSiteRoot()); 097 m_okButton.addClickListener(new ClickListener() { 098 099 private static final long serialVersionUID = 1L; 100 101 @SuppressWarnings("synthetic-access") 102 public void buttonClick(ClickEvent event) { 103 104 m_callback.onSiteSelect(getSite()); 105 } 106 }); 107 m_cancelButton.addClickListener(new ClickListener() { 108 109 private static final long serialVersionUID = 1L; 110 111 @SuppressWarnings("synthetic-access") 112 public void buttonClick(ClickEvent event) { 113 114 m_callback.onCancel(); 115 } 116 }); 117 } 118 119 /** 120 * Opens the site selection dialog in a window.<p> 121 * 122 * @param callback the callback to call when the dialog finishes 123 * @param windowCaption the window caption 124 */ 125 public static void openDialogInWindow(final I_Callback callback, String windowCaption) { 126 127 final Window window = CmsBasicDialog.prepareWindow(); 128 window.setCaption(windowCaption); 129 CmsSiteSelectDialog dialog = new CmsSiteSelectDialog(); 130 window.setContent(dialog); 131 dialog.setCallback(new I_Callback() { 132 133 public void onCancel() { 134 135 window.close(); 136 callback.onCancel(); 137 138 } 139 140 public void onSiteSelect(String site) { 141 142 window.close(); 143 callback.onSiteSelect(site); 144 } 145 }); 146 A_CmsUI.get().addWindow(window); 147 } 148 149 /** 150 * Gets the selected site.<p> 151 * 152 * @return the selected site 153 */ 154 public String getSite() { 155 156 return (String)(m_siteSelector.getValue()); 157 } 158 159 /** 160 * Sets the callback that should be called when the dialog finishes.<p> 161 * 162 * @param callback the callback to call when the dialog finishes 163 */ 164 public void setCallback(I_Callback callback) { 165 166 m_callback = callback; 167 } 168 169}