001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (c) Alkacon Software GmbH & Co. KG (https://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: https://www.alkacon.com 019 * 020 * For further information about OpenCms, please see the 021 * project website: https://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 072 m_appId = appId; 073 m_resources = resources != null ? resources : Collections.<CmsResource> emptyList(); 074 m_contextType = contextType; 075 } 076 077 /** 078 * @see org.opencms.ui.I_CmsDialogContext#error(java.lang.Throwable) 079 */ 080 public void error(Throwable error) { 081 082 closeWindow(); 083 CmsErrorDialog.showErrorDialog(error, new Runnable() { 084 085 public void run() { 086 087 finish(null); 088 } 089 }); 090 } 091 092 /** 093 * @see org.opencms.ui.I_CmsDialogContext#finish(org.opencms.file.CmsProject, java.lang.String) 094 */ 095 public void finish(CmsProject project, String siteRoot) { 096 097 if ((project != null) || (siteRoot != null)) { 098 reload(); 099 } else { 100 finish(null); 101 } 102 } 103 104 /** 105 * @see org.opencms.ui.I_CmsDialogContext#finish(java.util.Collection) 106 */ 107 public void finish(Collection<CmsUUID> result) { 108 109 closeWindow(); 110 CmsAppWorkplaceUi.get().enableGlobalShortcuts(); 111 } 112 113 /** 114 * @see org.opencms.ui.I_CmsDialogContext#getAppId() 115 */ 116 public String getAppId() { 117 118 return m_appId; 119 } 120 121 /** 122 * @see org.opencms.ui.I_CmsDialogContext#getCms() 123 */ 124 public CmsObject getCms() { 125 126 return A_CmsUI.getCmsObject(); 127 } 128 129 /** 130 * @see org.opencms.ui.I_CmsDialogContext#getContextType() 131 */ 132 public ContextType getContextType() { 133 134 return m_contextType; 135 } 136 137 /** 138 * @see org.opencms.ui.I_CmsDialogContext#getResources() 139 */ 140 public List<CmsResource> getResources() { 141 142 return m_resources; 143 } 144 145 /** 146 * Returns the window. 147 * 148 * @return the window 149 */ 150 public Window getWindow() { 151 152 return m_window; 153 } 154 155 /** 156 * @see org.opencms.ui.I_CmsDialogContext#navigateTo(java.lang.String) 157 */ 158 public void navigateTo(String appId) { 159 160 closeWindow(); 161 A_CmsUI.get().getNavigator().navigateTo(appId); 162 } 163 164 /** 165 * @see org.opencms.ui.I_CmsDialogContext#onViewChange() 166 */ 167 public void onViewChange() { 168 169 if (m_window != null) { 170 m_window.center(); 171 } 172 } 173 174 /** 175 * @see org.opencms.ui.I_CmsDialogContext#reload() 176 */ 177 public void reload() { 178 179 closeWindow(); 180 CmsAppWorkplaceUi.get().reload(); 181 } 182 183 /** 184 * @see org.opencms.ui.I_CmsDialogContext#setWindow(com.vaadin.ui.Window) 185 */ 186 public void setWindow(Window window) { 187 188 m_window = window; 189 } 190 191 /** 192 * @see org.opencms.ui.I_CmsDialogContext#start(java.lang.String, com.vaadin.ui.Component) 193 */ 194 public void start(String title, Component dialog) { 195 196 start(title, dialog, DialogWidth.narrow); 197 } 198 199 /** 200 * @see org.opencms.ui.I_CmsDialogContext#start(java.lang.String, com.vaadin.ui.Component) 201 */ 202 public void start(String title, Component dialog, DialogWidth style) { 203 204 if (dialog != null) { 205 CmsAppWorkplaceUi.get().disableGlobalShortcuts(); 206 m_window = CmsBasicDialog.prepareWindow(style); 207 m_window.setCaption(title); 208 m_window.setContent(dialog); 209 CmsAppWorkplaceUi.get().addWindow(m_window); 210 if (dialog instanceof CmsBasicDialog) { 211 ((CmsBasicDialog)dialog).initActionHandler(m_window); 212 } 213 } 214 } 215 216 /** 217 * Closes the dialog window.<p> 218 */ 219 protected void closeWindow() { 220 221 if (m_window != null) { 222 m_window.close(); 223 m_window = null; 224 } 225 } 226}