Package org.apache.myfaces.tobago.model

Examples of org.apache.myfaces.tobago.model.TreeState


    String jsClientId = TreeOldRenderer.createJavascriptVariable(clientId);
    String jsParentClientId = TreeOldRenderer.createJavascriptVariable(
        parentClientId);
//  rootId = HtmlUtils.createJavascriptVariable(rootId);

    TreeState treeState = root.getState();
    if (treeState == null) {
      if (LOG.isDebugEnabled()) {
        LOG.debug("No treeState found. clientId=" + clientId);
      }
    } else {

      DefaultMutableTreeNode node = (DefaultMutableTreeNode) treeNode.getValue();

      ResponseWriter writer = facesContext.getResponseWriter();

      String debuging = null;

      writer.writeText("  var ", null);
      writer.writeText(jsClientId, null);
      writer.writeText(" = new TreeOldNode('", null);
      // label
      Object name = treeNode.getAttributes().get(TobagoConstants.ATTR_NAME);
      if (LOG.isDebugEnabled()) {
        debuging += name + " : ";
      }
      if (name != null) {
        writer.writeText(StringEscapeUtils.escapeJavaScript(name.toString()), null);
      } else {
        LOG.warn("name = null");
      }
      writer.writeText("',", null);

      // tip
      Object tip = treeNode.getAttributes().get(TobagoConstants.ATTR_TIP);
      if (tip != null) {
        tip = StringEscapeUtils.escapeJavaScript(tip.toString());
        writer.writeText("'", null);
        writer.writeText((String) tip, null);
        writer.writeText("','", null);
      } else {
        writer.writeText("null,'", null);
      }

      // id
      writer.writeText(clientId, null);
      writer.writeText("','", null);

      writer.writeText(root.getMode(), null);
      writer.writeText("',", null);

      // is folder
      writer.writeText(component.getChildCount() > 0, null);
      writer.writeText(",", null);
      writer.writeText(Boolean.toString(!root.isShowIcons()), null);
      writer.writeText(",", null);
      writer.writeText(Boolean.toString(!root.isShowJunctions()), null);
      writer.writeText(",", null);
      writer.writeText(Boolean.toString(!root.isShowRootJunction()), null);
      writer.writeText(",", null);
      writer.writeText(Boolean.toString(!root.isShowRoot()), null);
      writer.writeText(",'", null);
      writer.writeText(rootId, null);
      writer.writeText("',", null);
      String selectable = ComponentUtil.getStringAttribute(root,
          TobagoConstants.ATTR_SELECTABLE);
      if (selectable != null
          && (!(selectable.equals("multi") || selectable.equals("multiLeafOnly")
          || selectable.equals("single") || selectable.equals("singleLeafOnly")
          || selectable.equals("sibling") || selectable.equals("siblingLeafOnly")))) {
        selectable = null;
      }
      if (selectable != null) {
        writer.writeText("'", null);
        writer.writeText(selectable, null);
        writer.writeText("'", null);
      } else {
        writer.writeText("false", null);
      }
      writer.writeText(",", null);
      writer.writeText(Boolean.toString(ComponentUtil.getBooleanAttribute(root,
          TobagoConstants.ATTR_MUTABLE)), null);
      writer.writeText(",'", null);
      writer.writeText(
          ComponentUtil.findPage(component).getFormId(facesContext), null);
      writer.writeText("',", null);
      if (component.getChildCount() == 0
          || (selectable != null && !selectable.endsWith("LeafOnly"))) {
        boolean selected = treeState.isSelected(node);
        writer.writeText(Boolean.toString(selected), null);
        if (LOG.isDebugEnabled()) {
          debuging += selected ? "S" : "-";
        }
      } else {
        writer.writeText("false", null);
        if (LOG.isDebugEnabled()) {
          debuging += "-";
        }
        if (treeState.isSelected(node)) {
          LOG.warn("Ignore selected FolderNode in LeafOnly selection tree!");
        }
      }
      writer.writeText(",", null);
      writer.writeText(Boolean.toString(treeState.isMarked(node)), null);
      writer.writeText(",", null);
      // expanded
      boolean expanded = treeState.isExpanded(node);
      writer.writeText(Boolean.toString(expanded), null);
      if (LOG.isDebugEnabled()) {
        debuging += expanded ? "E" : "-";
      }
      writer.writeText(",", null);
View Full Code Here


    if (state != null) {
      return state;
    } else {
      if (FacesUtils.hasValueBindingOrValueExpression(this, Attributes.STATE)) {
        final FacesContext facesContext = FacesContext.getCurrentInstance();
        TreeState state = (TreeState)
            FacesUtils.getValueFromValueBindingOrValueExpression(facesContext, this, Attributes.STATE);
        if (state == null) {
          state = new TreeState(new ExpandedState(2), new MarkedState());
          FacesUtils.setValueOfBindingOrExpression(facesContext, state, this, Attributes.STATE);
        }
        return state;
      } else {
        state = new TreeState(new ExpandedState(2), new MarkedState());
        return state;
      }
    }
  }
