Package org.richfaces.component

Examples of org.richfaces.component.UITree


  public void initializeLines(FacesContext context, UITreeNode treeNode)
  throws IOException {
    ComponentVariables variables = ComponentsVariableResolver.getVariables(
        this, treeNode);

    UITree tree = treeNode.getUITree();

    if (tree.isShowConnectingLines()) {
      if (((Boolean) (treeNode.getAttributes().get("isLastElement")))
          .booleanValue()) {
        variables.setVariable("line", "dr-tree-h-ic-line-last");
      } else {
        variables.setVariable("line", "dr-tree-h-ic-line-node");
      }
      if (tree.isExpanded()) {
        variables
        .setVariable("lineFirst", "dr-tree-h-ic-line-exp");
      } else {
        variables.setVariable("lineFirst",
        "dr-tree-h-ic-line-clp");
View Full Code Here


  public void initializeResources(FacesContext context, UITreeNode treeNode)
  throws IOException {
    ComponentVariables variables = ComponentsVariableResolver.getVariables(
        this, treeNode);

    UITree tree = treeNode.getUITree();
    String resource;
    String cssClass;
    resource = UITree.DEFAULT_HIGHLIGHTED_CSS_CLASS;
    resource += " rich-tree-node-highlighted";
    cssClass = tree.getHighlightedClass();
    if (cssClass != null) {
      resource += " " + cssClass;
    }
    cssClass = treeNode.getHighlightedClass();
    if (cssClass != null) {
      resource += " " + cssClass;
    }
    variables.setVariable("highlightedClass", resource);

    resource = UITree.DEFAULT_SELECTED_CSS_CLASS;
    resource += " rich-tree-node-selected";
    cssClass = tree.getSelectedClass();
    if (cssClass != null) {
      resource += " " + cssClass;
    }
    cssClass = treeNode.getSelectedClass();
    if (cssClass != null) {
      resource += " " + cssClass;
    }
    variables.setVariable("selectedClass", resource);


    resource = ViewUtil.getResourceURL(treeNode.getIcon());     
    if (resource == null) {
      resource = ViewUtil.getResourceURL(tree.getIcon());     
    }

    if (resource != null) {
      variables.setVariable("folder", resource);
    }

    resource = ViewUtil.getResourceURL(treeNode.getIconCollapsed());
    if (resource == null) {
      resource = ViewUtil.getResourceURL(tree.getIconCollapsed());
    }

    if (resource != null) {
      variables.setVariable("collapsed", resource);
    }

    resource = ViewUtil.getResourceURL(treeNode.getIconExpanded());
    if (resource == null) {
      resource = ViewUtil.getResourceURL(tree.getIconExpanded());
    }

    if (resource != null) {
      variables.setVariable("expanded", resource);
    }

    resource = ViewUtil.getResourceURL(treeNode.getIconLeaf());
    if (resource == null) {
      resource = ViewUtil.getResourceURL(tree.getIconLeaf());
    }

    if (resource != null) {
      variables.setVariable("leaf", resource);
    }
View Full Code Here

  protected void doDecode(FacesContext context, UIComponent component) {
    super.doDecode(context, component);

    UITreeNode node = (UITreeNode) component;
    UITree tree = node.getUITree();
    TreeRowKey key = (TreeRowKey) tree.getRowKey();
    Map requestMap = context.getExternalContext().getRequestParameterMap();
    String id = node.getClientId(context);
    TreeState componentState = (TreeState) tree.getComponentState();

    String nodeExpandedId = id + NODE_EXPANDED_INPUT_SUFFIX;
    Object nodeExpandedValue = requestMap.get(nodeExpandedId);
    if (nodeExpandedValue != null) {
      boolean nodeExpanded = Boolean.valueOf(nodeExpandedValue.toString()).booleanValue();
      if (tree.isExpanded() ^ nodeExpanded) {
        if (nodeExpanded) {
          new ExpandNodeCommandEvent(tree, key).queue();
        } else {
          new CollapseNodeCommandEvent(tree, key).queue();
        }

        if (Boolean.valueOf((String) requestMap.get(id + AJAX_EXPANDED_SUFFIX)).booleanValue()) {
          new AjaxExpandedEvent(node).queue();
          new AjaxExpandedEvent(tree).queue();
        } else {
          new NodeExpandedEvent(node).queue();
          new NodeExpandedEvent(tree).queue();
        }
      }
    }

    if (id.equals(tree.getAttributes()
        .get(UITree.SELECTION_INPUT_ATTRIBUTE))) {
      if (!componentState.isSelected(key)) {

        if (tree.getAttributes().get(
            UITree.SELECTED_NODE_PARAMETER_NAME) == null) {

          new NodeSelectedEvent(tree, componentState.getSelectedNode()).queue();
          new NodeSelectedEvent(node, componentState.getSelectedNode()).queue();
        } else {
          new AjaxSelectedEvent(tree, componentState.getSelectedNode()).queue();
          new AjaxSelectedEvent(node, componentState.getSelectedNode()).queue();
        }
      }

      tree.getAttributes().remove(UITree.SELECTION_INPUT_ATTRIBUTE);
    }
  }
View Full Code Here

    addParameterEncoder(DnDParametersEncoder.getInstance());
  }

  protected String getToggleScript(FacesContext context, UITreeNode treeNode, String to) {
    UITree tree = treeNode.getUITree();
    if ("handle".equals(to) && tree.isToggleOnClick() ||
        "mainRow".equals(to) && !tree.isToggleOnClick())
      return "";

    boolean showLines = tree.isShowConnectingLines();
    String id = treeNode.getClientId(context);

    if (UITree.SWITCH_AJAX.equals(tree.getSwitchType())) {
      UITreeNode nodeFacet = tree.getNodeFacet();
      JSFunction function = AjaxRendererUtils.buildAjaxFunction(nodeFacet,
          context);
      Map eventOptions = AjaxRendererUtils.buildEventOptions(context,
          nodeFacet);
      Map parameters = (Map) eventOptions.get("parameters");
      parameters.remove(id);

      parameters.put(id + NODE_EXPANDED_INPUT_SUFFIX, String.valueOf(!tree
          .isExpanded()));
      parameters.put(id + AJAX_EXPANDED_SUFFIX, Boolean.TRUE);
     
      function.addParameter(eventOptions);

      StringBuffer buffer = new StringBuffer();
      function.appendScript(buffer);
      buffer.append(";");
      return buffer.toString();
     
    } else if (UITree.SWITCH_SERVER.equals(tree.getSwitchType())) {
      String paramName = id + NODE_EXPANDED_INPUT_SUFFIX;
     
      StringBuffer result = new StringBuffer();
      result.append('{');
      result.append("var form = A4J.findForm(this);");
      result.append("var params = new Object();");
      result.append("params['");
      result.append(paramName);
      result.append("'] = ");
      result.append(!tree.isExpanded());
      result.append(';');
      result.append("Richfaces.jsFormSubmit('");
      result.append(id);
      result.append("', ");
      result.append("form.id, ");
View Full Code Here

  public void initializeLines(FacesContext context, UITreeNode treeNode)
  throws IOException {
    ComponentVariables variables = ComponentsVariableResolver.getVariables(
        this, treeNode);

    UITree tree = treeNode.getUITree();

    if (tree.isShowConnectingLines()) {
      if (((Boolean) (treeNode.getAttributes().get("isLastElement")))
          .booleanValue()) {
        variables.setVariable("line", "dr-tree-h-ic-line-last");
      } else {
        variables.setVariable("line", "dr-tree-h-ic-line-node");
      }
      if (tree.isExpanded()) {
        variables
        .setVariable("lineFirst", "dr-tree-h-ic-line-exp");
      } else {
        variables.setVariable("lineFirst",
        "dr-tree-h-ic-line-clp");
View Full Code Here

  public void initializeResources(FacesContext context, UITreeNode treeNode)
  throws IOException {
    ComponentVariables variables = ComponentsVariableResolver.getVariables(
        this, treeNode);

    UITree tree = treeNode.getUITree();
    String resource;
    String cssClass;
    resource = UITree.DEFAULT_HIGHLIGHTED_CSS_CLASS;
    resource += " rich-tree-node-highlighted";
    cssClass = tree.getHighlightedClass();
    if (cssClass != null) {
      resource += " " + cssClass;
    }
    cssClass = treeNode.getHighlightedClass();
    if (cssClass != null) {
      resource += " " + cssClass;
    }
    variables.setVariable("highlightedClass", resource);

    resource = UITree.DEFAULT_SELECTED_CSS_CLASS;
    resource += " rich-tree-node-selected";
    cssClass = tree.getSelectedClass();
    if (cssClass != null) {
      resource += " " + cssClass;
    }
    cssClass = treeNode.getSelectedClass();
    if (cssClass != null) {
      resource += " " + cssClass;
    }
    variables.setVariable("selectedClass", resource);


    resource = ViewUtil.getResourceURL(treeNode.getIcon());     
    if (resource == null) {
      resource = ViewUtil.getResourceURL(tree.getIcon());     
    }

    if (resource != null) {
      variables.setVariable("folder", resource);
    }

    resource = ViewUtil.getResourceURL(treeNode.getIconCollapsed());
    if (resource == null) {
      resource = ViewUtil.getResourceURL(tree.getIconCollapsed());
    }

    if (resource != null) {
      variables.setVariable("collapsed", resource);
    }

    resource = ViewUtil.getResourceURL(treeNode.getIconExpanded());
    if (resource == null) {
      resource = ViewUtil.getResourceURL(tree.getIconExpanded());
    }

    if (resource != null) {
      variables.setVariable("expanded", resource);
    }

    resource = ViewUtil.getResourceURL(treeNode.getIconLeaf());
    if (resource == null) {
      resource = ViewUtil.getResourceURL(tree.getIconLeaf());
    }

    if (resource != null) {
      variables.setVariable("leaf", resource);
    }
View Full Code Here

  protected void doDecode(FacesContext context, UIComponent component) {
    super.doDecode(context, component);

    UITreeNode node = (UITreeNode) component;
    UITree tree = node.getUITree();
    TreeRowKey key = (TreeRowKey) tree.getRowKey();
    Map requestMap = context.getExternalContext().getRequestParameterMap();
    String id = node.getClientId(context);
    TreeState componentState = (TreeState) tree.getComponentState();

    String nodeExpandedId = id + NODE_EXPANDED_INPUT_SUFFIX;
    Object nodeExpandedValue = requestMap.get(nodeExpandedId);
    if (nodeExpandedValue != null) {
      boolean nodeExpanded = Boolean.valueOf(nodeExpandedValue.toString()).booleanValue();
      if (tree.isExpanded() ^ nodeExpanded) {
        if (nodeExpanded) {
          new ExpandNodeCommandEvent(tree, key).queue();
        } else {
          new CollapseNodeCommandEvent(tree, key).queue();
        }

        if (Boolean.valueOf((String) requestMap.get(id + AJAX_EXPANDED_SUFFIX)).booleanValue()) {
          new AjaxExpandedEvent(node).queue();
          new AjaxExpandedEvent(tree).queue();
        } else {
          new NodeExpandedEvent(node).queue();
          new NodeExpandedEvent(tree).queue();
        }
      }
    }

    if (id.equals(tree.getAttributes()
        .get(UITree.SELECTION_INPUT_ATTRIBUTE))) {
      if (!componentState.isSelected(key)) {

        if (tree.getAttributes().get(
            UITree.SELECTED_NODE_PARAMETER_NAME) == null) {

          new NodeSelectedEvent(tree, componentState.getSelectedNode()).queue();
          new NodeSelectedEvent(node, componentState.getSelectedNode()).queue();
        } else {
          new AjaxSelectedEvent(tree, componentState.getSelectedNode()).queue();
          new AjaxSelectedEvent(node, componentState.getSelectedNode()).queue();
        }
      }

      tree.getAttributes().remove(UITree.SELECTION_INPUT_ATTRIBUTE);
    }
  }
View Full Code Here

      String path, Set ids, Set renderedAreas) throws IOException {
    super.encodeAjaxChildren(context, component, path, ids, renderedAreas);

    try {
      if (component instanceof UITree) {
        UITree tree = (UITree) component;

        String id = path + tree.getId();

        tree.captureOrigValue();
        //Object rowKey = tree.getRowKey();

        boolean encodeScripts = false;

        tree.setRowKey(context, null);

        //we should add xmlns to AJAX response
        //we'll write neutral inner element and add xmlns there
        ResponseWriter responseWriter = context.getResponseWriter();
        responseWriter.startElement("div", tree);
        writeNamespace(context, component);

        List encodedAreaIds = new ArrayList();
       
        try {
          List<RowKeyHolder> keyHoldersList = getKeyHoldersList(
            tree.getAllAjaxKeys(),
            tree.getAllAjaxNodeKeys(),
            id);

          Collections.sort(keyHoldersList, new Comparator<RowKeyHolder>() {

            public int compare(RowKeyHolder o1, RowKeyHolder o2) {
              int d1 = o1.rowKey == null ? 0 : o1.rowKey.depth();
              int d2 = o2.rowKey == null ? 0 : o2.rowKey.depth();

              return d1 < d2 ? -1 : (d2 > d1 ? 1 : 0);
            }

          });

          List<RowKeyHolder> holders = new ArrayList<RowKeyHolder>();
          for (RowKeyHolder holder : keyHoldersList) {
            boolean isSubKey = false;

            for (RowKeyHolder rowKeyHolder : holders) {
              if (rowKeyHolder.rowKey == null ||
                  rowKeyHolder.rowKey.isSubKey(holder.rowKey)) {

                isSubKey = true;
                break;
              }
            }

            if (!isSubKey) {
              holders.add(holder);
            }
          }

          Iterator<RowKeyHolder> ajaxKeysItr = holders.iterator();
          while (ajaxKeysItr.hasNext()) {
            RowKeyHolder keyHolder = ajaxKeysItr.next();
            TreeRowKey key = keyHolder.getRowKey();

            if (key != null && key.depth() == 0) {
              key = null;
            }

            tree.setRowKey(context, key);

            if (key == null || tree.isRowAvailable()) {
              String treeClientId;
              if (key == null) {
                treeClientId = tree.getClientId(context);
              } else {
                treeClientId = tree.getNodeFacet().getClientId(context);
              }

              encodeScripts = true;
             
              //should be added before children id
              renderedAreas.add(treeClientId);

              if (keyHolder.isNodeKey()) {
                writeContent(context, tree, key, false);
              } else {
                writeContent(context, tree, key, true);
                String treeChildrenId = treeClientId + NamingContainer.SEPARATOR_CHAR + "childs";
                renderedAreas.add(treeChildrenId);
              }

              //add node to set of nodes refreshed by script
              encodedAreaIds.add(treeClientId);
            } else {
              String cid = tree.getClientId(context);
              String message = MessageFormat.format(
                  "Failed to re-render tree node: {0} due to model data unavailability! " +
                  "Maybe parent node should be re-rendered instead?",
                  new Object[] { cid });

              ExternalContext externalContext = context.getExternalContext();
              externalContext.log(message);
            }
          }
          //ajaxKeys.clear();
        } catch (Exception e) {
          throw new FacesException(e);
        } finally {
          try {
            tree.setRowKey(context, null);
            tree.restoreOrigValue();
          } catch (Exception e) {
            context.getExternalContext().log(e.getMessage(), e);
          }
        }

        if (encodeScripts) {
          writeScript(context, tree, encodedAreaIds, renderedAreas);
        }

        responseWriter.endElement("div");
        tree.clearRequestKeysSet();
      }
    } finally {
      try {
        ComponentsVariableResolver.removeVariables(this, component);
      } catch (Exception e) {
View Full Code Here

    }
 
  public void dropListener(DropEvent dropEvent) {
    // resolve drag source attributes
    UITreeNode srcNode = (dropEvent.getDraggableSource() instanceof UITreeNode) ? (UITreeNode) dropEvent.getDraggableSource() : null;
    UITree srcTree = srcNode != null ? srcNode.getUITree() : null;
    TreeRowKey dragNodeKey = (dropEvent.getDragValue() instanceof TreeRowKey) ? (TreeRowKey) dropEvent.getDragValue() : null;
    TreeNode draggedNode = dragNodeKey != null ? srcTree.getTreeNode(dragNodeKey) : null;

    // resolve drag destination attributes
    UITreeNode destNode = (dropEvent.getSource() instanceof UITreeNode) ? (UITreeNode) dropEvent.getSource() : null;
    UITree destTree = destNode != null ? destNode.getUITree() : null;
    TreeRowKey dropNodeKey = (dropEvent.getDropValue() instanceof TreeRowKey) ? (TreeRowKey) dropEvent.getDropValue() : null;
    TreeNode droppedInNode = dropNodeKey != null ? destTree.getTreeNode(dropNodeKey) : null;
   
    // Note: check if we dropped node on to itself or to item instead of folder here
    if (droppedInNode != null && (droppedInNode.equals(draggedNode) || droppedInNode.getParent().getParent() != null || draggedNode.getParent().getParent() == null)) {
        System.out.println("Warning: Can't drop on itself or to pic itself! Also can't move folders");
        return;
    }

    FacesContext context = FacesContext.getCurrentInstance();
   
    if (dropNodeKey != null) {
        // add destination node for rerender
        destTree.addRequestKey(dropNodeKey);
       
      Object state = null;
      if (dragNodeKey != null) { // Drag from this or other tree
          TreeNode parentNode = draggedNode.getParent();
          // 1. remove node from tree
          state = srcTree.removeNode(dragNodeKey);
          // 2. add parent for rerender
          Object rowKey = srcTree.getTreeNodeRowKey(parentNode);
          srcTree.addRequestKey(rowKey);       
      } else if (dropEvent.getDragValue() != null) { // Drag from some drag source
          draggedNode = new TreeNodeImpl<String>();
          draggedNode.setData(dropEvent.getDragValue().toString());
      }
     
      // generate new node id
      Object id = getNewId(destTree.getTreeNode(dropNodeKey));
      destTree.addNode(dropNodeKey, draggedNode, id, state)
    }
   
    AjaxContext ac = AjaxContext.getCurrentInstance();
    // Add destination tree to reRender
    try {
View Full Code Here

      String path, Set ids, Set renderedAreas) throws IOException {
    super.encodeAjaxChildren(context, component, path, ids, renderedAreas);

    try {
      if (component instanceof UITree) {
        UITree tree = (UITree) component;

        String id = path + tree.getId();

        tree.captureOrigValue();
        //Object rowKey = tree.getRowKey();

        boolean encodeScripts = false;

        tree.setRowKey(context, null);

        //we should add xmlns to AJAX response
        //we'll write neutral inner element and add xmlns there
        ResponseWriter responseWriter = context.getResponseWriter();
        responseWriter.startElement("div", tree);
        writeNamespace(context, component);

        List encodedAreaIds = new ArrayList();

        try {
          Set ajaxKeys = tree.getAllAjaxKeys();
          if (ajaxKeys != null) {
            List sortedKeys = new ArrayList(ajaxKeys.size());
            sortedKeys.addAll(ajaxKeys);
            Collections.sort(sortedKeys, treeRowKeyComparator);
            Iterator ajaxKeysItr = sortedKeys.iterator();
            TreeRowKey lastKey = null;
            boolean nullRoot = false;

            while (!nullRoot && ajaxKeysItr.hasNext()) {
              TreeRowKey key = (TreeRowKey) ajaxKeysItr.next();

              if (lastKey == null) {
                lastKey = key;
              } else {
                if (!lastKey.isSubKey(key)) {
                  lastKey = key;
                } else {
                  //skip nodes that's parent nodes have been rendered
                  continue;
                }
              }

              if (key == null || key.depth() == 0) {
                nullRoot = true;
                key = null;
              }

              tree.setRowKey(context, key);

              if (tree.isRowAvailable()) {
                String treeClientId;
                if (key == null) {
                  treeClientId = tree.getClientId(context);
                } else {
                  treeClientId = tree.getNodeFacet().getClientId(context);
                }

                String treeChildrenId = treeClientId + NamingContainer.SEPARATOR_CHAR + "childs";
               
                writeContent(context, tree, key);
                encodeScripts = true;
                renderedAreas.add(treeClientId);
                encodedAreaIds.add(treeClientId);

                renderedAreas.add(treeChildrenId);
                //encodedAreaIds.add(id+":childs");
              } else {
                String cid = tree.getClientId(context);
                String message = MessageFormat.format(
                    "Failed to re-render tree node: {0} due to model data unavailability! " +
                    "Maybe parent node should be re-rendered instead?",
                    new Object[] { cid });
               
                ExternalContext externalContext = context.getExternalContext();
                externalContext.log(message);
              }
            }
            //ajaxKeys.clear();
          }
        } catch (Exception e) {
          throw new FacesException(e);
        } finally {
          try {
            tree.setRowKey(context, null);
            tree.restoreOrigValue();
          } catch (Exception e) {
            context.getExternalContext().log(e.getMessage(), e);
          }
        }
        if (encodeScripts) {
          writeScript(context, tree, encodedAreaIds, renderedAreas);

          String inputId = encodeSelectionStateInput(context, tree);
          if (inputId != null) {
            renderedAreas.add(inputId);
          }
        }

        responseWriter.endElement("div");
        tree.clearRequestKeysSet();
      }
    } finally {
      try {
        ComponentsVariableResolver.removeVariables(this, component);
      } catch (Exception e) {
View Full Code Here

TOP

Related Classes of org.richfaces.component.UITree

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.