]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.tests.modelled.ui/src/org/simantics/tests/modelled/ui/STSCounterPanel.java
Merge commit '3b5069d' into develop
[simantics/platform.git] / bundles / org.simantics.tests.modelled.ui / src / org / simantics / tests / modelled / ui / STSCounterPanel.java
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
7  *\r
8  * Contributors:\r
9  *     IBM Corporation - initial API and implementation\r
10  *******************************************************************************/\r
11 package org.simantics.tests.modelled.ui;\r
12 \r
13 \r
14 import java.text.MessageFormat;\r
15 \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
25 \r
26 /**\r
27  * A panel with counters for the number of Runs, Errors and Failures.\r
28  */\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
36 \r
37     private final Image fErrorIcon = null;\r
38     private final Image fFailureIcon = null;\r
39 \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
47 \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
51 \r
52         addDisposeListener(new DisposeListener() {\r
53             public void widgetDisposed(DisposeEvent e) {\r
54                 disposeIcons();\r
55             }\r
56         });\r
57     }\r
58 \r
59     private void disposeIcons() {\r
60         if (fErrorIcon != null)\r
61             fErrorIcon.dispose();\r
62         if (fFailureIcon != null)\r
63             fFailureIcon.dispose();\r
64     }\r
65 \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
71         }\r
72         label.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));\r
73 \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
78 \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
84         return value;\r
85     }\r
86 \r
87     public void reset() {\r
88         setErrorValue(0);\r
89         setFailureValue(0);\r
90         setRunValue(0, 0, 0);\r
91         total= 0;\r
92     }\r
93 \r
94     public void setTotal(int value) {\r
95         total= value;\r
96     }\r
97 \r
98     public int getTotal(){\r
99         return total;\r
100     }\r
101 \r
102     public void setRunValue(int value, int ignoredCount, int assumptionFailureCount) {\r
103         String runString;\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
114         } else {\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
117         }\r
118         numberOfRuns.setText(runString);\r
119         numberOfRuns.setToolTipText(runStringTooltip);\r
120 \r
121         if (ignoredCount == 0 && ignoredCount > 0  || ignoredCount != 0 && ignoredCount == 0) {\r
122             layout();\r
123         } else if (assumptionFailedCount == 0 && assumptionFailureCount > 0 || assumptionFailedCount != 0 && assumptionFailureCount == 0) {\r
124             layout();\r
125         } else {\r
126             numberOfRuns.redraw();\r
127             redraw();\r
128         }\r
129         assumptionFailedCount= assumptionFailureCount;\r
130     }\r
131 \r
132     public void setErrorValue(int value) {\r
133         numberOfErrors.setText(Integer.toString(value));\r
134         redraw();\r
135     }\r
136 \r
137     public void setFailureValue(int value) {\r
138         numberOfFailures.setText(Integer.toString(value));\r
139         redraw();\r
140     }\r
141     \r
142     private static class Messages {\r
143 \r
144         public static String format(String message, Object object) {\r
145             return MessageFormat.format(message, new Object[] { object});\r
146         }\r
147 \r
148         public static String format(String message, Object[] objects) {\r
149             return MessageFormat.format(message, objects);\r
150         }\r
151 \r
152         private Messages() {\r
153             // Not for instantiation\r
154         }\r
155     }\r
156 }\r