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 numberOfFailures;
32 protected Text numberOfRuns;
34 protected int ignoredCount;
35 protected int assumptionFailedCount;
37 private final Image fErrorIcon = null;
38 private final Image fFailureIcon = null;
40 public STSCounterPanel(Composite parent) {
41 super(parent, SWT.WRAP);
42 GridLayout gridLayout= new GridLayout();
43 gridLayout.numColumns= 9;
44 gridLayout.makeColumnsEqualWidth= false;
45 gridLayout.marginWidth= 0;
46 setLayout(gridLayout);
48 numberOfRuns= createLabel("Runs:", null, " 0/0 "); //$NON-NLS-1$
49 numberOfErrors= createLabel("Errors:", fErrorIcon, " 0 "); //$NON-NLS-1$
50 numberOfFailures= createLabel("Failures:", fFailureIcon, " 0 "); //$NON-NLS-1$
52 addDisposeListener(new DisposeListener() {
53 public void widgetDisposed(DisposeEvent e) {
59 private void disposeIcons() {
60 if (fErrorIcon != null)
62 if (fFailureIcon != null)
63 fFailureIcon.dispose();
66 private Text createLabel(String name, Image image, String init) {
67 Label label= new Label(this, SWT.NONE);
69 image.setBackground(label.getBackground());
70 label.setImage(image);
72 label.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
74 label = new Label(this, SWT.NONE);
76 label.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
77 //label.setFont(JFaceResources.getBannerFont());
79 Text value = new Text(this, SWT.READ_ONLY);
81 // bug: 39661 Junit test counters do not repaint correctly [JUnit]
82 // SWTUtil.fixReadonlyTextBackground(value);
83 value.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.HORIZONTAL_ALIGN_BEGINNING));
94 public void setTotal(int value) {
98 public int getTotal(){
102 public void setRunValue(int value, int ignoredCount, int assumptionFailureCount) {
104 String runStringTooltip;
105 if (ignoredCount == 0 && assumptionFailureCount == 0) {
106 runString= Messages.format("{0}/{1}", new String[] { Integer.toString(value), Integer.toString(total) });
107 runStringTooltip= runString;
108 } else if (ignoredCount != 0 && assumptionFailureCount == 0) {
109 runString= Messages.format("Skipped", new String[] { Integer.toString(value), Integer.toString(total), Integer.toString(ignoredCount) });
110 runStringTooltip= Messages.format("Ignored", new String[] { Integer.toString(value), Integer.toString(total), Integer.toString(ignoredCount) });
111 } else if (ignoredCount == 0 && assumptionFailureCount != 0) {
112 runString= Messages.format("Skipped", new String[] { Integer.toString(value), Integer.toString(total), Integer.toString(assumptionFailureCount) });
113 runStringTooltip= Messages.format("Failed", new String[] { Integer.toString(value), Integer.toString(total), Integer.toString(assumptionFailureCount) });
115 runString= Messages.format("Skipped", new String[] { Integer.toString(value), Integer.toString(total), Integer.toString(ignoredCount + assumptionFailureCount) });
116 runStringTooltip= Messages.format("Failed", new String[] { Integer.toString(value), Integer.toString(total), Integer.toString(ignoredCount), Integer.toString(assumptionFailureCount) });
118 numberOfRuns.setText(runString);
119 numberOfRuns.setToolTipText(runStringTooltip);
121 if (ignoredCount == 0 && ignoredCount > 0 || ignoredCount != 0 && ignoredCount == 0) {
123 } else if (assumptionFailedCount == 0 && assumptionFailureCount > 0 || assumptionFailedCount != 0 && assumptionFailureCount == 0) {
126 numberOfRuns.redraw();
129 assumptionFailedCount= assumptionFailureCount;
132 public void setErrorValue(int value) {
133 numberOfErrors.setText(Integer.toString(value));
137 public void setFailureValue(int value) {
138 numberOfFailures.setText(Integer.toString(value));
142 private static class Messages {
144 public static String format(String message, Object object) {
145 return MessageFormat.format(message, new Object[] { object});
148 public static String format(String message, Object[] objects) {
149 return MessageFormat.format(message, objects);
153 // Not for instantiation