Package org.primefaces.component.menu

Source Code of org.primefaces.component.menu.Menu

/*
* Copyright 2009 Prime Technology.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.primefaces.component.menu;

import org.primefaces.component.menu.AbstractMenu;
import javax.faces.context.FacesContext;
import javax.el.ValueExpression;
import javax.el.MethodExpression;
import javax.faces.render.Renderer;
import java.io.IOException;
import org.primefaces.renderkit.PartialRenderer;
import org.primefaces.component.resource.Resource;
import javax.faces.component.UIComponent;
import javax.faces.event.ListenerFor;
import javax.faces.event.PostAddToViewEvent;
import javax.faces.event.ComponentSystemEvent;
import javax.faces.event.AbortProcessingException;
import java.util.List;
import java.util.ArrayList;

@ListenerFor(systemEventClass = PostAddToViewEvent.class)
public class Menu extends AbstractMenu {


  public static final String COMPONENT_TYPE = "org.primefaces.component.Menu";
  public static final String COMPONENT_FAMILY = "org.primefaces.component";
  private static final String DEFAULT_RENDERER = "org.primefaces.component.MenuRenderer";
  private static final String OPTIMIZED_PACKAGE = "org.primefaces.component.";

  protected enum PropertyKeys {

    widgetVar
    ,model
    ,visible
    ,x
    ,y
    ,fixedCenter
    ,constraintToViewport
    ,position
    ,clickToHide
    ,keepOpen
    ,tiered
    ,effect
    ,effectDuration
    ,autoSubmenuDisplay
    ,showDelay
    ,hideDelay
    ,submenuHideDelay
    ,context
    ,style
    ,styleClass
    ,zindex;

    String toString;

    PropertyKeys(String toString) {
      this.toString = toString;
    }

    PropertyKeys() {}

    public String toString() {
      return ((this.toString != null) ? this.toString : super.toString());
}
  }

  public Menu() {
    setRendererType(DEFAULT_RENDERER);
  }

  public String getFamily() {
    return COMPONENT_FAMILY;
  }

  public java.lang.String getWidgetVar() {
    return (java.lang.String) getStateHelper().eval(PropertyKeys.widgetVar, null);
  }
  public void setWidgetVar(java.lang.String _widgetVar) {
    getStateHelper().put(PropertyKeys.widgetVar, _widgetVar);
    handleAttribute("widgetVar", _widgetVar);
  }

  public org.primefaces.model.MenuModel getModel() {
    return (org.primefaces.model.MenuModel) getStateHelper().eval(PropertyKeys.model, null);
  }
  public void setModel(org.primefaces.model.MenuModel _model) {
    getStateHelper().put(PropertyKeys.model, _model);
    handleAttribute("model", _model);
  }

  public boolean isVisible() {
    return (java.lang.Boolean) getStateHelper().eval(PropertyKeys.visible, false);
  }
  public void setVisible(boolean _visible) {
    getStateHelper().put(PropertyKeys.visible, _visible);
    handleAttribute("visible", _visible);
  }

  public int getX() {
    return (java.lang.Integer) getStateHelper().eval(PropertyKeys.x, -1);
  }
  public void setX(int _x) {
    getStateHelper().put(PropertyKeys.x, _x);
    handleAttribute("x", _x);
  }

  public int getY() {
    return (java.lang.Integer) getStateHelper().eval(PropertyKeys.y, -1);
  }
  public void setY(int _y) {
    getStateHelper().put(PropertyKeys.y, _y);
    handleAttribute("y", _y);
  }

  public boolean isFixedCenter() {
    return (java.lang.Boolean) getStateHelper().eval(PropertyKeys.fixedCenter, false);
  }
  public void setFixedCenter(boolean _fixedCenter) {
    getStateHelper().put(PropertyKeys.fixedCenter, _fixedCenter);
    handleAttribute("fixedCenter", _fixedCenter);
  }

  public boolean isConstraintToViewport() {
    return (java.lang.Boolean) getStateHelper().eval(PropertyKeys.constraintToViewport, true);
  }
  public void setConstraintToViewport(boolean _constraintToViewport) {
    getStateHelper().put(PropertyKeys.constraintToViewport, _constraintToViewport);
    handleAttribute("constraintToViewport", _constraintToViewport);
  }

  public java.lang.String getPosition() {
    return (java.lang.String) getStateHelper().eval(PropertyKeys.position, "static");
  }
  public void setPosition(java.lang.String _position) {
    getStateHelper().put(PropertyKeys.position, _position);
    handleAttribute("position", _position);
  }

  public boolean isClickToHide() {
    return (java.lang.Boolean) getStateHelper().eval(PropertyKeys.clickToHide, true);
  }
  public void setClickToHide(boolean _clickToHide) {
    getStateHelper().put(PropertyKeys.clickToHide, _clickToHide);
    handleAttribute("clickToHide", _clickToHide);
  }

  public boolean isKeepOpen() {
    return (java.lang.Boolean) getStateHelper().eval(PropertyKeys.keepOpen, false);
  }
  public void setKeepOpen(boolean _keepOpen) {
    getStateHelper().put(PropertyKeys.keepOpen, _keepOpen);
    handleAttribute("keepOpen", _keepOpen);
  }

  public boolean isTiered() {
    return (java.lang.Boolean) getStateHelper().eval(PropertyKeys.tiered, false);
  }
  public void setTiered(boolean _tiered) {
    getStateHelper().put(PropertyKeys.tiered, _tiered);
    handleAttribute("tiered", _tiered);
  }

  public java.lang.String getEffect() {
    return (java.lang.String) getStateHelper().eval(PropertyKeys.effect, "FADE");
  }
  public void setEffect(java.lang.String _effect) {
    getStateHelper().put(PropertyKeys.effect, _effect);
    handleAttribute("effect", _effect);
  }

  public double getEffectDuration() {
    return (java.lang.Double) getStateHelper().eval(PropertyKeys.effectDuration, 0.25);
  }
  public void setEffectDuration(double _effectDuration) {
    getStateHelper().put(PropertyKeys.effectDuration, _effectDuration);
    handleAttribute("effectDuration", _effectDuration);
  }

  public boolean isAutoSubmenuDisplay() {
    return (java.lang.Boolean) getStateHelper().eval(PropertyKeys.autoSubmenuDisplay, true);
  }
  public void setAutoSubmenuDisplay(boolean _autoSubmenuDisplay) {
    getStateHelper().put(PropertyKeys.autoSubmenuDisplay, _autoSubmenuDisplay);
    handleAttribute("autoSubmenuDisplay", _autoSubmenuDisplay);
  }

  public int getShowDelay() {
    return (java.lang.Integer) getStateHelper().eval(PropertyKeys.showDelay, 250);
  }
  public void setShowDelay(int _showDelay) {
    getStateHelper().put(PropertyKeys.showDelay, _showDelay);
    handleAttribute("showDelay", _showDelay);
  }

  public int getHideDelay() {
    return (java.lang.Integer) getStateHelper().eval(PropertyKeys.hideDelay, 0);
  }
  public void setHideDelay(int _hideDelay) {
    getStateHelper().put(PropertyKeys.hideDelay, _hideDelay);
    handleAttribute("hideDelay", _hideDelay);
  }

  public int getSubmenuHideDelay() {
    return (java.lang.Integer) getStateHelper().eval(PropertyKeys.submenuHideDelay, 250);
  }
  public void setSubmenuHideDelay(int _submenuHideDelay) {
    getStateHelper().put(PropertyKeys.submenuHideDelay, _submenuHideDelay);
    handleAttribute("submenuHideDelay", _submenuHideDelay);
  }

  public java.lang.String getContext() {
    return (java.lang.String) getStateHelper().eval(PropertyKeys.context, null);
  }
  public void setContext(java.lang.String _context) {
    getStateHelper().put(PropertyKeys.context, _context);
    handleAttribute("context", _context);
  }

  public java.lang.String getStyle() {
    return (java.lang.String) getStateHelper().eval(PropertyKeys.style, null);
  }
  public void setStyle(java.lang.String _style) {
    getStateHelper().put(PropertyKeys.style, _style);
    handleAttribute("style", _style);
  }

  public java.lang.String getStyleClass() {
    return (java.lang.String) getStateHelper().eval(PropertyKeys.styleClass, null);
  }
  public void setStyleClass(java.lang.String _styleClass) {
    getStateHelper().put(PropertyKeys.styleClass, _styleClass);
    handleAttribute("styleClass", _styleClass);
  }

  public int getZindex() {
    return (java.lang.Integer) getStateHelper().eval(PropertyKeys.zindex, java.lang.Integer.MAX_VALUE);
  }
  public void setZindex(int _zindex) {
    getStateHelper().put(PropertyKeys.zindex, _zindex);
    handleAttribute("zindex", _zindex);
  }


  protected FacesContext getFacesContext() {
    return FacesContext.getCurrentInstance();
  }

  public boolean resourceExists(FacesContext facesContext, String name) {
    java.util.List<UIComponent> resources = facesContext.getViewRoot().getComponentResources(facesContext, "head");
    for(UIComponent component : resources) {
      String value = component.toString();
      if(value != null && value.equals(name))
        return true;
    }
    return false;
  }

  @Override
  public void processEvent(ComponentSystemEvent event) throws AbortProcessingException {
    FacesContext facesContext = getFacesContext();
    javax.faces.component.UIViewRoot viewroot = facesContext.getViewRoot();
    Resource resource = null;
    if(!resourceExists(facesContext, "/primefaces/menu/menu.css")) {
      resource = (Resource) facesContext.getApplication().createComponent("org.primefaces.component.Resource");
      resource.setName("/primefaces/menu/menu.css");
      viewroot.addComponentResource(facesContext, resource, "head");
    }
    if(!resourceExists(facesContext, "/jquery/jquery.js")) {
      resource = (Resource) facesContext.getApplication().createComponent("org.primefaces.component.Resource");
      resource.setName("/jquery/jquery.js");
      viewroot.addComponentResource(facesContext, resource, "head");
    }
    if(!resourceExists(facesContext, "/yui/utilities/utilities.js")) {
      resource = (Resource) facesContext.getApplication().createComponent("org.primefaces.component.Resource");
      resource.setName("/yui/utilities/utilities.js");
      viewroot.addComponentResource(facesContext, resource, "head");
    }
    if(!resourceExists(facesContext, "/yui/container/container-min.js")) {
      resource = (Resource) facesContext.getApplication().createComponent("org.primefaces.component.Resource");
      resource.setName("/yui/container/container-min.js");
      viewroot.addComponentResource(facesContext, resource, "head");
    }
    if(!resourceExists(facesContext, "/primefaces/menu/menu.js")) {
      resource = (Resource) facesContext.getApplication().createComponent("org.primefaces.component.Resource");
      resource.setName("/primefaces/menu/menu.js");
      viewroot.addComponentResource(facesContext, resource, "head");
    }
    if(!resourceExists(facesContext, "/primefaces/core/core.js")) {
      resource = (Resource) facesContext.getApplication().createComponent("org.primefaces.component.Resource");
      resource.setName("/primefaces/core/core.js");
      viewroot.addComponentResource(facesContext, resource, "head");
    }
  }


  public void handleAttribute(String name, Object value) {
    List<String> setAttributes = (List<String>) this.getAttributes().get("javax.faces.component.UIComponentBase.attributesThatAreSet");
    if(setAttributes == null) {
      String cname = this.getClass().getName();
      if(cname != null && cname.startsWith(OPTIMIZED_PACKAGE)) {
        setAttributes = new ArrayList<String>(6);
        this.getAttributes().put("javax.faces.component.UIComponentBase.attributesThatAreSet", setAttributes);
      }
    }
    if(setAttributes != null) {
      if(value == null) {
        ValueExpression ve = getValueExpression(name);
        if(ve == null) {
          setAttributes.remove(name);
        } else if(!setAttributes.contains(name)) {
          setAttributes.add(name);
        }
      }
    }
  }
}
TOP

Related Classes of org.primefaces.component.menu.Menu

TOP
Copyright © 2018 www.massapi.com. 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.