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.editprovider.client; 029 030import org.opencms.ade.publish.client.CmsPublishDialog; 031import org.opencms.gwt.client.CmsCoreProvider; 032import org.opencms.gwt.client.rpc.CmsRpcAction; 033import org.opencms.gwt.client.ui.A_CmsToolbarHandler; 034import org.opencms.gwt.client.ui.CmsToolbarContextButton; 035import org.opencms.gwt.client.ui.I_CmsToolbarButton; 036import org.opencms.gwt.client.ui.contenteditor.I_CmsContentEditorHandler; 037import org.opencms.gwt.client.ui.contextmenu.I_CmsContextMenuCommand; 038import org.opencms.gwt.client.ui.contextmenu.I_CmsContextMenuCommandInitializer; 039import org.opencms.gwt.client.ui.contextmenu.I_CmsContextMenuEntry; 040import org.opencms.gwt.client.util.I_CmsSimpleCallback; 041import org.opencms.gwt.shared.CmsContextMenuEntryBean; 042import org.opencms.gwt.shared.CmsCoreData.AdeContext; 043import org.opencms.gwt.shared.CmsGwtConstants; 044import org.opencms.util.CmsUUID; 045 046import java.util.HashMap; 047import java.util.List; 048import java.util.Map; 049 050import com.google.gwt.core.client.GWT; 051import com.google.gwt.event.logical.shared.CloseEvent; 052import com.google.gwt.event.logical.shared.CloseHandler; 053import com.google.gwt.user.client.Window; 054import com.google.gwt.user.client.ui.PopupPanel; 055 056/** 057 * A toolbar handler for the Toolbar direct edit provider.<p> 058 * 059 * @since 8.0.0 060 */ 061public class CmsDirectEditToolbarHandler extends A_CmsToolbarHandler { 062 063 /** The currently active button. */ 064 private I_CmsToolbarButton m_activeButton; 065 066 /** The context menu button. */ 067 private CmsToolbarContextButton m_contextButton; 068 069 /** The context menu commands. */ 070 private Map<String, I_CmsContextMenuCommand> m_contextMenuCommands; 071 072 /** The editor handler. */ 073 private I_CmsContentEditorHandler m_editorHandler; 074 075 /** The entry point. */ 076 private CmsDirectEditEntryPoint m_entryPoint; 077 078 /** 079 * Constructor.<p> 080 * 081 * @param entryPoint the entry point 082 */ 083 public CmsDirectEditToolbarHandler(CmsDirectEditEntryPoint entryPoint) { 084 085 m_entryPoint = entryPoint; 086 m_editorHandler = new I_CmsContentEditorHandler() { 087 088 /** 089 * @see org.opencms.gwt.client.ui.contenteditor.I_CmsContentEditorHandler#onClose(java.lang.String, org.opencms.util.CmsUUID, boolean, boolean, boolean) 090 */ 091 public void onClose( 092 String sitePath, 093 CmsUUID structureId, 094 boolean isNew, 095 boolean hasChangedSettings, 096 boolean usedPublishDialog) { 097 098 Window.Location.reload(); 099 } 100 }; 101 } 102 103 /** 104 * @see org.opencms.gwt.client.ui.I_CmsToolbarHandler#activateSelection() 105 */ 106 public void activateSelection() { 107 108 // do nothing 109 } 110 111 /** 112 * De-activates the current button.<p> 113 */ 114 public void deactivateCurrentButton() { 115 116 if (m_activeButton != null) { 117 m_activeButton.setActive(false); 118 m_activeButton = null; 119 } 120 } 121 122 /** 123 * @see org.opencms.gwt.client.ui.contextmenu.I_CmsContextMenuHandler#ensureLockOnResource(org.opencms.util.CmsUUID, org.opencms.gwt.client.util.I_CmsSimpleCallback) 124 */ 125 public void ensureLockOnResource(CmsUUID structureId, I_CmsSimpleCallback<Boolean> callback) { 126 127 CmsCoreProvider.get().lock(structureId, callback); 128 } 129 130 /** 131 * @see org.opencms.gwt.client.ui.I_CmsToolbarHandler#getActiveButton() 132 */ 133 public I_CmsToolbarButton getActiveButton() { 134 135 return m_activeButton; 136 } 137 138 /** 139 * @see org.opencms.gwt.client.ui.contextmenu.I_CmsContextMenuHandler#getContextMenuCommands() 140 */ 141 public Map<String, I_CmsContextMenuCommand> getContextMenuCommands() { 142 143 if (m_contextMenuCommands == null) { 144 I_CmsContextMenuCommandInitializer initializer = GWT.create(I_CmsContextMenuCommandInitializer.class); 145 m_contextMenuCommands = initializer.initCommands(); 146 } 147 return m_contextMenuCommands; 148 } 149 150 /** 151 * @see org.opencms.gwt.client.ui.contextmenu.I_CmsContextMenuHandler#getContextType() 152 */ 153 public String getContextType() { 154 155 return CmsGwtConstants.CONTEXT_TYPE_APP_TOOLBAR; 156 } 157 158 /** 159 * @see org.opencms.gwt.client.ui.contextmenu.I_CmsContextMenuHandler#getEditorHandler() 160 */ 161 public I_CmsContentEditorHandler getEditorHandler() { 162 163 return m_editorHandler; 164 } 165 166 /** 167 * Inserts the context menu.<p> 168 * 169 * @param menuBeans the menu beans from the server 170 * @param structureId the structure id of the resource at which the workplace should be opened 171 */ 172 public void insertContextMenu(List<CmsContextMenuEntryBean> menuBeans, CmsUUID structureId) { 173 174 List<I_CmsContextMenuEntry> menuEntries = transformEntries(menuBeans, structureId); 175 m_contextButton.showMenu(menuEntries); 176 } 177 178 /** 179 * @see org.opencms.gwt.client.ui.contextmenu.I_CmsContextMenuHandler#leavePage(java.lang.String) 180 */ 181 public void leavePage(String targetUri) { 182 183 Window.Location.replace(targetUri); 184 } 185 186 /** 187 * @see org.opencms.gwt.client.ui.I_CmsToolbarHandler#loadContextMenu(org.opencms.util.CmsUUID, org.opencms.gwt.shared.CmsCoreData.AdeContext) 188 */ 189 public void loadContextMenu(final CmsUUID structureId, final AdeContext context) { 190 191 /** The RPC menu action for the container page dialog. */ 192 CmsRpcAction<List<CmsContextMenuEntryBean>> menuAction = new CmsRpcAction<List<CmsContextMenuEntryBean>>() { 193 194 /** 195 * @see org.opencms.gwt.client.rpc.CmsRpcAction#execute() 196 */ 197 @Override 198 public void execute() { 199 200 CmsCoreProvider.getService().getContextMenuEntries(structureId, context, this); 201 } 202 203 /** 204 * @see org.opencms.gwt.client.rpc.CmsRpcAction#onResponse(java.lang.Object) 205 */ 206 @Override 207 public void onResponse(List<CmsContextMenuEntryBean> menuBeans) { 208 209 insertContextMenu(menuBeans, structureId); 210 } 211 }; 212 menuAction.execute(); 213 214 } 215 216 /** 217 * @see org.opencms.gwt.client.ui.contextmenu.I_CmsContextMenuHandler#onSiteOrProjectChange(java.lang.String, java.lang.String) 218 */ 219 public void onSiteOrProjectChange(String sitePath, String serverLink) { 220 221 leavePage(serverLink); 222 } 223 224 /** 225 * @see org.opencms.gwt.client.ui.contextmenu.I_CmsContextMenuHandler#refreshResource(org.opencms.util.CmsUUID) 226 */ 227 public void refreshResource(CmsUUID structureId) { 228 229 Window.Location.reload(); 230 } 231 232 /** 233 * Sets the currently active tool-bar button.<p> 234 * 235 * @param button the button 236 */ 237 public void setActiveButton(I_CmsToolbarButton button) { 238 239 m_activeButton = button; 240 } 241 242 /** 243 * Sets the context menu button.<p> 244 * 245 * @param button the context menu button 246 */ 247 public void setContextMenuButton(CmsToolbarContextButton button) { 248 249 m_contextButton = button; 250 } 251 252 /** 253 * Opens the publish dialog.<p> 254 */ 255 public void showPublishDialog() { 256 257 CmsPublishDialog.showPublishDialog(new HashMap<String, String>(), new CloseHandler<PopupPanel>() { 258 259 /** 260 * @see com.google.gwt.event.logical.shared.CloseHandler#onClose(com.google.gwt.event.logical.shared.CloseEvent) 261 */ 262 public void onClose(CloseEvent<PopupPanel> event) { 263 264 deactivateCurrentButton(); 265 266 } 267 }, new Runnable() { 268 269 public void run() { 270 271 showPublishDialog(); 272 } 273 274 }, null); 275 } 276 277 /** 278 * Toggles the visibility of the toolbar.<p> 279 * 280 * @param show <code>true</code> to show the toolbar 281 */ 282 public void showToolbar(boolean show) { 283 284 m_entryPoint.toggleToolbar(show); 285 } 286 287 /** 288 * @see org.opencms.gwt.client.ui.contextmenu.I_CmsContextMenuHandler#unlockResource(org.opencms.util.CmsUUID) 289 */ 290 public void unlockResource(CmsUUID structureId) { 291 292 CmsCoreProvider.get().unlock(structureId); 293 } 294 295}