org.opencms.ade.sitemap.client.hoverbar.CmsHoverbarContextMenuButton Maven / Gradle / Ivy
Show all versions of opencms-gwt Show documentation
/*
* This library is part of OpenCms -
* the Open Source Content Management System
*
* Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* For further information about Alkacon Software, please see the
* company website: http://www.alkacon.com
*
* For further information about OpenCms, please see the
* project website: http://www.opencms.org
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.opencms.ade.sitemap.client.hoverbar;
import org.opencms.ade.sitemap.client.Messages;
import org.opencms.ade.sitemap.shared.CmsClientSitemapEntry;
import org.opencms.gwt.client.ui.CmsMenuButton;
import org.opencms.gwt.client.ui.I_CmsButton;
import org.opencms.gwt.client.ui.contextmenu.CmsContextMenu;
import org.opencms.gwt.client.ui.contextmenu.CmsContextMenuCloseHandler;
import org.opencms.gwt.client.ui.contextmenu.I_CmsContextMenuEntry;
import org.opencms.gwt.client.ui.css.I_CmsLayoutBundle;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import com.google.common.collect.Lists;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.logical.shared.CloseEvent;
import com.google.gwt.event.logical.shared.CloseHandler;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.PopupPanel;
/**
* Sitemap context menu button.
*
* @since 8.0.0
*/
public class CmsHoverbarContextMenuButton extends CmsMenuButton implements I_CmsContextMenuItemProvider {
/** The context menu entries. */
private List m_entries;
/** The main content widget. */
private FlexTable m_menuPanel;
/**
* Constructor.
*
* @param hoverbar the hoverbar
* @param menuItemProvider the context menu item provider
*/
public CmsHoverbarContextMenuButton(
final CmsSitemapHoverbar hoverbar,
I_CmsContextMenuItemProvider menuItemProvider) {
super(null, I_CmsButton.CONTEXT_MENU_SMALL);
// create the menu panel (it's a table because of ie6)
m_menuPanel = new FlexTable();
// set a style name for the menu table
m_menuPanel.getElement().addClassName(I_CmsLayoutBundle.INSTANCE.contextmenuCss().menuPanel());
m_button.setSize(I_CmsButton.Size.medium);
// set the widget
setMenuWidget(m_menuPanel);
// getPopupContent().removeAutoHidePartner(getElement());
getPopup().addAutoHidePartner(getElement());
getPopup().setWidth(0);
getPopup().addStyleName(I_CmsLayoutBundle.INSTANCE.dialogCss().contextMenu());
m_entries = new ArrayList();
if (menuItemProvider == null) {
menuItemProvider = this;
}
m_entries.addAll(menuItemProvider.createContextMenu(hoverbar));
setTitle(Messages.get().key(Messages.GUI_HOVERBAR_TITLE_0));
setVisible(true);
addClickHandler(new ClickHandler() {
/**
* @see com.google.gwt.event.dom.client.ClickHandler#onClick(com.google.gwt.event.dom.client.ClickEvent)
*/
public void onClick(ClickEvent event) {
if (!isOpen()) {
showMenu(hoverbar);
} else {
closeMenu();
}
}
});
}
/**
* @see org.opencms.ade.sitemap.client.hoverbar.I_CmsContextMenuItemProvider#createContextMenu(org.opencms.ade.sitemap.client.hoverbar.CmsSitemapHoverbar)
*/
public List createContextMenu(CmsSitemapHoverbar hoverbar) {
List result = Lists.newArrayList();
result.add(new CmsGotoMenuEntry(hoverbar));
result.add(new CmsGotoExplorerMenuEntry(hoverbar));
result.add(new CmsOpenGalleryMenuEntry(hoverbar));
result.add(new CmsEditRedirectMenuEntry(hoverbar));
result.add(new CmsEditModelPageMenuEntry(hoverbar));
result.add(new CmsDeleteModelPageMenuEntry(hoverbar));
result.add(new CmsDisableMenuEntry(hoverbar));
result.add(new CmsEditMenuEntry(hoverbar));
result.add(new CmsCopyPageMenuEntry(hoverbar));
result.add(new CmsCopyModelPageMenuEntry(hoverbar));
result.add(new CmsSetDefaultModelMenuEntry(hoverbar));
result.add(new CmsCopyAsModelGroupPageMenuEntry(hoverbar));
result.add(new CmsCreateGalleryMenuEntry(hoverbar));
result.add(new CmsResourceInfoMenuEntry(hoverbar));
result.add(new CmsParentSitemapMenuEntry(hoverbar));
result.add(new CmsGotoSubSitemapMenuEntry(hoverbar));
result.add(new CmsNewChoiceMenuEntry(hoverbar));
result.add(new CmsHideMenuEntry(hoverbar));
result.add(new CmsShowMenuEntry(hoverbar));
result.add(new CmsAddToNavMenuEntry(hoverbar));
result.add(new CmsBumpDetailPageMenuEntry(hoverbar));
result.add(new CmsRefreshMenuEntry(hoverbar));
result.add(
new CmsAdvancedSubmenu(
hoverbar,
Arrays.asList(
new CmsAvailabilityMenuEntry(hoverbar),
new CmsLockReportMenuEntry(hoverbar),
new CmsSeoMenuEntry(hoverbar),
new CmsSubSitemapMenuEntry(hoverbar),
new CmsMergeMenuEntry(hoverbar),
new CmsRemoveMenuEntry(hoverbar))));
result.add(new CmsModelPageLockReportMenuEntry(hoverbar));
result.add(new CmsDeleteMenuEntry(hoverbar));
return result;
}
/**
* Rests the button state and hides the hoverbar.
*
* @param hoverbar the hoverbar
*/
protected void onMenuClose(CmsSitemapHoverbar hoverbar) {
m_button.setDown(false);
if (!hoverbar.isHovered()) {
hoverbar.hide();
} else {
hoverbar.setLocked(false);
}
}
/**
* Sets the context menu visible.
*
* @param hoverbar the hoverbar instance
*/
protected void setMenuVisible(final CmsSitemapHoverbar hoverbar) {
updateVisibility();
CmsContextMenu menu = new CmsContextMenu(new ArrayList(m_entries), false, getPopup());
m_menuPanel.setWidget(0, 0, menu);
// add the close handler for the menu
getPopup().addCloseHandler(new CmsContextMenuCloseHandler(menu));
getPopup().addCloseHandler(new CloseHandler() {
public void onClose(CloseEvent closeEvent) {
onMenuClose(hoverbar);
closeMenu();
}
});
openMenu();
}
/**
* Shows the context menu.
*
* @param hoverbar the hoverbar instance
*/
protected void showMenu(final CmsSitemapHoverbar hoverbar) {
// lock the hoverbar visibility to avoid hide on mouse out
hoverbar.setLocked(true);
hoverbar.loadEntry(new AsyncCallback() {
public void onFailure(Throwable caught) {
// TODO Auto-generated method stub
}
public void onSuccess(CmsClientSitemapEntry result) {
setMenuVisible(hoverbar);
}
});
}
/**
* Updates the entry visibility.
*/
private void updateVisibility() {
for (A_CmsSitemapMenuEntry entry : m_entries) {
updateVisibility(entry);
}
}
/**
* Updates the visibility for an entry and its sub-entries.
*
* @param entry the entry to update
*/
private void updateVisibility(A_CmsSitemapMenuEntry entry) {
if (entry.getSubMenu() != null) {
for (I_CmsContextMenuEntry subItem : entry.getSubMenu()) {
updateVisibility((A_CmsSitemapMenuEntry)subItem);
}
}
entry.onShow();
}
}