All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.sun.webui.jsf.component.Alarm Maven / Gradle / Ivy

/*
 * The contents of this file are subject to the terms
 * of the Common Development and Distribution License
 * (the License).  You may not use this file except in
 * compliance with the License.
 * 
 * You can obtain a copy of the license at
 * https://woodstock.dev.java.net/public/CDDLv1.0.html.
 * See the License for the specific language governing
 * permissions and limitations under the License.
 * 
 * When distributing Covered Code, include this CDDL
 * Header Notice in each file and include the License file
 * at https://woodstock.dev.java.net/public/CDDLv1.0.html.
 * If applicable, add the following below the CDDL Header,
 * with the fields enclosed by brackets [] replaced by
 * you own identifying information:
 * "Portions Copyrighted [year] [name of copyright owner]"
 * 
 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
 */
package com.sun.webui.jsf.component;

import java.util.Comparator;
import java.io.IOException;

import com.sun.faces.annotation.Component;
import com.sun.faces.annotation.Property;

import javax.el.ValueExpression;
import javax.faces.context.FacesContext;

/** 
 * The Alarm component is used to display a theme-specific image to indicate  
 * the condition of an object.
 */
@Component(type = "com.sun.webui.jsf.Alarm", family = "com.sun.webui.jsf.Alarm",
helpKey = "projrave_ui_elements_palette_wdstk-jsf1.2_alarm",
propertiesHelpKey = "projrave_ui_elements_palette_wdstk-jsf1.2_propsheets_alarm_props")
public class Alarm extends ImageComponent implements Comparator {

    /**
     * Down alarm severity.
     */
    public static final String SEVERITY_DOWN = "down";
    /**
     * Critical alarm severity.
     */
    public static final String SEVERITY_CRITICAL = "critical";
    /**
     * Major alarm severity.
     */
    public static final String SEVERITY_MAJOR = "major";
    /**
     * Minor alarm severity.
     */
    public static final String SEVERITY_MINOR = "minor";
    /**
     * Ok alarm severity.
     */
    public static final String SEVERITY_OK = "ok";
    /**
     * Default severity, SEVERITY_OK.
     */
    public static final String DEFAULT_SEVERITY = SEVERITY_OK;

    // Severity level of an alarm.
    private final int SEVERITY_LEVEL_DOWN = 1;
    private final int SEVERITY_LEVEL_CRITICAL = 2;
    private final int SEVERITY_LEVEL_MAJOR = 3;
    private final int SEVERITY_LEVEL_MINOR = 4;
    private final int SEVERITY_LEVEL_OK = 5;

    /** Default constructor. */
    public Alarm() {
    }

    /** Create an instance with the given severity. */
    public Alarm(String severity) {
        setSeverity(severity);
        setRendererType("com.sun.webui.jsf.Alarm");
    }

