--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2000, 2013 IBM Corporation and others.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * IBM Corporation - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.tests.modelled.ui;\r
+\r
+\r
+import java.text.MessageFormat;\r
+\r
+import org.eclipse.swt.SWT;\r
+import org.eclipse.swt.events.DisposeEvent;\r
+import org.eclipse.swt.events.DisposeListener;\r
+import org.eclipse.swt.graphics.Image;\r
+import org.eclipse.swt.layout.GridData;\r
+import org.eclipse.swt.layout.GridLayout;\r
+import org.eclipse.swt.widgets.Composite;\r
+import org.eclipse.swt.widgets.Label;\r
+import org.eclipse.swt.widgets.Text;\r
+\r
+/**\r
+ * A panel with counters for the number of Runs, Errors and Failures.\r
+ */\r
+public class STSCounterPanel extends Composite {\r
+ protected Text numberOfErrors;\r
+ protected Text numberOfFailures;\r
+ protected Text numberOfRuns;\r
+ protected int total;\r
+ protected int ignoredCount;\r
+ protected int assumptionFailedCount;\r
+\r
+ private final Image fErrorIcon = null;\r
+ private final Image fFailureIcon = null;\r
+\r
+ public STSCounterPanel(Composite parent) {\r
+ super(parent, SWT.WRAP);\r
+ GridLayout gridLayout= new GridLayout();\r
+ gridLayout.numColumns= 9;\r
+ gridLayout.makeColumnsEqualWidth= false;\r
+ gridLayout.marginWidth= 0;\r
+ setLayout(gridLayout);\r
+\r
+ numberOfRuns= createLabel("Runs:", null, " 0/0 "); //$NON-NLS-1$\r
+ numberOfErrors= createLabel("Errors:", fErrorIcon, " 0 "); //$NON-NLS-1$\r
+ numberOfFailures= createLabel("Failures:", fFailureIcon, " 0 "); //$NON-NLS-1$\r
+\r
+ addDisposeListener(new DisposeListener() {\r
+ public void widgetDisposed(DisposeEvent e) {\r
+ disposeIcons();\r
+ }\r
+ });\r
+ }\r
+\r
+ private void disposeIcons() {\r
+ if (fErrorIcon != null)\r
+ fErrorIcon.dispose();\r
+ if (fFailureIcon != null)\r
+ fFailureIcon.dispose();\r
+ }\r
+\r
+ private Text createLabel(String name, Image image, String init) {\r
+ Label label= new Label(this, SWT.NONE);\r
+ if (image != null) {\r
+ image.setBackground(label.getBackground());\r
+ label.setImage(image);\r
+ }\r
+ label.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));\r
+\r
+ label = new Label(this, SWT.NONE);\r
+ label.setText(name);\r
+ label.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));\r
+ //label.setFont(JFaceResources.getBannerFont());\r
+\r
+ Text value = new Text(this, SWT.READ_ONLY);\r
+ value.setText(init);\r
+ // bug: 39661 Junit test counters do not repaint correctly [JUnit]\r
+// SWTUtil.fixReadonlyTextBackground(value);\r
+ value.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.HORIZONTAL_ALIGN_BEGINNING));\r
+ return value;\r
+ }\r
+\r
+ public void reset() {\r
+ setErrorValue(0);\r
+ setFailureValue(0);\r
+ setRunValue(0, 0, 0);\r
+ total= 0;\r
+ }\r
+\r
+ public void setTotal(int value) {\r
+ total= value;\r
+ }\r
+\r
+ public int getTotal(){\r
+ return total;\r
+ }\r
+\r
+ public void setRunValue(int value, int ignoredCount, int assumptionFailureCount) {\r
+ String runString;\r
+ String runStringTooltip;\r
+ if (ignoredCount == 0 && assumptionFailureCount == 0) {\r
+ runString= Messages.format("{0}/{1}", new String[] { Integer.toString(value), Integer.toString(total) });\r
+ runStringTooltip= runString;\r
+ } else if (ignoredCount != 0 && assumptionFailureCount == 0) {\r
+ runString= Messages.format("Skipped", new String[] { Integer.toString(value), Integer.toString(total), Integer.toString(ignoredCount) });\r
+ runStringTooltip= Messages.format("Ignored", new String[] { Integer.toString(value), Integer.toString(total), Integer.toString(ignoredCount) });\r
+ } else if (ignoredCount == 0 && assumptionFailureCount != 0) {\r
+ runString= Messages.format("Skipped", new String[] { Integer.toString(value), Integer.toString(total), Integer.toString(assumptionFailureCount) });\r
+ runStringTooltip= Messages.format("Failed", new String[] { Integer.toString(value), Integer.toString(total), Integer.toString(assumptionFailureCount) });\r
+ } else {\r
+ runString= Messages.format("Skipped", new String[] { Integer.toString(value), Integer.toString(total), Integer.toString(ignoredCount + assumptionFailureCount) });\r
+ runStringTooltip= Messages.format("Failed", new String[] { Integer.toString(value), Integer.toString(total), Integer.toString(ignoredCount), Integer.toString(assumptionFailureCount) });\r
+ }\r
+ numberOfRuns.setText(runString);\r
+ numberOfRuns.setToolTipText(runStringTooltip);\r
+\r
+ if (ignoredCount == 0 && ignoredCount > 0 || ignoredCount != 0 && ignoredCount == 0) {\r
+ layout();\r
+ } else if (assumptionFailedCount == 0 && assumptionFailureCount > 0 || assumptionFailedCount != 0 && assumptionFailureCount == 0) {\r
+ layout();\r
+ } else {\r
+ numberOfRuns.redraw();\r
+ redraw();\r
+ }\r
+ assumptionFailedCount= assumptionFailureCount;\r
+ }\r
+\r
+ public void setErrorValue(int value) {\r
+ numberOfErrors.setText(Integer.toString(value));\r
+ redraw();\r
+ }\r
+\r
+ public void setFailureValue(int value) {\r
+ numberOfFailures.setText(Integer.toString(value));\r
+ redraw();\r
+ }\r
+ \r
+ private static class Messages {\r
+\r
+ public static String format(String message, Object object) {\r
+ return MessageFormat.format(message, new Object[] { object});\r
+ }\r
+\r
+ public static String format(String message, Object[] objects) {\r
+ return MessageFormat.format(message, objects);\r
+ }\r
+\r
+ private Messages() {\r
+ // Not for instantiation\r
+ }\r
+ }\r
+}\r