/**
   * Creates the edit container
   *
   * @return editContainer
   */
  private UIComponent getEditContainer(IWContext iwc, boolean submitted) {
    WFContainer mainContainer = new WFContainer();
    WFResourceUtil localizer = WFResourceUtil.getResourceUtilContent();
    if (getDisplayHeader()) {
      mainContainer.add(localizer.getHeaderTextVB("categories"));
    }
    mainContainer.add(getCategoriesTable(iwc, submitted));

    if (isAddCategoryCreator()) {
      mainContainer.add(getAddCategoryContainer());
    }

    return mainContainer;
  }
  /**
   * Returns a container with "add category" UI
   *
   * @return WFContainer
   */
  private WFContainer getAddCategoryContainer() {
    WFContainer container = new WFContainer();
    WFResourceUtil localizer = WFResourceUtil.getResourceUtilContent();
    // Text
    HtmlOutputText addText = localizer.getTextVB("new_category");
    container.add(addText);
    // Input
    HtmlInputText newCategoryInput = new HtmlInputText();
    newCategoryInput.setSize(40);
    newCategoryInput.setId(getAddCategoryInputId());
    container.add(newCategoryInput);
    // Button
    HtmlCommandButton addCategoryButton = localizer.getButtonVB(getAddButtonId(), "add", this);
    container.add(addCategoryButton);

    return container;
  }
  /**
   * Creates a table with checkboxes for all the available categories
   *
   * @param resourcePath
   * @return table
   */
  private Table getCategoriesTable(IWContext iwc, boolean submitted) {
    if (!areCategoriesFetched) {
      getSelectedAndNotSelectedCategories(iwc);
    }

    Table categoriesTable = new Table();
    int categoriesCount = 0;
    Locale locale = getLocale(iwc);

    List<ContentCategory> allCategories = new ArrayList<ContentCategory>(selectedCategories);
    allCategories.addAll(notSelectedCategories);
    allCategories = getSortedCategories(allCategories, locale);
    if (ListUtil.isEmpty(allCategories)) {
      return categoriesTable;
    }

    for (ContentCategory category : allCategories) {
      HtmlSelectBooleanCheckbox categoryCheckBox =
          (HtmlSelectBooleanCheckbox)
              iwc.getApplication().createComponent(HtmlSelectBooleanCheckbox.COMPONENT_TYPE);
      categoryCheckBox.setId(getCategoryKey(category));
      if (selectedCategories.contains(category)) {
        categoryCheckBox.setSelected(Boolean.TRUE);
      } else {
        if (!submitted) {
          if (notSelectedCategories.size() == 1
              && selectedCategories.size() == 0
              && selectAnyCategory) {
            categoryCheckBox.setSelected(Boolean.TRUE);
          }
        }
      }
      categoriesTable.add(
          categoryCheckBox, categoriesCount % COLLUMNS + 1, categoriesCount / COLLUMNS + 1);

      Label categoryName = new Label(category.getName(locale.toString()), categoryCheckBox);
      categoriesTable.add(
          categoryName, categoriesCount % COLLUMNS + 1, categoriesCount / COLLUMNS + 1);
      categoriesCount++;
    }

    categoriesTable.setColumns(Math.min(categoriesCount, COLLUMNS));
    categoriesCount--;
    categoriesTable.setRows(categoriesCount / COLLUMNS + 1);

    if (getDisplaySaveButton()) {
      //	Add the save button
      if (this.resourcePath != null && this.resourcePath.length() > 0) {
        WFResourceUtil localizer = WFResourceUtil.getResourceUtilContent();
        HtmlCommandButton addCategoryButton =
            localizer.getButtonVB(getSaveButtonId(), "save", this);
        categoriesTable.add(addCategoryButton, 1, categoriesCount / COLLUMNS + 2);
        categoriesTable.setRows(categoriesCount / COLLUMNS + 2);
      }
    }

    categoriesTable.setId(categoriesTable.getId() + "_ver");
    categoriesTable.setStyleClass("wf_listtable");

    return categoriesTable;
  }