1 /*******************************************************************************
2 * Copyright (c) 2000, 2013 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
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package org.simantics.tests.modelled.ui;
14 import java.text.MessageFormat;
16 import org.eclipse.swt.SWT;
17 import org.eclipse.swt.events.DisposeEvent;
18 import org.eclipse.swt.events.DisposeListener;
19 import org.eclipse.swt.graphics.Image;
20 import org.eclipse.swt.layout.GridData;
21 import org.eclipse.swt.layout.GridLayout;
22 import org.eclipse.swt.widgets.Composite;
23 import org.eclipse.swt.widgets.Label;
24 import org.eclipse.swt.widgets.Text;
27 * A panel with counters for the number of Runs, Errors and Failures.
29 public class STSCounterPanel extends Composite {
30 protected Text numberOfErrors;
31 protected Text numberOfSkipped;
32 protected Text numberOfFailures;
33 protected Text numberOfRuns;
35 protected int ignoredCount;
36 protected int assumptionFailedCount;
38 private final Image fErrorIcon = null;
39 private final Image fFailureIcon = null;
41 public STSCounterPanel(Composite parent) {
42 super(parent, SWT.WRAP);
43 GridLayout gridLayout= new GridLayout();
44 gridLayout.numColumns= 9;
45 gridLayout.makeColumnsEqualWidth= false;
46 gridLayout.marginWidth= 0;
47 setLayout(gridLayout);
49 numberOfRuns= createLabel("Runs:", null, " 0/0 "); //$NON-NLS-1$
50 numberOfSkipped = createLabel("Skipped:", null," 0 ");
51 numberOfErrors= createLabel("Errors:", fErrorIcon, " 0 "); //$NON-NLS-1$
52 numberOfFailures= createLabel("Failures:", fFailureIcon, " 0 "); //$NON-NLS-1$
54 addDisposeListener(new DisposeListener() {
55 public void widgetDisposed(DisposeEvent e) {
61 private void disposeIcons() {
62 if (fErrorIcon != null)
64 if (fFailureIcon != null)
65 fFailureIcon.dispose();
68 private Text createLabel(String name, Image image, String init) {
69 Label label= new Label(this, SWT.NONE);
71 image.setBackground(label.getBackground());
72 label.setImage(image);
74 label.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
76 label = new Label(this, SWT.NONE);
78 label.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
79 //label.setFont(JFaceResources.getBannerFont());
81 Text value = new Text(this, SWT.READ_ONLY);
83 // bug: 39661 Junit test counters do not repaint correctly [JUnit]
84 // SWTUtil.fixReadonlyTextBackground(value);
85 value.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.HORIZONTAL_ALIGN_BEGINNING));
96 public void setTotal(int value) {
100 public int getTotal(){
104 public void setRunValue(int value, int ignoredCount, int assumptionFailureCount) {
106 String runStringTooltip;
107 if (ignoredCount == 0 && assumptionFailureCount == 0) {
108 runString= Messages.format("{0}/{1}", new String[] { Integer.toString(value), Integer.toString(total) });
109 runStringTooltip= runString;
110 } else if (ignoredCount != 0 && assumptionFailureCount == 0) {
111 runString= Messages.format("Skipped", new String[] { Integer.toString(value), Integer.toString(total), Integer.toString(ignoredCount) });
112 runStringTooltip= Messages.format("Ignored", new String[] { Integer.toString(value), Integer.toString(total), Integer.toString(ignoredCount) });
113 } else if (ignoredCount == 0 && assumptionFailureCount != 0) {
114 runString= Messages.format("Skipped", new String[] { Integer.toString(value), Integer.toString(total), Integer.toString(assumptionFailureCount) });
115 runStringTooltip= Messages.format("Failed", new String[] { Integer.toString(value), Integer.toString(total), Integer.toString(assumptionFailureCount) });
117 runString= Messages.format("Skipped", new String[] { Integer.toString(value), Integer.toString(total), Integer.toString(ignoredCount + assumptionFailureCount) });
118 runStringTooltip= Messages.format("Failed", new String[] { Integer.toString(value), Integer.toString(total), Integer.toString(ignoredCount), Integer.toString(assumptionFailureCount) });
120 numberOfRuns.setText(runString);
121 numberOfRuns.setToolTipText(runStringTooltip);
123 if (ignoredCount == 0 && ignoredCount > 0 || ignoredCount != 0 && ignoredCount == 0) {
125 } else if (assumptionFailedCount == 0 && assumptionFailureCount > 0 || assumptionFailedCount != 0 && assumptionFailureCount == 0) {
128 numberOfRuns.redraw();
131 assumptionFailedCount= assumptionFailureCount;
134 public void setIgnoredValue(int value) {
135 numberOfSkipped.setText(Integer.toString(value));
139 public void setErrorValue(int value) {
140 numberOfErrors.setText(Integer.toString(value));
144 public void setFailureValue(int value) {
145 numberOfFailures.setText(Integer.toString(value));
149 private static class Messages {
151 public static String format(String message, Object object) {
152 return MessageFormat.format(message, new Object[] { object});
155 public static String format(String message, Object[] objects) {
156 return MessageFormat.format(message, objects);
160 // Not for instantiation