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

com.github.gwtbootstrap.client.ui.DropdownContainer Maven / Gradle / Ivy

There is a newer version: 2.3.2.0
Show newest version
/*
 *  Copyright 2012 GWT-Bootstrap
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package com.github.gwtbootstrap.client.ui;

import com.github.gwtbootstrap.client.ui.base.IconAnchor;
import com.github.gwtbootstrap.client.ui.base.UnorderedList;
import com.github.gwtbootstrap.client.ui.event.HideEvent;
import com.github.gwtbootstrap.client.ui.event.HideHandler;
import com.github.gwtbootstrap.client.ui.event.ShowEvent;
import com.github.gwtbootstrap.client.ui.event.ShowHandler;
import com.google.gwt.dom.client.Style;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.shared.HandlerManager;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.user.client.ui.Widget;

//@formatter:off
/**
 * A dropdown that accepts any type of widget.
 * 

*

UiBinder Usage:

* *
 * {@code
 * 
 *     Header
 *     Link 1
 *     Link 2
 *     Hey you, I'm a button
 * 
 * }
 * 
*

* * @since 2.0.4.0 * * @author Carlos Alexandro Becker * @author Cássio de Freitas e Silva * * @see Bootstrap documentation * @see DropdownButton * @see SplitDropdownButton * @see Dropdown */ public class DropdownContainer extends Dropdown { private UnorderedList menu = new UnorderedList(); private boolean menuVisible; private HandlerManager handlerManager; @Override protected IconAnchor createTrigger() { final IconAnchor trigger = super.createTrigger(); trigger.addDomHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { if (menuVisible) { hideContainer(); } else { showContainer(); } } }, ClickEvent.getType()); return trigger; } public DropdownContainer() { this(""); } public DropdownContainer(String caption) { super(caption); for (Widget widget : getChildren()) { if (widget instanceof UnorderedList) { menu = (UnorderedList) widget; break; } } menu.getElement().getStyle().clearDisplay(); menu.getElement().getStyle().setDisplay(Style.Display.NONE); handlerManager = createHandlerManager(); } public void showContainer() { menu.getElement().getStyle().setDisplay(Style.Display.BLOCK); menuVisible = true; for (int i = 0; i < handlerManager.getHandlerCount(ShowEvent.getType()); i++) { ShowHandler sh = handlerManager.getHandler(ShowEvent.getType(), i); sh.onShow(new ShowEvent(null)); } } public void hideContainer() { menu.getElement().getStyle().setDisplay(Style.Display.NONE); menuVisible = false; for (int i = 0; i < handlerManager.getHandlerCount(HideEvent.getType()); i++) { HideHandler hh = handlerManager.getHandler(HideEvent.getType(), i); hh.onHide(new HideEvent(null)); } } public HandlerRegistration addHideHandler(HideHandler hideHandler) { return handlerManager.addHandler(HideEvent.getType(), hideHandler); } public HandlerRegistration addShowHandler(ShowHandler showHandler) { return handlerManager.addHandler(ShowEvent.getType(), showHandler); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy