001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (C) Alkacon Software (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.sitemap.client.toolbar; 029 030import org.opencms.ade.sitemap.client.CmsSitemapView; 031import org.opencms.gwt.client.CmsCoreProvider; 032import org.opencms.gwt.client.I_CmsDisableable; 033import org.opencms.gwt.client.ui.A_CmsToolbarHandler; 034import org.opencms.gwt.client.ui.I_CmsToolbarButton; 035import org.opencms.gwt.client.ui.contenteditor.I_CmsContentEditorHandler; 036import org.opencms.gwt.client.ui.contextmenu.I_CmsContextMenuCommand; 037import org.opencms.gwt.client.ui.contextmenu.I_CmsContextMenuCommandInitializer; 038import org.opencms.gwt.client.ui.contextmenu.I_CmsContextMenuEntry; 039import org.opencms.gwt.client.util.I_CmsSimpleCallback; 040import org.opencms.gwt.shared.CmsContextMenuEntryBean; 041import org.opencms.gwt.shared.CmsCoreData.AdeContext; 042import org.opencms.gwt.shared.CmsGwtConstants; 043import org.opencms.util.CmsUUID; 044 045import java.util.ArrayList; 046import java.util.List; 047import java.util.Map; 048 049import com.google.gwt.core.client.GWT; 050import com.google.gwt.user.client.Window; 051 052/** 053 * The toolbar handler used for the sitemap toolbar context menu.<p> 054 */ 055public class CmsSitemapToolbarHandler extends A_CmsToolbarHandler { 056 057 /** The currently active button. */ 058 private I_CmsToolbarButton m_activeButton; 059 060 /** The available context menu commands. */ 061 private Map<String, I_CmsContextMenuCommand> m_contextMenuCommands; 062 063 /** The context menu entries. */ 064 private List<I_CmsContextMenuEntry> m_contextMenuEntries; 065 066 /** The content editor handler. */ 067 private I_CmsContentEditorHandler m_editorHandler; 068 069 /** 070 * Constructor.<p> 071 * 072 * @param menuBeans the context menu entry beans 073 */ 074 public CmsSitemapToolbarHandler(List<CmsContextMenuEntryBean> menuBeans) { 075 076 m_contextMenuEntries = transformEntries(menuBeans, null); 077 m_editorHandler = new I_CmsContentEditorHandler() { 078 079 public void onClose( 080 String sitePath, 081 CmsUUID structureId, 082 boolean isNew, 083 boolean hasChangedSettings, 084 boolean usedPublishDialog) { 085 086 CmsSitemapView.getInstance().getController().updateEntry(sitePath); 087 } 088 }; 089 } 090 091 /** 092 * @see org.opencms.gwt.client.ui.I_CmsToolbarHandler#activateSelection() 093 */ 094 public void activateSelection() { 095 096 // do nothing 097 } 098 099 /** 100 * @see org.opencms.gwt.client.ui.I_CmsToolbarHandler#deactivateCurrentButton() 101 */ 102 public void deactivateCurrentButton() { 103 104 if (m_activeButton != null) { 105 m_activeButton.setActive(false); 106 m_activeButton = null; 107 } 108 } 109 110 /** 111 * @see org.opencms.gwt.client.ui.contextmenu.I_CmsContextMenuHandler#ensureLockOnResource(org.opencms.util.CmsUUID, org.opencms.gwt.client.util.I_CmsSimpleCallback) 112 */ 113 public void ensureLockOnResource(CmsUUID structureId, I_CmsSimpleCallback<Boolean> callback) { 114 115 CmsCoreProvider.get().lock(structureId, callback); 116 } 117 118 /** 119 * @see org.opencms.gwt.client.ui.I_CmsToolbarHandler#getActiveButton() 120 */ 121 public I_CmsToolbarButton getActiveButton() { 122 123 return m_activeButton; 124 } 125 126 /** 127 * @see org.opencms.gwt.client.ui.contextmenu.I_CmsContextMenuHandler#getContextMenuCommands() 128 */ 129 public Map<String, I_CmsContextMenuCommand> getContextMenuCommands() { 130 131 if (m_contextMenuCommands == null) { 132 I_CmsContextMenuCommandInitializer initializer = GWT.create(I_CmsContextMenuCommandInitializer.class); 133 m_contextMenuCommands = initializer.initCommands(); 134 List<String> toRemove = new ArrayList<String>(); 135 for (Map.Entry<String, I_CmsContextMenuCommand> entry : m_contextMenuCommands.entrySet()) { 136 I_CmsContextMenuCommand command = entry.getValue(); 137 if ((command != null) 138 && (command instanceof I_CmsDisableable) 139 && ((I_CmsDisableable)command).isDisabled()) { 140 toRemove.add(entry.getKey()); 141 } 142 } 143 for (String removeKey : toRemove) { 144 m_contextMenuCommands.remove(removeKey); 145 } 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_SITEMAP_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 * @see org.opencms.gwt.client.ui.contextmenu.I_CmsContextMenuHandler#leavePage(java.lang.String) 168 */ 169 public void leavePage(String targetUri) { 170 171 Window.Location.assign(targetUri); 172 } 173 174 /** 175 * @see org.opencms.gwt.client.ui.I_CmsToolbarHandler#loadContextMenu(org.opencms.util.CmsUUID, org.opencms.gwt.shared.CmsCoreData.AdeContext) 176 */ 177 public void loadContextMenu(CmsUUID structureId, AdeContext context) { 178 179 CmsSitemapView.getInstance().getToolbar().getContextMenuButton().showMenu(m_contextMenuEntries); 180 } 181 182 /** 183 * @see org.opencms.gwt.client.ui.contextmenu.I_CmsContextMenuHandler#onSiteOrProjectChange(java.lang.String, java.lang.String) 184 */ 185 public void onSiteOrProjectChange(String sitePath, String serverLink) { 186 187 CmsSitemapView.getInstance().getController().openSiteMap(sitePath, true); 188 } 189 190 /** 191 * @see org.opencms.gwt.client.ui.contextmenu.I_CmsContextMenuHandler#refreshResource(org.opencms.util.CmsUUID) 192 */ 193 public void refreshResource(CmsUUID structureId) { 194 195 Window.Location.reload(); 196 } 197 198 /** 199 * Sets the currently active tool-bar button.<p> 200 * 201 * @param button the button 202 */ 203 public void setActiveButton(I_CmsToolbarButton button) { 204 205 m_activeButton = button; 206 } 207 208 /** 209 * @see org.opencms.gwt.client.ui.A_CmsToolbarHandler#transformEntries(java.util.List, org.opencms.util.CmsUUID) 210 */ 211 @Override 212 public List<I_CmsContextMenuEntry> transformEntries(List<CmsContextMenuEntryBean> menuBeans, CmsUUID structureId) { 213 214 List<I_CmsContextMenuEntry> result = super.transformEntries(menuBeans, structureId); 215 return result; 216 } 217 218 /** 219 * @see org.opencms.gwt.client.ui.contextmenu.I_CmsContextMenuHandler#unlockResource(org.opencms.util.CmsUUID) 220 */ 221 public void unlockResource(CmsUUID structureId) { 222 223 CmsCoreProvider.get().unlock(structureId); 224 } 225 226}