private String getTitle(CategoryItem categoryItem) {
   if (categoryItem == null) {
     return Constants.INSTANCE.CreateANewTopLevelCategory();
   } else {
     return Constants.INSTANCE.CreateNewCategoryUnder0(categoryItem.getName());
   }
 }
    void ok() {

      if ("".equals(this.name.getText())) {
        ErrorPopup.showMessage(Constants.INSTANCE.CanNotHaveAnEmptyCategoryName());
      } else {
        if (parent.contains(name.getText())) {
          ErrorPopup.showMessage(Constants.INSTANCE.CategoryWasNotSuccessfullyCreated());
        } else {
          isDirty = true;
          explorer.addChildren(parent, name.getText(), description.getText());
          hide();
        }
      }
    }
    /** This is used when creating a new category */
    public CategoryEditor(final CategoryItem parent) {
      super.setTitle(getTitle(parent));
      this.parent = parent;

      addAttribute(Constants.INSTANCE.CategoryName(), name);

      Button ok = new Button(Constants.INSTANCE.OK());
      ok.addClickHandler(
          new ClickHandler() {
            public void onClick(ClickEvent event) {
              ok();
            }
          });
      addAttribute("", ok);
    }
  @PostConstruct
  public void init() {
    explorer = new CategoryTreeEditorWidget();
    form = new PrettyFormLayout();

    form.addHeader(Images.INSTANCE.EditCategories(), new HTML(Constants.INSTANCE.EditCategories()));
    form.startSection(Constants.INSTANCE.CategoriesPurposeTip());

    final SimplePanel editable = new SimplePanel();
    editable.add(explorer);

    form.addAttribute(Constants.INSTANCE.CurrentCategories(), editable);

    final HorizontalPanel actions = new HorizontalPanel();

    form.addAttribute("", actions);

    final Button newCat = new Button(Constants.INSTANCE.NewCategory());
    newCat.setTitle(Constants.INSTANCE.CreateANewCategory());
    newCat.addClickHandler(
        new ClickHandler() {
          public void onClick(ClickEvent w) {
            final CategoryEditor newCat;
            if (explorer.getSelectedCategory() == null) {
              newCat = new CategoryEditor(explorer.getCategories());
            } else {
              newCat = new CategoryEditor(explorer.getSelectedCategory());
            }

            newCat.show();
          }
        });

    actions.add(newCat);

    final Button rename = new Button(Constants.INSTANCE.RenameSelected());
    rename.addClickHandler(
        new ClickHandler() {
          public void onClick(ClickEvent w) {
            if (!explorer.isSelected()) {
              Window.alert(Constants.INSTANCE.PleaseSelectACategoryToRename());
              return;
            }
            final String name = Window.prompt(Constants.INSTANCE.CategoryNewNamePleaseEnter(), "");
            if (name != null) {
              isDirty = true;
              explorer.renameSelected(name);
            }
          }
        });

    actions.add(rename);

    final Button delete = new Button(Constants.INSTANCE.DeleteSelected());
    delete.addClickHandler(
        new ClickHandler() {
          public void onClick(final ClickEvent w) {
            if (!explorer.isSelected()) {
              Window.alert(Constants.INSTANCE.PleaseSelectACategoryToDelete());
              return;
            }
            if (Window.confirm(
                Constants.INSTANCE.AreYouSureYouWantToDeleteCategory()
                    + explorer.getSelectedCategory().getName())) {
              isDirty = true;
              explorer.removeSelected();
            }
          }
        });
    delete.setTitle(Constants.INSTANCE.DeleteSelectedCat());

    actions.add(delete);

    form.endSection();

    initWidget(form);
  }