Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
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 org.cdlflex.ui.markup.html.button;
 
 import java.util.List;
 
A Bootstrap DropDownButton. Adapted from de.agilecoders wicket-bootstrap.
 
 public abstract class DropDownButton extends AbstractLink implements IActivatable {
     private static final long serialVersionUID = 1L;
 
     private final IModel<Buttons.SizebuttonSize = Model.of(..);
     private final IModel<Buttons.TypebuttonType = Model.of(..);
     private final IModel<BooleandropUp = Model.of(false);
     private final ButtonList buttonListView;
     private final WebMarkupContainer baseButton;
     private final Icon icon;

    
Construct.

Parameters:
id The markup id
model The label of the main button
 
     public DropDownButton(final String idfinal IModel<?> model) {
         this(idmodel, Model.of((IconTypenull));
     }

    
Construct.

Parameters:
markupId The markup id
model The label of the main button
iconTypeModel the type of the icon
 
     public DropDownButton(final String markupIdfinal IModel<?> modelfinal IModel<IconTypeiconTypeModel) {
         super(markupIdmodel);
 
          = newButton("btn"modeliconTypeModel);
         add();
         WebMarkupContainer dropdownMenu = new WebMarkupContainer("dropdown-menu") {
             private static final long serialVersionUID = 1L;
 
             @Override
             protected void onComponentTag(ComponentTag tag) {
                 super.onComponentTag(tag);
                 tag.put("aria-labelledby"DropDownButton.this.getMarkupId());
             }
         };
         add(dropdownMenu);
          = newButtonList("buttons");
         dropdownMenu.add();
 
         this. = newButtonIcon("icon"iconTypeModel);
 
         addIconToBaseButton();
     }

    
Returns the base css class name of button container element.

Returns:
base css class name of button container element
 
     protected String createCssClassName() {
         return "dropdown";
     }

    
adds an icon to the base button.

Parameters:
iconElement The icon to add
    protected void addIconToBaseButton(final Icon iconElement) {
        .add(iconElement);
    }

    
adds a org.apache.wicket.behavior.Behavior to the base button.

Parameters:
behavior to add
Returns:
this instance for chaining
    public final DropDownButton addToButton(final Behavior behavior) {
        .add(behavior);
        return this;
    }

    
sets the icon of the base button element.

Parameters:
iconType The org.cdlflex.ui.markup.css.icon.IconType of the icon
Returns:
this element instance
    public final DropDownButton setIconType(final IconType iconType) {
        .setIconType(iconType);
        return this;
    }

    
creates a new button instance.

Parameters:
markupId The component's id
labelModel The label text as model
iconTypeModel The icon type as model
Returns:
a new button component
    protected WebMarkupContainer newButton(final String markupIdfinal IModel<?> labelModel,
        final IModel<IconTypeiconTypeModel) {
        final WebMarkupContainer button = new WebMarkupContainer(markupId);
        button.setOutputMarkupId(true);
        button.add(newButtonLabel("label"labelModel));
        return button;
    }

    
creates a new icon component with given org.cdlflex.ui.markup.css.icon.IconType.

Parameters:
markupId The component' id
labelModel The label text as model
Returns:
new label component
    protected Component newButtonLabel(final String markupIdfinal IModel<?> labelModel) {
        final Label label = new Label(markupIdlabelModel);
        label.setRenderBodyOnly(true);
        return label;
    }

    
creates a new icon component with given org.cdlflex.ui.markup.css.icon.IconType.

Parameters:
markupId The component' id
iconTypeModel The icon type as model
Returns:
new icon component
    protected Icon newButtonIcon(final String markupIdfinal IModel<IconTypeiconTypeModel) {
        return new Icon(markupIdiconTypeModel);
    }

    
adds the button behavior to the base button of this dropdown component.

Parameters:
typeModel mandatory parameter
sizeModel mandatory parameter
    protected void addButtonBehavior(final IModel<Buttons.TypetypeModelfinal IModel<Buttons.SizesizeModel) {
        .add(new ButtonBehavior(typeModelsizeModel));
    }

    
creates a list of sub menu buttons which will be shown if sub menu will be opened.

Parameters:
buttonMarkupId the markup id that all sub menu buttons must be use.
Returns:
list of sub menu buttons
    protected abstract List<AbstractLinknewSubMenuButtons(final String buttonMarkupId);

    
creates a new ButtonList that contains all buttons from newButtonList(java.lang.String)

Parameters:
markupId the markup id of ButtonList
Returns:
new ButtonList instance
    private ButtonList newButtonList(final String markupId) {
        final ButtonList buttonList = new ButtonList(markupIdnewSubMenuButtons(ButtonList.getButtonMarkupId()));
        buttonList.setRenderBodyOnly(true);
        return buttonList;
    }

    
whether to use default dropdown behavior (default value is false which means default behavior) or to open the dropdown menu at the top of dropdown button, also the button icon will be rotated.

Parameters:
isDropUp true, to use a 180deg rotated button and open menu on top
Returns:
this instance for chaining
    public DropDownButton setDropUp(final boolean isDropUp) {
        this..setObject(isDropUp);
        return this;
    }

    
sets the size of the button.

Parameters:
size mandatory parameter
Returns:
this instance for chaining
    public DropDownButton setSize(final Buttons.Size size) {
        this..setObject(size);
        return this;
    }

    
sets the type of the button.

Parameters:
type mandatory parameter
Returns:
this instance for chaining
    public DropDownButton setType(final Buttons.Type type) {
        this..setObject(type);
        return this;
    }
    @Override
        return new PanelMarkupSourcingStrategy(false);
    }
    @Override
    protected void onComponentTag(final ComponentTag tag) {
        super.onComponentTag(tag);
        if (.getObject()) {
            CssClassNameAppender.append(tag"dropup");
        }
        CssClassNameAppender.append(tagcreateCssClassName());
    }
    @Override
    public boolean isActive(final Component item) {
        return .hasActiveButton(item);
    }
New to GrepCode? Check out our FAQ X