package com.sdl.selenium.web.form;

import com.extjs.selenium.Utils;
import com.sdl.selenium.web.WebLocator;
import org.apache.log4j.Logger;
import org.openqa.selenium.Keys;

public class SimpleMultipleSelect extends SimpleComboBox {
    private static final Logger logger = Logger.getLogger(SimpleMultipleSelect.class);

    public SimpleMultipleSelect() {
        setClassName("SimpleMultipleSelect");
    }

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

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

    public boolean selectRows(String... values) {
        boolean select = false;
        if (ready()) {
            sendKeys(Keys.CONTROL);
            for (String value : values) {
                WebLocator el = new WebLocator(this, "//*[contains(text(),'" + value + "')]");
                select = el.click();
                if (!select) {
                    sendKeys(Keys.UP);
                    return false;
                }
            }
            sendKeys(Keys.UP);
        }
        return select;
    }

    protected String getItemPath(boolean disabled) {
        String selector = getBasePathSelector();
        selector = Utils.fixPathSelector(selector);
        selector = getTag() + (selector.length() > 0 ? ("[" + selector + "]") : "");
        return selector;
    }

    @Override
    protected String afterItemPathCreated(String itemPath) {
        if (hasLabel()) {
            itemPath = getLabelPath() + "//following-sibling::" + itemPath;
        } else {
            itemPath = "//" + itemPath;
        }
        itemPath = addPositionToPath(itemPath);
        return itemPath;
    }
}

@@ -62,16 +62,56 @@
 .Utils;%0A
+import com.sdl.selenium.web.SearchType;%0A
 import c
@@ -201,20 +201,109 @@
 elenium.
-Keys
+By;%0Aimport org.openqa.selenium.WebElement;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.List
 ;%0A%0Apubli
@@ -873,24 +873,26 @@
 (ready()) %7B%0A
+//
             
@@ -1012,49 +1012,42 @@
 this
-, %22//*%5Bcontains(text(),'%22 + value + %22')%5D%22
+).setText(value, SearchType.EQUALS
 );%0A 
@@ -1117,47 +1117,8 @@
 ) %7B%0A
-                    sendKeys(Keys.UP);%0A
     
@@ -1183,39 +1183,8 @@
   %7D%0A
-            sendKeys(Keys.UP);%0A
     
@@ -1215,24 +1215,428 @@
 ect;%0A    %7D%0A%0A
+    public List%3CString%3E getValues() %7B%0A        List%3CWebElement%3E elements = WebLocator.getDriver().findElements(By.xpath(new WebLocator(this).getPath()));%0A        List%3CString%3E list = new ArrayList%3C%3E();%0A        for (int i = 0; i %3C elements.size(); i++) %7B%0A            String text = elements.get(i).getText();%0A            logger.debug(text);%0A            list.add(text);%0A        %7D%0A        return list;%0A    %7D%0A%0A%0A
     protecte

Add getValues() and selectRows() for SimpleMultipleSelect