public void main(IWContext iwc) throws Exception {
    ELUtil.getInstance().autowire(this);

    String val = iwc.getParameter("submitBtn");
    if (!StringUtil.isEmpty(val)) {
      dao.createDish(
          iwc.getParameter("dishName"),
          iwc.getParameter("dishDescription"),
          iwc.getParameter("dishPrice"));
    }

    Layer container = new Layer(); // 	<div>
    add(container);

    IWResourceBundle iwrb = getResourceBundle(iwc);

    Form form = new Form();
    container.add(form);

    createField(form, "Dish", "dish_name", new TextInput("dishName"), iwrb);
    createField(form, "Description", "description", new TextArea("dishDescription"), iwrb);
    createField(form, "Price", "price", new TextInput("dishPrice"), iwrb);

    SubmitButton submitBtn =
        new SubmitButton("submitBtn", iwrb.getLocalizedString("submit", "Submit"));
    form.add(submitBtn);
  }
    public void main(IWContext iwc) throws Exception {

      Form myForm = new Form();
      myForm.maintainParameter(_PARAMETER_GROUP_ID);

      int groupId = -1;
      try {
        groupId = Integer.parseInt(iwc.getParameter(_PARAMETER_GROUP_ID));
      } catch (Exception ex) {
        // do Nothing
      }

      if (iwc.getParameter("commit") != null) {

        // Save

        // System.out.println("----------------------------");
        // System.out.println("users: "+iwc.getParameterValues(_USERS_RELATED));

        UserGroupBusiness.updateUsersInGroup(groupId, iwc.getParameterValues(_USERS_RELATED));

        this.setParentToReload();
        this.close();

      } else {
        UserList uList = new UserList(_USERS_RELATED);

        List lDirect =
            com.idega.core.user.business.UserGroupBusiness.getUsersContainedDirectlyRelated(
                groupId);
        Set direct = new HashSet();
        if (lDirect != null) {
          Iterator iter = lDirect.iterator();
          while (iter.hasNext()) {
            User item = (User) iter.next();
            direct.add(Integer.toString(item.getGroupID()));
          }
        }
        uList.setDirectlyRelatedUserIds(direct);

        List lNotDirect =
            com.idega.core.user.business.UserGroupBusiness.getUsersContainedNotDirectlyRelated(
                groupId);
        Set notDirect = new HashSet();
        if (lNotDirect != null) {
          Iterator iter2 = lNotDirect.iterator();
          while (iter2.hasNext()) {
            User item = (User) iter2.next();
            notDirect.add(Integer.toString(item.getGroupID()));
          }
        }
        uList.setRelatedUserIdsNotDirectly(notDirect);

        myForm.add(uList);

        myForm.add(new SubmitButton("commit", "    OK   "));
        myForm.add(new CloseButton("  Cancel  "));
        this.add(myForm);
      }
    }
    private void LineUpElements(IWContext iwc) {

      Form form = new Form();

      Table frameTable = new Table(3, 3);
      frameTable.setWidth("100%");
      frameTable.setHeight("100%");
      // frameTable.setBorder(1);

      SelectionDoubleBox sdb =
          new SelectionDoubleBox(GroupGroupSetter.FIELDNAME_SELECTION_DOUBLE_BOX, "Not in", "In");

      SelectionBox left = sdb.getLeftBox();
      left.setHeight(8);
      left.selectAllOnSubmit();

      SelectionBox right = sdb.getRightBox();
      right.setHeight(8);
      right.selectAllOnSubmit();

      String stringGroupId = iwc.getParameter(GroupGroupSetter.PARAMETER_GROUP_ID);
      int groupId = Integer.parseInt(stringGroupId);
      form.addParameter(GroupGroupSetter.PARAMETER_GROUP_ID, stringGroupId);

      List directGroups = UserGroupBusiness.getGroupsContainingDirectlyRelated(groupId);

      Iterator iter = null;
      if (directGroups != null) {
        iter = directGroups.iterator();
        while (iter.hasNext()) {
          Object item = iter.next();
          right.addElement(
              Integer.toString(((GenericGroup) item).getID()), ((GenericGroup) item).getName());
        }
      }
      List notDirectGroups = UserGroupBusiness.getRegisteredGroupsNotDirectlyRelated(groupId, iwc);
      if (notDirectGroups != null) {
        iter = notDirectGroups.iterator();
        while (iter.hasNext()) {
          Object item = iter.next();
          left.addElement(
              Integer.toString(((GenericGroup) item).getID()), ((GenericGroup) item).getName());
        }
      }

      // left.addSeparator();
      // right.addSeparator();

      frameTable.setAlignment(2, 2, "center");
      frameTable.add("GroupId: " + groupId, 2, 1);
      frameTable.add(sdb, 2, 2);
      frameTable.add(new SubmitButton("  Save  ", "save", "true"), 2, 3);
      frameTable.add(new CloseButton("  Cancel  "), 2, 3);
      frameTable.setAlignment(2, 3, "right");
      form.add(frameTable);
      this.add(form);
    }
  private void addForm(IWContext iwc) {
    Form form = new Form();
    form.maintainParameter(PARAMETER_GROUP_ID);

    Table mainTable = new Table();
    mainTable.setWidth(660);
    mainTable.setHeight(200);
    mainTable.setCellpadding(0);
    mainTable.setCellspacing(0);
    form.add(mainTable);

    Table topTable = new Table(1, 1);
    topTable.setStyleClass(MAIN_STYLECLASS);
    topTable.setWidth(Table.HUNDRED_PERCENT);
    topTable.setHeight(160);

    topTable.add(
        this.iwrb.getLocalizedString(
            UPDATE_INFO, "Press Update to update all clubs linked to this league."),
        1,
        1);

    CloseButton close =
        new CloseButton(
            this.iwrb.getLocalizedImageButton("updateclubdivisiontemplate.close", "Close"));
    SubmitButton start =
        new SubmitButton(
            this.iwrb.getLocalizedImageButton("updateclubdivisiontemplate.update", "Update"),
            ACTION,
            ACTION_UPDATE);
    start.setSubmitConfirm(
        this.iwrb.getLocalizedString(
            "updateclubdivisiontemplate.confirm_message",
            "Are you sure you want to start the update process? The process will start in the background and once it is running you can not stop it nor start a new one."));
    Help help = getHelp(HELP_TEXT_KEY);

    Table bottomTable = new Table();
    bottomTable.setCellpadding(0);
    bottomTable.setCellspacing(5);
    bottomTable.setWidth(Table.HUNDRED_PERCENT);
    bottomTable.setHeight(39);
    bottomTable.setStyleClass(MAIN_STYLECLASS);
    bottomTable.add(help, 1, 1);
    bottomTable.setAlignment(2, 1, Table.HORIZONTAL_ALIGN_RIGHT);
    bottomTable.add(start, 2, 1);
    bottomTable.add(Text.getNonBrakingSpace(), 2, 1);
    bottomTable.add(close, 2, 1);

    mainTable.setVerticalAlignment(1, 1, Table.VERTICAL_ALIGN_TOP);
    mainTable.setVerticalAlignment(1, 3, Table.VERTICAL_ALIGN_TOP);
    mainTable.add(topTable, 1, 1);
    mainTable.add(bottomTable, 1, 3);

    add(form, iwc);
  }
  private void addInfo(IWContext iwc) {
    Form form = new Form();
    form.maintainParameter(PARAMETER_GROUP_ID);

    Table mainTable = new Table();
    mainTable.setWidth(660);
    mainTable.setHeight(200);
    mainTable.setCellpadding(0);
    mainTable.setCellspacing(0);
    form.add(mainTable);

    Table topTable = new Table(1, 1);
    topTable.setStyleClass(MAIN_STYLECLASS);
    topTable.setWidth(Table.HUNDRED_PERCENT);
    topTable.setHeight(160);

    topTable.add(
        this.iwrb.getLocalizedString(
            UPDATE_RUNNING,
            "The update process is now running in the background. You cannot start another one while this one is running."),
        1,
        1);

    CloseButton close =
        new CloseButton(
            this.iwrb.getLocalizedImageButton("updateclubdivisiontemplate.close", "Close"));
    Help help = getHelp(HELP_TEXT_KEY);

    Table bottomTable = new Table();
    bottomTable.setCellpadding(0);
    bottomTable.setCellspacing(5);
    bottomTable.setWidth(Table.HUNDRED_PERCENT);
    bottomTable.setHeight(39);
    bottomTable.setStyleClass(MAIN_STYLECLASS);
    bottomTable.add(help, 1, 1);
    bottomTable.setAlignment(2, 1, Table.HORIZONTAL_ALIGN_RIGHT);
    bottomTable.add(close, 2, 1);

    mainTable.setVerticalAlignment(1, 1, Table.VERTICAL_ALIGN_TOP);
    mainTable.setVerticalAlignment(1, 3, Table.VERTICAL_ALIGN_TOP);
    mainTable.add(topTable, 1, 1);
    mainTable.add(bottomTable, 1, 3);

    add(form, iwc);
  }
  private void createField(
      Form form, String defaultLabel, String locKey, InterfaceObject io, IWResourceBundle iwrb) {

    Layer container = new Layer();
    form.add(container);

    Label label = new Label(iwrb.getLocalizedString(locKey, defaultLabel), io);
    container.add(label);
    container.add(io);
  }
  // public PresentationObject getVisitForm(IWContext iwc, User userVK) throws
  // java.rmi.RemoteException {
  public UIComponent getDoctorForm() {
    IWResourceBundle iwrb = this.getResourceBundle(_iwc);
    Form myForm = new Form();
    myForm.setName(prmForm);

    Table table = new Table(3, 3);
    table.setCellpadding(0);
    table.setCellspacing(0);
    table.setBorder(0);
    table.setVerticalAlignment(1, 1, Table.VERTICAL_ALIGN_TOP);
    table.setVerticalAlignment(3, 1, Table.VERTICAL_ALIGN_TOP);
    table.setVerticalAlignment(1, 2, Table.VERTICAL_ALIGN_BOTTOM);
    table.setVerticalAlignment(1, 3, Table.VERTICAL_ALIGN_BOTTOM);

    table.setWidth(400);
    table.setWidth(2, 1, 15);
    table.setWidth(1, 1, 73);

    myForm.add(table);

    Age age = null;
    String doctorInfo = null;

    if (user != null && user.getDateOfBirth() != null) age = new Age(user.getDateOfBirth());
    else if (user != null && user.getPersonalID() != null)
      age = new Age(PIDChecker.getInstance().getDateFromPersonalID(user.getPersonalID()));

    int userIDDr = 45;

    if (age != null && age.getYears() >= 70) {
      userIDDr = 46; // 45   41047
    }

    PresentationObject picture = null;
    User doctor = null;

    int userImageID = -1;
    try {
      doctor =
          ((UserBusiness) IBOLookup.getServiceInstance(_iwc, UserBusiness.class)).getUser(userIDDr);
    } catch (Exception fe) {
      log(fe);
    }

    if (doctor != null) userImageID = doctor.getSystemImageID();

    if (userImageID == -1) {
      Table fakeImageTable = new Table(1, 1);
      fakeImageTable.setAlignment(1, 1, Table.HORIZONTAL_ALIGN_CENTER);
      fakeImageTable.setBorder(4);
      fakeImageTable.setHeight(140);
      fakeImageTable.setWidth(100);
      String fakeImageColor = "#CCCCCC";
      Text photoText = new Text(iwrb.getLocalizedString("managerview.photo_text", "Photo"));
      photoText.setBold();
      photoText.setFontColor(fakeImageColor);
      photoText.setFontSize(Text.FONT_SIZE_12_STYLE_TAG);
      fakeImageTable.add(photoText, 1, 1);
      fakeImageTable.setBorderColor(fakeImageColor);
      picture = fakeImageTable;
    } else {
      Image image = new Image();
      image.setImageID(userImageID);
      image.setWidth(73);

      picture = image;
    }
    table.add(picture, 1, 1);

    if (age != null && age.getYears() >= 70) {
      doctorInfo =
          "<b>Dr. Inga Pren</b><br>Allmänläkare<br>Telefon:<br>018-987624<br>Telefontid: Mån-ons, kl 08:30-10.00<br>Webbsida: <a href='http://www.flogsta.se' target='_new'>www.flogsta.se</a>";
    } else {
      doctorInfo =
          "<b>Dr. Magne Syhl</b><br>Allmänläkare<br>Telefon:<br>018-987654<br>Telefontid: Mån-ons, kl 08-10.00<br>Webbsida: <a href='http://www.gimovc.se' target='_new'>www.gimovc.se</a>";
    }

    table.add(doctorInfo, 3, 1);
    GenericButton message =
        getButton(new GenericButton("send_message", localize(prmSendMessage, "Send message")));
    if (_messagePage != null) message.setPageToOpen(_messagePage);

    table.add(message, 3, 2);
    table.setHeight(3, 2, "25");

    GenericButton visitbooking =
        getButton(new GenericButton("visit", localize(prmVisitBooking, "Book an appointment")));
    if (_appointmentPage != null) visitbooking.setPageToOpen(_appointmentPage);

    SubmitButton smb = new SubmitButton();
    smb.setStyleClass("ehealth_InterfaceButton");
    smb.setValue("Skicka meddelande >");
    smb.setPageToOpen(132);

    table.add(visitbooking, 3, 3);

    return myForm;
  }
  public void main(IWContext iwc) throws Exception {
    parseAction(iwc);
    IWResourceBundle resourceBundle = getResourceBundle(iwc);

    // uploading
    Text uploadingText =
        new Text(
            resourceBundle.getLocalizedString(
                "query_uploader_upload_query_headline", "Upload Query"));
    uploadingText.setBold();
    add(uploadingText);
    Form form = new Form();
    addMaintainParametersToForm(form);
    Table table = new Table(2, 4);
    int row = 1;
    String queryInfo =
        resourceBundle.getLocalizedString("query_uploader_replace_query", "Replace query");
    table.add(queryInfo, 1, row);
    PresentationObject queryList = getDropDownOfQueriesForReplacing(resourceBundle, iwc);
    table.add(queryList, 2, row);
    row++;
    String defaultName =
        resourceBundle.getLocalizedString("query_uploader_default_queryname", "My query");
    TextInput textInput = new TextInput(KEY_QUERY_NAME, defaultName);
    Text info =
        new Text(resourceBundle.getLocalizedString("query_uploader_query_name", "set query name"));
    table.add(info, 1, row);
    table.add(textInput, 2, row);
    row++;
    table.add(getPrivatePublicRadioButtons(resourceBundle), 2, row);
    SimpleFileChooser uploader = new SimpleFileChooser(form, KEY_QUERY_FILE_ID);
    row++;
    table.add(uploader, 2, row);

    form.add(table);
    form.addParameter(KEY_QUERY_UPLOAD_IS_SUBMITTED, KEY_QUERY_UPLOAD_IS_SUBMITTED);
    add(form);

    // downloading
    add(Text.getBreak());
    Text downloadingText =
        new Text(
            resourceBundle.getLocalizedString(
                "query_uploader_download_query_headline", "Download Query"));
    downloadingText.setBold();
    add(downloadingText);
    Form downloadForm = new Form();
    row = 1;
    addMaintainParametersToForm(downloadForm);
    Table downloadTable = new Table(2, 3);
    PresentationObject downloadQueryList = getDropDownOfQueriesForDownloading(iwc);
    downloadTable.add(downloadQueryList, 1, row);
    downloadTable.add(getDownloadButton(resourceBundle), 2, row++);
    if (this.downloadUrl != null) {
      String downloadText =
          resourceBundle.getLocalizedString("query_uploader_download_query", "Download");
      downloadTable.add(new Link(downloadText, this.downloadUrl), 1, row++);
    }
    downloadTable.add(getGoBackButton(resourceBundle), 1, row);
    downloadForm.add(downloadTable);
    add(downloadForm);
  }
 private void addMaintainParametersToForm(Form form) {
   form.addParameter(ReportQueryBuilder.PARAM_LAYOUT_FOLDER_ID, this.layoutFolderId);
 }
  private void drawForm(IWContext iwc) {
    Form form = new Form();
    Table T = new Table();
    T.setCellpadding(2);
    T.setCellspacing(2);
    T.setBorder(0);
    form.add(T);

    Table table = new Table();
    //		table.setWidth(getWidth());
    table.setCellpadding(2);
    table.setCellspacing(2);
    table.setBorder(0);
    T.add(table, 1, 1);
    T.setWidth(2, 1, "20");

    T.setVerticalAlignment(1, 1, Table.VERTICAL_ALIGN_BOTTOM);
    T.setVerticalAlignment(3, 1, Table.VERTICAL_ALIGN_BOTTOM);

    int row = 1;

    String personalID =
        PersonalIDFormatter.format(
            user.getPersonalID(), iwc.getIWMainApplication().getSettings().getApplicationLocale());

    table.add(new Break(2), 1, row);
    table.add(getSmallHeader(localize(KEY_PID, DEFAULT_PID)), 1, row);

    if (user.getPersonalID() != null) {
      table.add(getSmallText(personalID), 2, row);
      table.setVerticalAlignment(1, row, Table.VERTICAL_ALIGN_BOTTOM);
      table.setVerticalAlignment(2, row, Table.VERTICAL_ALIGN_BOTTOM);
    }
    row++;
    table.add(getSmallHeader(localize(KEY_LOGIN, DEFAULT_LOGIN)), 1, row);
    LoginTable loginTable =
        LoginDBHandler.getUserLogin(((Integer) user.getPrimaryKey()).intValue());
    if (loginTable != null) {
      table.add(new HiddenInput(PARAMETER_OLD_LOGIN, loginTable.getUserLogin()), 2, row);
      table.add(getSmallText(loginTable.getUserLogin()), 2, row);
      table.setVerticalAlignment(1, row, Table.VERTICAL_ALIGN_BOTTOM);
      table.setVerticalAlignment(2, row, Table.VERTICAL_ALIGN_BOTTOM);
    }

    String valueCurrentPassword =
        iwc.getParameter(PARAMETER_CURRENT_PASSWORD) != null
            ? iwc.getParameter(PARAMETER_CURRENT_PASSWORD)
            : "";
    String valueNewPassword =
        iwc.getParameter(PARAMETER_NEW_PASSWORD) != null
            ? iwc.getParameter(PARAMETER_NEW_PASSWORD)
            : "";
    String valueNewPasswordRepeated =
        iwc.getParameter(PARAMETER_NEW_PASSWORD_REPEATED) != null
            ? iwc.getParameter(PARAMETER_NEW_PASSWORD_REPEATED)
            : "";

    // Text tLogin = getSmallHeader(localize(KEY_LOGIN, DEFAULT_LOGIN));
    Text tCurrentPassword =
        getSmallHeader(localize(KEY_CURRENT_PASSWORD, DEFAULT_CURRENT_PASSWORD));
    Text tNewPassword = getSmallHeader(localize(KEY_NEW_PASSWORD, DEFAULT_NEW_PASSWORD));
    Text tNewPasswordRepeated =
        getSmallHeader(localize(KEY_NEW_PASSWORD_REPEATED, DEFAULT_NEW_PASSWORD_REPEATED));

    PasswordInput tiCurrentPassword =
        (PasswordInput) getStyledInterface(new PasswordInput(PARAMETER_CURRENT_PASSWORD));
    if (valueCurrentPassword != null) {
      tiCurrentPassword.setValue(valueCurrentPassword);
    }
    PasswordInput tiNewPassword =
        (PasswordInput) getStyledInterface(new PasswordInput(PARAMETER_NEW_PASSWORD));
    if (valueNewPassword != null) {
      tiNewPassword.setValue(valueNewPassword);
    }
    PasswordInput tiNewPasswordRepeated =
        (PasswordInput) getStyledInterface(new PasswordInput(PARAMETER_NEW_PASSWORD_REPEATED));
    if (valueNewPasswordRepeated != null) {
      tiNewPasswordRepeated.setValue(valueNewPasswordRepeated);
    }

    SubmitButton sbUpdate =
        (SubmitButton)
            getStyledInterface(
                new SubmitButton(
                    localize(KEY_UPDATE, DEFAULT_UPDATE), PARAMETER_FORM_SUBMIT, "true"));

    row++;
    table.setHeight(row, 12);

    if (requirePasswordVerification) {
      row++;
      table.add(tCurrentPassword, 1, row);
      table.add(tiCurrentPassword, 2, row);
    }

    row++;
    table.add(tNewPassword, 1, row);
    table.add(tiNewPassword, 2, row);

    row++;
    table.add(tNewPasswordRepeated, 1, row);
    table.add(tiNewPasswordRepeated, 2, row);

    row++;
    table.setHeight(row, 12);

    row++;
    table.mergeCells(1, row, 2, row);
    table.setAlignment(1, row, Table.HORIZONTAL_ALIGN_RIGHT);

    table.add(Text.NON_BREAKING_SPACE, 1, row);
    table.add(sbUpdate, 1, row);

    add(form);
  }
  public UIComponent getOverviewForm() {
    Form myForm = new Form();
    myForm.setName(prmForm);
    Table T = new Table(3, 3);
    T.setCellpadding(0);
    T.setCellspacing(0);
    T.setBorder(0);
    T.setBorderColor("#000000");
    T.setVerticalAlignment(1, 1, Table.VERTICAL_ALIGN_TOP);
    T.setVerticalAlignment(3, 1, Table.VERTICAL_ALIGN_TOP);
    // T.setVerticalAlignment(1, 4, Table.VERTICAL_ALIGN_BOTTOM);
    // T.add(getNavigationTree(iwc), 1, 1);
    T.add(getNavigationTree(), 1, 1);
    //	T.add(getInfoLayer(), 2, 1);

    T.add(new Break(3), 3, 1);
    //		T.setHeight(1, 3, "130");
    // T.setHeight(1, 4, "90");
    T.setWidth(2, 1, "40");
    myForm.add(T);

    Page pVisit = this.getParentPage();
    if (pVisit != null) {
      Script S = pVisit.getAssociatedScript();
      // pVisit.setOnLoad("setRowColor(document.getElementById('inf1_1'));");

      S.addFunction("setRowColor(obj)", setRowColorScript());
      S.addFunction("showHideLayer(obj)", showHideLayerScript());
      Script timeScript = myForm.getAssociatedFormScript();
      if (timeScript == null) {
        timeScript = new Script();
        myForm.setAssociatedFormScript(timeScript);
      }
    }

    ArrayList texts1 = new ArrayList();
    ArrayList texts2 = new ArrayList();

    if (age != null && age.getYears() >= 70) {
      texts1.add(localize(keySet1Text1U1, "Texten"));
      texts1.add(localize(keySet1Text2U1, "Texten"));
      texts1.add(localize(keySet1Text3U1, "Texten"));
      texts1.add(localize(keySet1Text4U1, "Texten"));
      texts1.add(localize(keySet1Text5U1, "Texten"));

      texts2.add(localize(keySet2Text1U1, "Texten"));
      texts2.add(localize(keySet2Text2U1, "Texten"));
      texts2.add(localize(keySet2Text3U1, "Texten"));
      texts2.add(localize(keySet2Text4U1, "Texten"));
      texts2.add(localize(keySet2Text5U1, "Texten"));

    } else {
      texts1.add(localize(keySet1Text1U2, "Texten"));
      texts1.add(localize(keySet1Text2U2, "Texten"));
      texts1.add(localize(keySet1Text3U2, "Texten"));
      texts1.add(localize(keySet1Text4U2, "Texten"));
      texts1.add(localize(keySet1Text5U2, "Texten"));

      texts2.add(localize(keySet2Text1U2, "Texten"));
      texts2.add(localize(keySet2Text2U2, "Texten"));
      texts2.add(localize(keySet2Text3U2, "Texten"));
      texts2.add(localize(keySet2Text4U2, "Texten"));
      texts2.add(localize(keySet2Text5U2, "Texten"));
    }

    Layer layerOut = new Layer(Layer.DIV);
    layerOut.setVisibility("visible");
    layerOut.setOverflow("scroll");
    layerOut.setPositionType("absolute");
    layerOut.setWidth("280");
    layerOut.setHeight("170");
    layerOut.setMarkupAttribute("class", "ehealth_div");

    Layer layer = new Layer(Layer.DIV);
    layer.setVisibility("hidden");
    layer.setOverflow("hidden");
    layer.setPositionType("absolute");
    layer.setWidth("250");
    layer.setHeight("145");
    layer.setMarkupAttribute("class", "ehealth_div_no_border");

    int theRow = 1;
    int i = 1;

    Iterator iter1 = texts1.iterator();
    Iterator iter2 = texts2.iterator();

    while (iter1.hasNext()) {
      Layer layers = (Layer) layer.clone();
      layers.setID("info" + i + "_" + theRow);
      String text = (String) iter1.next();
      layers.add(text);
      layerOut.add(layers);

      theRow++;
    }
    i++;
    theRow = 1;
    while (iter2.hasNext()) {
      Layer layers = (Layer) layer.clone();
      layers.setID("info" + i + "_" + theRow);
      String text = (String) iter2.next();
      layers.add(text);
      layerOut.add(layers);

      theRow++;
    }

    T.add(layerOut, 3, 1);
    return myForm;
  }
  private void listExisting(IWContext iwc) throws FinderException, RemoteException {
    getApplicationBusiness(iwc).checkApplicationCategoryPriorityConstraint();
    Collection categories =
        getApplicationBusiness(iwc).getApplicationCategoryHome().findAllOrderedByPriority();

    Form form = new Form();
    form.setID("applicationCategoryCreator");
    form.setStyleClass("adminForm");

    Table2 table = new Table2();
    table.setWidth("100%");
    table.setCellpadding(0);
    table.setCellspacing(0);
    table.setStyleClass("ruler");
    table.setStyleClass("adminTable");
    form.add(table);

    TableRowGroup group = table.createHeaderRowGroup();
    TableRow row = group.createRow();
    TableCell2 cell = row.createHeaderCell();
    cell.setStyleClass("firstColumn");
    cell.setStyleClass("category");
    cell.add(new Text(this.iwrb.getLocalizedString("category", "Category")));

    cell = row.createHeaderCell();
    cell.setStyleClass("description");
    cell.add(new Text(this.iwrb.getLocalizedString("description", "Description")));

    cell = row.createHeaderCell();
    cell.setStyleClass("description");
    cell.add(new Text(this.iwrb.getLocalizedString("priority", "Priority")));

    cell = row.createHeaderCell();
    cell.setStyleClass("edit");
    cell.add(Text.getNonBrakingSpace());

    cell = row.createHeaderCell();
    cell.setStyleClass("remove");
    cell.setStyleClass("lastColumn");
    cell.add(Text.getNonBrakingSpace());

    group = table.createBodyRowGroup();
    int iRow = 1;

    Iterator iter = categories.iterator();
    while (iter.hasNext()) {
      ApplicationCategory cat = (ApplicationCategory) iter.next();
      row = table.createRow();

      Link edit =
          new Link(this.iwb.getImage("edit.png", this.iwrb.getLocalizedString("edit", "Edit")));
      edit.addParameter(PARAMETER_ACTION, ACTION_EDIT);
      edit.addParameter("id", cat.getPrimaryKey().toString());

      Link delete =
          new Link(
              this.iwb.getImage("delete.png", this.iwrb.getLocalizedString("remove", "Remove")));
      delete.addParameter(PARAMETER_ACTION, ACTION_DELETE);
      delete.addParameter("id", cat.getPrimaryKey().toString());

      if (iRow % 2 == 0) {
        row.setStyleClass("evenRow");
      } else {
        row.setStyleClass("oddRow");
      }

      cell = row.createCell();
      cell.setStyleClass("firstColumn");
      cell.setStyleClass("category");
      cell.add(new Text(cat.getName()));

      cell = row.createCell();
      cell.setStyleClass("description");
      if (cat.getDescription() != null) {
        String description = cat.getDescription();
        if (description.length() > 35) {
          description = description.substring(0, 35) + "...";
        }
        cell.add(new Text(description));
      } else {
        cell.add(new Text(Text.NON_BREAKING_SPACE));
      }

      cell = row.createCell();
      cell.setStyleClass("description");

      Link up =
          new Link(
              this.iwb.getImage("previous.png", this.iwrb.getLocalizedString("previous", "Up")));
      up.addParameter(PARAMETER_ACTION, ACTION_CATEGORY_UP);
      up.addParameter("id", cat.getPrimaryKey().toString());
      up.setStyleClass("flippedImageLink");
      cell.add(up);

      if (iRow <= 1) {

        up.setStyleAttribute("visibility", "hidden");
      }

      Link down =
          new Link(this.iwb.getImage("next.png", this.iwrb.getLocalizedString("next", "Down")));
      down.addParameter(PARAMETER_ACTION, ACTION_CATEGORY_DOWN);
      down.addParameter("id", cat.getPrimaryKey().toString());
      down.setStyleClass("flippedImageLink");
      cell.add(down);

      if (iRow >= categories.size()) {

        down.setStyleAttribute("visibility", "hidden");
      }

      cell = row.createCell();
      cell.setStyleClass("edit");
      cell.add(edit);

      cell = row.createCell();
      cell.setStyleClass("lastColumn");
      cell.setStyleClass("remove");
      cell.add(delete);

      iRow++;
    }

    Layer buttonLayer = new Layer(Layer.DIV);
    buttonLayer.setStyleClass("buttonLayer");
    form.add(buttonLayer);

    SubmitButton newLink =
        new SubmitButton(
            this.iwrb.getLocalizedString("new_category", "New Category"),
            PARAMETER_ACTION,
            ACTION_CREATE);
    buttonLayer.add(newLink);

    add(form);
  }
  /**
   * this method creates the form for creating new categories as well as editing the properties of
   * existing ones, plus it allows to see all the applications within this category and change their
   * display ordering
   *
   * @throws RemoteException
   */
  private void getCategoryCreationForm(
      IWContext iwc, ApplicationCategory cat, List<ICLocale> locales) throws RemoteException {
    if (cat != null) {
      getApplicationBusiness(iwc).checkApplicationPriorityConstraint(cat);
    }

    Form form = new Form();
    form.setID("applicationCategoryCreator");
    form.setStyleClass("adminForm");

    TextInput tName = new TextInput("name");
    TextArea tDesc = new TextArea("desc");

    if (cat != null) {
      tName.setContent(cat.getName());
      tDesc.setContent(cat.getDescription());
      form.addParameter("id", cat.getPrimaryKey().toString());
    }

    Layer layer = new Layer(Layer.DIV);
    layer.setStyleClass("formSection");
    form.add(layer);

    Layer formItem = new Layer(Layer.DIV);
    formItem.setStyleClass("formItem");
    Label label = new Label(this.iwrb.getLocalizedString("default_name", "Default name"), tName);
    formItem.add(label);
    formItem.add(tName);
    layer.add(formItem);

    formItem = new Layer(Layer.DIV);
    formItem.setStyleClass("formItem");
    label =
        new Label(
            this.iwrb.getLocalizedString("default_description", "Default description"), tDesc);
    formItem.add(label);
    formItem.add(tDesc);
    layer.add(formItem);

    for (Iterator<ICLocale> it = locales.iterator(); it.hasNext(); ) {
      ICLocale locale = it.next();
      Locale javaLocale = ICLocaleBusiness.getLocaleFromLocaleString(locale.getLocale());

      TextInput locInput = new TextInput(locale.getName() + "_locale");
      if (cat != null) {
        LocalizedText text = cat.getLocalizedText(locale.getLocaleID());
        locInput.setValue(text == null ? "" : text.getBody());
      }
      formItem = new Layer(Layer.DIV);
      formItem.setStyleClass("formItem");
      label = new Label(javaLocale.getDisplayLanguage(), locInput);
      formItem.add(label);
      formItem.add(locInput);
      layer.add(formItem);
    }

    List apps = null;
    if (cat != null) {
      try {
        apps =
            new ArrayList(
                getApplicationBusiness(iwc)
                    .getApplicationHome()
                    .findAllByCategoryOrderedByPriority(cat));
      } catch (FinderException f) {
        f.printStackTrace();
      }
    }

    if (apps != null && !apps.isEmpty()) {
      Table2 table = new Table2();
      table.setWidth("100%");
      table.setCellpadding(0);
      table.setCellspacing(0);
      table.setStyleClass("ruler");
      table.setStyleClass("adminTable");

      TableRowGroup group = table.createHeaderRowGroup();
      TableRow row = group.createRow();
      TableCell2 cell = row.createHeaderCell();
      cell.setStyleClass("firstColumn");
      cell.setStyleClass("application");
      cell.add(new Text(this.iwrb.getLocalizedString("application", "Application")));

      cell = row.createHeaderCell();
      cell.setStyleClass("description");
      cell.add(new Text(this.iwrb.getLocalizedString("priority", "Priority")));

      group = table.createBodyRowGroup();
      int iRow = 1;

      Iterator iter = apps.iterator();

      while (iter.hasNext()) {
        Application app = (Application) iter.next();

        row = table.createRow();

        if (iRow % 2 == 0) {
          row.setStyleClass("evenRow");
        } else {
          row.setStyleClass("oddRow");
        }

        cell = row.createCell();
        cell.setStyleClass("firstColumn");
        cell.setStyleClass("application");
        cell.add(new Text(app.getName()));

        cell = row.createCell();
        cell.setStyleClass("description");
        cell.setStyleClass("lastColumn");

        Link up =
            new Link(
                this.iwb.getImage("previous.png", this.iwrb.getLocalizedString("previous", "Up")));
        up.addParameter(PARAMETER_ACTION, ACTION_APP_UP);
        up.addParameter("app_id", app.getPrimaryKey().toString());
        up.addParameter("id", cat.getPrimaryKey().toString());
        up.setStyleClass("flippedImageLink");
        cell.add(up);

        if (iRow <= 1) {
          up.setStyleAttribute("visibility", "hidden");
        }

        Link down =
            new Link(this.iwb.getImage("next.png", this.iwrb.getLocalizedString("next", "Down")));
        down.addParameter(PARAMETER_ACTION, ACTION_APP_DOWN);
        down.addParameter("app_id", app.getPrimaryKey().toString());
        down.addParameter("id", cat.getPrimaryKey().toString());
        down.setStyleClass("flippedImageLink");
        cell.add(down);

        if (iRow >= apps.size()) {
          down.setStyleAttribute("visibility", "hidden");
        }

        iRow++;
      }

      Layer clearLayer = new Layer(Layer.DIV);
      clearLayer.setStyleClass("Clear");
      layer.add(clearLayer);

      form.add(table);
    }

    Layer buttonLayer = new Layer(Layer.DIV);
    buttonLayer.setStyleClass("buttonLayer");
    form.add(buttonLayer);

    SubmitButton back =
        new SubmitButton(this.iwrb.getLocalizedString("back", "Back"), PARAMETER_ACTION, "list");
    buttonLayer.add(back);

    SubmitButton save =
        new SubmitButton(this.iwrb.getLocalizedString("save", "Save"), PARAMETER_ACTION, "save");
    buttonLayer.add(save);

    add(form);
  }
 /* (non-Javadoc)
  * @see com.idega.presentation.ui.AbstractChooser#addParametersToForm(com.idega.presentation.ui.Form)
  */
 @Override
 protected void addParametersToForm(Form form) {
   if (this.submitForm) {
     form.addParameter(GroupChooserWindow.SUBMIT_PARENT_FORM_AFTER_CHANGE, "true");
   }
 }