View Full Code Here

    final ELContext elContext = FacesContext.getCurrentInstance().getELContext();
    final ValueExpression expression = getValueExpression(Attributes.STATE);

    if (expression != null) {
      TreeState state = (TreeState) expression.getValue(elContext);
      if (state == null) {
        state = new TreeState(new ExpandedState(2), new SelectedState());
        expression.setValue(elContext, state);
      }
      return state;
    }

    state = new TreeState(new ExpandedState(2), new SelectedState());
    return state;
  }
View Full Code Here

        new Node("Astronomy", "astro"));
    temp2.insert(new DefaultMutableTreeNode(new Node("Education", "edu")), 0);
    temp2.insert(new DefaultMutableTreeNode(new Node("Pictures", "pic")), 0);
    temp.insert(temp2, 2);
    tree.insert(temp, 2);
    treeState = new TreeState();
    treeState.addExpandState(tree);
    treeState.addSelection(temp2);
    treeState.setMarker(music);
    String[] values = {"none", "single", "singleLeafOnly", "multi", "multiLeafOnly"};
    selectionItems = getSelectItems(values, "demo");
View Full Code Here

    bestPractice.add(new DefaultMutableTreeNode(new Node("theme", "best-practice/theme")));
    bestPractice.add(new DefaultMutableTreeNode(new Node("transition", "best-practice/transition")));
    bestPractice.add(new DefaultMutableTreeNode(new Node("nonFacesResponse", "best-practice/non-faces-response")));
    tree.add(bestPractice);

    state = new TreeState();
    state.expand(tree, 2);
    state.setMarker(overview);
  }
View Full Code Here

    DefaultMutableTreeNode temp2 = new DefaultMutableTreeNode("Astronomy");
    temp2.insert(new DefaultMutableTreeNode("Education"), 0);
    temp2.insert(new DefaultMutableTreeNode("Pictures"), 0);
    temp.insert(temp2, 2);
    tree.insert(temp, 2);
    state = new TreeState();
    state.addExpandState(tree);
    state.addExpandState(temp);
    state.setMarker(music);
  }
View Full Code Here

        new Node("Astronomy", "astro"));
    temp2.insert(new DefaultMutableTreeNode(new Node("Education", "edu")), 0);
    temp2.insert(new DefaultMutableTreeNode(new Node("Pictures", "pic")), 0);
    temp.insert(temp2, 2);
    tree.insert(temp, 2);
    treeState = new TreeState();
    treeState.addExpandState(tree);
    treeState.addSelection(temp2);
    treeState.setMarker(music);
    String[] values = {"none", "single", "singleLeafOnly", "multi", "multiLeafOnly"};
    selectionItems = getSelectItems(values, "demo");
