Home | History | Annotate | Download | only in model
      1 /*******************************************************************************
      2  * Copyright (c) 2000, 2009 IBM Corporation and others.
      3  * All rights reserved. This program and the accompanying materials
      4  * are made available under the terms of the Eclipse Public License v1.0
      5  * which accompanies this distribution, and is available at
      6  * http://www.eclipse.org/legal/epl-v10.html
      7  *
      8  * Contributors:
      9  *     IBM Corporation - initial API and implementation
     10  *******************************************************************************/
     11 package org.eclipse.test.internal.performance.results.model;
     12 
     13 import java.util.Vector;
     14 
     15 import org.eclipse.test.internal.performance.data.Dim;
     16 import org.eclipse.test.internal.performance.results.db.*;
     17 import org.eclipse.ui.views.properties.IPropertyDescriptor;
     18 import org.eclipse.ui.views.properties.PropertyDescriptor;
     19 import org.eclipse.ui.views.properties.TextPropertyDescriptor;
     20 
     21 public class DimResultsElement extends ResultsElement {
     22 
     23 	Dim dim;
     24 
     25 	// Property descriptors
     26     static final String P_ID_DIMENSION = "DimResultsElement.dim"; //$NON-NLS-1$
     27     static final String P_ID_COUNT = "DimResultsElement.count"; //$NON-NLS-1$
     28     static final String P_ID_AVERAGE = "DimResultsElement.average"; //$NON-NLS-1$
     29     static final String P_ID_STDDEV = "DimResultsElement.stddev"; //$NON-NLS-1$
     30     static final String P_ID_ERROR= "DimResultsElement.error"; //$NON-NLS-1$
     31     static final String P_ID_HAD_VALUES = "DimResultsElement.hadvalues"; //$NON-NLS-1$
     32 
     33     static final String P_STR_DIMENSION = "dimension"; //$NON-NLS-1$
     34     static final String P_STR_COUNT= "count"; //$NON-NLS-1$
     35     static final String P_STR_AVERAGE = "average"; //$NON-NLS-1$
     36     static final String P_STR_STDDEV = "std dev"; //$NON-NLS-1$
     37     static final String P_STR_ERROR = "error"; //$NON-NLS-1$
     38     static final String P_STR_HAD_VALUES = "had values"; //$NON-NLS-1$
     39 
     40 	private static final TextPropertyDescriptor DIMENSION_DESCRIPTOR = new TextPropertyDescriptor(P_ID_DIMENSION, P_STR_DIMENSION);
     41 	private static final PropertyDescriptor DIM_COUNT_DESCRIPTOR = new PropertyDescriptor(P_ID_COUNT, P_STR_COUNT);
     42 	private static final PropertyDescriptor DIM_AVERAGE_DESCRIPTOR = new PropertyDescriptor(P_ID_AVERAGE, P_STR_AVERAGE);
     43 	private static final PropertyDescriptor DIM_STDDEV_DESCRIPTOR = new PropertyDescriptor(P_ID_STDDEV, P_STR_STDDEV);
     44 	private static final PropertyDescriptor DIM_ERROR_DESCRIPTOR = new PropertyDescriptor(P_ID_ERROR, P_STR_ERROR);
     45 	private static final PropertyDescriptor DIM_HAD_VALUES_DESCRIPTOR = new PropertyDescriptor(P_ID_HAD_VALUES, P_STR_HAD_VALUES);
     46 
     47     private static Vector DESCRIPTORS;
     48     static Vector initDescriptors(int status) {
     49         DESCRIPTORS = new Vector();
     50 		// Status category
     51 		DESCRIPTORS.add(getInfosDescriptor(status));
     52 		DESCRIPTORS.add(getWarningsDescriptor(status));
     53 		DESCRIPTORS.add(ERROR_DESCRIPTOR);
     54 		ERROR_DESCRIPTOR.setCategory("Status");
     55 		// Results category
     56         DESCRIPTORS.addElement(DIMENSION_DESCRIPTOR);
     57 		DIMENSION_DESCRIPTOR.setCategory("Results");
     58         DESCRIPTORS.addElement(DIM_COUNT_DESCRIPTOR);
     59 		DIM_COUNT_DESCRIPTOR.setCategory("Results");
     60         DESCRIPTORS.addElement(DIM_AVERAGE_DESCRIPTOR);
     61 		DIM_AVERAGE_DESCRIPTOR.setCategory("Results");
     62         DESCRIPTORS.addElement(DIM_STDDEV_DESCRIPTOR);
     63 		DIM_STDDEV_DESCRIPTOR.setCategory("Results");
     64         DESCRIPTORS.addElement(DIM_ERROR_DESCRIPTOR);
     65 		DIM_ERROR_DESCRIPTOR.setCategory("Results");
     66         DESCRIPTORS.addElement(DIM_HAD_VALUES_DESCRIPTOR);
     67 		DIM_HAD_VALUES_DESCRIPTOR.setCategory("Results");
     68 		// Survey category
     69 		DESCRIPTORS.add(COMMENT_DESCRIPTOR);
     70 		COMMENT_DESCRIPTOR.setCategory("Survey");
     71         return DESCRIPTORS;
     72    	}
     73     static Vector getDescriptors() {
     74     	return DESCRIPTORS;
     75 	}
     76 
     77 public DimResultsElement(AbstractResults results, ResultsElement parent, Dim d) {
     78 	super(results, parent);
     79 	this.dim = d;
     80 }
     81 
     82 ResultsElement createChild(AbstractResults testResults) {
     83 	return null;
     84 }
     85 
     86 private BuildResults getBuildResults() {
     87 	return (BuildResults) this.results;
     88 }
     89 
     90 public String getLabel(Object o) {
     91 	return this.dim.getName();
     92 }
     93 
     94 /* (non-Javadoc)
     95  * @see org.eclipse.ui.views.properties.IPropertySource#getPropertyDescriptors()
     96  */
     97 public IPropertyDescriptor[] getPropertyDescriptors() {
     98 	Vector descriptors = getDescriptors();
     99 	if (descriptors == null) {
    100 		descriptors = initDescriptors(getStatus());
    101 	}
    102 	int size = descriptors.size();
    103 	IPropertyDescriptor[] descriptorsArray = new IPropertyDescriptor[size];
    104 	descriptorsArray[0] = getInfosDescriptor(getStatus());
    105 	descriptorsArray[1] = getWarningsDescriptor(getStatus());
    106 	for (int i=2; i<size; i++) {
    107 		descriptorsArray[i] = (IPropertyDescriptor) descriptors.get(i);
    108 	}
    109 	return descriptorsArray;
    110 }
    111 
    112 /* (non-Javadoc)
    113  * @see org.eclipse.ui.views.properties.IPropertySource#getPropertyValue(java.lang.Object)
    114  */
    115 public Object getPropertyValue(Object propKey) {
    116 	BuildResults buildResults = getBuildResults();
    117     if (propKey.equals(P_ID_DIMENSION)) {
    118     	return  this.dim.getDescription();
    119     }
    120     if (propKey.equals(P_ID_COUNT)) {
    121 	    long count = buildResults.getCount(this.dim.getId());
    122 	    return new Double(count);
    123     }
    124     if (propKey.equals(P_ID_AVERAGE))
    125         return new Double(buildResults.getValue(this.dim.getId()));
    126     if (propKey.equals(P_ID_STDDEV))
    127         return new Double(buildResults.getDeviation(this.dim.getId()));
    128     if (propKey.equals(P_ID_ERROR))
    129         return new Double(buildResults.getError(this.dim.getId()));
    130     if (propKey.equals(P_ID_HAD_VALUES))
    131         return new Boolean(buildResults.hadValues());
    132     return super.getPropertyValue(propKey);
    133 }
    134 
    135 }
    136