Package org.primefaces.component.resizable

Source Code of org.primefaces.component.resizable.Resizable

/*
* 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.resizable;

import javax.faces.component.UIComponentBase;
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 Resizable extends UIComponentBase {


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

  protected enum PropertyKeys {

    widgetVar
    ,proxy
    ,status
    ,handles
    ,ghost
    ,knobHandles
    ,animate
    ,effect
    ,animateDuration
    ,maxWidth
    ,maxHeight
    ,minWidth
    ,minHeight;

    String toString;

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

    PropertyKeys() {}

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

  public Resizable() {
    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 boolean isProxy() {
    return (java.lang.Boolean) getStateHelper().eval(PropertyKeys.proxy, false);
  }
  public void setProxy(boolean _proxy) {
    getStateHelper().put(PropertyKeys.proxy, _proxy);
    handleAttribute("proxy", _proxy);
  }

  public boolean isStatus() {
    return (java.lang.Boolean) getStateHelper().eval(PropertyKeys.status, false);
  }
  public void setStatus(boolean _status) {
    getStateHelper().put(PropertyKeys.status, _status);
    handleAttribute("status", _status);
  }

  public java.lang.String getHandles() {
    return (java.lang.String) getStateHelper().eval(PropertyKeys.handles, null);
  }
  public void setHandles(java.lang.String _handles) {
    getStateHelper().put(PropertyKeys.handles, _handles);
    handleAttribute("handles", _handles);
  }

  public boolean isGhost() {
    return (java.lang.Boolean) getStateHelper().eval(PropertyKeys.ghost, false);
  }
  public void setGhost(boolean _ghost) {
    getStateHelper().put(PropertyKeys.ghost, _ghost);
    handleAttribute("ghost", _ghost);
  }

  public boolean isKnobHandles() {
    return (java.lang.Boolean) getStateHelper().eval(PropertyKeys.knobHandles, false);
  }
  public void setKnobHandles(boolean _knobHandles) {
    getStateHelper().put(PropertyKeys.knobHandles, _knobHandles);
    handleAttribute("knobHandles", _knobHandles);
  }

  public boolean isAnimate() {
    return (java.lang.Boolean) getStateHelper().eval(PropertyKeys.animate, false);
  }
  public void setAnimate(boolean _animate) {
    getStateHelper().put(PropertyKeys.animate, _animate);
    handleAttribute("animate", _animate);
  }

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

  public double getAnimateDuration() {
    return (java.lang.Double) getStateHelper().eval(PropertyKeys.animateDuration, 0.75);
  }
  public void setAnimateDuration(double _animateDuration) {
    getStateHelper().put(PropertyKeys.animateDuration, _animateDuration);
    handleAttribute("animateDuration", _animateDuration);
  }

  public int getMaxWidth() {
    return (java.lang.Integer) getStateHelper().eval(PropertyKeys.maxWidth, Integer.MIN_VALUE);
  }
  public void setMaxWidth(int _maxWidth) {
    getStateHelper().put(PropertyKeys.maxWidth, _maxWidth);
    handleAttribute("maxWidth", _maxWidth);
  }

  public int getMaxHeight() {
    return (java.lang.Integer) getStateHelper().eval(PropertyKeys.maxHeight, Integer.MIN_VALUE);
  }
  public void setMaxHeight(int _maxHeight) {
    getStateHelper().put(PropertyKeys.maxHeight, _maxHeight);
    handleAttribute("maxHeight", _maxHeight);
  }

  public int getMinWidth() {
    return (java.lang.Integer) getStateHelper().eval(PropertyKeys.minWidth, Integer.MIN_VALUE);
  }
  public void setMinWidth(int _minWidth) {
    getStateHelper().put(PropertyKeys.minWidth, _minWidth);
    handleAttribute("minWidth", _minWidth);
  }

  public int getMinHeight() {
    return (java.lang.Integer) getStateHelper().eval(PropertyKeys.minHeight, Integer.MIN_VALUE);
  }
  public void setMinHeight(int _minHeight) {
    getStateHelper().put(PropertyKeys.minHeight, _minHeight);
    handleAttribute("minHeight", _minHeight);
  }


  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, "/yui/resize/assets/skins/sam/resize.css")) {
      resource = (Resource) facesContext.getApplication().createComponent("org.primefaces.component.Resource");
      resource.setName("/yui/resize/assets/skins/sam/resize.css");
      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/resize/resize-min.js")) {
      resource = (Resource) facesContext.getApplication().createComponent("org.primefaces.component.Resource");
      resource.setName("/yui/resize/resize-min.js");
      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, "/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.resizable.Resizable

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.