    /**
     * 

Return the family for this component.

*/ @Override public String getFamily() { return "com.sun.webui.jsf.Alarm"; } /** * Compare the given objects for severity order. */ public int compare(Object o1, Object o2) throws ClassCastException { int s1 = getSeverityLevel((Alarm) o1); int s2 = getSeverityLevel((Alarm) o2); return (s1 > s2) ? -1 : s1 == s2 ? 0 : 1; } /** * Indicates whether some other object is "equal to" this Comparator. */ //TODO implement hashcode @Override public boolean equals(Object o) throws ClassCastException { if (o == null) { return false; } if (o instanceof Alarm) { return getSeverityLevel(this) == getSeverityLevel((Alarm) o); } else { return false; } } /** * Helper method to get the severity level of an alarm. */ private int getSeverityLevel(Alarm alarm) { int severity = SEVERITY_LEVEL_OK; String alarmSeverity = alarm.getSeverity(); if (alarmSeverity == null) { return severity; } if (alarmSeverity.equals(SEVERITY_DOWN)) { severity = SEVERITY_LEVEL_DOWN; } else if (alarmSeverity.equals(SEVERITY_CRITICAL)) { severity = SEVERITY_LEVEL_CRITICAL; } else if (alarmSeverity.equals(SEVERITY_MAJOR)) { severity = SEVERITY_LEVEL_MAJOR; } else if (alarmSeverity.equals(SEVERITY_MINOR)) { severity = SEVERITY_LEVEL_MINOR; } return severity; } // Note that this component is implemented differently than // other components. First its renderer extends ImageRenderer // and second, it does not support a call like "getImageComponent" // which would return an appropriately initialized image component // representing the severity of this alarm. Once that component is // obtained AlarmRenderer would just call the returned component's // renderer. @Override public void encodeBegin(FacesContext context) throws IOException { if (context == null) { throw new NullPointerException(); } if (!isRendered()) { return; } String rendererType = getRendererType(); if (rendererType != null) { getRenderer(context).encodeBegin(context, this); } } // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Tag attribute methods // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /** * The component identifier for this component. This value must be unique * within the closest parent component that is a naming container. */ @Property(name = "id") @Override public void setId(String id) { super.setId(id); } /** * Use the rendered attribute to indicate whether the HTML code for the * component should be included in the rendered HTML page. If set to false, * the rendered HTML page does not include the HTML for the component. If * the component is not rendered, it is also not processed on any subsequent * form submission. */ @Property(name = "rendered") @Override public void setRendered(boolean rendered) { super.setRendered(rendered); } // Hide value @Property(name = "value", isHidden = true, isAttribute = false) @Override public Object getValue() { return super.getValue(); } /** *

Alternative textual description of the image rendered by this component. The alt * text can be used by screen readers and in tool tips, and when image display is turned off in * the web browser.

*/ @Property(name = "alt", displayName = "Alt Text", category = "Accessibility", editorClassName = "com.sun.rave.propertyeditors.StringPropertyEditor") private String alt = null; /** *

Alternative textual description of the image rendered by this component. The alt * text can be used by screen readers and in tool tips, and when image display is turned off in * the web browser.

*/ @Override public String getAlt() { if (this.alt != null) { return this.alt; } ValueExpression _vb = getValueExpression("alt"); if (_vb != null) { return (String) _vb.getValue(getFacesContext().getELContext()); } return null; } /** *

Alternative textual description of the image rendered by this component. The alt * text can be used by screen readers and in tool tips, and when image display is turned off in * the web browser.

* @see #getAlt() */ @Override public void setAlt(String alt) { this.alt = alt; } /** *

Scripting code executed when a mouse click * occurs over this component.

*/ @Property(name = "onClick", displayName = "Click Script", category = "Javascript", editorClassName = "com.sun.rave.propertyeditors.JavaScriptPropertyEditor") private String onClick = null; /** *

Scripting code executed when a mouse click * occurs over this component.

*/ @Override public String getOnClick() { if (this.onClick != null) { return this.onClick; } ValueExpression _vb = getValueExpression("onClick"); if (_vb != null) { return (String) _vb.getValue(getFacesContext().getELContext()); } return null; } /** *

Scripting code executed when a mouse click * occurs over this component.

* @see #getOnClick() */ @Override public void setOnClick(String onClick) { this.onClick = onClick; } /** *

Scripting code executed when a mouse double click * occurs over this component.

*/ @Property(name = "onDblClick", displayName = "Double Click Script", category = "Javascript", editorClassName = "com.sun.rave.propertyeditors.JavaScriptPropertyEditor") private String onDblClick = null; /** *

Scripting code executed when a mouse double click * occurs over this component.

*/ @Override public String getOnDblClick() { if (this.onDblClick != null) { return this.onDblClick; } ValueExpression _vb = getValueExpression("onDblClick"); if (_vb != null) { return (String) _vb.getValue(getFacesContext().getELContext()); } return null; } /** *

Scripting code executed when a mouse double click * occurs over this component.

* @see #getOnDblClick() */ @Override public void setOnDblClick(String onDblClick) { this.onDblClick = onDblClick; } /** *

Scripting code executed when the user presses down on a key while the * component has focus.

*/ @Property(name = "onKeyDown", displayName = "Key Down Script", category = "Javascript", editorClassName = "com.sun.rave.propertyeditors.JavaScriptPropertyEditor") private String onKeyDown = null; /** *

Scripting code executed when the user presses down on a key while the * component has focus.

*/ public String getOnKeyDown() { if (this.onKeyDown != null) { return this.onKeyDown; } ValueExpression _vb = getValueExpression("onKeyDown"); if (_vb != null) { return (String) _vb.getValue(getFacesContext().getELContext()); } return null; } /** *

Scripting code executed when the user presses down on a key while the * component has focus.

* @see #getOnKeyDown() */ public void setOnKeyDown(String onKeyDown) { this.onKeyDown = onKeyDown; } /** *

Scripting code executed when the user presses and releases a key while * the component has focus.

*/ @Property(name = "onKeyPress", displayName = "Key Press Script", category = "Javascript", editorClassName = "com.sun.rave.propertyeditors.JavaScriptPropertyEditor") private String onKeyPress = null; /** *

Scripting code executed when the user presses and releases a key while * the component has focus.

*/ public String getOnKeyPress() { if (this.onKeyPress != null) { return this.onKeyPress; } ValueExpression _vb = getValueExpression("onKeyPress"); if (_vb != null) { return (String) _vb.getValue(getFacesContext().getELContext()); } return null; } /** *

Scripting code executed when the user presses and releases a key while * the component has focus.

* @see #getOnKeyPress() */ public void setOnKeyPress(String onKeyPress) { this.onKeyPress = onKeyPress; } /** *

Scripting code executed when the user releases a key while the * component has focus.

*/ @Property(name = "onKeyUp", displayName = "Key Up Script", category = "Javascript", editorClassName = "com.sun.rave.propertyeditors.JavaScriptPropertyEditor") private String onKeyUp = null; /** *

Scripting code executed when the user releases a key while the * component has focus.

*/ public String getOnKeyUp() { if (this.onKeyUp != null) { return this.onKeyUp; } ValueExpression _vb = getValueExpression("onKeyUp"); if (_vb != null) { return (String) _vb.getValue(getFacesContext().getELContext()); } return null; } /** *

Scripting code executed when the user releases a key while the * component has focus.

* @see #getOnKeyUp() */ public void setOnKeyUp(String onKeyUp) { this.onKeyUp = onKeyUp; } /** *

Scripting code executed when the user presses a mouse button while the * mouse pointer is on the component.

*/ @Property(name = "onMouseDown", displayName = "Mouse Down Script", category = "Javascript", editorClassName = "com.sun.rave.propertyeditors.JavaScriptPropertyEditor") private String onMouseDown = null; /** *

Scripting code executed when the user presses a mouse button while the * mouse pointer is on the component.

*/ @Override public String getOnMouseDown() { if (this.onMouseDown != null) { return this.onMouseDown; } ValueExpression _vb = getValueExpression("onMouseDown"); if (_vb != null) { return (String) _vb.getValue(getFacesContext().getELContext()); } return null; } /** *

Scripting code executed when the user presses a mouse button while the * mouse pointer is on the component.

* @see #getOnMouseDown() */ @Override public void setOnMouseDown(String onMouseDown) { this.onMouseDown = onMouseDown; } /** *

Scripting code executed when the user moves the mouse pointer while * over the component.

*/ @Property(name = "onMouseMove", displayName = "Mouse Move Script", category = "Javascript", editorClassName = "com.sun.rave.propertyeditors.JavaScriptPropertyEditor") private String onMouseMove = null; /** *

Scripting code executed when the user moves the mouse pointer while * over the component.

*/ @Override public String getOnMouseMove() { if (this.onMouseMove != null) { return this.onMouseMove; } ValueExpression _vb = getValueExpression("onMouseMove"); if (_vb != null) { return (String) _vb.getValue(getFacesContext().getELContext()); } return null; } /** *

Scripting code executed when the user moves the mouse pointer while * over the component.

* @see #getOnMouseMove() */ @Override public void setOnMouseMove(String onMouseMove) { this.onMouseMove = onMouseMove; } /** *

Scripting code executed when a mouse out movement * occurs over this component.

*/ @Property(name = "onMouseOut", displayName = "Mouse Out Script", category = "Javascript", editorClassName = "com.sun.rave.propertyeditors.JavaScriptPropertyEditor") private String onMouseOut = null; /** *

Scripting code executed when a mouse out movement * occurs over this component.

*/ @Override public String getOnMouseOut() { if (this.onMouseOut != null) { return this.onMouseOut; } ValueExpression _vb = getValueExpression("onMouseOut"); if (_vb != null) { return (String) _vb.getValue(getFacesContext().getELContext()); } return null; } /** *

Scripting code executed when a mouse out movement * occurs over this component.

* @see #getOnMouseOut() */ @Override public void setOnMouseOut(String onMouseOut) { this.onMouseOut = onMouseOut; } /** *

Scripting code executed when the user moves the mouse pointer into * the boundary of this component.

*/ @Property(name = "onMouseOver", displayName = "Mouse In Script", category = "Javascript", editorClassName = "com.sun.rave.propertyeditors.JavaScriptPropertyEditor") private String onMouseOver = null; /** *

Scripting code executed when the user moves the mouse pointer into * the boundary of this component.

*/ @Override public String getOnMouseOver() { if (this.onMouseOver != null) { return this.onMouseOver; } ValueExpression _vb = getValueExpression("onMouseOver"); if (_vb != null) { return (String) _vb.getValue(getFacesContext().getELContext()); } return null; } /** *

Scripting code executed when the user moves the mouse pointer into * the boundary of this component.

* @see #getOnMouseOver() */ @Override public void setOnMouseOver(String onMouseOver) { this.onMouseOver = onMouseOver; } /** *

Scripting code executed when the user releases a mouse button while * the mouse pointer is on the component.

*/ @Property(name = "onMouseUp", displayName = "Mouse Up Script", category = "Javascript", editorClassName = "com.sun.rave.propertyeditors.JavaScriptPropertyEditor") private String onMouseUp = null; /** *

Scripting code executed when the user releases a mouse button while * the mouse pointer is on the component.

*/ @Override public String getOnMouseUp() { if (this.onMouseUp != null) { return this.onMouseUp; } ValueExpression _vb = getValueExpression("onMouseUp"); if (_vb != null) { return (String) _vb.getValue(getFacesContext().getELContext()); } return null; } /** *

Scripting code executed when the user releases a mouse button while * the mouse pointer is on the component.

* @see #getOnMouseUp() */ @Override public void setOnMouseUp(String onMouseUp) { this.onMouseUp = onMouseUp; } /** *

Specifies the severity of the alarm. Valid values are: *

    *
  • critical
  • *
  • major
  • *
  • minor
  • *
  • down
  • *
  • ok
  • *
* The default value is "ok", which renders no alarm icon.

*/ @Property(name = "severity", displayName = "Severity", category = "Appearance", isDefault = true, editorClassName = "com.sun.webui.jsf.component.propertyeditors.AlertTypesEditor") private String severity = null; /** *

Specifies the severity of the alarm. Valid values are: *

    *
  • critical
  • *
  • major
  • *
  • minor
  • *
  • down
  • *
  • ok
  • *
* The default value is "ok", which renders no alarm icon.

*/ public String getSeverity() { if (this.severity != null) { return this.severity; } ValueExpression _vb = getValueExpression("severity"); if (_vb != null) { return (String) _vb.getValue(getFacesContext().getELContext()); } return null; } /** *

Specifies the severity of the alarm. Valid values are: *

    *
  • critical
  • *
  • major
  • *
  • minor
  • *
  • down
  • *
  • ok
  • *
* The default value is "ok", which renders no alarm icon.

* @see #getSeverity() */ public void setSeverity(String severity) { this.severity = severity; } /** *

CSS style(s) to be applied to the outermost HTML element when this * component is rendered.

*/ @Property(name = "style", displayName = "CSS Style(s)", category = "Appearance", editorClassName = "com.sun.jsfcl.std.css.CssStylePropertyEditor") private String style = null; /** *

CSS style(s) to be applied to the outermost HTML element when this * component is rendered.

*/ @Override public String getStyle() { if (this.style != null) { return this.style; } ValueExpression _vb = getValueExpression("style"); if (_vb != null) { return (String) _vb.getValue(getFacesContext().getELContext()); } return null; } /** *

CSS style(s) to be applied to the outermost HTML element when this * component is rendered.

* @see #getStyle() */ @Override public void setStyle(String style) { this.style = style; } /** *

CSS style class(es) to be applied to the outermost HTML element when this * component is rendered.

*/ @Property(name = "styleClass", displayName = "CSS Style Class(es)", category = "Appearance", editorClassName = "com.sun.rave.propertyeditors.StyleClassPropertyEditor") private String styleClass = null; /** *

CSS style class(es) to be applied to the outermost HTML element when this * component is rendered.

*/ @Override public String getStyleClass() { if (this.styleClass != null) { return this.styleClass; } ValueExpression _vb = getValueExpression("styleClass"); if (_vb != null) { return (String) _vb.getValue(getFacesContext().getELContext()); } return null; } /** *

CSS style class(es) to be applied to the outermost HTML element when this * component is rendered.

* @see #getStyleClass() */ @Override public void setStyleClass(String styleClass) { this.styleClass = styleClass; } /** *

The text description of the alarm.

*/ @Property(name = "text", displayName = "Alarm Text") private String text = null; /** *

The text description of the alarm.

*/ public String getText() { if (this.text != null) { return this.text; } ValueExpression _vb = getValueExpression("text"); if (_vb != null) { return (String) _vb.getValue(getFacesContext().getELContext()); } return null; } /** *

The text description of the alarm.

* @see #getText() */ public void setText(String text) { this.text = text; } /** *

Specifies where the text will be placed relative to the image. The valid values * currently are "right" or "left". By default, text is placed to the right of the image.

*/ @Property(name = "textPosition", displayName = "Text Position") private String textPosition = null; /** *

Specifies where the text will be placed relative to the image. The valid values * currently are "right" or "left". By default, text is placed to the right of the image.

*/ public String getTextPosition() { if (this.textPosition != null) { return this.textPosition; } ValueExpression _vb = getValueExpression("textPosition"); if (_vb != null) { return (String) _vb.getValue(getFacesContext().getELContext()); } return "right"; } /** *

Specifies where the text will be placed relative to the image. The valid values * currently are "right" or "left". By default, text is placed to the right of the image.

* @see #getTextPosition() */ public void setTextPosition(String textPosition) { this.textPosition = textPosition; } /** *

Sets the value of the title attribute for the HTML element. * The specified text will display as a tooltip if the mouse cursor hovers * over the HTML element.

*/ @Property(name = "toolTip", displayName = "Tool Tip", category = "Behavior", editorClassName = "com.sun.rave.propertyeditors.StringPropertyEditor") private String toolTip = null; /** *

Sets the value of the title attribute for the HTML element. * The specified text will display as a tooltip if the mouse cursor hovers * over the HTML element.

*/ @Override public String getToolTip() { if (this.toolTip != null) { return this.toolTip; } ValueExpression _vb = getValueExpression("toolTip"); if (_vb != null) { return (String) _vb.getValue(getFacesContext().getELContext()); } return null; } /** *

Sets the value of the title attribute for the HTML element. * The specified text will display as a tooltip if the mouse cursor hovers * over the HTML element.

* @see #getToolTip() */ @Override public void setToolTip(String toolTip) { this.toolTip = toolTip; } /** *

Use the visible attribute to indicate whether the component should be * viewable by the user in the rendered HTML page. If set to false, the * HTML code for the component is present in the page, but the component * is hidden with style attributes. By default, visible is set to true, so * HTML for the component HTML is included and visible to the user. If the * component is not visible, it can still be processed on subsequent form * submissions because the HTML is present.

*/ @Property(name = "visible", displayName = "Visible", category = "Behavior") private boolean visible = false; private boolean visible_set = false; /** *

Use the visible attribute to indicate whether the component should be * viewable by the user in the rendered HTML page. If set to false, the * HTML code for the component is present in the page, but the component * is hidden with style attributes. By default, visible is set to true, so * HTML for the component HTML is included and visible to the user. If the * component is not visible, it can still be processed on subsequent form * submissions because the HTML is present.

*/ @Override public boolean isVisible() { if (this.visible_set) { return this.visible; } ValueExpression _vb = getValueExpression("visible"); if (_vb != null) { Object _result = _vb.getValue(getFacesContext().getELContext()); if (_result == null) { return false; } else { return ((Boolean) _result).booleanValue(); } } return true; } /** *

Use the visible attribute to indicate whether the component should be * viewable by the user in the rendered HTML page. If set to false, the * HTML code for the component is present in the page, but the component * is hidden with style attributes. By default, visible is set to true, so * HTML for the component HTML is included and visible to the user. If the * component is not visible, it can still be processed on subsequent form * submissions because the HTML is present.

* @see #isVisible() */ @Override public void setVisible(boolean visible) { this.visible = visible; this.visible_set = true; } /** *

Restore the state of this component.

*/ @Override public void restoreState(FacesContext _context, Object _state) { Object _values[] = (Object[]) _state; super.restoreState(_context, _values[0]); this.alt = (String) _values[1]; this.onClick = (String) _values[2]; this.onDblClick = (String) _values[3]; this.onKeyDown = (String) _values[4]; this.onKeyPress = (String) _values[5]; this.onKeyUp = (String) _values[6]; this.onMouseDown = (String) _values[7]; this.onMouseMove = (String) _values[8]; this.onMouseOut = (String) _values[9]; this.onMouseOver = (String) _values[10]; this.onMouseUp = (String) _values[11]; this.severity = (String) _values[12]; this.style = (String) _values[13]; this.styleClass = (String) _values[14]; this.text = (String) _values[15]; this.textPosition = (String) _values[16]; this.toolTip = (String) _values[17]; this.visible = ((Boolean) _values[18]).booleanValue(); this.visible_set = ((Boolean) _values[19]).booleanValue(); } /** *

Save the state of this component.

*/ @Override public Object saveState(FacesContext _context) { Object _values[] = new Object[20]; _values[0] = super.saveState(_context); _values[1] = this.alt; _values[2] = this.onClick; _values[3] = this.onDblClick; _values[4] = this.onKeyDown; _values[5] = this.onKeyPress; _values[6] = this.onKeyUp; _values[7] = this.onMouseDown; _values[8] = this.onMouseMove; _values[9] = this.onMouseOut; _values[10] = this.onMouseOver; _values[11] = this.onMouseUp; _values[12] = this.severity; _values[13] = this.style; _values[14] = this.styleClass; _values[15] = this.text; _values[16] = this.textPosition; _values[17] = this.toolTip; _values[18] = this.visible ? Boolean.TRUE : Boolean.FALSE; _values[19] = this.visible_set ? Boolean.TRUE : Boolean.FALSE; return _values; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy