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.sitemap.client.hoverbar; 029 030import org.opencms.ade.sitemap.client.CmsSitemapView; 031import org.opencms.ade.sitemap.client.Messages; 032import org.opencms.ade.sitemap.client.control.CmsSitemapController; 033import org.opencms.ade.sitemap.shared.CmsClientSitemapEntry; 034import org.opencms.gwt.client.dnd.I_CmsDragHandle; 035import org.opencms.gwt.client.dnd.I_CmsDraggable; 036import org.opencms.gwt.client.ui.CmsListItem; 037import org.opencms.gwt.client.ui.CmsPushButton; 038import org.opencms.gwt.client.ui.I_CmsButton; 039import org.opencms.gwt.client.ui.I_CmsButton.ButtonStyle; 040import org.opencms.util.CmsStringUtil; 041 042import com.google.gwt.event.shared.HandlerRegistration; 043 044/** 045 * Sitemap hoverbar move button.<p> 046 * 047 * @since 8.0.0 048 */ 049public class CmsHoverbarMoveButton extends CmsPushButton implements I_CmsDragHandle { 050 051 /** The mouse down handler registration. */ 052 protected HandlerRegistration m_mouseDownHandlerReg; 053 054 /** The current site path. */ 055 protected String m_sitePath; 056 057 /** 058 * Constructor.<p> 059 * 060 * @param hoverbar the hoverbar 061 */ 062 public CmsHoverbarMoveButton(final CmsSitemapHoverbar hoverbar) { 063 064 addStyleName(CmsListItem.MOVE_HANDLE_MARKER_CLASS); 065 setImageClass(I_CmsButton.MOVE_SMALL); 066 setButtonStyle(ButtonStyle.FONT_ICON, null); 067 setTitle(Messages.get().key(Messages.GUI_HOVERBAR_MOVE_0)); 068 hoverbar.addShowHandler(new I_CmsHoverbarShowHandler() { 069 070 /** 071 * @see org.opencms.ade.sitemap.client.hoverbar.I_CmsHoverbarShowHandler#onShow(org.opencms.ade.sitemap.client.hoverbar.CmsHoverbarShowEvent) 072 */ 073 public void onShow(CmsHoverbarShowEvent event) { 074 075 if (hoverbar.getEntry() == null) { 076 // Can sometimes happen after deleting an element 077 return; 078 } 079 080 m_sitePath = hoverbar.getEntry().getSitePath(); 081 final CmsSitemapController controller = hoverbar.getController(); 082 CmsClientSitemapEntry entry = hoverbar.getEntry(); 083 if (CmsSitemapView.getInstance().isNavigationMode() && (entry != null)) { 084 085 if (!entry.isInNavigation()) { 086 CmsHoverbarMoveButton.this.setVisible(false); 087 } else if (controller.isRoot(m_sitePath)) { 088 disable(Messages.get().key(Messages.GUI_DISABLED_ROOT_ITEM_0)); 089 CmsHoverbarMoveButton.this.setVisible(true); 090 } else if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(entry.getNoEditReason())) { 091 disable(entry.getNoEditReason()); 092 CmsHoverbarMoveButton.this.setVisible(true); 093 } else if (entry.hasForeignFolderLock()) { 094 disable(Messages.get().key(Messages.GUI_DISABLED_PARENT_LOCK_0)); 095 CmsHoverbarMoveButton.this.setVisible(true); 096 } else if (entry.hasBlockingLockedChildren()) { 097 disable(Messages.get().key(Messages.GUI_DISABLED_BLOCKING_LOCKED_CHILDREN_0)); 098 CmsHoverbarMoveButton.this.setVisible(true); 099 } else { 100 enable(); 101 m_mouseDownHandlerReg = addMouseDownHandler( 102 CmsSitemapView.getInstance().getTree().getDnDHandler()); 103 CmsHoverbarMoveButton.this.setVisible(true); 104 } 105 } else { 106 CmsHoverbarMoveButton.this.setVisible(false); 107 } 108 } 109 }); 110 hoverbar.addHideHandler(new I_CmsHoverbarHideHandler() { 111 112 /** 113 * @see org.opencms.ade.sitemap.client.hoverbar.I_CmsHoverbarHideHandler#onHide(org.opencms.ade.sitemap.client.hoverbar.CmsHoverbarHideEvent) 114 */ 115 public void onHide(CmsHoverbarHideEvent event) { 116 117 if (m_mouseDownHandlerReg != null) { 118 m_mouseDownHandlerReg.removeHandler(); 119 m_mouseDownHandlerReg = null; 120 } 121 } 122 }); 123 } 124 125 /** 126 * @see org.opencms.gwt.client.dnd.I_CmsDragHandle#getDraggable() 127 */ 128 public I_CmsDraggable getDraggable() { 129 130 return CmsSitemapView.getInstance().getTreeItem(m_sitePath); 131 } 132}