de.jwic.controls.mobile.MSelectBox Maven / Gradle / Ivy
package de.jwic.controls.mobile;
import de.jwic.base.Control;
import de.jwic.base.IControlContainer;
import de.jwic.base.JavaScriptSupport;
/**
* Created by boogie on 11/11/14.
*/
@JavaScriptSupport
public class MSelectBox extends Control {
/*
private final EnableableHandler enableableHandler;
private final SelectionHandler selectionHandler;
private final PropertiesHandler propertiesHandler;
private final Map possibleSelections;
private final LabelEvaluator evaluator;
private T currentSelection;*/
/**
* Constructs a new control instance and adds it to the specified
* container with the specified name. If the name is null
,
* a unique name will be chosen by the container.
*
* @param container
* @param name
*/
public MSelectBox(IControlContainer container, String name) {
super(container, name);
/*this.enableableHandler = new EnableableHandler(this);
this.selectionHandler = new SelectionHandler(this);
this.propertiesHandler = new PropertiesHandler(this);
this.possibleSelections = new LinkedHashMap();
this.evaluator = evaluator;*/
}
/*
@Override
public void actionPerformed(String actionId, String parameter) {
if(!this.isEnabled()){
return;
}
if("select".equals(actionId)){
setSelectionNoRedraw(this.possibleSelections.get(parameter));
}
}
private void setSelectionNoRedraw(T selection) {
this.currentSelection = selection;
this.propertiesHandler.setPropertyNoRedraw("selection", currentSelection);
this.selectionHandler.select();
}
public T getSelection(){
return this.currentSelection;
}
public void addSelection(T selection){
this.possibleSelections.put(this.evaluator.evaluate(selection), selection);
this.currentSelection = selection;
this.requireRedraw();
}
public void removeSelection(T selection){
this.possibleSelections.remove(this.evaluator.evaluate(selection));
}
public void setSelection(T selection){
setSelectionNoRedraw(selection);
this.requireRedraw();
}
@Override
public void enable() {
enableableHandler.enable();
}
@Override
public void disable() {
enableableHandler.disable();
}
@Override
@IncludeJsOption
public boolean isEnabled() {
return enableableHandler.isEnabled();
}
@Override
public void setEnabled(boolean enabled) {
enableableHandler.setEnabled(enabled);
}
@Override
public void addPropertyChangedListener(PropertyChangedListener listener) {
this.propertiesHandler.addPropertyChangedListener(listener);
}
@Override
public void removePropertyChangedListener(PropertyChangedListener listener) {
this.propertiesHandler.removePropertyChangedListener(listener);
}
@Override
public void select() {
this.selectionHandler.select();
}
@Override
public void addSelectionListener(SelectionListener listener) {
this.selectionHandler.addSelectionListener(listener);
}
@Override
public void removeSelectionListener(SelectionListener listener) {
this.selectionHandler.removeSelectionListener(listener);
}
@IncludeJsOption
public final Set getSelectionSet(){
return Collections.unmodifiableSet(this.possibleSelections.keySet());
}
@IncludeJsOption
public final String getCurrentSelectionString(){
return this.currentSelection == null ? "" : this.evaluator.evaluate(this.currentSelection);
}
public static interface LabelEvaluator{
String evaluate(T obj);
}
@SuppressWarnings("unchecked")
public static LabelEvaluator toStringLabelEvaluator(){
return (LabelEvaluator) ToStringEvaluator.INSTANCE;
}
private static enum ToStringEvaluator implements LabelEvaluator
© 2015 - 2025 Weber Informatics LLC | Privacy Policy