Skip to content

Commit

Permalink
Kendo UI: added IMenuItem#isSelected
Browse files Browse the repository at this point in the history
  • Loading branch information
Tedlabs46 authored and sbriquet committed Jun 16, 2018
1 parent 9fc1ac8 commit 337ef22
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package com.googlecode.wicket.kendo.ui.widget.menu;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

Expand All @@ -32,6 +31,7 @@
import org.apache.wicket.markup.html.panel.Fragment;
import org.apache.wicket.model.Model;
import org.apache.wicket.util.lang.Args;
import org.apache.wicket.util.lang.Generics;

import com.googlecode.wicket.jquery.core.JQueryPanel;
import com.googlecode.wicket.jquery.core.Options;
Expand All @@ -54,7 +54,7 @@ public class Menu extends JQueryPanel implements IMenuListener
private WebMarkupContainer root;

/** Keep a reference to the {@link MenuItem}{@code s} hash */
private Map<String, IMenuItem> map = new HashMap<String, IMenuItem>();
private Map<String, IMenuItem> map = Generics.newHashMap();

/**
* Constructor
Expand Down Expand Up @@ -223,6 +223,11 @@ protected void populateItem(ListItem<IMenuItem> item)
{
item.add(AttributeModifier.append("disabled", Model.of("disabled")));
}

if (menuItem.isSelected())
{
item.add(AttributeModifier.append("class", Model.of("menu-item-selected")));
}
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public abstract class AbstractMenuItem implements IMenuItem
private IModel<String> title;
private String icon;
private boolean enabled = true;
private boolean selected = false;

/**
* Constructor
Expand Down Expand Up @@ -110,6 +111,26 @@ public AbstractMenuItem setEnabled(boolean enabled)
return this;
}

@Override
public boolean isSelected() {

return this.selected;
}

/**
* Sets whether the menu-item is selected
*
* @param selected
* true or false
* @return this, for chaining
*/
public AbstractMenuItem setSelected(boolean selected) {

this.selected = selected;

return this;
}

@Override
public List<IMenuItem> getItems()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,36 +36,49 @@ public interface IMenuItem extends IClusterable
{
/**
* Gets the menu-item markup id
*
* @return the menu-item markup id
*/
String getId();

/**
* Gets the menu-item title
*
* @return the menu-item title
*/
IModel<String> getTitle();

/**
* Gets the icon being displayed in the {@link Menu}
*
* @return the icon css class
*/
String getIcon();

/**
* Indicates whether the menu-item is enabled
*
* @return true or false
*/
boolean isEnabled();

/**
* Indicates whether the menu-item is selected
*
* @return true or false
*/
boolean isSelected();

/**
* Gets the {@link List} of submenu-items
*
* @return the {@link List} of submenu-items
*/
List<IMenuItem> getItems();

/**
* Triggered when the menu-item is clicked
*
* @param target the {@link AjaxRequestTarget}
*/
void onClick(AjaxRequestTarget target);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,11 @@ public boolean isEnabled()
{
return super.isEnabled() && !RequestCycleUtils.getPageClass().isAssignableFrom(this.pageReference.get());
}

@Override
public boolean isSelected() {

return RequestCycleUtils.getPageClass().isAssignableFrom(this.pageReference.get());
}

}

0 comments on commit 337ef22

Please sign in to comment.