public void setOrder(Order order) {

    for (SalesOrderEntry entry : order.getFiles(SalesOrderEntry.class).toList()) {
      CartItem item = new CartItem();

      String productCode = entry.getProductCode();

      QueryParameters params = new QueryParameters();
      List l =
          SpringUtil.getRepositoryService()
              .executeQuery(
                  params
                      .setEntity(Product.class)
                      .addRestriction(Restrictions.eq("providedBy", order.getOrderedFrom()))
                      .addRestriction(Restrictions.eq("code", item.getCode())),
                  Util.getRemoteUser());

      if (l.size() > 0) {
        Product p = (Product) l.get(0);
        entry.setProduct(item, p);
        item.setProduct(p);
        item.setQty(entry.getQuantity());
      }
    }
    update();
  }
  public static void teminateOnDeath(Container source) {
    final Order order =
        (Order)
            SpringUtil.getRepositoryService()
                .getFile(source.getAttribute("path"), Util.getRemoteUser());
    BillingInformation bi = order.getBillingInformation();
    final String email = bi.getEmail();

    EXDynaformPanel panel = new EXDynaformPanel("deceased", "Termination on Death");
    panel.setStyle("z-index", "4000");
    source.getAncestorOfType(PopupContainer.class).addPopup(panel);

    panel.addField("Name of person deceased :", new EXInput("nameofperson"));
    panel.addButton(new EXButton("Send", "Send Mail"));
    panel.addButton(new EXButton("cancel", "Cancel"));
    panel
        .getDescendentByName("Send")
        .addEvent(
            new Event() {

              @Override
              public void Success(ClientProxy container, Map<String, String> request)
                  throws UIException {
                // TODO Auto-generated method stub

              }

              @Override
              public boolean ServerAction(Container container, Map<String, String> request)
                  throws UIException {

                String person =
                    container
                        .getAncestorOfType(EXDynaformPanel.class)
                        .getField("nameofperson")
                        .getValue()
                        .toString();

                sendMail(person, email);

                container.getAncestorOfType(EXDynaformPanel.class).remove();

                order.setStatus(21);
                BillingInformation b = order.getBillingInformation();
                b.setOtherProperty(
                    "dateTerminated", new SimpleDateFormat("dd/MM/yyyy").format(new Date()));
                order.save();
                return true;
              }

              @Override
              public void ClientAction(ClientProxy container) {
                container
                    .mask(container.getAncestorOfType(EXDynaformPanel.class))
                    .makeServerRequest(this);
              }
            },
            Event.CLICK);
  }
 public static void cancel(Container source) {
   final Order order =
       (Order)
           SpringUtil.getRepositoryService()
               .getFile(source.getAttribute("path"), Util.getRemoteUser());
   BillingInformation bi = order.getBillingInformation();
   bi.setOtherProperty("dateCancelled", new SimpleDateFormat("dd/MM/yyyy").format(new Date()));
   bi.save();
 }
  public static void useInvNumber(String invNumber) {
    Merchant merchant = MallUtil.getCurrentMerchant();
    String dir = merchant.getAbsolutePath() + "/invoiceCodes" + "/" + invNumber;
    try {
      Value val = (Value) SpringUtil.getRepositoryService().getFile(dir, Util.getRemoteUser());
      val.setStatus(40);
      val.save();
    } catch (FileNotFoundException fne) {

    }
  }
  public EXInviteFriends(String name) {
    super(name, "div");
    setAttribute(
        "style",
        "margin: auto; width: 600px; padding: 12px; border-radius: 5px 5px 5px 5px; background: -moz-linear-gradient(center top, rgb(36, 36, 39) 0%, rgb(21, 21, 22) 100% ) repeat scroll 0px 0px transparent; box-shadow: 5px 5px 5px black;");
    addChild(
        new EXXHTMLFragment(
            "sd",
            ResourceUtil.getDownloadURL(
                "classpath", "org/castafiore/facebook/ui/InviteInfo.xhtml")));

    EXGrid grid = new EXGrid("", 4, 1);
    String facebooklogin =
        SpringUtil.getBeanOfType(FacebookGraphAPIClient.class)
            .getAuthorizationUrl(
                "180567415418654",
                "ef8be0651a0d0aa94a51ec454b9a9165",
                "http://www.emallofmauritius.com/templates.html?facebook=true");
    Container facebook =
        new EXContainer("", "a")
            .setAttribute("href", facebooklogin)
            .setText(
                "<img src=http://icons.iconarchive.com/icons/yootheme/social-bookmark/72/social-facebook-box-blue-icon.png></img>");

    grid.getCell(0, 0).addChild(facebook);
    grid.getCell(1, 0)
        .setText(
            "<img src=http://icons.iconarchive.com/icons/yootheme/social-bookmark/72/social-google-box-blue-icon.png></img>");
    grid.getCell(2, 0)
        .setText(
            "<img src=http://icons.iconarchive.com/icons/yootheme/social-bookmark/72/social-linkedin-box-blue-icon.png></img>");
    grid.getCell(3, 0)
        .setText(
            "<img src=http://icons.iconarchive.com/icons/yootheme/social-bookmark/72/social-twitter-box-blue-icon.png></img>");
    // addChild(grid);

    addChild(
        new EXContainer("div", "div")
            .setAttribute(
                "style",
                "padding: 8px; background: none repeat scroll 0px 0px white; margin-top: 12px;")
            .addChild(grid));

    // facebook
    // linkedin
    // google+
    // twitter
    //
  }
  public static boolean createItem(ReconcilationDTO tr, CashBook cb) {

    String ref = tr.getRefNumber();
    String amount = tr.getAmount();
    try {
      if (StringUtil.isNotEmpty(ref) && StringUtil.isNotEmpty(amount)) {
        //			BigDecimal bAmount = new BigDecimal(amount);
        //			CashBookEntry entry = cb.createEntry(System.currentTimeMillis() + "" +
        // StringUtil.nextString(10));
        //			entry.setAccountCode( ref);
        //			entry.setSummary("Installment " + ref + " "+ tr.getDate());
        //			entry.setTitle(entry.getSummary());
        //			entry.setTotal(bAmount);
        //			entry.setDateOfTransaction(new SimpleDateFormat("dd MMM yyyy").parse(tr.getDate()));
        //			entry.save();
        String nm = new Date().getTime() + StringUtil.nextString(10);
        String code = StringUtil.nextString(10);
        String sql =
            "insert into WFS_FILE (clazz, dateCreated, lastModified, name, parent_id, summary, title, code, paymentMethod,total, accountCode, dateOfTransaction, DTYPE, absolutePath, size, status, commentable, dislikeit, likeit,ratable) values "
                + "('org.castafiore.accounting.CashBookEntry',now(),now(),'"
                + nm
                + "', "
                + "'/root/users/elieandsons/Applications/e-Shop/elieandsons/DefaultCashBook', "
                + "'Installment "
                + tr.getName()
                + "  "
                + tr.getDate()
                + "', 'Installment "
                + tr.getName()
                + "  "
                + tr.getDate()
                + "', '"
                + code
                + "', 'Standing Order', '"
                + tr.getAmount()
                + "', '"
                + tr.getName()
                + "',now() ,'CashBookEntry','/root/users/elieandsons/Applications/e-Shop/elieandsons/DefaultCashBook/"
                + nm
                + "',1,1,true,1,1, true);";

        SpringUtil.getBeanOfType(Dao.class).getSession().createSQLQuery(sql).executeUpdate();
        return true;
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
    return false;
  }
  @Override
  public boolean ServerAction(Container container, Map<String, String> request) throws UIException {
    String selectedFile =
        container.getAncestorOfType(EXFinderContainer.class).getAttribute("selectedFile");
    File f = SpringUtil.getRepositoryService().getFile(selectedFile, Util.getRemoteUser());
    File parent = f.getParent();
    f.remove();
    parent.save();

    Container c = container.getAncestorOfType(EXFinder.class).getDescendentByName(selectedFile);
    c.setDisplay(false);
    // SpringUtil.getRepositoryService().delete(SpringUtil.getRepositoryService().getFile(selectedFile, Util.getRemoteUser()), Util.getRemoteUser());

    return true;
  }
 public static void analyseImport() throws Exception {
   Workbook wb = new HSSFWorkbook(new FileInputStream("/usr/local/software/clients.xls"));
   Dao dao = SpringUtil.getBeanOfType(Dao.class);
   Session session = dao.getReadOnlySession();
   Sheet s = wb.getSheetAt(0);
   for (int i = 0; i < s.getLastRowNum(); i++) {
     String code = s.getRow(i).getCell(0).getStringCellValue();
     List res =
         session
             .createSQLQuery(
                 "select code from WFS_FILE where dtype='Order' and code='" + code + "'")
             .list();
     if (res.size() == 0) {
       writeLog(code + " Not created");
     } else if (res.size() > 1) {
       writeLog(code + " Duplicate");
     }
   }
 }
 public static String checkInvNumber(String invNumber) {
   Merchant merchant = MallUtil.getCurrentMerchant();
   String dir = merchant.getAbsolutePath() + "/invoiceCodes" + "/" + invNumber;
   try {
     Value val = (Value) SpringUtil.getRepositoryService().getFile(dir, Util.getRemoteUser());
     if (val.getStatus() == 40) {
       return "used";
     } else if (val.getStatus() == File.STATE_PUBLISHED) {
       return "ok";
     } else {
       return "notprinted";
     }
   } catch (FileNotFoundException fne) {
     Order order = getOrder(invNumber);
     if (order != null) {
       return "used";
     } else {
       return "ok";
     }
   }
 }
  private static void sendMail(String person, String email) {
    String content =
        IOUtil.getStreamContentAsString(
            Thread.currentThread()
                .getContextClassLoader()
                .getResourceAsStream("com/eliensons/reminders/terminate.xhtml"));

    content = content.replace("${person}", person);

    try {
      JavaMailSender sender = SpringUtil.getBeanOfType(JavaMailSender.class);
      MimeMessage message = sender.createMimeMessage();
      MimeMessageHelper helper = new MimeMessageHelper(message, true);
      helper.setSubject("Sincere sympath from Elie and Sons");
      helper.setFrom(MallUtil.getCurrentMerchant().getEmail());
      helper.setTo(email);
      helper.setText(content, true);
      sender.send(message);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
  public FileIterator<File> getFiles(FileFilter filter) {

    List<File> result = new ArrayList<File>();

    try {
      if (children.size() > 0) {
        for (File f : children) {
          if (f.getStatus() != File.STATE_DELETED
              && f.canRead()
              && (filter == null || filter.accept(f))) {
            result.add(f);
          }
        }
      }

    } catch (Exception li) {
      if (getAbsolutePath() != null) {
        QueryParameters params =
            new QueryParameters()
                .setEntity(FileImpl.class)
                .addRestriction(Restrictions.eq("parent.absolutePath", getAbsolutePath()));
        List<File> files =
            SpringUtil.getRepositoryService().executeQuery(params, Util.getRemoteUser());
        for (File f : files) {
          if (f.getStatus() != File.STATE_DELETED
              && f.canRead()
              && (filter == null || filter.accept(f))) {
            result.add(f);
          }
        }
      } else {
        throw new RepositoryException(
            new IllegalStateException("illegal state when getting children", li));
      }
    }

    return new SimpleFileIterator(result);
  }
  public static Map<String, String> getParams(Order order) {
    User customer = SpringUtil.getSecurityService().loadUserByUsername(order.getOrderedBy());
    BillingInformation bi = order.getBillingInformation();
    SalesOrderEntry entry = order.getFiles(SalesOrderEntry.class).get(0);
    Map<String, String> res = new HashMap<String, String>();
    res.put("cname", customer.toString());
    res.put("caddress", bi.getAddressLine1() + " " + bi.getAddressLine2());
    res.put("cphone", bi.getPhone() + "/" + bi.getMobile());
    res.put("email", bi.getEmail());
    res.put("fsNumber", order.getCode());
    res.put("date", new SimpleDateFormat("dd/MMM/yyyy").format(order.getDateOfTransaction()));
    Calendar cal = Calendar.getInstance();
    cal.setTime(order.getDateOfTransaction());
    cal.add(Calendar.MONTH, 6);
    Date effDate = cal.getTime();
    res.put("effDate", new SimpleDateFormat("dd/MMM/yyyy").format(effDate));

    res.put("salesman", order.getOwner());
    res.put("plan", entry.getTitle());
    res.put("jFee", StringUtil.toCurrency("MUR", order.getJoiningFee()));
    res.put("inst", StringUtil.toCurrency("MUR", order.getInstallment()));
    res.put("total", StringUtil.toCurrency("MUR", order.getTotal()));
    res.put("paymentMode", order.getPaymentMethod());

    cal.add(Calendar.MONTH, -5);
    res.put("firstInstallment", new SimpleDateFormat("dd/MMM/yyyy").format(cal.getTime()));

    Value val = bi.getFile("applicationForm", Value.class);
    String[] as =
        StringUtils.splitByWholeSeparator(
            val.getString(), "-:;:-"); // StringUtil.split(val.getString(), "-:;:-");
    Map<String, String> f = new HashMap<String, String>();
    for (String s : as) {

      String[] kv = StringUtil.split(s, ":");
      if (kv.length > 1 && !kv[1].equalsIgnoreCase("null")) {
        f.put(kv[0], kv[1]);
      } else {
        if (kv.length > 0) {
          f.put(kv[0], "");
        }
      }
    }

    for (int i = 1; i <= 6; i++) {
      if (f.containsKey("c" + i + "surname")) {
        res.put("member" + (i + 1), f.get("c" + i + "surname") + " " + f.get("c" + i + "name"));
        StringBuilder dob = new StringBuilder();
        for (int c = 1; c <= 11; c++) {
          String key = "c" + i + c;
          dob.append(f.get(key));
        }
        res.put("dob" + (i + 1), dob.toString());
        res.put("sn" + (i + 1), i + "");

      } else {
        res.put("member" + (i + 1), "");
        res.put("dob" + (i + 1), "");
        res.put("sn" + (i + 1), "");
      }
    }
    res.put("dob", f.get("pdob"));

    if (res.containsKey("pidnumber")) {
      res.put("dob", res.get("pidnumber") + " " + f.get("pdob"));
    }
    res.put("cname", f.get("cfullName") + " " + f.get("cSurname"));
    res.put("address", f.get("presi") + " " + f.get("presi2"));
    res.put("phone", f.get("ptelhome") + "/" + f.get("pcell"));
    res.put("email", f.get("email"));
    res.put("name", f.get("pfullName") + " " + f.get("pSurname"));
    if (f.containsKey("sSurname") || f.containsKey("sfullName")) {
      res.put("sname", f.get("sfullName") + " " + f.get("sSurname"));
    } else {
      res.put("sname", f.get(""));
    }

    if (f.containsKey("sdob")) {
      res.put("sdob", f.get("sdob"));
    } else {
      res.put("sdob", "");
    }
    if (f.containsKey("sidnumber")) {
      String dob = res.get("sdob");
      res.put("sdob", f.get("sidnumber").toString() + " " + dob);
    }

    return res;
  }
  @Override
  public Container getTabContentAt(TabPanel pane, int index) {

    if (index == 3) {
      Product p =
          (Product)
              SpringUtil.getRepositoryService().getFile(getAttribute("path"), Util.getRemoteUser());
      Container c = new EXContainer("", "div");

      List<Product> sameProvider =
          MallUtil.getMerchant(p.getProvidedBy())
              .getManager()
              .getMyProducts(Product.STATE_PUBLISHED);
      for (int i = 0; i < sameProvider.size(); i++) {

        Product pp = sameProvider.get(i);
        if (pp.getAbsolutePath().equalsIgnoreCase(getAttribute("path"))) continue;
        String url = pp.getImageUrl("");
        if (!StringUtil.isNotEmpty(url)) {
          url = "emimg/detail/img1.png";
        }
        Container cc =
            new EXContainer("sp" + i, "img")
                .setAttribute("src", "emimg/detail/img1.png")
                .setStyle("cursor", "pointer");
        c.addChild(cc.setAttribute("src", url).setAttribute("path", pp.getAbsolutePath()));
      }
      return c.setStyle("min-height", "250px");

    } else if (index == 4) {
      Product p =
          (Product)
              SpringUtil.getRepositoryService().getFile(getAttribute("path"), Util.getRemoteUser());
      Container c = new EXContainer("", "div");

      List<Product> sameProvider =
          MallUtil.getMerchant(p.getProvidedBy())
              .getManager()
              .getMyProducts(Product.STATE_PUBLISHED);
      for (int i = 0; i < sameProvider.size(); i++) {

        Product pp = sameProvider.get(i);
        if (pp.getAbsolutePath().equalsIgnoreCase(getAttribute("path"))) continue;
        String url = pp.getImageUrl("");
        if (!StringUtil.isNotEmpty(url)) {
          url = "emimg/detail/img1.png";
        }
        Container cc =
            new EXContainer("hap" + i, "img")
                .setAttribute("src", "emimg/detail/img1.png")
                .setStyle("cursor", "pointer");
        c.addChild(cc.setAttribute("src", url).setAttribute("path", pp.getAbsolutePath()));
      }
      return c.setStyle("min-height", "250px");
    } else if (index == 0) {
      if (StringUtil.isNotEmpty(getAttribute("path"))) {
        Product p =
            (Product)
                SpringUtil.getRepositoryService()
                    .getFile(getAttribute("path"), Util.getRemoteUser());
        return new EXContainer("summary", "div")
            .setText(p.getSummary())
            .setStyle("min-height", "250px");
      } else {
        return new EXContainer("sd", "div");
      }

    } else if (index == 2) {
      return new EXContainer("", "div")
          .addChild(new EXContainer("sas", "h5").setText("Coming soon"))
          .setStyle("min-height", "250px");
    } else if (index == 1) {
      Product p =
          (Product)
              SpringUtil.getRepositoryService().getFile(getAttribute("path"), Util.getRemoteUser());
      List<KeyValuePair> vnps = p.getCategories();
      EXFieldSet fs = new EXFieldSet("categories", "Specifications", false);
      for (KeyValuePair vk : vnps) fs.addField(vk.getKey(), new EXLabel("", vk.getValue()));

      return new EXContainer("", "div").addChild(fs).setStyle("min-height", "250px");
      // return new EXContainer("sas", "h3").setText("Coming soon");
    } else return null;
  }
  @Override
  public boolean ServerAction(Container container, Map<String, String> request) throws UIException {
    if (container.getName().equals("title")
        || container.getName().equals("image")
        || container.getName().equals("img")) {

      return false;
    }

    if (container.getName().startsWith("sp")) {
      String path = container.getAttribute("path");
      if (StringUtil.isNotEmpty(path) && !path.equalsIgnoreCase("null")) {
        Product p =
            (Product)
                SpringUtil.getRepositoryService()
                    .getFile(container.getAttribute("path"), Util.getRemoteUser());
        setProduct(p);
      }
      return true;
    }

    if (container.getName().startsWith("star")) {
      int index = Integer.parseInt(container.getName().replace("star", "")) + 1;
      Product p =
          (Product)
              SpringUtil.getRepositoryService().getFile(getAttribute("path"), Util.getRemoteUser());
      for (int i = 0; i < index; i++) {
        getChild("star" + i).setStyle("background", "green");
      }

      String u = Util.getRemoteUser();
      if (!StringUtil.isNotEmpty(u)) {
        u = "anonymous";
      }
      Directory votes = (Directory) p.getFile("votes");
      if (votes == null) {
        votes = p.createFile("votes", Directory.class);
      }

      String cur = votes.getProperty(u);

      if (cur == null) {
        cur = "0";
      }
      try {
        Integer.parseInt(cur);

      } catch (Exception e) {
        cur = "0";
      }

      votes.setProperty(u, (Integer.parseInt(cur) + index) + "");

      p.save();
      return true;
    }

    if (container.getName().startsWith("tn")) {
      for (Container c : getChildren()) {
        if (c.getName().startsWith("tn")) {
          c.setStyleClass("uibutton");
        }
      }
      container.setStyleClass("uibutton uibutton_active");
      getChild("image").setAttribute("src", container.getAttribute("src"));
      return true;
    }

    if (container.getName().equals("merchant")) {
      Merchant m = MallUtil.getMerchant(container.getAttribute("merchant"));
      // EXMerchantInfo info = new EXMerchantInfo("");
      EXMerchantCardV2 info = new EXMerchantCardV2("sd", m);
      EXPanel panel = new EXPanel("mm", m.getCompanyName());
      panel.setBody(info);
      // info.setMerchant(m);
      container
          .getAncestorOfType(PopupContainer.class)
          .addPopup(panel.setStyle("z-index", "3000").setStyle("width", "704px"));
      return true;
    }

    if (container.getName().equals("thumbUp")) {
      Product p =
          (Product)
              SpringUtil.getRepositoryService().getFile(getAttribute("path"), Util.getRemoteUser());
      p.thumbUp();
      p.save();
      return true;
    }

    if (container.getName().equals("thumbDown")) {
      Product p =
          (Product)
              SpringUtil.getRepositoryService().getFile(getAttribute("path"), Util.getRemoteUser());
      p.thumbDown();
      p.save();
      return true;
    }

    EXInput in = getDescendentOfType(EXInput.class);
    int value = Integer.parseInt(in.getValue().toString());
    if (container.getName().equals("addQty")) {
      in.setValue((value + 1) + "");
    } else if (container.getName().equals("delQty")) {
      if (value > 0) {
        in.setValue((value - 1) + "");
      }
    } else if (container.getName().equals("addToCart")) {
      if (container.getAncestorOfType(EXMall.class) != null) {
        Product p =
            (Product)
                SpringUtil.getRepositoryService()
                    .getFile(getAttribute("path"), Util.getRemoteUser());
        EXMiniCarts carts = getRoot().getDescendentOfType(EXMiniCarts.class);
        if (carts.getChildren().size() == 0) {
          carts.addChild(
              new EXContainer("totalll", "h4")
                  .addClass("ui-widget-header")
                  .setStyle("margin", "0")
                  .setStyle("width", "100%")
                  .setStyle("text-align", "center"));
        }
        EXMiniCart cart =
            getRoot().getDescendentOfType(EXMiniCarts.class).getMiniCart(p.getProvidedBy());
        if (!cart.getTemplateLocation().endsWith("EXMinicartNG.xhtml")) {
          cart.setTemplateLocation("templates/ng/EXMinicartNG.xhtml");
          cart.getParent().setStyle("float", "right").setStyle("margin-top", "12px");
          cart.addChild(new EXContainer("images", "div").setStyle("height", "20px"));
          cart.removeClass("cart-widget")
              .setStyle("margin", "0")
              .setStyle("padding", "0")
              .setStyle("margin-top", "0");
          cart.addChild(
              new EXContainer("checkout", "a")
                  .addEvent(new CartDetailEvent(), Event.CLICK)
                  .setAttribute("href", "#")
                  .setText("<img src=\"blueprint/images/checkout.png\"></img>"));
        }
        CartItem item = cart.getItem(p.getAbsolutePath());
        if (item == null) {
          cart.getChild("images")
              .addChild(
                  new EXContainer("img", "img")
                      .setStyle("cursor", "pointer")
                      .setAttribute("path", p.getAbsolutePath())
                      .addEvent(this, CLICK)
                      .setStyle("margin", "4px 4px 0px 4px")
                      .setStyle("width", "30px")
                      .setStyle("height", "30px")
                      .setAttribute("src", p.getImageUrl("")));
        }
        CartItem citem = cart.addToCart(p, value, container);
      } else {
        Product p =
            (Product)
                SpringUtil.getRepositoryService()
                    .getFile(getAttribute("path"), Util.getRemoteUser());
        getRoot().getDescendentOfType(EXMiniCart.class).addToCart(p, 1, container);
      }
    } else {
      Product p =
          (Product)
              SpringUtil.getRepositoryService().getFile(getAttribute("path"), Util.getRemoteUser());
      try {
        MallUtil.getCurrentUser().addToFavorite(p.getAbsolutePath());
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
    return true;
  }
  public static void partlyTerminate(Container source) {
    final Order order =
        (Order)
            SpringUtil.getRepositoryService()
                .getFile(source.getAttribute("path"), Util.getRemoteUser());
    BillingInformation bi = order.getBillingInformation();
    final String email = bi.getEmail();

    EXDynaformPanel panel = new EXDynaformPanel("deceased", "Partly terminate on Death");
    panel.setStyle("z-index", "4000");
    source.getAncestorOfType(PopupContainer.class).addPopup(panel);
    Map<String, String> props = order.getBillingInformation().getOtherProperties();

    List<String> dict = new ArrayList<String>();
    for (int i = 1; i <= 6; i++) {
      // "c1surname","c1name"
      String key1 = "c" + i + "surname";
      String key2 = "c" + i + "name";

      if (StringUtil.isNotEmpty(props.get(key1)) || StringUtil.isNotEmpty(props.get(key2))) {
        String val =
            (StringUtil.isNotEmpty(props.get(key1)) ? props.get(key1) + " " : "")
                + (StringUtil.isNotEmpty(props.get(key2)) ? props.get(key2) : "");
        dict.add(val);
      }
    }

    panel.addField("Name of person deceased :", new EXAutoComplete("nameofperson", "", dict));
    panel.addButton(new EXButton("Send", "Send Mail"));
    panel.addButton(new EXButton("cancel", "Cancel"));
    panel
        .getDescendentByName("Send")
        .addEvent(
            new Event() {

              @Override
              public void Success(ClientProxy container, Map<String, String> request)
                  throws UIException {
                // TODO Auto-generated method stub

              }

              @Override
              public boolean ServerAction(Container container, Map<String, String> request)
                  throws UIException {

                String person =
                    container
                        .getAncestorOfType(EXDynaformPanel.class)
                        .getField("nameofperson")
                        .getValue()
                        .toString();

                sendMail(person, email);

                container.getAncestorOfType(EXDynaformPanel.class).remove();

                order.setStatus(21);
                BillingInformation b = order.getBillingInformation();
                b.setOtherProperty(
                    "datePartlyTerminated", new SimpleDateFormat("dd/MM/yyyy").format(new Date()));
                order.save();
                return true;
              }

              @Override
              public void ClientAction(ClientProxy container) {
                container
                    .mask(container.getAncestorOfType(EXDynaformPanel.class))
                    .makeServerRequest(this);
              }
            },
            Event.CLICK);
  }
 @Override
 public boolean ServerAction(Container container, Map<String, String> request) throws UIException {
   String sessionId = container.getAttribute("sessionid");
   SpringUtil.getSecurityService().logout(sessionId);
   return true;
 }
 public static List<Order> loadOrders() {
   List result =
       SpringUtil.getRepositoryService()
           .executeQuery(new QueryParameters().setEntity(Order.class), Util.getRemoteUser());
   return result;
 }
  public EXRoleWidget(String name) throws Exception {
    super(name, 3, 0);
    addClass("ui-widget");
    addClass("ui-corner-all");
    setStyle("border-collapse", "collapse");
    setStyle("margin-left", "2px");
    setWidth(Dimension.parse("159px"));
    SecurityService service = SpringUtil.getBeanOfType(SecurityService.class);
    List<Group> groups = service.getGroups();
    // int index = 0;
    for (Group g : groups) {
      String gname = g.getName();
      int id = g.getId();
      EXRow row = addRow();
      row.setAttribute("grp-name", g.getName());
      EXCheckBox cb = new EXCheckBox("");
      cb.addEvent(
          new Event() {

            public void ClientAction(ClientProxy container) {
              container.makeServerRequest(this);
            }

            public boolean ServerAction(Container container, Map<String, String> request)
                throws UIException {

              EXIconButton ic =
                  container
                      .getAncestorOfType(PermissionButton.class)
                      .getDescendentOfType(EXIconButton.class);
              ic.setAttribute("isdirty", "true");
              String text = ic.getLabel();
              if (!text.endsWith("*")) {
                ic.setLabel(text + " *");
              }

              List<Container> checkBoxes = new ArrayList<Container>();
              ComponentUtil.getDescendentsOfType(
                  container.getParent().getParent().getDescendentOfType(EXGroupWidget.class),
                  checkBoxes,
                  EXCheckBox.class);

              for (Container c : checkBoxes) {
                ((EXCheckBox) c).setChecked(((EXCheckBox) container).isChecked());
              }
              return true;
            }

            public void Success(ClientProxy container, Map<String, String> request)
                throws UIException {
              // TODO Auto-generated method stub

            }
          },
          Event.CHANGE);
      cb.setAttribute("rId", id + "");
      row.addInCell(0, cb);

      Container uiName = ComponentUtil.getContainer("label", "span", gname, null);
      row.addInCell(1, uiName);

      Container span = ComponentUtil.getContainer("", "span", null, "ui-icon ui-icon-circle-plus");
      span.setAttribute("close", "true");
      span.addEvent(
          new Event() {

            public void ClientAction(ClientProxy container) {

              ClientProxy open =
                  container
                      .clone()
                      .setAttribute("close", "false")
                      .removeClass("ui-icon-circle-plus")
                      .addClass("ui-icon-circle-minus")
                      .getParent()
                      .getParent()
                      .getDescendentByName("childWidget")
                      .slideDown(200);
              ClientProxy close =
                  container
                      .clone()
                      .setAttribute("close", "true")
                      .removeClass("ui-icon-circle-minus")
                      .addClass("ui-icon-circle-plus")
                      .getParent()
                      .getParent()
                      .getDescendentByName("childWidget")
                      .slideUp(200);
              container.IF(container.getAttribute("close").equal("true"), open, close);
              // container.getParent().getParent().getDescendentByName("childWidget").slideDown(200);
              // container.makeServerRequest(this);

            }

            public boolean ServerAction(Container container, Map<String, String> request)
                throws UIException {
              // TODO Auto-generated method stub
              return false;
            }

            public void Success(ClientProxy container, Map<String, String> request)
                throws UIException {
              // TODO Auto-generated method stub

            }
          },
          Event.CLICK);

      row.addInCell(2, span);

      row.addClass("ui-widget-content");
      row.getChildByIndex(0).setAttribute("valign", "top");
      row.getChildByIndex(1).setAttribute("valign", "top");
      row.getChildByIndex(2).setAttribute("valign", "top");
      row.getChildByIndex(1).setAttribute("width", "125px");

      EXContainer gw = new EXContainer("childWidget", "div");
      gw.setStyle("padding-top", "3px");
      gw.setStyle("padding-left", "1px");
      gw.setDisplay(false);
      gw.addClass("roles-class");
      EXGroupWidget gWidget = new EXGroupWidget("");
      gWidget.setWidth(Dimension.parse("100%"));
      gw.addChild(gWidget);
      row.addInCell(1, gw);

      // index++;
    }
  }