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 (http://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: http://www.alkacon.com 020 * 021 * For further information about OpenCms, please see the 022 * project website: http://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.v7.data.util.IndexedContainer; 037import com.vaadin.ui.Button; 038import com.vaadin.ui.Button.ClickEvent; 039import com.vaadin.ui.Button.ClickListener; 040import com.vaadin.v7.ui.ComboBox; 041import com.vaadin.ui.Window; 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 CmsVaadinUtils.readAndLocalizeDesign(this, CmsVaadinUtils.getWpMessagesForCurrentLocale(), null); 089 CmsObject cms = A_CmsUI.getCmsObject(); 090 IndexedContainer container = CmsVaadinUtils.getAvailableSitesContainer(cms, CAPTION_PROP); 091 092 m_siteSelector.setContainerDataSource(container); 093 m_siteSelector.setItemCaptionPropertyId(CAPTION_PROP); 094 m_siteSelector.setNullSelectionAllowed(false); 095 m_siteSelector.setValue(cms.getRequestContext().getSiteRoot()); 096 m_okButton.addClickListener(new ClickListener() { 097 098 private static final long serialVersionUID = 1L; 099 100 @SuppressWarnings("synthetic-access") 101 public void buttonClick(ClickEvent event) { 102 103 m_callback.onSiteSelect(getSite()); 104 } 105 }); 106 m_cancelButton.addClickListener(new ClickListener() { 107 108 private static final long serialVersionUID = 1L; 109 110 @SuppressWarnings("synthetic-access") 111 public void buttonClick(ClickEvent event) { 112 113 m_callback.onCancel(); 114 } 115 }); 116 } 117 118 /** 119 * Opens the site selection dialog in a window.<p> 120 * 121 * @param callback the callback to call when the dialog finishes 122 * @param windowCaption the window caption 123 */ 124 public static void openDialogInWindow(final I_Callback callback, String windowCaption) { 125 126 final Window window = CmsBasicDialog.prepareWindow(); 127 window.setCaption(windowCaption); 128 CmsSiteSelectDialog dialog = new CmsSiteSelectDialog(); 129 window.setContent(dialog); 130 dialog.setCallback(new I_Callback() { 131 132 public void onCancel() { 133 134 window.close(); 135 callback.onCancel(); 136 137 } 138 139 public void onSiteSelect(String site) { 140 141 window.close(); 142 callback.onSiteSelect(site); 143 } 144 }); 145 A_CmsUI.get().addWindow(window); 146 } 147 148 /** 149 * Gets the selected site.<p> 150 * 151 * @return the selected site 152 */ 153 public String getSite() { 154 155 return (String)(m_siteSelector.getValue()); 156 } 157 158 /** 159 * Sets the callback that should be called when the dialog finishes.<p< 160 * 161 * @param callback the callback to call when the dialog finishes 162 */ 163 public void setCallback(I_Callback callback) { 164 165 m_callback = callback; 166 } 167 168}