1 /*******************************************************************************
\r
2 * Copyright (c) 2000, 2013 IBM Corporation and others.
\r
3 * All rights reserved. This program and the accompanying materials
\r
4 * are made available under the terms of the Eclipse Public License v1.0
\r
5 * which accompanies this distribution, and is available at
\r
6 * http://www.eclipse.org/legal/epl-v10.html
\r
9 * IBM Corporation - initial API and implementation
\r
10 *******************************************************************************/
\r
11 package org.simantics.tests.modelled.ui;
\r
14 import java.text.MessageFormat;
\r
16 import org.eclipse.swt.SWT;
\r
17 import org.eclipse.swt.events.DisposeEvent;
\r
18 import org.eclipse.swt.events.DisposeListener;
\r
19 import org.eclipse.swt.graphics.Image;
\r
20 import org.eclipse.swt.layout.GridData;
\r
21 import org.eclipse.swt.layout.GridLayout;
\r
22 import org.eclipse.swt.widgets.Composite;
\r
23 import org.eclipse.swt.widgets.Label;
\r
24 import org.eclipse.swt.widgets.Text;
\r
27 * A panel with counters for the number of Runs, Errors and Failures.
\r
29 public class STSCounterPanel extends Composite {
\r
30 protected Text numberOfErrors;
\r
31 protected Text numberOfFailures;
\r
32 protected Text numberOfRuns;
\r
33 protected int total;
\r
34 protected int ignoredCount;
\r
35 protected int assumptionFailedCount;
\r
37 private final Image fErrorIcon = null;
\r
38 private final Image fFailureIcon = null;
\r
40 public STSCounterPanel(Composite parent) {
\r
41 super(parent, SWT.WRAP);
\r
42 GridLayout gridLayout= new GridLayout();
\r
43 gridLayout.numColumns= 9;
\r
44 gridLayout.makeColumnsEqualWidth= false;
\r
45 gridLayout.marginWidth= 0;
\r
46 setLayout(gridLayout);
\r
48 numberOfRuns= createLabel("Runs:", null, " 0/0 "); //$NON-NLS-1$
\r
49 numberOfErrors= createLabel("Errors:", fErrorIcon, " 0 "); //$NON-NLS-1$
\r
50 numberOfFailures= createLabel("Failures:", fFailureIcon, " 0 "); //$NON-NLS-1$
\r
52 addDisposeListener(new DisposeListener() {
\r
53 public void widgetDisposed(DisposeEvent e) {
\r
59 private void disposeIcons() {
\r
60 if (fErrorIcon != null)
\r
61 fErrorIcon.dispose();
\r
62 if (fFailureIcon != null)
\r
63 fFailureIcon.dispose();
\r
66 private Text createLabel(String name, Image image, String init) {
\r
67 Label label= new Label(this, SWT.NONE);
\r
68 if (image != null) {
\r
69 image.setBackground(label.getBackground());
\r
70 label.setImage(image);
\r
72 label.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
\r
74 label = new Label(this, SWT.NONE);
\r
75 label.setText(name);
\r
76 label.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
\r
77 //label.setFont(JFaceResources.getBannerFont());
\r
79 Text value = new Text(this, SWT.READ_ONLY);
\r
80 value.setText(init);
\r
81 // bug: 39661 Junit test counters do not repaint correctly [JUnit]
\r
82 // SWTUtil.fixReadonlyTextBackground(value);
\r
83 value.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.HORIZONTAL_ALIGN_BEGINNING));
\r
87 public void reset() {
\r
90 setRunValue(0, 0, 0);
\r
94 public void setTotal(int value) {
\r
98 public int getTotal(){
\r
102 public void setRunValue(int value, int ignoredCount, int assumptionFailureCount) {
\r
104 String runStringTooltip;
\r
105 if (ignoredCount == 0 && assumptionFailureCount == 0) {
\r
106 runString= Messages.format("{0}/{1}", new String[] { Integer.toString(value), Integer.toString(total) });
\r
107 runStringTooltip= runString;
\r
108 } else if (ignoredCount != 0 && assumptionFailureCount == 0) {
\r
109 runString= Messages.format("Skipped", new String[] { Integer.toString(value), Integer.toString(total), Integer.toString(ignoredCount) });
\r
110 runStringTooltip= Messages.format("Ignored", new String[] { Integer.toString(value), Integer.toString(total), Integer.toString(ignoredCount) });
\r
111 } else if (ignoredCount == 0 && assumptionFailureCount != 0) {
\r
112 runString= Messages.format("Skipped", new String[] { Integer.toString(value), Integer.toString(total), Integer.toString(assumptionFailureCount) });
\r
113 runStringTooltip= Messages.format("Failed", new String[] { Integer.toString(value), Integer.toString(total), Integer.toString(assumptionFailureCount) });
\r
115 runString= Messages.format("Skipped", new String[] { Integer.toString(value), Integer.toString(total), Integer.toString(ignoredCount + assumptionFailureCount) });
\r
116 runStringTooltip= Messages.format("Failed", new String[] { Integer.toString(value), Integer.toString(total), Integer.toString(ignoredCount), Integer.toString(assumptionFailureCount) });
\r
118 numberOfRuns.setText(runString);
\r
119 numberOfRuns.setToolTipText(runStringTooltip);
\r
121 if (ignoredCount == 0 && ignoredCount > 0 || ignoredCount != 0 && ignoredCount == 0) {
\r
123 } else if (assumptionFailedCount == 0 && assumptionFailureCount > 0 || assumptionFailedCount != 0 && assumptionFailureCount == 0) {
\r
126 numberOfRuns.redraw();
\r
129 assumptionFailedCount= assumptionFailureCount;
\r
132 public void setErrorValue(int value) {
\r
133 numberOfErrors.setText(Integer.toString(value));
\r
137 public void setFailureValue(int value) {
\r
138 numberOfFailures.setText(Integer.toString(value));
\r
142 private static class Messages {
\r
144 public static String format(String message, Object object) {
\r
145 return MessageFormat.format(message, new Object[] { object});
\r
148 public static String format(String message, Object[] objects) {
\r
149 return MessageFormat.format(message, objects);
\r
152 private Messages() {
\r
153 // Not for instantiation
\r