package com.sdl.bootstrap.button;

import com.sdl.selenium.web.WebLocator;
import org.apache.log4j.Logger;
import org.openqa.selenium.interactions.Actions;

public class UploadFile extends WebLocator {
    private static final Logger logger = Logger.getLogger(UploadFile.class);

    public UploadFile() {
        setClassName("UploadFile");
        setCls("fileupload");
        setTag("div");
    }

    /**
     * @param container
     */
    public UploadFile(WebLocator container) {
        this();
        setContainer(container);
    }

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

    /**
     * Upload file with AutoIT.
     * Use only this: button.upload("Browse", new String[] {"C:\\upload.exe", "C:\\text.txt"});
     *
     * @param text
     * @param filePath
     */
    public void upload(String text, String[] filePath) {
        WebLocator upload = new WebLocator(this).setTag("span").setCls("fileupload-new").setText(text);
        upload(upload, filePath);
    }

    public void change(String[] filePath) {
        change("Change", filePath);
    }

    public void change(String text, String[] filePath) {
        WebLocator upload = new WebLocator(this).setTag("span").setCls("fileupload-exists").setText(text);
        upload(upload, filePath);
    }

    /**
     * Upload file with AutoIT.
     * Use only this: button.upload(new String[] {"C:\\upload.exe", "C:\\text.txt"});
     *
     * @param filePath new String[] {"C:\\upload.exe", "C:\\text.txt"}
     */
    public void upload(String[] filePath) {
        WebLocator uploadButton = new WebLocator(this, "//span[contains(@class,'fileupload-new') and count(.//i[@class='icon-folder-open']) > 0]");
        upload(uploadButton, filePath);
    }

    public void reUpload(String[] filePath) {
        WebLocator uploadButton = new WebLocator(this, "//span[contains(@class,'fileupload-exists') and count(.//i[@class='icon-refresh']) > 0]");
        upload(uploadButton, filePath);
    }

    public boolean removeFile() {
        WebLocator removeButton = new WebLocator(this, "//a[contains(@class,'fileupload-exists') and count(.//i[@class='icon-trash']) > 0]");
        return removeButton.clickAt();
    }

    public String uploadedNameFile() {
        WebLocator upload = new WebLocator(this).setTag("span").setCls("fileupload-preview");
        return upload.getHtmlText();
    }

    public boolean upload(WebLocator el, String[] filePath) {
        driver.switchTo().window(driver.getWindowHandle());
        el.focus();
        Actions builder = new Actions(driver);
        builder.moveToElement(el.currentElement).build().perform();
        builder.click().build().perform();
        driver.switchTo().defaultContent();
        return RunExe.getInstance().upload(filePath);
    }
}
@@ -850,36 +850,39 @@
   */%0A    public 
-void
+boolean
  upload(String t
@@ -1011,32 +1011,39 @@
 (text);%0A        
+return 
 upload(upload, f
@@ -1149,36 +1149,39 @@
   %7D%0A%0A    public 
-void
+boolean
  change(String t
@@ -1313,32 +1313,39 @@
 (text);%0A        
+return 
 upload(upload, f
@@ -1584,20 +1584,23 @@
  public 
-void
+boolean
  upload(
@@ -1768,32 +1768,39 @@
 %3E 0%5D%22);%0A        
+return 
 upload(uploadBut
@@ -1833,20 +1833,23 @@
  public 
-void
+boolean
  reUploa
@@ -2026,16 +2026,23 @@
         
+return 
 upload(u

make boolean upload methods