Package org.apache.myfaces.tobago.internal.component

Examples of org.apache.myfaces.tobago.internal.component.AbstractUITree


  }

  @Override
  public void encodeEnd(final FacesContext facesContext, final UIComponent component) throws IOException {

    final AbstractUITree tree = (AbstractUITree) component;

    final String clientId = tree.getClientId(facesContext);
    final UIComponent root = ComponentUtils.findDescendant(tree, UITreeNode.class);
    if (root == null) {
      LOG.error("Can't find the tree root. This may occur while updating a tree from Tobago 1.0 to 1.5. "
          + "Please refer the documentation to see how to use tree tags.");
      return;
    }

    final TobagoResponseWriter writer = HtmlRendererUtils.getTobagoResponseWriter(facesContext);

    writer.startElement(HtmlElements.DIV, tree);
    writer.writeClassAttribute(Classes.create(tree));
    final Style style = new Style(facesContext, tree);
    writer.writeStyleAttribute(style);
    writer.writeIdAttribute(clientId);
    HtmlRendererUtils.writeDataAttributes(facesContext, writer, tree);
    writer.writeAttribute("data-tobago-scroll-panel", "true", true);

    final Selectable selectable = tree.getSelectableAsEnum();
    if (selectable.isSupportedByTree()) {
      writer.writeAttribute(DataAttributes.SELECTABLE, selectable.getValue(), false);
    }

    final SelectedState selectedState = tree.getSelectedState();
    final StringBuilder selectedValue = new StringBuilder(",");

    final ExpandedState expandedState = tree.getExpandedState();
    final StringBuilder expandedValue = new StringBuilder(",");

    final int last = tree.isRowsUnlimited() ? Integer.MAX_VALUE : tree.getFirst() + tree.getRows();
    for (int rowIndex = tree.getFirst(); rowIndex < last; rowIndex++) {
      tree.setRowIndex(rowIndex);
      if (!tree.isRowAvailable()) {
        break;
      }

      final TreePath path = tree.getPath();

      if (selectedState.isSelected(path)) {
        selectedValue.append(rowIndex);
        selectedValue.append(",");
      }

      if (tree.isFolder() && expandedState.isExpanded(path)) {
        expandedValue.append(rowIndex);
        expandedValue.append(",");
      }

      for (final UIComponent child : tree.getChildren()) {
        EncodeUtils.prepareRendererAll(facesContext, child);
        RenderUtils.encode(facesContext, child);
      }
    }
    tree.setRowIndex(-1);

    writer.startElement(HtmlElements.INPUT, tree);
    writer.writeAttribute(HtmlAttributes.TYPE, HtmlInputTypes.HIDDEN, false);
    final String selectedId = clientId + ComponentUtils.SUB_SEPARATOR + AbstractUITree.SUFFIX_SELECTED;
    writer.writeNameAttribute(selectedId);
View Full Code Here


    if (ComponentUtils.isOutputOnly(node)) {
      return;
    }

    final AbstractUITree tree = ComponentUtils.findAncestor(node, AbstractUITree.class);
    final String treeId = tree.getClientId(facesContext);
    final String nodeStateId = node.nodeStateId(facesContext);
    final Map<String, String> requestParameterMap = facesContext.getExternalContext().getRequestParameterMap();
    final String id = node.getClientId(facesContext);
    final boolean folder = node.isFolder();

    // expand state
    if (folder) {
      final boolean expanded = Boolean.parseBoolean(requestParameterMap.get(id + "-expanded"));
      if (node.isExpanded() != expanded) {
        new TreeExpansionEvent(node, node.isExpanded(), expanded).queue();
      }
    }

    // select
    if (tree.getSelectableAsEnum() != Selectable.NONE) { // selection
      final String selected = requestParameterMap.get(treeId + AbstractUITree.SELECT_STATE);
      final String searchString = ";" + node.getClientId(facesContext) + ";";
      final UITreeSelect treeSelect = ComponentUtils.findDescendant(node, UITreeSelect.class);
      if (treeSelect != null) {
        treeSelect.setSubmittedValue(selected.contains(searchString));
View Full Code Here

  private static final Logger LOG = LoggerFactory.getLogger(TreeRenderer.class);

  @Override
  public void decode(FacesContext facesContext, UIComponent component) {
    RenderUtils.decodeScrollPosition(facesContext, component);
    final AbstractUITree tree = (AbstractUITree) component;
    RenderUtils.decodedStateOfTreeData(facesContext, tree);
  }
View Full Code Here

  }

  @Override
  public void encodeEnd(FacesContext facesContext, UIComponent component) throws IOException {

    AbstractUITree tree = (AbstractUITree) component;

    String clientId = tree.getClientId(facesContext);
    UIComponent root = ComponentUtils.findDescendant(tree, UITreeNode.class);
    if (root == null) {
      LOG.error("Can't find the tree root. This may occur while updating a tree from Tobago 1.0 to 1.5. "
          + "Please refer the documentation to see how to use tree tags.");
      return;
    }

    TobagoResponseWriter writer = HtmlRendererUtils.getTobagoResponseWriter(facesContext);

    writer.startElement(HtmlElements.DIV, tree);
    writer.writeClassAttribute(Classes.create(tree));
    Style style = new Style(facesContext, tree);
    writer.writeStyleAttribute(style);
    writer.writeIdAttribute(clientId);
    HtmlRendererUtils.writeDataAttributes(facesContext, writer, tree);
    writer.writeAttribute("data-tobago-scroll-panel", "true", true);

    final Selectable selectable = tree.getSelectableAsEnum();
    if (selectable.isSupportedByTree()) {
      writer.writeAttribute(DataAttributes.SELECTABLE, selectable.getValue(), false);
    }

    final SelectedState selectedState = tree.getSelectedState();
    final StringBuilder selectedValue = new StringBuilder(",");

    final ExpandedState expandedState = tree.getExpandedState();
    final StringBuilder expandedValue = new StringBuilder(",");

    final int last = tree.isRowsUnlimited() ? Integer.MAX_VALUE : tree.getFirst() + tree.getRows();
    for (int rowIndex = tree.getFirst(); rowIndex < last; rowIndex++) {
      tree.setRowIndex(rowIndex);
      if (!tree.isRowAvailable()) {
        break;
      }

      final TreePath path = tree.getPath();

      if (selectedState.isSelected(path)) {
        selectedValue.append(rowIndex);
        selectedValue.append(",");
      }

      if (tree.isFolder() && expandedState.isExpanded(path)) {
        expandedValue.append(rowIndex);
        expandedValue.append(",");
      }

      for (UIComponent child : tree.getChildren()) {
        RenderUtils.prepareRendererAll(facesContext, child);
        RenderUtils.encode(facesContext, child);
      }
    }
    tree.setRowIndex(-1);

    writer.startElement(HtmlElements.INPUT, tree);
    writer.writeAttribute(HtmlAttributes.TYPE, HtmlInputTypes.HIDDEN, false);
    final String selectedId = clientId + ComponentUtils.SUB_SEPARATOR + AbstractUITree.SUFFIX_SELECTED;
    writer.writeNameAttribute(selectedId);
View Full Code Here

    if (ComponentUtils.isOutputOnly(node)) {
      return;
    }

    final AbstractUITree tree = ComponentUtils.findAncestor(node, AbstractUITree.class);
    final String treeId = tree.getClientId(facesContext);
    final String nodeStateId = node.nodeStateId(facesContext);
    final Map<String, String> requestParameterMap = facesContext.getExternalContext().getRequestParameterMap();
    final String id = node.getClientId(facesContext);
    final boolean folder = node.isFolder();

    // expand state
    if (folder) {
      boolean expanded = Boolean.parseBoolean((String) requestParameterMap.get(id + "-expanded"));
      if (node.isExpanded() != expanded) {
        new TreeExpansionEvent(node, node.isExpanded(), expanded).queue();
      }
    }

    // select
    if (tree.getSelectableAsEnum() != Selectable.NONE) { // selection
      String selected = (String) requestParameterMap.get(treeId + AbstractUITree.SELECT_STATE);
      String searchString = ";" + node.getClientId(facesContext) + ";";
      UITreeSelect treeSelect = ComponentUtils.findDescendant(node, UITreeSelect.class);
      if (treeSelect != null) {
        treeSelect.setSubmittedValue(StringUtils.contains(selected, searchString));
View Full Code Here

  private static final Logger LOG = LoggerFactory.getLogger(TreeRenderer.class);

  @Override
  public void decode(FacesContext facesContext, UIComponent component) {
    final AbstractUITree tree = (AbstractUITree) component;
    RenderUtils.decodedStateOfTreeData(facesContext, tree);
  }
View Full Code Here

  }

  @Override
  public void encodeEnd(FacesContext facesContext, UIComponent component) throws IOException {

    AbstractUITree tree = (AbstractUITree) component;

    String clientId = tree.getClientId(facesContext);
    UIComponent root = ComponentUtils.findDescendant(tree, UITreeNode.class);
    if (root == null) {
      LOG.error("Can't find the tree root. This may occur while updating a tree from Tobago 1.0 to 1.5. "
          + "Please refer the documentation to see how to use tree tags.");
      return;
    }

    TobagoResponseWriter writer = HtmlRendererUtils.getTobagoResponseWriter(facesContext);

    writer.startElement(HtmlElements.DIV, tree);
    writer.writeClassAttribute(Classes.create(tree));
    Style style = new Style(facesContext, tree);
    writer.writeStyleAttribute(style);
    writer.writeIdAttribute(clientId);

    writer.startElement(HtmlElements.INPUT, tree);
    writer.writeAttribute(HtmlAttributes.TYPE, HtmlInputTypes.HIDDEN, false);
    final String markedId = clientId + ComponentUtils.SUB_SEPARATOR + AbstractUITree.SUFFIX_MARKED;
    writer.writeNameAttribute(markedId);
    writer.writeIdAttribute(markedId);
    writer.writeClassAttribute(Classes.create(tree, AbstractUITree.SUFFIX_MARKED));
    writer.writeAttribute(HtmlAttributes.VALUE, "", false);
    writer.endElement(HtmlElements.INPUT);

    writer.startElement(HtmlElements.INPUT, tree);
    writer.writeAttribute(HtmlAttributes.TYPE, HtmlInputTypes.HIDDEN, false);
    final String expandedId = clientId + ComponentUtils.SUB_SEPARATOR + AbstractUIData.SUFFIX_EXPANDED;
    writer.writeNameAttribute(expandedId);
    writer.writeIdAttribute(expandedId);
    writer.writeClassAttribute(Classes.create(tree, AbstractUIData.SUFFIX_EXPANDED));
    writer.writeAttribute(HtmlAttributes.VALUE, ",", false);
    writer.endElement(HtmlElements.INPUT);

    final int last = tree.isRowsUnlimited() ? Integer.MAX_VALUE : tree.getFirst() + tree.getRows();
    for (int rowIndex = tree.getFirst(); rowIndex < last; rowIndex++) {
      tree.setRowIndex(rowIndex);
      if (!tree.isRowAvailable()) {
        break;
      }

      for (UIComponent child : tree.getChildren()) {
        RenderUtils.prepareRendererAll(facesContext, child);
        RenderUtils.encode(facesContext, child);
      }
    }
    tree.setRowIndex(-1);

    writer.endElement(HtmlElements.DIV);
  }
View Full Code Here

  }

  @Override
  public void encodeEnd(final FacesContext facesContext, final UIComponent component) throws IOException {

    final AbstractUITree tree = (AbstractUITree) component;
    final String clientId = tree.getClientId(facesContext);
    final TobagoResponseWriter writer = HtmlRendererUtils.getTobagoResponseWriter(facesContext);
    final Style style = new Style(facesContext, tree);
    final Style scrollDivStyle = new Style();

    writer.startElement(HtmlElements.DIV, tree);
    scrollDivStyle.setWidth(Measure.valueOf(6 * 160)); // todo: depth * width of a select
    scrollDivStyle.setHeight(style.getHeight() // todo: what, when there is no scrollbar?
        .subtract(15)); // todo: scrollbar height
    scrollDivStyle.setPosition(Position.ABSOLUTE);
    writer.writeStyleAttribute(scrollDivStyle);

    writer.startElement(HtmlElements.DIV, tree);
    writer.writeClassAttribute(Classes.create(tree));
    HtmlRendererUtils.writeDataAttributes(facesContext, writer, tree);
    writer.writeStyleAttribute(style);

    writer.startElement(HtmlElements.INPUT, tree);
    writer.writeAttribute(HtmlAttributes.TYPE, HtmlInputTypes.HIDDEN, false);
    writer.writeNameAttribute(clientId);
    writer.writeIdAttribute(clientId);
    writer.writeAttribute(HtmlAttributes.VALUE, ";", false);
    writer.endElement(HtmlElements.INPUT);

    writer.startElement(HtmlElements.INPUT, tree);
    writer.writeAttribute(HtmlAttributes.TYPE, HtmlInputTypes.HIDDEN, false);
    writer.writeNameAttribute(clientId + ComponentUtils.SUB_SEPARATOR + AbstractUITree.SUFFIX_MARKED);
    writer.writeIdAttribute(clientId + ComponentUtils.SUB_SEPARATOR + AbstractUITree.SUFFIX_MARKED);
    writer.writeAttribute(HtmlAttributes.VALUE, "", false);
    writer.endElement(HtmlElements.INPUT);

    if (tree.getSelectableAsEnum().isSupportedByTreeListbox()) {
      writer.startElement(HtmlElements.INPUT, tree);
      writer.writeAttribute(HtmlAttributes.TYPE, HtmlInputTypes.HIDDEN, false);
      writer.writeNameAttribute(clientId + AbstractUITree.SELECT_STATE);
      writer.writeIdAttribute(clientId + AbstractUITree.SELECT_STATE);
      writer.writeAttribute(HtmlAttributes.VALUE, ";", false);
      writer.writeAttribute(DataAttributes.SELECTION_MODE, tree.getSelectableAsEnum().name(), false);
      writer.endElement(HtmlElements.INPUT);
    }

    List<Integer> thisLevel = new ArrayList<Integer>();
    thisLevel.add(0);
    List<Integer> nextLevel = new ArrayList<Integer>();
    final int depth = tree.getTreeDataModel().getDepth() != -1
        ? tree.getTreeDataModel().getDepth()
        : 7// XXX not a fix value!!!
    // todo: use (TreeListbox ?)Layout
    final Measure currentWidth = tree.getCurrentWidth();
    final Measure width = currentWidth.divide(depth);
    for (int level = 0; level < depth; level++) {

      writer.startElement(HtmlElements.DIV, null);
      writer.writeClassAttribute(Classes.create(tree, "level"));
      final Style levelStyle = new Style();
      levelStyle.setLeft(width.multiply(level));
      levelStyle.setWidth(width);
      writer.writeStyleAttribute(levelStyle);
      // at the start of each div there is an empty and disabled select tag to show empty area.
      // this is not needed for the 1st level.
      if (level > 0) {
        writer.startElement(HtmlElements.SELECT, null);
        writer.writeAttribute(HtmlAttributes.DISABLED, true);
        writer.writeAttribute(HtmlAttributes.SIZE, 9); // must be > 1, but the real size comes from the layout
        writer.writeClassAttribute(Classes.create(tree, "select"));
        writer.endElement(HtmlElements.SELECT);
      }

      for(final Integer rowIndex : thisLevel) {
        encodeSelectBox(facesContext, tree, writer, rowIndex, nextLevel);
      }

      thisLevel.clear();
      final List<Integer> swap = thisLevel;
      thisLevel = nextLevel;
      nextLevel = swap;

      writer.endElement(HtmlElements.DIV);
    }

    writer.endElement(HtmlElements.DIV);
    writer.endElement(HtmlElements.DIV);

    tree.setRowIndex(-1);
  }
View Full Code Here

  private static final Logger LOG = LoggerFactory.getLogger(TreeRenderer.class);

  @Override
  public void decode(final FacesContext facesContext, final UIComponent component) {
    RenderUtils.decodeScrollPosition(facesContext, component);
    final AbstractUITree tree = (AbstractUITree) component;
    RenderUtils.decodedStateOfTreeData(facesContext, tree);
  }
View Full Code Here

  }

  @Override
  public void encodeEnd(final FacesContext facesContext, final UIComponent component) throws IOException {

    final AbstractUITree tree = (AbstractUITree) component;

    final String clientId = tree.getClientId(facesContext);
    final UIComponent root = ComponentUtils.findDescendant(tree, UITreeNode.class);
    if (root == null) {
      LOG.error("Can't find the tree root. This may occur while updating a tree from Tobago 1.0 to 1.5. "
          + "Please refer the documentation to see how to use tree tags.");
      return;
    }

    final TobagoResponseWriter writer = HtmlRendererUtils.getTobagoResponseWriter(facesContext);

    writer.startElement(HtmlElements.DIV, tree);
    writer.writeClassAttribute(Classes.create(tree));
    final Style style = new Style(facesContext, tree);
    writer.writeStyleAttribute(style);
    writer.writeIdAttribute(clientId);
    HtmlRendererUtils.writeDataAttributes(facesContext, writer, tree);
    writer.writeAttribute("data-tobago-scroll-panel", "true", true);

    final Selectable selectable = tree.getSelectableAsEnum();
    if (selectable.isSupportedByTree()) {
      writer.writeAttribute(DataAttributes.SELECTABLE, selectable.getValue(), false);
    }

    final SelectedState selectedState = tree.getSelectedState();
    final StringBuilder selectedValue = new StringBuilder(",");

    final ExpandedState expandedState = tree.getExpandedState();
    final StringBuilder expandedValue = new StringBuilder(",");

    final int last = tree.isRowsUnlimited() ? Integer.MAX_VALUE : tree.getFirst() + tree.getRows();
    for (int rowIndex = tree.getFirst(); rowIndex < last; rowIndex++) {
      tree.setRowIndex(rowIndex);
      if (!tree.isRowAvailable()) {
        break;
      }

      final TreePath path = tree.getPath();

      if (selectedState.isSelected(path)) {
        selectedValue.append(rowIndex);
        selectedValue.append(",");
      }

      if (tree.isFolder() && expandedState.isExpanded(path)) {
        expandedValue.append(rowIndex);
        expandedValue.append(",");
      }

      for (final UIComponent child : tree.getChildren()) {
        EncodeUtils.prepareRendererAll(facesContext, child);
        RenderUtils.encode(facesContext, child);
      }
    }
    tree.setRowIndex(-1);

    writer.startElement(HtmlElements.INPUT, tree);
    writer.writeAttribute(HtmlAttributes.TYPE, HtmlInputTypes.HIDDEN, false);
    final String selectedId = clientId + ComponentUtils.SUB_SEPARATOR + AbstractUITree.SUFFIX_SELECTED;
    writer.writeNameAttribute(selectedId);
View Full Code Here

TOP

Related Classes of org.apache.myfaces.tobago.internal.component.AbstractUITree

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.