public void saveTab(FormEvent event) throws IOException {

    String lang = event.getPortletRequest().getLocale().getLanguage();
    String name = event.getPortletRequest().getParameter("myTF");
    String label = event.getAction().getParameter("tabid");

    PortletTabbedPane pane = layoutMgr.getUserTabbedPane(event.getPortletRequest());
    List tabs = pane.getPortletTabs();
    Iterator it = tabs.iterator();
    while (it.hasNext()) {
      PortletTab tab = (PortletTab) it.next();
      if (tab.getLabel().equals(label)) {
        tab.setTitle(lang, name);
        tab.setLabel(URLEncoder.encode(name, "UTF-8"));
      }
    }
    pane.save();
    PortletPage page = layoutMgr.getPortletPage(event.getPortletRequest());
    PortletTabbedPane mypane = page.getPortletTabbedPane();
    it = mypane.getPortletTabs().iterator();
    while (it.hasNext()) {
      PortletTab tab = (PortletTab) it.next();
      if (tab.getLabel().equals(label)) {
        tab.setTitle(lang, name);
        tab.setLabel(URLEncoder.encode(name, "UTF-8"));
      }
    }
    layoutMgr.reloadPage(event.getPortletRequest());
  }
  public void createNewTab(FormEvent event) throws PortletException, IOException {

    String tabName = event.getTextFieldBean("userTabTF").getValue();
    RadioButtonBean rb = event.getRadioButtonBean("colsRB");
    String rbtype = rb.getSelectedValue();

    int cols = Integer.valueOf(rbtype).intValue();
    if (tabName == null) {
      createErrorMessage(
          event, this.getLocalizedText(event.getPortletRequest(), "LAYOUT_NOTAB_ERROR"));
      return;
    }
    log.debug("creating tab " + tabName + " cols= " + cols);
    PortletTabbedPane pane = layoutMgr.getUserTabbedPane(event.getPortletRequest());
    if (pane != null) {
      Iterator it = pane.getPortletTabs().iterator();
      while (it.hasNext()) {
        PortletTab tab = (PortletTab) it.next();
        if (tab.getLabel().equals(tabName + "Tab")) {
          createErrorMessage(
              event, this.getLocalizedText(event.getPortletRequest(), "LAYOUT_SAMETAB_ERROR"));
          return;
        }
      }
    }

    pane = layoutMgr.createUserTabbedPane(event.getPortletRequest(), cols, tabName);

    PortletTab tab = pane.getLastPortletTab();

    pane.save();
    PortletPage page = layoutMgr.getPortletPage(event.getPortletRequest());
    PortletTabbedPane mypane = page.getPortletTabbedPane();
    List tabs = mypane.getPortletTabs();
    tabs.add(tab);
    Collections.sort(tabs, new PortletTab());
    layoutMgr.reloadPage(event.getPortletRequest());
  }
  public void deleteTab(FormEvent event) throws IOException {
    String label = event.getAction().getParameter("tabid");

    PortletTabbedPane pane = layoutMgr.getUserTabbedPane(event.getPortletRequest());
    List tabs = pane.getPortletTabs();
    Iterator it = tabs.iterator();
    while (it.hasNext()) {
      PortletTab tab = (PortletTab) it.next();
      if (tab.getLabel().equals(label)) {
        it.remove();
      }
    }
    pane.save();
    PortletPage page = layoutMgr.getPortletPage(event.getPortletRequest());
    PortletTabbedPane mypane = page.getPortletTabbedPane();
    it = mypane.getPortletTabs().iterator();
    while (it.hasNext()) {
      PortletTab tab = (PortletTab) it.next();
      if (tab.getLabel().equals(label)) {
        it.remove();
      }
    }
    layoutMgr.reloadPage(event.getPortletRequest());
  }
  public void doRender(FormEvent event) {
    PortletRequest req = event.getPortletRequest();

    req.setAttribute("lang", req.getLocale().getLanguage());

    ListBoxBean themeLB = event.getListBoxBean("themeLB");
    PortletPage page = layoutMgr.getPortletPage(req);
    String theme = page.getTheme();
    themeLB.clear();

    String themesPath = getPortletConfig().getContext().getRealPath("/themes");
    /// retrieve the current renderkit
    themesPath += "/" + page.getRenderKit();

    File f = new File(themesPath);
    if (f.isDirectory()) {
      themes = f.list();
    }

    for (int i = 0; i < themes.length; i++) {
      ListBoxItemBean lb = new ListBoxItemBean();
      lb.setValue(themes[i].trim());
      if (themes[i].trim().equalsIgnoreCase(theme)) lb.setSelected(true);
      themeLB.addBean(lb);
    }

    PortletTabbedPane pane = layoutMgr.getUserTabbedPane(req);
    List tabs;
    if (pane != null) {
      tabs = pane.getPortletTabs();
    } else {
      tabs = new ArrayList();
    }
    req.setAttribute("tabs", tabs);
    setNextState(req, VIEW_JSP);
  }