/*
 * Copyright to the original author or authors.
 *
 * 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.rioproject.tools.ui.servicenotification;

import org.rioproject.sla.SLA;
import org.rioproject.sla.SLAThresholdEvent;
import org.rioproject.tools.ui.Constants;
import org.rioproject.watch.ThresholdEvent;

/**
 * @author Dennis Reedy
 */
public class SLAThresholdEventNode extends RemoteServiceEventNode<SLAThresholdEvent> {

    public SLAThresholdEventNode(SLAThresholdEvent event) {
        super(event);
    }

    @Override
    public Throwable getThrown() {
        return null;
    }

    @Override
    public String getDescription() {
        StringBuilder builder = new StringBuilder();
        SLA sla = getEvent().getSLA();
        builder.append("Threshold low: ").append(sla.getCurrentLowThreshold());
        builder.append(" high: ").append(sla.getCurrentHighThreshold());
        builder.append(" value: ").append(getEvent().getCalculable().getValue());
        return builder.toString();
    }

    @Override
    public String getOperationalStringName() {
        return getEvent().getServiceElement().getOperationalStringName();
    }

    @Override
    public String getServiceName() {
        return getEvent().getServiceElement().getName();
    }

    public String getStatus() {
        return getEvent().getType() == ThresholdEvent.BREACHED?"BREACHED":"CLEARED";
    }

    @Override
    public String toString() {
        return getServiceName();
    }

    @Override
    public int getColumnCount() {
        return 3;
    }

    @Override
    public Object getValueAt(int column) {
        String value;
        if (column == 0) {
            value = getStatus();
        } else if (column == 1) {
            value = getDescription();
        } else {
            value = Constants.DATE_FORMAT.format(getDate());
        }
        return value;
    }
}


@@ -824,16 +824,48 @@
 Event;%0A%0A
+import java.text.NumberFormat;%0A%0A
 /**%0A * @
@@ -974,16 +974,64 @@
 Event%3E %7B
+%0A    private final NumberFormat numberFormatter;
 %0A%0A    pu
@@ -1106,16 +1106,177 @@
 event);%0A
+        numberFormatter = NumberFormat.getNumberInstance();%0A        numberFormatter.setGroupingUsed(false);%0A        numberFormatter.setMaximumFractionDigits(2);%0A
     %7D%0A%0A 
@@ -1521,60 +1521,191 @@
 end(
-%22Threshold low: %22).append(sla.getCurrentLowT
+sla.getIdentifier()).append(%22: %22);%0A        builder.append(%22value: %22).append(numberFormatter.format(getEvent().getCalculable().getValue()));%0A        builder.append(%22 declared t
 hreshold
 ());
@@ -1692,34 +1692,36 @@
 clared threshold
-()
+s: %22
 );%0A        build
@@ -1735,15 +1735,12 @@
 nd(%22
- high: 
+low=
 %22).a
@@ -1741,24 +1741,47 @@
 w=%22).append(
+numberFormatter.format(
 sla.getCurre
@@ -1786,12 +1786,11 @@
 rent
-High
+Low
 Thre
@@ -1797,16 +1797,17 @@
 shold())
+)
 ;%0A      
@@ -1825,23 +1825,21 @@
 ppend(%22 
-value: 
+high=
 %22).appen
@@ -1844,44 +1844,60 @@
 end(
-getEvent().getCalculable().getValue(
+numberFormatter.format(sla.getCurrentHighThreshold()
 ));%0A

Format the SLAThresholdEvent's description for display in the remote event table