| /* |
| * Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. |
| * |
| * This program and the accompanying materials are made available under the |
| * terms of the Eclipse Public License v. 2.0, which is available at |
| * http://www.eclipse.org/legal/epl-2.0. |
| * |
| * This Source Code may also be made available under the following Secondary |
| * Licenses when the conditions for such availability set forth in the |
| * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, |
| * version 2 with the GNU Classpath Exception, which is available at |
| * https://www.gnu.org/software/classpath/license.html. |
| * |
| * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 |
| */ |
| |
| /* |
| * $Id: GraphMenuNodeTag.java,v 1.3 2004/11/14 07:33:16 tcfujii Exp $ |
| */ |
| |
| // GraphMenuNodeTag.java |
| |
| package components.taglib; |
| |
| import components.model.Graph; |
| import components.model.Node; |
| import components.renderkit.Util; |
| |
| import jakarta.faces.context.FacesContext; |
| import jakarta.faces.webapp.UIComponentBodyTag; |
| import jakarta.servlet.jsp.JspException; |
| import jakarta.servlet.jsp.tagext.BodyTag; |
| import jakarta.servlet.jsp.tagext.TagSupport; |
| |
| /** |
| * <B>GraphMenuNodeTag</B> builds the graph as the nodes are processed. |
| * This tag creates a node with specified properties. Locates the parent of |
| * this node by using the node name from its immediate parent tag of the |
| * type GraphTreeNodeTag. If the parent could not be located, then the created |
| * node is assumed to be root. |
| */ |
| |
| public class GraphMenuNodeTag extends UIComponentBodyTag { |
| |
| // |
| // Protected Constants |
| // |
| |
| // |
| // Class Variables |
| // |
| |
| // |
| // Instance Variables |
| // |
| |
| // Attribute Instance Variables |
| |
| private String name = null; |
| private String icon = null; |
| private String label = null; |
| private String action = null; |
| private boolean expanded; |
| private boolean enabled = true; |
| |
| // Relationship Instance Variables |
| |
| // |
| // Constructors and Initializers |
| // |
| |
| public GraphMenuNodeTag() { |
| super(); |
| } |
| |
| // |
| // Class methods |
| // |
| |
| // |
| // General Methods |
| // |
| |
| /** |
| * Name of the node |
| */ |
| public void setName(String name) { |
| this.name = name; |
| } |
| |
| |
| public String getName() { |
| return this.name; |
| } |
| |
| |
| /** |
| * Should the node appear expanded by default |
| */ |
| public void setExpanded(boolean expanded) { |
| this.expanded = expanded; |
| } |
| |
| |
| /** |
| * Icon representing the node. |
| */ |
| public void setIcon(String icon) { |
| this.icon = icon; |
| } |
| |
| |
| /** |
| * Label for the node. |
| */ |
| public void setLabel(String label) { |
| this.label = label; |
| } |
| |
| |
| /** |
| * Should the node be enabled by default |
| */ |
| public void setEnabled(boolean enabled) { |
| this.enabled = enabled; |
| } |
| |
| |
| /** |
| * Link the node points to. |
| */ |
| public void setAction(String action) { |
| this.action = action; |
| } |
| |
| |
| public String getComponentType() { |
| return null; |
| } |
| |
| |
| public String getRendererType() { |
| return null; |
| } |
| |
| |
| // |
| // Methods from FacesBodyTag |
| // |
| public int doStartTag() throws JspException { |
| |
| FacesContext context = FacesContext.getCurrentInstance(); |
| Graph graph = (Graph) |
| ((Util.getValueBinding("#{sessionScope.graph_menu}").getValue( |
| context))); |
| // In the postback case, graph and the node exist already.So make sure |
| // it doesn't created again. |
| if (graph.findNodeByName(name) != null) { |
| return BodyTag.EVAL_BODY_BUFFERED; |
| } |
| Node node = new Node(name, label, action, icon, enabled, expanded); |
| |
| // get the immediate ancestor/parent of this node. |
| GraphMenuNodeTag parentNode = null; |
| try { |
| parentNode = (GraphMenuNodeTag) TagSupport.findAncestorWithClass( |
| this, |
| GraphMenuNodeTag.class); |
| } catch (Exception e) { |
| System.out.println( |
| "Exception while locating GraphMenuNodeTag.class"); |
| } |
| |
| if (parentNode == null) { |
| // then this should be root |
| graph.setRoot(node); |
| } else { |
| Node nodeToAdd = graph.findNodeByName(parentNode.getName()); |
| // this node should exist |
| if (nodeToAdd != null) { |
| nodeToAdd.addChild(node); |
| } |
| } |
| |
| return BodyTag.EVAL_BODY_BUFFERED; |
| } |
| |
| |
| public int doEndTag() throws JspException { |
| return (EVAL_PAGE); |
| } |
| |
| } |
| |
| |