| /* |
| * 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: GraphMenuTreeTag.java,v 1.3 2004/11/14 07:33:16 tcfujii Exp $ |
| */ |
| |
| package components.taglib; |
| |
| import components.components.GraphComponent; |
| import components.model.Graph; |
| |
| import jakarta.faces.component.UIComponent; |
| import jakarta.faces.context.FacesContext; |
| import jakarta.faces.el.MethodBinding; |
| import jakarta.faces.el.ValueBinding; |
| import jakarta.faces.event.ActionEvent; |
| import jakarta.faces.webapp.UIComponentBodyTag; |
| |
| |
| /** |
| * This class creates a <code>Graph</code> instance if there is no modelReference |
| * attribute specified on the component, represented by this tag and |
| * stores it against the attribute name "graph_tree" in session scope. |
| */ |
| public class GraphMenuTreeTag extends UIComponentBodyTag { |
| |
| protected String actionListener = null; |
| protected String styleClass = null; |
| protected String selectedClass = null; |
| protected String unselectedClass = null; |
| protected String value = null; |
| protected String immediate = null; |
| |
| |
| /** |
| * method reference to handle menu expansion and contraction events |
| */ |
| public void setActionListener(String actionListener) { |
| this.actionListener = actionListener; |
| } |
| |
| |
| /** |
| * Value Binding reference expression that points to a Graph in scoped |
| * namespace. |
| */ |
| public void setValue(String newValue) { |
| value = newValue; |
| } |
| |
| |
| /** |
| * The CSS style <code>class</code> to be applied to the text |
| * of selected nodes. This can be value or a value binding reference |
| * expression. |
| */ |
| public void setSelectedClass(String styleSelected) { |
| this.selectedClass = styleSelected; |
| } |
| |
| |
| /** |
| * The CSS style <code>class</code> to be applied to the text |
| * of unselected nodes. This can be value or a value binding reference |
| * expression. |
| */ |
| public void setUnselectedClass(String styleUnselected) { |
| this.unselectedClass = styleUnselected; |
| } |
| |
| |
| /** |
| * The CSS style <code>class</code> to be applied to the entire menu. |
| * This can be value or a value binding reference |
| * expression. |
| */ |
| public void setStyleClass(String style) { |
| this.styleClass = style; |
| } |
| |
| |
| /** |
| * A flag indicating that the default ActionListener should execute |
| * immediately (that is, during the Apply Request Values phase of the |
| * request processing lifecycle, instead of waiting for Invoke |
| * Application phase). The default value of this property must be false. |
| * This can be value or a value binding reference expression. |
| */ |
| public void setImmediate(java.lang.String immediate) { |
| this.immediate = immediate; |
| } |
| |
| |
| public String getComponentType() { |
| return ("Graph"); |
| } |
| |
| |
| public String getRendererType() { |
| return ("MenuTree"); |
| } |
| |
| |
| protected void setProperties(UIComponent component) { |
| super.setProperties(component); |
| FacesContext context = FacesContext.getCurrentInstance(); |
| ValueBinding vb = null; |
| |
| GraphComponent graphComponent = (GraphComponent) component; |
| |
| if (actionListener != null) { |
| if (isValueReference(actionListener)) { |
| Class args[] = {ActionEvent.class}; |
| MethodBinding mb = FacesContext.getCurrentInstance() |
| .getApplication() |
| .createMethodBinding(actionListener, args); |
| graphComponent.setActionListener(mb); |
| } else { |
| Object params [] = {actionListener}; |
| throw new jakarta.faces.FacesException(); |
| } |
| } |
| |
| // if the attributes are values set them directly on the component, if |
| // not set the ValueBinding reference so that the expressions can be |
| // evaluated lazily. |
| if (styleClass != null) { |
| if (isValueReference(styleClass)) { |
| vb = context.getApplication().createValueBinding(styleClass); |
| graphComponent.setValueBinding("styleClass", vb); |
| } else { |
| graphComponent.getAttributes().put("styleClass", styleClass); |
| } |
| } |
| if (selectedClass != null) { |
| if (isValueReference(selectedClass)) { |
| vb = |
| context.getApplication().createValueBinding(selectedClass); |
| graphComponent.setValueBinding("selectedClass", vb); |
| } else { |
| graphComponent.getAttributes().put("selectedClass", |
| selectedClass); |
| } |
| } |
| if (unselectedClass != null) { |
| if (isValueReference(unselectedClass)) { |
| vb = |
| context.getApplication().createValueBinding( |
| unselectedClass); |
| graphComponent.setValueBinding("unselectedClass", vb); |
| } else { |
| graphComponent.getAttributes().put("unselectedClass", |
| unselectedClass); |
| } |
| } |
| |
| if (immediate != null) { |
| if (isValueReference(immediate)) { |
| vb = context.getApplication().createValueBinding(immediate); |
| graphComponent.setValueBinding("immediate", vb); |
| } else { |
| boolean _immediate = new Boolean(immediate).booleanValue(); |
| graphComponent.setImmediate(_immediate); |
| } |
| } |
| |
| if (value != null) { |
| // if the value is not value reference expression, we need |
| // to build the graph using the node tags. |
| if (isValueReference(value)) { |
| vb = context.getApplication().createValueBinding(value); |
| component.setValueBinding("value", vb); |
| } |
| } |
| |
| // if there is no valueRef attribute set on this tag, then |
| // we need to build the graph. |
| if (value == null) { |
| vb = |
| context.getApplication().createValueBinding( |
| "#{sessionScope.graph_tree}"); |
| component.setValueBinding("value", vb); |
| |
| // In the postback case, graph exists already. So make sure |
| // it doesn't created again. |
| Graph graph = (Graph) ((GraphComponent) component).getValue(); |
| if (graph == null) { |
| graph = new Graph(); |
| vb.setValue(context, graph); |
| } |
| } |
| } |
| |
| |
| } |