All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.opencms.gwt.client.ui.CmsQuickLauncher Maven / Gradle / Ivy

Go to download

OpenCms is an enterprise-ready, easy to use website content management system based on Java and XML technology. Offering a complete set of features, OpenCms helps content managers worldwide to create and maintain beautiful websites fast and efficiently.

The newest version!
/*
 * 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.gwt.client.ui;

import org.opencms.gwt.client.CmsCoreProvider;
import org.opencms.gwt.client.Messages;
import org.opencms.gwt.client.rpc.CmsRpcAction;
import org.opencms.gwt.client.ui.css.I_CmsLayoutBundle;
import org.opencms.gwt.client.ui.css.I_CmsLayoutBundle.I_CmsToolbarCss;
import org.opencms.gwt.shared.CmsQuickLaunchData;
import org.opencms.gwt.shared.CmsQuickLaunchParams;
import org.opencms.util.CmsStringUtil;

import java.util.Collection;
import java.util.List;

import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.safehtml.client.SafeHtmlTemplates;
import com.google.gwt.safehtml.shared.SafeHtml;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Panel;

/**
 * The user info toolbar button.

*/ public class CmsQuickLauncher extends CmsMenuButton implements I_CmsToolbarButton { /** * Abstract class for standard handling of quick launh items.

*/ public abstract static class A_QuickLaunchHandler implements I_QuickLaunchHandler { /** * @see org.opencms.gwt.client.ui.CmsQuickLauncher.I_QuickLaunchHandler#handleQuickLaunch(org.opencms.gwt.shared.CmsQuickLaunchData) */ public void handleQuickLaunch(CmsQuickLaunchData data) { if (data.getErrorMessage() != null) { CmsAlertDialog alert = new CmsAlertDialog("" + data.getErrorTitle(), data.getErrorMessage()); alert.center(); } else if (data.isReload()) { Window.Location.reload(); } else { Window.Location.assign(data.getDefaultUrl()); } } } /** * The quick launch handler interface.

*/ public static interface I_QuickLaunchHandler { /** * Gets the quick launch parameters.

* * @return the quick launch parameters */ CmsQuickLaunchParams getParameters(); /** * Processes a click on a quick launch item. * * @param data the bean representing the quick launch item * */ void handleQuickLaunch(CmsQuickLaunchData data); } /** * Button for an individual entry in the quick launch menu.

*/ public class QuickLaunchButton extends HTML { /** * Creates a new button instance for the given bean.

* * @param data the quick launch data bean */ public QuickLaunchButton(final CmsQuickLaunchData data) { super(); I_CmsToolbarCss toolbarCss = I_CmsLayoutBundle.INSTANCE.toolbarCss(); SafeHtml html; if (data.getIconUrl().startsWith(FONT_ICON_PREFIX)) { SafeHtml iconHtml = new FontIconHtml(data.getIconUrl()); html = BUTTON_TEMPLATES.iconButtonHtml(iconHtml, data.getTitle()); } else { html = BUTTON_TEMPLATES.imageButtonHtml(data.getIconUrl(), data.getTitle()); } setHTML(html); setStyleName(toolbarCss.quickButton()); addStyleName("v-button-o-app-button"); if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(data.getButtonStyle())) { addStyleName(data.getButtonStyle()); } if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(data.getErrorMessage())) { setTitle(data.getErrorMessage()); addStyleName(toolbarCss.quickButtonDeactivated()); } else { addDomHandler(new ClickHandler() { public void onClick(ClickEvent event) { closeMenu(); m_quickLaunchHandler.handleQuickLaunch(data); } }, ClickEvent.getType()); } } } /** The font icon HTML. */ protected class FontIconHtml implements SafeHtml { /** The serial version id. */ private static final long serialVersionUID = 1L; /** The font icon HTML. */ private String m_html; /** * Constructor.

* * @param iconHtml the icon HTML prefixed with 'fonticon:' */ protected FontIconHtml(String iconHtml) { m_html = iconHtml.substring(FONT_ICON_PREFIX.length()); } /** * @see com.google.gwt.safehtml.shared.SafeHtml#asString() */ public String asString() { return m_html; } } /** * The button HTML generator templates.

*/ protected interface I_ButtonTemplates extends SafeHtmlTemplates { /** * Generates the icon button HTML.

* * @param iconHtml the icon HTML * @param titel the button title * * @return the HTML */ @Template("{0}{1}") SafeHtml iconButtonHtml(SafeHtml iconHtml, String titel); /** * Generates the image button HTML.

* * @param imageUri the image URI * @param titel the button title * * @return the HTML */ @Template("{1}") SafeHtml imageButtonHtml(String imageUri, String titel); } /** Html for the menu button. */ public static final String BUTTON_HTML = "\ue617"; /** The font icon HTML prefix. */ protected static final String FONT_ICON_PREFIX = "fonticon:"; /** The button template generator instance. */ static final I_ButtonTemplates BUTTON_TEMPLATES = GWT.create(I_ButtonTemplates.class); /** The quick launch handler. */ I_QuickLaunchHandler m_quickLaunchHandler; /** The handler instance. */ private I_CmsToolbarHandler m_handler; /** The panel containing the individual quick launch buttons. */ private Panel m_itemContainer; /** * Constructor.

*/ public CmsQuickLauncher() { super(); setVisible(false); // only turn visible once the handler is set getPopup().addStyleName(I_CmsLayoutBundle.INSTANCE.dialogCss().contextMenu()); getPopup().setWidth(0); m_button.getUpFace().setHTML(BUTTON_HTML); m_button.setTitle(Messages.get().key(Messages.GUI_QUICK_LAUCNH_0)); m_button.getElement().getStyle().setBottom(1, Unit.PX); setToolbarMode(true); FlowPanel panel = new FlowPanel(); panel.addStyleName(I_CmsLayoutBundle.INSTANCE.toolbarCss().quickLaunchContainer()); m_itemContainer = panel; setMenuWidget(panel); addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { onToolbarClick(); } }); } /** * @see org.opencms.gwt.client.ui.I_CmsToolbarButton#isActive() */ public boolean isActive() { return isOpen(); } /** * @see org.opencms.gwt.client.ui.I_CmsToolbarButton#onToolbarActivate() */ public void onToolbarActivate() { CmsRpcAction> action = new CmsRpcAction>() { @Override public void execute() { start(150, false); CmsCoreProvider.getVfsService().loadQuickLaunchItems(m_quickLaunchHandler.getParameters(), this); } @Override protected void onResponse(List result) { stop(false); fillItems(result); openMenu(); } }; action.execute(); } /** * @see org.opencms.gwt.client.ui.I_CmsToolbarButton#onToolbarClick() */ public void onToolbarClick() { boolean active = isActive(); setActive(!active); } /** * @see org.opencms.gwt.client.ui.I_CmsToolbarButton#onToolbarDeactivate() */ public void onToolbarDeactivate() { // nothing to do } /** * @see org.opencms.gwt.client.ui.I_CmsToolbarButton#setActive(boolean) */ public void setActive(boolean active) { if (active) { if (m_handler != null) { m_handler.deactivateCurrentButton(); m_handler.setActiveButton(this); } m_popup.catchNotifications(); onToolbarActivate(); openMenu(); } else { onToolbarDeactivate(); closeMenu(); if (m_handler != null) { m_handler.setActiveButton(null); m_handler.activateSelection(); } } } /** * Sets the button handler.

* * @param handler the button handler */ public void setHandler(I_CmsToolbarHandler handler) { m_handler = handler; } /** * Sets the quick launch handler and makes the button visible.

* * @param handler the quick launch handler */ public void setQuicklaunchHandler(I_QuickLaunchHandler handler) { m_quickLaunchHandler = handler; setVisible(true); } /** * @see org.opencms.gwt.client.ui.CmsMenuButton#autoClose() */ @Override protected void autoClose() { super.autoClose(); onToolbarDeactivate(); if (m_handler != null) { m_handler.setActiveButton(null); m_handler.activateSelection(); } } /** * Fills the quick launch menu with buttons corresponding to the given quick launch beans.

* * @param quickLaunchData the list of quick launch beans */ protected void fillItems(Collection quickLaunchData) { Panel container = getItemContainer(); container.clear(); for (CmsQuickLaunchData item : quickLaunchData) { container.add(new QuickLaunchButton(item)); } } /** * Returns the container-page handler.

* * @return the container-page handler */ protected I_CmsToolbarHandler getHandler() { return m_handler; } /** * Gets the item container.

* * @return the item container */ private Panel getItemContainer() { return m_itemContainer; } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy