package com.dd.bootstrap.components;

import com.webobjects.appserver.WOContext;
import com.webobjects.appserver.WOResponse;
import com.webobjects.foundation.NSArray;
import com.webobjects.foundation.NSMutableArray;

public class BSEditorRowSelectMultiple extends BSComponent {
    
    
    public int index;
	private String _id;
	
	public BSEditorRowSelectMultiple(WOContext context) {
        super(context);
    }
    
    @Override
    public boolean isStateless() {
    	return true;
    }
    
    @Override
    public void reset() {
    	super.reset();
    	_id = null;
    }
    
	/*
	 *  api of component
	 */
	public static interface Bindings {
		public static final String selections = "selections";
		public static final String item = "item";
		public static final String id = "id";
		public static final String name = "name";
		public static final String index = "index";
		public static final String prefix = "prefix";	// TODO
		public static final String suffix = "suffix";	// TODO
	}
    
    // accesors
	private NSArray selections() {
    	return (NSArray) valueForBinding(Bindings.selections);
    }
    
    private Object item() {
    	return valueForBinding(Bindings.item);
    }
    
    public Object selection() {
    	if (selections() == null) return null;
    	return selections().contains(item()) ? item() : null;
    }
    
    public void setSelection(Object value) {
     	NSMutableArray selections = (selections() != null) ? selections().mutableClone() : new NSMutableArray();
    	if (value != null) {
    		selections.addObject(item());
    	} else {
    		selections.removeObject(item());
    	}
    	setValueForBinding(selections, Bindings.selections);
    }
    
    public String elementName() {
    	return hasBinding(Bindings.name) ? (String) valueForBinding(Bindings.name) : _id();
    }
    
    public String id() {
    	return _id() + "_" + index;
    }
    
    private String _id() {
    	if (_id == null) _id = hasBinding(Bindings.id) ? (String)  valueForBinding(Bindings.id) : context().javaScriptElementID();
    	return _id;
    }
    
    public void setIndex(int i) {
    	index = i;
    	setValueForBinding(Integer.valueOf(index), Bindings.index);
    }
    
}
@@ -78,52 +78,8 @@
 xt;%0A
-import com.webobjects.appserver.WOResponse;%0A
 impo
@@ -166,16 +166,112 @@
 Array;%0A%0A
+// Further optimization with this plugin%0A// http://davidstutz.github.io/bootstrap-multiselect/%0A%0A
 public c
@@ -1067,16 +1067,47 @@
 ccesors%0A
+%09@SuppressWarnings(%22rawtypes%22)%0A
 %09private
@@ -1426,32 +1426,80 @@
 %0A    %7D%0A    %0A    
+@SuppressWarnings(%7B %22unchecked%22, %22rawtypes%22 %7D)%0A%09
 public void setS

Clean up, adds link to bootstrap multi-select enhancement, later optimization.