@Override
  public AbsPage zTreeItem(Action action, Button option, IItem folder) throws HarnessException {

    tracer.trace("Click " + action + " then " + option + " on folder " + folder.getName());

    // Validate the arguments
    if ((action == null) || (option == null) || (folder == null)) {
      throw new HarnessException("Must define an action, option, and addressbook");
    }

    if (folder instanceof FolderMountpointItem) {
      return (zTreeItem(action, option, (FolderMountpointItem) folder));
    } else if (folder instanceof SavedSearchFolderItem) {
      return (zTreeItem(action, option, (SavedSearchFolderItem) folder));
      // } else if ( folder instanceof ZimletItem ) {
      //	return (zTreeItem(action, option, (ZimletItem)folder));
    } else if (folder instanceof TagItem) {
      return (zTreeItem(action, option, (TagItem) folder));
    } else if (folder instanceof FolderItem) { // FolderItem needs to go last
      return (zTreeItem(action, option, (FolderItem) folder));
    }

    throw new HarnessException(
        "Must use TagItem FolderItem or SavedSearchFolderItem or ZimletItem as argument, but was "
            + folder.getClass());
  }
  public AbsPage zTreeItem(Action action, IItem item, boolean isRowAdded) throws HarnessException {

    tracer.trace("Click " + action + " on folder " + item.getName());

    String treeItemLocator = Locators.briefcaseTreeView + "]";

    AbsPage page = zTreeItem(action, item);

    zWaitForElementPresent(treeItemLocator);

    String listItemLocator = "css=div[id^=zl__BDLV][class=DwtListView-Rows]";

    if (isRowAdded) listItemLocator += ">div[id^=zli__BDLV][class^=Row]";

    zWaitForElementPresent(listItemLocator);

    return page;
  }
  @Override
  public AbsPage zTreeItem(Action action, Button option, IItem item) throws HarnessException {
    // Validate the arguments
    if ((action == null) || (option == null) || (item == null)) {
      throw new HarnessException(
          "zTreeItem(Action, Button, IItem): Must define an action, option, and item");
    }

    logger.info(
        myPageName() + " zTreeItem(" + action + ", " + option + ", " + item.getName() + ")");

    tracer.trace("Click " + action + " then " + option + " on item " + item.getName());

    AbsPage page = null;
    String actionLocator = null;
    String optionLocator = null;

    if (item instanceof TagItem) {
      actionLocator =
          "css=td[id^=zti__main_Briefcase__]:contains(" + ((TagItem) item).getName() + ")";
    } else if (item instanceof FolderItem) {
      actionLocator =
          "css=td[id^=zti__main_Briefcase__" + ((FolderItem) item).getId() + "_textCell]";
    } else {
      throw new HarnessException("Must use IItem as argument, but was " + item.getClass());
    }

    zWaitForElementVisible(actionLocator);

    if (action == Action.A_RIGHTCLICK) {
      this.zRightClickAt(actionLocator, "0,0");
    } else {
      throw new HarnessException("implement me! " + action + ": not implemented");
    }

    if (option == Button.B_TREE_NEWTAG) {

      optionLocator = Locators.zNewTagTreeMenuItem;

      page = new DialogTag(MyApplication, ((AppAjaxClient) MyApplication).zPageBriefcase);

    } else if (option == Button.B_TREE_RENAMETAG) {

      optionLocator = Locators.zRenameTagTreeMenuItem;

      page = new DialogRenameTag(MyApplication, ((AppAjaxClient) MyApplication).zPageBriefcase);
    } else if (option == Button.B_TREE_DELETE) {

      optionLocator = Locators.zDeleteTreeMenuItem;

      if (item instanceof TagItem) {
        page =
            new DialogWarning(
                DialogWarning.DialogWarningID.DeleteTagWarningMessage,
                MyApplication,
                ((AppAjaxClient) MyApplication).zPageBriefcase);
      }
    } else if (option == Button.B_TREE_NEWFOLDER) {

      optionLocator = Locators.zNewFolderTreeMenuItem;

      page =
          new DialogCreateBriefcaseFolder(
              MyApplication, ((AppAjaxClient) MyApplication).zPageBriefcase);

    } else if (option == Button.B_TREE_EDIT_PROPERTIES) {

      optionLocator = Locators.zEditPropertiesTreeMenuItem;

      page =
          new DialogEditProperties(MyApplication, ((AppAjaxClient) MyApplication).zPageBriefcase);

    } else {
      throw new HarnessException("button " + option + " not yet implemented");
    }

    this.zWaitForBusyOverlay();

    zWaitForElementVisible(optionLocator);

    // Default behavior. Click the locator
    zClickAt(optionLocator, "");

    // If there is a busy overlay, wait for that to finish
    this.zWaitForBusyOverlay();

    if (page != null) {
      // Wait for the page to become active, if it was specified
      page.zWaitForActive();
    }
    return (page);
  }
  @Override
  public AbsPage zTreeItem(Action action, IItem item) throws HarnessException {
    // Validate the arguments
    if ((action == null) || (item == null)) {
      throw new HarnessException("zTreeItem(Action, IItem): Must define an action, and item");
    }
    logger.info(myPageName() + " zTreeItem(" + action + ", " + item.getName() + ")");

    tracer.trace("Click " + action + " on item " + item.getName());

    AbsPage page = null;
    String locator = null;

    if (item instanceof TagItem) {
      locator = "css=td[id^=zti__main_Briefcase__]:contains(" + ((TagItem) item).getName() + ")";
    } else if (item instanceof FolderItem) {
      locator = Locators.briefcaseTreeView + ((FolderItem) item).getId() + "_imageCell]";

    } else if (item instanceof LinkItem) {
      page = new DialogFindShares(MyApplication, ((AppAjaxClient) MyApplication).zPageBriefcase);
      if (ZimbraSeleniumProperties.isWebDriver()) {
        clickBy(By.id("ztih__main_Briefcase__BRIEFCASE"), By.linkText("Find Shares..."));
        return page;
      } else {
        locator = "css=div[id=ztih__main_Briefcase__BRIEFCASE] a[id$=_addshare_link]";
        page = new DialogFindShares(MyApplication, ((AppAjaxClient) MyApplication).zPageBriefcase);
      }

      if (!this.sIsElementPresent(locator)) {
        throw new HarnessException("Unable to locate link in the tree " + locator);
      }

      this.sClickAt(locator, "0,0");

      zWaitForBusyOverlay();

      return page;

    } else {
      throw new HarnessException("Must use IItem as argument, but was " + item.getClass());
    }

    if (action == Action.A_LEFTCLICK) {

      zWaitForBusyOverlay();

      // FALL THROUGH
    } else if (action == Action.A_RIGHTCLICK) {

      if (!this.sIsElementPresent(locator))
        throw new HarnessException("Unable to locate folder in the tree " + locator);

      // Select the folder
      this.zRightClickAt(locator, "0,0");

      // return a context menu
      return (new ContextMenu(MyApplication));
    } else {
      throw new HarnessException("Action " + action + " not yet implemented");
    }

    if (!this.sIsElementPresent(locator))
      throw new HarnessException("Unable to locate folder in the tree " + locator);

    // Default behavior. Click the locator
    zClickAt(locator, "0,0");

    // If there is a busy overlay, wait for that to finish
    zWaitForBusyOverlay();

    return (page);
  }