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.ui; 029 030import org.opencms.file.CmsObject; 031import org.opencms.file.CmsProject; 032import org.opencms.file.CmsResource; 033import org.opencms.ui.apps.CmsAppWorkplaceUi; 034import org.opencms.ui.components.CmsBasicDialog; 035import org.opencms.ui.components.CmsBasicDialog.DialogWidth; 036import org.opencms.ui.components.CmsErrorDialog; 037import org.opencms.util.CmsUUID; 038 039import java.util.Collection; 040import java.util.Collections; 041import java.util.List; 042 043import com.vaadin.ui.Component; 044import com.vaadin.ui.Window; 045 046/** 047 * Abstract dialog context.<p> 048 */ 049public abstract class A_CmsDialogContext implements I_CmsDialogContext { 050 051 /** The window used to display the dialog. */ 052 protected Window m_window; 053 054 /** The app id. */ 055 private String m_appId; 056 057 /** The context type. */ 058 private ContextType m_contextType; 059 060 /** The list of resources. */ 061 private List<CmsResource> m_resources; 062 063 /** 064 * Constructor.<p> 065 * 066 * @param appId the app id 067 * @param contextType the context type, to be used for visibility evaluation 068 * @param resources the list of resources 069 */ 070 protected A_CmsDialogContext(String appId, ContextType contextType, List<CmsResource> resources) { 071 m_appId = appId; 072 m_resources = resources != null ? resources : Collections.<CmsResource> emptyList(); 073 m_contextType = contextType; 074 } 075 076 /** 077 * @see org.opencms.ui.I_CmsDialogContext#error(java.lang.Throwable) 078 */ 079 public void error(Throwable error) { 080 081 closeWindow(); 082 CmsErrorDialog.showErrorDialog(error, new Runnable() { 083 084 public void run() { 085 086 finish(null); 087 } 088 }); 089 } 090 091 /** 092 * @see org.opencms.ui.I_CmsDialogContext#finish(org.opencms.file.CmsProject, java.lang.String) 093 */ 094 public void finish(CmsProject project, String siteRoot) { 095 096 if ((project != null) || (siteRoot != null)) { 097 reload(); 098 } else { 099 finish(null); 100 } 101 } 102 103 /** 104 * @see org.opencms.ui.I_CmsDialogContext#finish(java.util.Collection) 105 */ 106 public void finish(Collection<CmsUUID> result) { 107 108 closeWindow(); 109 CmsAppWorkplaceUi.get().enableGlobalShortcuts(); 110 } 111 112 /** 113 * @see org.opencms.ui.I_CmsDialogContext#getAppId() 114 */ 115 public String getAppId() { 116 117 return m_appId; 118 } 119 120 /** 121 * @see org.opencms.ui.I_CmsDialogContext#getCms() 122 */ 123 public CmsObject getCms() { 124 125 return A_CmsUI.getCmsObject(); 126 } 127 128 /** 129 * @see org.opencms.ui.I_CmsDialogContext#getContextType() 130 */ 131 public ContextType getContextType() { 132 133 return m_contextType; 134 } 135 136 /** 137 * @see org.opencms.ui.I_CmsDialogContext#getResources() 138 */ 139 public List<CmsResource> getResources() { 140 141 return m_resources; 142 } 143 144 /** 145 * @see org.opencms.ui.I_CmsDialogContext#navigateTo(java.lang.String) 146 */ 147 public void navigateTo(String appId) { 148 149 closeWindow(); 150 A_CmsUI.get().getNavigator().navigateTo(appId); 151 } 152 153 /** 154 * @see org.opencms.ui.I_CmsDialogContext#onViewChange() 155 */ 156 public void onViewChange() { 157 158 if (m_window != null) { 159 m_window.center(); 160 } 161 } 162 163 /** 164 * @see org.opencms.ui.I_CmsDialogContext#reload() 165 */ 166 public void reload() { 167 168 closeWindow(); 169 CmsAppWorkplaceUi.get().reload(); 170 } 171 172 /** 173 * @see org.opencms.ui.I_CmsDialogContext#setWindow(com.vaadin.ui.Window) 174 */ 175 public void setWindow(Window window) { 176 177 m_window = window; 178 } 179 180 /** 181 * @see org.opencms.ui.I_CmsDialogContext#start(java.lang.String, com.vaadin.ui.Component) 182 */ 183 public void start(String title, Component dialog) { 184 185 start(title, dialog, DialogWidth.narrow); 186 } 187 188 /** 189 * @see org.opencms.ui.I_CmsDialogContext#start(java.lang.String, com.vaadin.ui.Component) 190 */ 191 public void start(String title, Component dialog, DialogWidth style) { 192 193 if (dialog != null) { 194 CmsAppWorkplaceUi.get().disableGlobalShortcuts(); 195 m_window = CmsBasicDialog.prepareWindow(style); 196 m_window.setCaption(title); 197 m_window.setContent(dialog); 198 CmsAppWorkplaceUi.get().addWindow(m_window); 199 if (dialog instanceof CmsBasicDialog) { 200 ((CmsBasicDialog)dialog).initActionHandler(m_window); 201 } 202 } 203 } 204 205 /** 206 * Closes the dialog window.<p> 207 */ 208 protected void closeWindow() { 209 210 if (m_window != null) { 211 m_window.close(); 212 m_window = null; 213 } 214 } 215}