Package org.primefaces.component.editor

Source Code of org.primefaces.component.editor.Editor

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

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


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

  protected enum PropertyKeys {

    widgetVar
    ,width
    ,height
    ,resizable
    ,language
    ,title
    ,disabled;

    String toString;

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

    PropertyKeys() {}

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

  public Editor() {
    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 java.lang.String getWidth() {
    return (java.lang.String) getStateHelper().eval(PropertyKeys.width, "500px");
  }
  public void setWidth(java.lang.String _width) {
    getStateHelper().put(PropertyKeys.width, _width);
    handleAttribute("width", _width);
  }

  public java.lang.String getHeight() {
    return (java.lang.String) getStateHelper().eval(PropertyKeys.height, "300px");
  }
  public void setHeight(java.lang.String _height) {
    getStateHelper().put(PropertyKeys.height, _height);
    handleAttribute("height", _height);
  }

  public boolean isResizable() {
    return (java.lang.Boolean) getStateHelper().eval(PropertyKeys.resizable, false);
  }
  public void setResizable(boolean _resizable) {
    getStateHelper().put(PropertyKeys.resizable, _resizable);
    handleAttribute("resizable", _resizable);
  }

  public java.lang.String getLanguage() {
    return (java.lang.String) getStateHelper().eval(PropertyKeys.language, null);
  }
  public void setLanguage(java.lang.String _language) {
    getStateHelper().put(PropertyKeys.language, _language);
    handleAttribute("language", _language);
  }

  public java.lang.String getTitle() {
    return (java.lang.String) getStateHelper().eval(PropertyKeys.title, null);
  }
  public void setTitle(java.lang.String _title) {
    getStateHelper().put(PropertyKeys.title, _title);
    handleAttribute("title", _title);
  }

  public boolean isDisabled() {
    return (java.lang.Boolean) getStateHelper().eval(PropertyKeys.disabled, false);
  }
  public void setDisabled(boolean _disabled) {
    getStateHelper().put(PropertyKeys.disabled, _disabled);
    handleAttribute("disabled", _disabled);
  }


  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/menu/assets/skins/sam/menu.css")) {
      resource = (Resource) facesContext.getApplication().createComponent("org.primefaces.component.Resource");
      resource.setName("/yui/menu/assets/skins/sam/menu.css");
      viewroot.addComponentResource(facesContext, resource, "head");
    }
    if(!resourceExists(facesContext, "/yui/button/assets/skins/sam/button.css")) {
      resource = (Resource) facesContext.getApplication().createComponent("org.primefaces.component.Resource");
      resource.setName("/yui/button/assets/skins/sam/button.css");
      viewroot.addComponentResource(facesContext, resource, "head");
    }
    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/container/assets/skins/sam/container.css")) {
      resource = (Resource) facesContext.getApplication().createComponent("org.primefaces.component.Resource");
      resource.setName("/yui/container/assets/skins/sam/container.css");
      viewroot.addComponentResource(facesContext, resource, "head");
    }
    if(!resourceExists(facesContext, "/yui/editor/assets/skins/sam/editor.css")) {
      resource = (Resource) facesContext.getApplication().createComponent("org.primefaces.component.Resource");
      resource.setName("/yui/editor/assets/skins/sam/editor.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, "/yui/menu/menu-min.js")) {
      resource = (Resource) facesContext.getApplication().createComponent("org.primefaces.component.Resource");
      resource.setName("/yui/menu/menu-min.js");
      viewroot.addComponentResource(facesContext, resource, "head");
    }
    if(!resourceExists(facesContext, "/yui/button/button-min.js")) {
      resource = (Resource) facesContext.getApplication().createComponent("org.primefaces.component.Resource");
      resource.setName("/yui/button/button-min.js");
      viewroot.addComponentResource(facesContext, resource, "head");
    }
    if(!resourceExists(facesContext, "/yui/editor/editor-min.js")) {
      resource = (Resource) facesContext.getApplication().createComponent("org.primefaces.component.Resource");
      resource.setName("/yui/editor/editor-min.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, "/primefaces/core/core.js")) {
      resource = (Resource) facesContext.getApplication().createComponent("org.primefaces.component.Resource");
      resource.setName("/primefaces/core/core.js");
      viewroot.addComponentResource(facesContext, resource, "head");
    }
    if(!resourceExists(facesContext, "/primefaces/editor/editor.js")) {
      resource = (Resource) facesContext.getApplication().createComponent("org.primefaces.component.Resource");
      resource.setName("/primefaces/editor/editor.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.editor.Editor

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.