Package org.rhq.enterprise.gui.common.metric.MetricComponent

Examples of org.rhq.enterprise.gui.common.metric.MetricComponent.TimeUnit


    public void encodeBegin(FacesContext context, UIComponent component) throws IOException {
        ResponseWriter writer = context.getResponseWriter();

        MetricComponent metric = (MetricComponent) component;
        MetricRangePreferences rangePreferences = metric.getMetricRangePreferences();
        TimeUnit preferencesUnit = null;
        int lastN = 0;

        writer.startElement("b", null);
        writer.write("Metric Display Range:");
        writer.endElement("b");
        writer.write(" ");
        if (rangePreferences.readOnly) {
            writer.write(new Date(rangePreferences.begin) + " to " + new Date(rangePreferences.end));
            writer.write(" ");
        } else {
            preferencesUnit = TimeUnit.getUnitByMetricOrdinal(rangePreferences.unit);
            lastN = rangePreferences.lastN;
            writer.write("Last :");

            writer.write(" ");

            writer.startElement("select", metric);
            writer.writeAttribute("id", MetricComponent.VALUE, null);
            writer.writeAttribute("name", MetricComponent.VALUE, null);

            List<Integer> timeIntervals = new ArrayList<Integer>(timeIntervalValues);
            if (!timeIntervals.contains(Integer.valueOf(lastN))) {
                timeIntervals.add(lastN);
            }
            Collections.sort(timeIntervals);

            for (int timeIntervalOption : timeIntervals) {
                writer.startElement("option", metric);
                writer.writeAttribute("value", timeIntervalOption, MetricComponent.VALUE);
                if (timeIntervalOption == lastN) {
                    // this doesn't work in all browsers, we have javascript below to close the gaps
                    writer.writeAttribute("SELECTED", "SELECTED", null);
                }
                writer.write(String.valueOf(timeIntervalOption));
                writer.endElement("option");
            }
            writer.endElement("select");

            writer.write(" ");

            writer.startElement("select", metric);
            writer.writeAttribute("id", MetricComponent.UNIT, null);
            writer.writeAttribute("name", MetricComponent.UNIT, null);

            for (TimeUnit unit : metric.getUnitOptions()) {
                writer.startElement("option", metric);
                writer.writeAttribute("value", unit.name(), MetricComponent.UNIT);
                if (unit.equals(preferencesUnit)) {
                    // this doesn't work in all browsers, we have javascript below to close the gaps
                    writer.writeAttribute("SELECTED", "SELECTED", null);
                }
                writer.write(unit.getDisplayName());
                writer.endElement("option");
            }
            writer.endElement("select");

            writer.write(" ");
        }
        writer.write(" ");

        writer.startElement("a", null);
        writer.writeAttribute("href", "#", null);
        writer.writeAttribute("onclick",
            "javascript:window.open('/rhq/common/metric/advanced.xhtml','Metric Display Range Settings','"
                + getWindowOptions() + "');", null);
        if (rangePreferences.readOnly) {
            writer.write("Edit Settings...");
        } else {
            writer.write("Advanced Settings...");
        }
        writer.endElement("a");
        if (rangePreferences.readOnly) {
            writer.write(" | ");
        }

        writer.startElement("script", null);
        writer.writeAttribute("type", "text/javascript", null);
        if (rangePreferences.readOnly == false) {
            // both dropdowns needs to be updated when we're NOT in readOnly mode
            writer.write("changeComboBox('" + MetricComponent.VALUE + "','" + lastN + "');");
            writer.write("changeComboBox('" + MetricComponent.UNIT + "','" + preferencesUnit.name() + "');");
        }

        writer.endElement("script");
    }
View Full Code Here

TOP

Related Classes of org.rhq.enterprise.gui.common.metric.MetricComponent.TimeUnit

Copyright © 2018 www.massapicom. 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.