|
package com.asbitec.vbi.framework.client.ui.widgets.list; |
|
|
|
import com.asbitec.vbi.framework.client.activity.MenuOption; |
|
import com.asbitec.vbi.framework.client.ui.widgets.cells.MenuOptionCell; |
|
import com.google.gwt.core.shared.GWT; |
|
import com.google.gwt.event.shared.HandlerRegistration; |
|
import com.google.gwt.resources.client.ClientBundle; |
|
import com.google.gwt.resources.client.CssResource; |
|
import com.google.gwt.safehtml.shared.SafeHtml; |
|
import com.google.gwt.safehtml.shared.SafeHtmlBuilder; |
|
import com.google.gwt.user.client.ui.IsWidget; |
|
import com.google.gwt.user.client.ui.Widget; |
|
import com.sencha.gxt.core.client.IdentityValueProvider; |
|
import com.sencha.gxt.core.client.Style.SelectionMode; |
|
import com.sencha.gxt.core.client.resources.CommonStyles; |
|
import com.sencha.gxt.data.shared.ListStore; |
|
import com.sencha.gxt.theme.base.client.listview.ListViewCustomAppearance; |
|
import com.sencha.gxt.widget.core.client.ListView; |
|
import com.sencha.gxt.widget.core.client.selection.SelectionChangedEvent.HasSelectionChangedHandlers; |
|
import com.sencha.gxt.widget.core.client.selection.SelectionChangedEvent.SelectionChangedHandler; |
|
|
|
public class NavigationList implements IsWidget, HasSelectionChangedHandlers<MenuOption> { |
|
private ListView<MenuOption, MenuOption> list; |
|
private MenuOptionCell cell; |
|
private ListStore<MenuOption> store; |
|
private Style style; |
|
|
|
public interface Bundle extends ClientBundle { |
|
|
|
@Source("NavigationList.css") |
|
Style css(); |
|
} |
|
|
|
public interface Style extends CssResource { |
|
|
|
String listWrap(); |
|
|
|
String listOver(); |
|
|
|
String listSelect(); |
|
|
|
} |
|
|
|
public NavigationList(ListStore<MenuOption> store) { |
|
super(); |
|
this.store = store; |
|
this.buildUI(); |
|
} |
|
|
|
protected void buildUI(){ |
|
final Bundle bundle=GWT.create(Bundle.class); |
|
bundle.css().ensureInjected(); |
|
style=bundle.css(); |
|
|
|
ListViewCustomAppearance<MenuOption> appearance=new ListViewCustomAppearance<MenuOption>("." + style.listWrap(), style.listOver(), style.listSelect()) { |
|
|
|
|
|
@Override |
|
public void renderEnd(SafeHtmlBuilder builder) { |
|
String markup = new StringBuilder("<div class=\"").append(CommonStyles.get().clear()).append("\"></div>").toString(); |
|
builder.appendHtmlConstant(markup); |
|
} |
|
|
|
@Override |
|
public void renderItem(SafeHtmlBuilder builder, SafeHtml content) { |
|
builder.appendHtmlConstant("<div class='" + style.listWrap() + "'>"); |
|
builder.append(content); |
|
builder.appendHtmlConstant("</div>"); |
|
} |
|
}; |
|
cell=new MenuOptionCell(); |
|
list=new ListView<>(store, new IdentityValueProvider<MenuOption>(), appearance); |
|
list.setCell(cell); |
|
list.setBorders(false); |
|
list.getSelectionModel().setSelectionMode(SelectionMode.SINGLE); |
|
list.getElement().getStyle().setBackgroundColor("#54A2F9"); |
|
|
|
} |
|
|
|
@Override |
|
public Widget asWidget() { |
|
return list; |
|
} |
|
|
|
@Override |
|
public HandlerRegistration addSelectionChangedHandler(SelectionChangedHandler<MenuOption> handler) { |
|
return this.list.getSelectionModel().addSelectionChangedHandler(handler); |
|
} |
|
|
|
|
|
|
|
|
|
} |