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 *******************************************************************************/ 11package org.eclipse.test.internal.performance.results.model; 12 13import java.util.Vector; 14 15import org.eclipse.core.runtime.preferences.IEclipsePreferences; 16import org.eclipse.core.runtime.preferences.InstanceScope; 17import org.eclipse.test.internal.performance.results.db.*; 18import org.eclipse.test.internal.performance.results.utils.IPerformancesConstants; 19import org.eclipse.test.internal.performance.results.utils.Util; 20import org.eclipse.ui.views.properties.IPropertyDescriptor; 21import org.eclipse.ui.views.properties.TextPropertyDescriptor; 22 23public class ScenarioResultsElement extends ResultsElement { 24 25 // Property descriptors 26 static final String P_ID_SCENARIO_LABEL = "ScenarioResultsElement.label"; //$NON-NLS-1$ 27 static final String P_ID_SCENARIO_FILE_NAME = "ScenarioResultsElement.filename"; //$NON-NLS-1$ 28 static final String P_ID_SCENARIO_SHORT_NAME = "ScenarioResultsElement.shortname"; //$NON-NLS-1$ 29 30 static final String P_STR_SCENARIO_LABEL = "label"; //$NON-NLS-1$ 31 static final String P_STR_SCENARIO_FILE_NAME = "file name"; //$NON-NLS-1$ 32 static final String P_STR_SCENARIO_SHORT_NAME = "short name"; //$NON-NLS-1$ 33 34 private static final TextPropertyDescriptor SCENARIO_LABEL_DESCRIPTOR = new TextPropertyDescriptor(P_ID_SCENARIO_LABEL, P_STR_SCENARIO_LABEL); 35 private static final TextPropertyDescriptor SCENARIO_FILE_NAME_DESCRIPTOR = new TextPropertyDescriptor(P_ID_SCENARIO_FILE_NAME, P_STR_SCENARIO_FILE_NAME); 36 private static final TextPropertyDescriptor SCENARIO_SHORT_NAME_DESCRIPTOR = new TextPropertyDescriptor(P_ID_SCENARIO_SHORT_NAME, P_STR_SCENARIO_SHORT_NAME); 37 38 private static Vector DESCRIPTORS; 39 static Vector initDescriptors(int status) { 40 DESCRIPTORS = new Vector(); 41 // Status category 42 DESCRIPTORS.add(getInfosDescriptor(status)); 43 DESCRIPTORS.add(getWarningsDescriptor(status)); 44 DESCRIPTORS.add(ERROR_DESCRIPTOR); 45 ERROR_DESCRIPTOR.setCategory("Status"); 46 // Results category 47 DESCRIPTORS.addElement(SCENARIO_LABEL_DESCRIPTOR); 48 SCENARIO_LABEL_DESCRIPTOR.setCategory("Results"); 49 DESCRIPTORS.addElement(SCENARIO_FILE_NAME_DESCRIPTOR); 50 SCENARIO_FILE_NAME_DESCRIPTOR.setCategory("Results"); 51 DESCRIPTORS.addElement(SCENARIO_SHORT_NAME_DESCRIPTOR); 52 SCENARIO_SHORT_NAME_DESCRIPTOR.setCategory("Results"); 53 // Survey category 54 DESCRIPTORS.add(COMMENT_DESCRIPTOR); 55 COMMENT_DESCRIPTOR.setCategory("Survey"); 56 return DESCRIPTORS; 57 } 58 static Vector getDescriptors() { 59 return DESCRIPTORS; 60 } 61 62ScenarioResultsElement(AbstractResults results, ResultsElement parent) { 63 super(results, parent); 64} 65 66ResultsElement createChild(AbstractResults testResults) { 67 return new ConfigResultsElement(testResults, this); 68} 69 70public String getLabel(Object o) { 71 return ((ScenarioResults) this.results).getShortName(); 72} 73 74/* (non-Javadoc) 75 * @see org.eclipse.ui.views.properties.IPropertySource#getPropertyDescriptors() 76 */ 77public IPropertyDescriptor[] getPropertyDescriptors() { 78 Vector descriptors = getDescriptors(); 79 if (descriptors == null) { 80 descriptors = initDescriptors(getStatus()); 81 } 82 int size = descriptors.size(); 83 IPropertyDescriptor[] descriptorsArray = new IPropertyDescriptor[size]; 84 descriptorsArray[0] = getInfosDescriptor(getStatus()); 85 descriptorsArray[1] = getWarningsDescriptor(getStatus()); 86 for (int i=2; i<size; i++) { 87 descriptorsArray[i] = (IPropertyDescriptor) descriptors.get(i); 88 } 89 return descriptorsArray; 90} 91 92/* (non-Javadoc) 93 * @see org.eclipse.ui.views.properties.IPropertySource#getPropertyValue(java.lang.Object) 94 */ 95public Object getPropertyValue(Object propKey) { 96 ScenarioResults scenarioResults = (ScenarioResults) this.results; 97 if (propKey.equals(P_ID_SCENARIO_LABEL)) 98 return scenarioResults.getLabel(); 99 if (propKey.equals(P_ID_SCENARIO_FILE_NAME)) 100 return scenarioResults.getFileName(); 101 if (propKey.equals(P_ID_SCENARIO_SHORT_NAME)) 102 return scenarioResults.getShortName(); 103 return super.getPropertyValue(propKey); 104} 105 106/** 107 * Returns whether one of the scenario's config has a summary or not. 108 * 109 * @return <code>true</code> if one of the scenario's config has a summary 110 * <code>false</code> otherwise. 111 */ 112public boolean hasSummary() { 113 if (this.results == null) return false; 114 return ((ScenarioResults)this.results).hasSummary(); 115} 116 117void initStatus() { 118 if (onlyFingerprints()) { 119 if (hasSummary()) { 120 super.initStatus(); 121 } else { 122 this.status = READ; 123 } 124 } else { 125 super.initStatus(); 126 } 127} 128 129StringBuffer writableStatus(StringBuffer buffer, int kind, StringBuffer excluded) { 130 // Write status for scenarios having error 131 if ((getStatus() & ERROR_MASK) != 0) { 132 133 // Get children status 134 StringBuffer childrenBuffer = super.writableStatus(new StringBuffer(), kind, excluded); 135 136 // Write status on file if not excluded 137 if (childrenBuffer.length() > 0) { 138 buffer.append(" "); 139 buffer.append(getLabel(null)); 140 IEclipsePreferences preferences = new InstanceScope().getNode(IPerformancesConstants.PLUGIN_ID); 141 String comment = preferences.get(getId(), null); 142 if (comment != null) { 143 if ((kind & IPerformancesConstants.STATUS_VALUES) != 0) { 144 buffer.append(" "); 145 } else { 146 buffer.append(" "); 147 } 148 buffer.append(comment); 149 } 150 buffer.append(Util.LINE_SEPARATOR); 151 buffer.append(childrenBuffer); 152 buffer.append(Util.LINE_SEPARATOR); 153 } 154 } 155 return buffer; 156} 157 158} 159