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);
      }
    }
  @Override
  protected void doPost(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException {
    IWContext iwc = new IWContext(req, resp, req.getSession().getServletContext());
    if (iwc.isParameterSet(PARAMETER_WELL_PK)) {
      WebApplicationContext springContext =
          WebApplicationContextUtils.getWebApplicationContext(iwc.getServletContext());
      HephaestusService service = (HephaestusService) springContext.getBean("hephaestusService");

      Well well = service.getWell(Long.parseLong(iwc.getParameter(PARAMETER_WELL_PK)));
      List<LogHeader> headers = new ArrayList<LogHeader>();
      if (iwc.isParameterSet(PARAMETER_LOG_PK)) {
        String[] logPKs = iwc.getParameterValues(PARAMETER_LOG_PK);
        for (String pk : logPKs) {
          headers.add(service.getLogHeader(Long.parseLong(pk)));
        }
      }

      String measurementType = iwc.getParameter(PARAMETER_MEASUREMENT_TYPE);

      String imageURL = HephaestusUtil.getImageForWell(well, headers, measurementType);
      if (imageURL == null || imageURL.isEmpty()) {
        resp.setStatus(404);
        return;
      }

      resp.setStatus(200);
      resp.setContentType("image/png");

      File f = new File(imageURL);
      BufferedImage bi = ImageIO.read(f);
      OutputStream out = resp.getOutputStream();
      ImageIO.write(bi, "png", out);
      out.close();

    } else {
      resp.setStatus(404);
    }
  }
  private void catalog(IWContext iwc) throws RemoteException, FinderException {
    try {
      Link createLink = ProductEditorWindow.getEditorLink(-1);
      createLink.setImage(this.iCreate);
      //			createLink.addParameter(ProductEditorWindow.PRODUCT_CATALOG_OBJECT_INSTANCE_ID,
      // getICObjectInstanceID());
      createLink.setToolTip(
          this.iwrb.getLocalizedString(
              "trade.product_catalog.create_new_product", "Create new product"));
      Link detachLink =
          getCategoryLink(
              com.idega.block.trade.stockroom.data.ProductCategoryBMPBean.CATEGORY_TYPE_PRODUCT);
      detachLink.addParameter(CategoryWindow.prmObjInstId, getICObjectInstanceID());
      detachLink.setImage(this.iDetach);
      detachLink.setToolTip(
          this.iwrb.getLocalizedString(
              "trade.product_catalog.select_categories", "Select categories"));
      if (hasEditPermission()) {
        add(createLink);
        if (!this._useParameterCategory) {
          add(detachLink);
        }
      }
      this.layout = (AbstractProductCatalogLayout) this._layoutClass.newInstance();
      this.productCategories = new Vector();
      if (iwc.isParameterSet(CATEGORY_ID)) {
        String[] categoryIDs = iwc.getParameterValues(CATEGORY_ID);
        for (int a = 0; a < categoryIDs.length; a++) {
          this.productCategories.add(
              CategoryFinder.getInstance().getCategory(Integer.parseInt(categoryIDs[a])));
        }
      }
      if (this.productCategories.size() == 0 || !this._useParameterCategory) {
        try {
          this.productCategories = (List) getCategories();
          if (this.productCategories == null) {
            this.productCategories = new Vector();
          }
          Collections.sort(this.productCategories, new CategoryComparator(this));
        } catch (Exception e) {
          e.printStackTrace(System.err);
        }
      }

      Iterator iter = this.productCategories.iterator();
      while (iter.hasNext()) {
        createLink.addParameter(
            ProductEditorWindow.PARAMETER_CATEGORY_ID,
            ((ICCategory) iter.next()).getPrimaryKey().toString());
      }
      Table table = new Table();
      table.setCellpadding(0);
      table.setCellspacing(0);
      if (this._width != null) {
        table.setWidth(this._width);
      } else {
        table.setWidth(Table.HUNDRED_PERCENT);
      }
      PresentationObject po = this.layout.getCatalog(this, iwc, this.productCategories);
      table.add(po);
      /*      if (hasEditPermission()) {
        Link clearCache = new Link(iwrb.getLocalizedImageButton("clear_cache","Clear cache"));
          clearCache.addParameter(prmClrCache, "true");
        table.add(clearCache, 1, 2);
      }*/
      add(table);
    } catch (IllegalAccessException iae) {
      iae.printStackTrace(System.err);
    } catch (InstantiationException ie) {
      ie.printStackTrace(System.err);
    }
  }
  /** @see com.idega.presentation.PresentationObject#main(IWContext) */
  public void main(IWContext iwc) throws Exception {

    if (this.applicationGroup != null) {
      if (iwc.isParameterSet(USER_NAME_PARAM) && iwc.isParameterSet(PIN_PARAM)) {

        GroupApplicationBusiness biz = this.getGroupApplicationBusiness(iwc);

        String name = iwc.getParameter(USER_NAME_PARAM);
        String pin = iwc.getParameter(PIN_PARAM);
        String gender = iwc.getParameter(GENDER_PARAM);
        String email = iwc.getParameter(EMAIL_PARAM);
        String email2 = iwc.getParameter(EMAIL2_PARAM);
        String address = iwc.getParameter(ADDRESS_PARAM);
        String postal = iwc.getParameter(POSTAL_CODE_PARAM);
        String phone = iwc.getParameter(PHONE_PARAM);
        String phone2 = iwc.getParameter(PHONE2_PARAM);
        String comment = iwc.getParameter(COMMENT_PARAM);
        String adminComment = iwc.getParameter(ADMIN_COMMENT_PARAM);

        // KR hack
        if (adminComment == null) {
          String paymentType = iwc.getParameter("payment_type");
          String validMonth = iwc.getParameter("valid_month");
          String validYear = iwc.getParameter("valid_year");
          String nameOnCard = iwc.getParameter("name_on_credit_card");
          String pinOnCard = iwc.getParameter("credit_card_pin");
          String caretakerName = iwc.getParameter("caretaker_name");
          String caretakerPin = iwc.getParameter("caretaker_pin");
          String caretakerEmail = iwc.getParameter("caretaker_email");
          String cardNumber = iwc.getParameter("credit_card_number");
          boolean credit = false;

          if (paymentType != null) {
            if (paymentType.equals("C")) {
              credit = true;
            } else if (paymentType.equals("M")) {
              credit = false;
            }
          }

          if (credit && cardNumber != null) {
            adminComment =
                "Vill borga með kredit korti:\n"
                    + "Kortanúmer : "
                    + cardNumber
                    + "\n"
                    + "Gildir til : "
                    + validMonth
                    + "/"
                    + validYear
                    + "\n"
                    + "Korthafi : "
                    + nameOnCard
                    + "\n"
                    + "Kennitala korthafa : "
                    + pinOnCard
                    + "\n";
          } else if (!credit) {
            adminComment = "Vill staðgreiða\n";
          } else {
            adminComment = "Vill borga með korti en kortanúmerið vantar!\n";
          }

          if (caretakerName != null) {
            adminComment +=
                "Forráðamaður : "
                    + caretakerName
                    + "\n"
                    + "Kennitala forráðamanns : "
                    + caretakerPin
                    + "\n"
                    + "Netfang forráðamanns : "
                    + caretakerEmail
                    + "\n";
          }
        }

        String[] groups = iwc.getParameterValues(GROUPS_PARAM);
        if (groups == null) {
          System.err.println("GROUPS are Null!");
        }

        try {
          biz.createGroupApplication(
              this.applicationGroup,
              name,
              pin,
              gender,
              email,
              email2,
              address,
              postal,
              phone,
              phone2,
              comment,
              adminComment,
              groups);

        } catch (Exception e) {
          add("Error : Application creation failed!");
          e.printStackTrace();
        }

      } else {
        add("Error : No name and PIN!");
      }

    } else {
      add("The application group parameter has not been set");
    }
  }
    public void main(IWContext iwc) throws Exception {

      String save = iwc.getParameter("save");
      if (save != null) {
        String stringGroupId = iwc.getParameter(GroupGroupSetter.PARAMETER_GROUP_ID);
        int groupId = Integer.parseInt(stringGroupId);

        String[] related = iwc.getParameterValues(GroupGroupSetter.FIELDNAME_SELECTION_DOUBLE_BOX);

        GenericGroup group =
            ((com.idega.core.data.GenericGroupHome)
                    com.idega.data.IDOLookup.getHomeLegacy(GenericGroup.class))
                .findByPrimaryKeyLegacy(groupId);
        List currentRelationShip = group.getParentGroups();

        if (related != null) {

          if (currentRelationShip != null) {
            for (int i = 0; i < related.length; i++) {
              int id = Integer.parseInt(related[i]);
              GenericGroup gr =
                  ((com.idega.core.data.GenericGroupHome)
                          com.idega.data.IDOLookup.getHomeLegacy(GenericGroup.class))
                      .findByPrimaryKeyLegacy(id);
              if (!currentRelationShip.remove(gr)) {
                gr.addGroup(group);
              }
            }

            Iterator iter = currentRelationShip.iterator();
            while (iter.hasNext()) {
              Object item = iter.next();
              ((GenericGroup) item).removeGroup(group);
            }

          } else {
            for (int i = 0; i < related.length; i++) {
              ((com.idega.core.data.GenericGroupHome)
                      com.idega.data.IDOLookup.getHomeLegacy(GenericGroup.class))
                  .findByPrimaryKeyLegacy(Integer.parseInt(related[i]))
                  .addGroup(group);
            }
          }

        } else if (currentRelationShip != null) {
          Iterator iter = currentRelationShip.iterator();
          while (iter.hasNext()) {
            Object item = iter.next();
            ((GenericGroup) item).removeGroup(group);
          }
        }

        this.close();
        this.setParentToReload();
      } else {
        LineUpElements(iwc);
      }

      /*
            Enumeration enum = iwc.getParameterNames();
             System.err.println("--------------------------------------------------");
            if(enum != null){
              while (enum.hasMoreElements()) {
                Object item = enum.nextElement();
                if(item.equals("save")){
                  this.close();
                }
                String val[] = iwc.getParameterValues((String)item);
                System.err.print(item+" = ");
                if(val != null){
                  for (int i = 0; i < val.length; i++) {
                    System.err.print(val[i]+", ");
                  }
                }
                System.err.println();
              }
            }
      */
    }