Ejemplo n.º 1
0
  private int getTotalChildNo(PrivateMessageDecoratedBean dmb, List beanList) {
    MessageForumsMessageManager messageManager =
        (MessageForumsMessageManager)
            ComponentManager.get(
                "org.sakaiproject.api.app.messageforums.MessageForumsMessageManager");
    List allChild = new ArrayList();
    messageManager.getChildMsgs(dmb.getMsg().getId(), allChild);
    int no = 0;

    for (int i = 0; i < beanList.size(); i++) {
      PrivateMessageDecoratedBean thisBean = (PrivateMessageDecoratedBean) beanList.get(i);
      for (int j = 0; j < allChild.size(); j++) {
        Message child = (Message) allChild.get(j);
        if (thisBean.getMsg().getId().equals(child.getId())) {
          no++;
          break;
        }
      }
    }
    return no;
  }
Ejemplo n.º 2
0
  public void encodeChildren(FacesContext context, UIComponent component) throws IOException {

    if ((context == null) || (component == null)) {
      throw new NullPointerException(
          Util.getExceptionMessageString(Util.NULL_PARAMETERS_ERROR_MESSAGE_ID));
    }
    if (log.isTraceEnabled()) {
      log.trace("Begin encoding children " + component.getId());
    }
    if (!component.isRendered()) {
      if (log.isTraceEnabled()) {
        log.trace(
            "No encoding necessary "
                + component.getId()
                + " since "
                + "rendered attribute is set to false ");
      }
      return;
    }
    UIData data = (UIData) component;

    ValueBinding msgsBinding = component.getValueBinding("value");
    List msgBeanList = (List) msgsBinding.getValue(context);

    // Set up variables we will need
    String columnClasses[] = getColumnClasses(data);
    int columnStyle = 0;
    int columnStyles = columnClasses.length;
    String rowClasses[] = getRowClasses(data);
    int rowStyles = rowClasses.length;
    ResponseWriter writer = context.getResponseWriter();
    Iterator kids = null;
    Iterator grandkids = null;

    // Iterate over the rows of data that are provided
    int processed = 0;
    int rowIndex = data.getFirst() - 1;
    int rows = data.getRows();
    int rowStyle = 0;

    writer.startElement("tbody", component);
    writer.writeText("\n", null);
    int hideDivNo = 0;
    while (true) {
      //			PrivateMessageDecoratedBean dmb = null;
      //			if(msgBeanList !=null && msgBeanList.size()>(rowIndex+1) &&
      // rowIndex>=-1)
      //			{
      //				dmb = (PrivateMessageDecoratedBean)msgBeanList.get(rowIndex+1);
      //			}
      //			boolean hasChildBoolean = false;
      //			if(dmb != null)
      //			{
      //				for(int i=0; i<msgBeanList.size(); i++)
      //				{
      //					PrivateMessageDecoratedBean tempDmb =
      // (PrivateMessageDecoratedBean)msgBeanList.get(i);
      //					if(tempDmb.getUiInReply() != null &&
      // tempDmb.getUiInReply().getId().equals(dmb.getMsg().getId()))
      //					{
      //						hasChildBoolean = true;
      //						break;
      //					}
      //				}
      //			}
      // Have we displayed the requested number of rows?
      if ((rows > 0) && (++processed > rows)) {
        break;
      }
      // Select the current row
      data.setRowIndex(++rowIndex);
      if (!data.isRowAvailable()) {
        break; // Scrolled past the last row
      }

      PrivateMessageDecoratedBean dmb = null;
      dmb = (PrivateMessageDecoratedBean) data.getRowData();
      boolean hasChildBoolean = false;
      if (dmb != null) {
        // if dmb has depth = 0, check for children
        if (dmb.getDepth() == 0) {
          // first, get the index of the dmb
          int index = -1;

          for (int i = 0; i < msgBeanList.size(); i++) {
            PrivateMessageDecoratedBean tempDmb = (PrivateMessageDecoratedBean) msgBeanList.get(i);
            if (dmb.getMsg().getId().equals(tempDmb.getMsg().getId())) {
              index = i;
              break;
            }
          }
          if (index < (msgBeanList.size() - 1) && index >= 0) {
            PrivateMessageDecoratedBean nextDmb =
                (PrivateMessageDecoratedBean) msgBeanList.get(index + 1);

            if (nextDmb.getDepth() > 0) {
              hasChildBoolean = true;
            }
          }
        }
      }

      if (dmb != null && dmb.getDepth() > 0) {
        writer.write(
            "<tr style=\"display:none\" id=\"_id_"
                + new Integer(hideDivNo).toString()
                + "__hide_division_"
                + "\">");
      } else {
        writer.write("<tr>");
      }

      if (rowStyles > 0) {
        writer.writeAttribute("class", rowClasses[rowStyle++], "rowClasses");
        if (rowStyle >= rowStyles) {
          rowStyle = 0;
        }
      }
      writer.writeText("\n", null);

      // Iterate over the child UIColumn components for each row
      columnStyle = 0;
      kids = getColumns(data);
      while (kids.hasNext()) {

        // Identify the next renderable column
        UIColumn column = (UIColumn) kids.next();

        // Render the beginning of this cell
        writer.startElement("td", column);
        if (columnStyles > 0) {
          writer.writeAttribute("class", columnClasses[columnStyle++], "columnClasses");
          if (columnStyle >= columnStyles) {
            columnStyle = 0;
          }
        }

        if (dmb != null && dmb.getDepth() > 0) {
          if (column.getId().endsWith("_msg_subject")) {
            StringBuilder indent = new StringBuilder();
            int indentInt = dmb.getDepth() * 4;
            for (int i = 0; i < indentInt; i++) {
              indent.append("&nbsp;");
            }
            writer.write(indent.toString());
          }
        } else {
          if (column.getId().endsWith("_msg_subject")) {
            if (hasChildBoolean && dmb.getDepth() == 0) {
              writer.write(
                  " <img src=\""
                      + BARIMG
                      + "\" style=\""
                      + CURSOR
                      + "\" id=\"_id_"
                      + Integer.valueOf(hideDivNo).toString()
                      + "__img_hide_division_\""
                      + " onclick=\"");
              int childNo = getTotalChildNo(dmb, msgBeanList);
              String hideTr = "";
              for (int i = 0; i < childNo; i++) {
                hideTr +=
                    "javascript:showHideDiv('_id_"
                        + (hideDivNo + i)
                        + "', '"
                        + RESOURCE_PATH
                        + "');";
              }
              writer.write(hideTr);
              writer.write("\" />");
            }
          }
        }
        // Render the contents of this cell by iterating over
        // the kids of our kids
        grandkids = getChildren(column);
        while (grandkids.hasNext()) {
          encodeRecursive(context, (UIComponent) grandkids.next());
        }

        // Render the ending of this cell
        writer.endElement("td");
        writer.writeText("\n", null);
      }

      // Render the ending of this row
      writer.endElement("tr");
      writer.writeText("\n", null);
      if (dmb != null && dmb.getDepth() > 0) {
        ////
        /*ValueBinding expandedBinding =
        	component.getValueBinding("expanded");
        String expanded = "";
        if(expandedBinding != null)
        	expanded = (String)expandedBinding.getValue(context);

        if(expanded.equalsIgnoreCase("true"))
        {*/
        writer.write("<script type=\"text/javascript\">");
        writer.write(" showHideDiv('_id_" + hideDivNo + "', '" + RESOURCE_PATH + "');");
        writer.write("</script>");
        //////				}

        hideDivNo++;
      }
    }
    writer.endElement("tbody");
    writer.writeText("\n", null);

    // Clean up after ourselves
    data.setRowIndex(-1);
    if (log.isTraceEnabled()) {
      log.trace("End encoding children " + component.getId());
    }
  }