View Full Code Here

    reference.add(new DefaultMutableTreeNode(new Node("reference_tool", "reference/tool")));
    reference.add(new DefaultMutableTreeNode(new Node("reference_partial", "reference/partial")));
    reference.add(new DefaultMutableTreeNode(new Node("reference_upload", "reference/upload")));
    tree.add(reference);

    state = new TreeState();
    state.expand(tree, 1);
    state.expand(overview, 1);
    state.expand(bestPractice, 1);
    state.setMarker(overview);
  }
View Full Code Here

      LOG.error("No tree found!");
      return;
    }

    UITreeOld tree = (UITreeOld) component;
    TreeState treeState = tree.getState();
    DefaultMutableTreeNode marker = treeState.getMarker();
    String command = actionEvent.getComponent().getId();

    if (LOG.isDebugEnabled()) {
      LOG.debug("marker      " + marker);
      LOG.debug("lastMarker  " + treeState.getLastMarker());
      LOG.debug("root        " + tree.getValue());
      LOG.debug("command     " + command);
      LOG.debug("lastCommand " + treeState.getLastCommand());
    }
    if (marker != null) {
      boolean isRoot = tree.getValue().equals(marker);
      if (UITreeOld.COMMAND_NEW.equals(command)) {
        treeState.commandNew(create(facesContext));
      } else if (UITreeOld.COMMAND_DELETE.equals(command)) {
        if (!isRoot) {
          marker.removeFromParent();
        }
        treeState.setLastMarker(null);
        treeState.setLastCommand(null);
      } else if (UITreeOld.COMMAND_CUT.equals(command)) {
        if (!isRoot) {
          treeState.setLastMarker(marker);
          treeState.setLastCommand(command);
        }
      } else if (UITreeOld.COMMAND_COPY.equals(command)) {
        treeState.setLastMarker(marker);
        treeState.setLastCommand(command);
      } else if (UITreeOld.COMMAND_PASTE.equals(command)) {
        if (treeState.getLastMarker() != null) {
          if (UITreeOld.COMMAND_CUT.equals(treeState.getLastCommand())) {
            marker.insert(treeState.getLastMarker(), 0);
          } else if (UITreeOld.COMMAND_COPY.equals(treeState.getLastCommand())) {
            marker.insert(copy(treeState.getLastMarker()), 0);
          }
          treeState.setLastMarker(null);
          treeState.setLastCommand(null);
        }
      } else if (UITreeOld.COMMAND_MOVE_UP.equals(command)) {
        if (!isRoot) {
          MutableTreeNode node = marker;
          MutableTreeNode parent = (MutableTreeNode) node.getParent();
          int index = parent.getIndex(node);
          index = Math.max(index - 1, 0);
          parent.insert(node, index);
        }
        treeState.setLastMarker(null);
        treeState.setLastCommand(null);
      } else if (UITreeOld.COMMAND_MOVE_DOWN.equals(command)) {
        if (!isRoot) {
          MutableTreeNode node = marker;
          MutableTreeNode parent = (MutableTreeNode) node.getParent();
          int index = parent.getIndex(node);
          index = Math.min(index + 1, parent.getChildCount() - 1);
          parent.insert(node, index);
        }
        treeState.setLastMarker(null);
        treeState.setLastCommand(null);
      }
    }
  }
View Full Code Here

      return treeState;
    }
    ValueBinding valueBinding = getValueBinding(TobagoConstants.ATTR_STATE);
    if (valueBinding != null) {
      FacesContext facesContext = getFacesContext();
      TreeState state = (TreeState) valueBinding.getValue(facesContext);
      if (state == null) {
        state = new TreeState();
        valueBinding.setValue(facesContext, state);
      }
      return state;
    } else {
      treeState = new TreeState();
      return treeState;
    }
  }
View Full Code Here

TOP

Related Classes of org.apache.myfaces.tobago.model.TreeState

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.