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);
  }
  private Table2 getRaceParticipantListForEvent(
      IWContext iwc, List eventParticipants, RaceEvent raceEvent) throws RemoteException {
    Table2 table = new Table2();
    table.setStyleClass("raceParticipantTable");
    table.setStyleClass("ruler");
    table.setWidth("100%");
    table.setCellpadding(0);
    table.setCellspacing(0);

    TableRowGroup group = table.createHeaderRowGroup();
    TableRow row = group.createRow();
    TableCell2 cell = row.createHeaderCell();
    cell.setStyleClass("firstColumn");
    cell.setStyleClass("raceNumber");
    cell.add(
        new Text(getResourceBundle().getLocalizedString("race_participant_list.race_number", "#")));

    cell = row.createHeaderCell();
    cell.setStyleClass("name");
    cell.add(
        new Text(getResourceBundle().getLocalizedString("race_participant_list.name", "Name")));

    cell = row.createHeaderCell();
    cell.setStyleClass("raceVehicle");
    cell.add(
        new Text(
            getResourceBundle()
                .getLocalizedString("race_participant_list.race_vehicle", "Race vehicle")));

    cell = row.createHeaderCell();
    cell.setStyleClass("raceVehicleSubtype");
    cell.add(
        new Text(
            getResourceBundle()
                .getLocalizedString("race_participant_list.race_vehicle_subtype", "Subtype")));

    cell = row.createHeaderCell();
    cell.setStyleClass("raceEngineCC");
    cell.add(
        new Text(
            getResourceBundle()
                .getLocalizedString("race_participant_list.race_engine_CC", "Engine CC")));

    cell = row.createHeaderCell();
    cell.setStyleClass("raceEngine");
    cell.add(
        new Text(
            getResourceBundle().getLocalizedString("race_participant_list.race_engine", "Engine")));

    cell = row.createHeaderCell();
    cell.setStyleClass("raceTeam");
    cell.add(
        new Text(
            getResourceBundle().getLocalizedString("race_participant_list.race_team", "Team")));

    cell = row.createHeaderCell();
    cell.setStyleClass("raceSponsor");
    cell.add(
        new Text(
            getResourceBundle()
                .getLocalizedString("race_participant_list.race_sponsor", "Sponsor")));

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

    if (!ListUtil.isEmpty(eventParticipants)) {
      Iterator iter = eventParticipants.iterator();
      while (iter.hasNext()) {
        Participant participant = (Participant) iter.next();
        if (participant == null) {
          getLogger().warning("Participant is unknown for race event: " + raceEvent);
          continue;
        }

        row = group.createRow();

        User user = null;
        RaceUserSettings settings = null;
        try {
          user = participant.getUser();
          settings = this.getRaceBusiness(iwc).getRaceUserSettings(user);
        } catch (Exception e) {
          getLogger()
              .log(
                  Level.WARNING,
                  "Error getting settings for participant "
                      + participant
                      + ", user: "******"" : "(ID: " + user.getId() + ")")
                      + ". Race event: "
                      + raceEvent,
                  e);
        }
        if (user == null) {
          getLogger()
              .warning(
                  "User can not be found for participant "
                      + participant
                      + ", race event: "
                      + raceEvent);
        }
        if (settings == null) {
          getLogger()
              .warning(
                  "Settings can not be found for participant "
                      + participant
                      + ", race event: "
                      + raceEvent);
        }

        if (iRow == 1) {
          row.setStyleClass("firstRow");
        } else if (!iter.hasNext()) {
          row.setStyleClass("lastRow");
        }

        cell = row.createCell();
        cell.setStyleClass("firstColumn");
        cell.setStyleClass("raceNumber");
        cell.add(new Text(participant.getRaceNumber() != null ? participant.getRaceNumber() : ""));

        cell = row.createCell();
        cell.setStyleClass("name");
        cell.add(new Text(user != null ? user.getName() : ""));

        cell = row.createCell();
        cell.setStyleClass("raceVehicle");
        String raceVehicleString = "";
        if (settings != null && settings.getVehicleType() != null) {
          raceVehicleString =
              getResourceBundle()
                  .getLocalizedString(
                      settings.getVehicleType().getLocalizationKey(),
                      settings.getVehicleType().getLocalizationKey());
        }
        cell.add(new Text(raceVehicleString));

        cell = row.createCell();
        cell.setStyleClass("raceVehicleSubtype");
        String raceVehicleSubtypeString = "";
        if (settings != null && settings.getVehicleSubType() != null) {
          raceVehicleSubtypeString =
              getResourceBundle()
                  .getLocalizedString(
                      settings.getVehicleSubType().getLocalizationKey(),
                      settings.getVehicleSubType().getLocalizationKey());
        }
        cell.add(new Text(raceVehicleSubtypeString));

        cell = row.createCell();
        cell.setStyleClass("raceEngineCC");
        cell.add(
            new Text(
                settings == null
                    ? ""
                    : settings.getEngineCC() != null ? settings.getEngineCC() : ""));

        cell = row.createCell();
        cell.setStyleClass("raceEngine");
        cell.add(
            new Text(
                settings == null ? "" : settings.getEngine() != null ? settings.getEngine() : ""));

        cell = row.createCell();
        cell.setStyleClass("raceTeam");
        cell.add(
            new Text(settings == null ? "" : settings.getTeam() != null ? settings.getTeam() : ""));

        StringBuffer sponsorString = new StringBuffer("");
        if (settings != null && settings.getSponsor() != null) {
          if (settings.getSponsor().length() > 30) {
            sponsorString.append(settings.getSponsor().substring(0, 30));
          } else {
            sponsorString.append(settings.getSponsor());
          }
        }
        cell = row.createCell();
        cell.setStyleClass("raceSponsor");
        cell.add(new Text(sponsorString.toString()));

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

        iRow++;
      }
    } else {
      getLogger().warning("Participants not provided");
    }

    return table;
  }
  /**
   * 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);
  }