package com.sdl.bootstrap.form;

import com.sdl.selenium.web.WebLocator;
import com.sdl.selenium.web.form.ICombo;

public class MultiSelect extends WebLocator implements ICombo {

    public MultiSelect() {
        setClassName("SelectPicker");
        setBaseCls("btn dropdown-toggle");
        setTag("button");
    }

    public MultiSelect(WebLocator container) {
        this();
        setContainer(container);
    }

    public MultiSelect(WebLocator container, String label) {
        this(container);
        setLabel(label);
    }

    @Override
    public boolean select(String value) {
        if (click()) {
            WebLocator select = new WebLocator(this, "//following-sibling::*[contains(@class, 'dropdown-menu')]//span[text()='" + value + "']")
                    .setInfoMessage("select: '" + value + "'");
            return select.click();
        }
        return false;
    }

    @Override
    public String getValue() {
        return getHtmlText().trim();
    }

    @Override
    public boolean setValue(String value) {
        return select(value);
    }
}
@@ -60,60 +60,232 @@
 web.
-WebLocator;%0D%0Aimport com.sdl.selenium.web.form.ICombo
+SearchType;%0D%0Aimport com.sdl.selenium.web.WebDriverConfig;%0D%0Aimport com.sdl.selenium.web.WebLocator;%0D%0Aimport org.openqa.selenium.By;%0D%0Aimport org.openqa.selenium.WebElement;%0D%0A%0D%0Aimport java.util.ArrayList;%0D%0Aimport java.util.List
 ;%0D%0A%0D
@@ -333,26 +333,8 @@
 tor 
-implements ICombo 
 %7B%0D%0A%0D
@@ -388,20 +388,19 @@
 me(%22
+Multi
 Select
-Picker
 %22);%0D
@@ -424,11 +424,19 @@
 ls(%22
-btn
+multiselect
  dro
@@ -447,16 +447,20 @@
 n-toggle
+ btn
 %22);%0D%0A   
@@ -719,39 +719,24 @@
 ;%0D%0A    %7D%0D%0A%0D%0A
-    @Override%0D%0A
     public b
@@ -751,35 +751,74 @@
 elect(String
+...
  value
+s
 ) %7B%0D%0A
+        boolean selected = false;%0D%0A
         if (
@@ -944,62 +944,243 @@
 u')%5D
-//span%5Btext()='%22 + value + %22'%5D%22)%0D%0A                    
+%22);%0D%0A            select.ready();%0D%0A            for (String val : values) %7B%0D%0A                WebLocator el = new WebLocator(select).setTag(%22label%22).setText(val, SearchType.HTML_NODE);%0D%0A                CheckBox checkBox = new CheckBox(el)
 .set
@@ -1192,22 +1192,21 @@
 essage(%22
-select
+check
 : '%22 + v
@@ -1207,18 +1207,16 @@
 '%22 + val
-ue
  + %22'%22);
@@ -1229,29 +1229,39 @@
         
-return
+   
  select
+ed = checkBox
 .click()
@@ -1275,56 +1275,169 @@
     
-%7D%0D%0A        return false;%0D%0A    %7D%0D%0A%0D%0A    @Override
+        if (!selected) %7B%0D%0A                    return false;%0D%0A                %7D%0D%0A            %7D%0D%0A            click();%0D%0A        %7D%0D%0A        return selected;%0D%0A    %7D%0D%0A
 %0D%0A  
@@ -1445,22 +1445,28 @@
  public 
+List%3C
 String
+%3E
  getValu
@@ -1466,16 +1466,24 @@
 getValue
+Selected
 () %7B%0D%0A  
@@ -1492,105 +1492,498 @@
     
-return getHtmlText().trim();%0D%0A    %7D%0D%0A%0D%0A    @Override%0D%0A    public boolean setValue(String value) %7B
+List%3CString%3E list = null;%0D%0A        if (click()) %7B%0D%0A            list = new ArrayList%3CString%3E();%0D%0A            WebLocator select = new WebLocator(this, %22//following-sibling::*%5Bcontains(@class, 'dropdown-menu')%5D%22);%0D%0A            WebLocator li = new WebLocator(select).setTag(%22li%22).setCls(%22active%22);%0D%0A            WebLocator el = new WebLocator(li).setTag(%22label%22);%0D%0A            el.ready();%0D%0A            List%3CWebElement%3E elements = WebDriverConfig.getDriver().findElements(By.xpath(el.getPath()));
 %0D%0A  
@@ -1992,28 +1992,201 @@
     
-return select(value)
+    for (WebElement element : elements) %7B%0D%0A                String text = element.getText();%0D%0A                list.add(text);%0D%0A            %7D%0D%0A            click();%0D%0A        %7D%0D%0A        return list
 ;%0D%0A 

fix MultiSelects