Package: TraceOptionsDialog

TraceOptionsDialog

nameinstructionbranchcomplexitylinemethod
TraceOptionsDialog(Composite, int)
M: 45 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 16 C: 0
0%
M: 1 C: 0
0%
createComboReductionType()
M: 58 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 12 C: 0
0%
M: 1 C: 0
0%
createSeedSpinner()
M: 28 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
createSubsetSpinner()
M: 28 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
getPreferenceStore()
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getSeed()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getSubset()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getTraceReductionType()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
initialize()
M: 139 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 27 C: 0
0%
M: 1 C: 0
0%
loadDisplayState()
M: 41 C: 0
0%
M: 6 C: 0
0%
M: 4 C: 0
0%
M: 11 C: 0
0%
M: 1 C: 0
0%
readSeedPref()
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
readSubsetPref()
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
readTraceReductionPrefStr()
M: 10 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
selectComboReductionItem(String)
M: 31 C: 0
0%
M: 6 C: 0
0%
M: 4 C: 0
0%
M: 8 C: 0
0%
M: 1 C: 0
0%
static {...}
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * #%~
3: * Combinatorial Testing
4: * %%
5: * Copyright (C) 2008 - 2014 Overture
6: * %%
7: * This program is free software: you can redistribute it and/or modify
8: * it under the terms of the GNU General Public License as
9: * published by the Free Software Foundation, either version 3 of the
10: * License, or (at your option) any later version.
11: *
12: * This program is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: * GNU General Public License for more details.
16: *
17: * You should have received a copy of the GNU General Public
18: * License along with this program. If not, see
19: * <http://www.gnu.org/licenses/gpl-3.0.html>.
20: * #~%
21: */
22: package org.overture.ide.plugins.combinatorialtesting.views;
23:
24: import org.eclipse.core.runtime.preferences.InstanceScope;
25: import org.eclipse.jface.preference.IPreferenceStore;
26: import org.eclipse.swt.SWT;
27: import org.eclipse.swt.graphics.Point;
28: import org.eclipse.swt.layout.GridData;
29: import org.eclipse.swt.layout.GridLayout;
30: import org.eclipse.swt.widgets.Button;
31: import org.eclipse.swt.widgets.Combo;
32: import org.eclipse.swt.widgets.Composite;
33: import org.eclipse.swt.widgets.Event;
34: import org.eclipse.swt.widgets.Label;
35: import org.eclipse.swt.widgets.Listener;
36: import org.eclipse.swt.widgets.Spinner;
37: import org.eclipse.ui.preferences.ScopedPreferenceStore;
38: import org.overture.ide.plugins.combinatorialtesting.ITracesConstants;
39: import org.overture.interpreter.traces.TraceReductionType;
40:
41: public class TraceOptionsDialog extends Composite
42: {
43:         public boolean isCanceled = false;
44:         private Button buttonCancel = null;
45:         private Button buttonOk = null;
46:         private Button restorePreferences = null;
47:         private Combo comboReductionType = null;
48:         private Label label1 = null;
49:         private Label label2 = null;
50:         private Label label3 = null;
51:         private Spinner subsetSpinner = null;
52:         private Spinner seedSpinner = null;
53:         private static TraceOptionsDisplayState displayState = null;
54:
55:         public TraceOptionsDialog(Composite parent, int style)
56:         {
57:                 super(parent, style);
58:                 initialize();
59:                 loadDisplayState();
60:         }
61:
62:         private void initialize()
63:         {
64:                 GridLayout gridLayout = new GridLayout();
65:                 gridLayout.numColumns = 2;
66:
67:                 this.setLayout(gridLayout);
68:                 label1 = new Label(this, SWT.NONE);
69:                 label1.setText("Trace reduction type:");
70:                 createComboReductionType();
71:                 setSize(new Point(421, 224));
72:                 label2 = new Label(this, SWT.NONE);
73:                 label2.setText("Trace filtering seed:");
74:                 createSeedSpinner();
75:                 label3 = new Label(this, SWT.NONE);
76:                 label3.setText("Subset limitation (%):");
77:                 createSubsetSpinner();
78:                 buttonCancel = new Button(this, SWT.NONE);
79:                 buttonCancel.setText("Cancel");
80:                 buttonCancel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
81:                 buttonCancel.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter()
82:                 {
83:                         public void widgetSelected(org.eclipse.swt.events.SelectionEvent e)
84:                         {
85:                                 isCanceled = true;
86:                                 getShell().close();
87:                         }
88:                 });
89:                 buttonOk = new Button(this, SWT.NONE);
90:                 buttonOk.setText("Ok");
91:                 buttonOk.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
92:                 buttonOk.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter()
93:                 {
94:                         public void widgetSelected(org.eclipse.swt.events.SelectionEvent e)
95:                         {
96:                                 isCanceled = false;
97:                                 subset = subsetSpinner.getSelection() / 100.0F;// Float.parseFloat(comboSubset.getText().replace('%',
98:                                                                                                                                 // ' ').trim())/100;
99:                                 seed = seedSpinner.getSelection();
100:                                 reductionType = TraceReductionType.findValue(comboReductionType.getText());
101:                                 getShell().close();
102:                         }
103:                 });
104:
105:                 this.addListener(SWT.Dispose, new Listener()
106:                 {
107:
108:                         @Override
109:                         public void handleEvent(Event event)
110:                         {
111:
112:                                 // Note that the 'GUI types' are used, i.e. the spinner uses int etc.
113:                                 int subset = subsetSpinner.getSelection();
114:                                 int seed = seedSpinner.getSelection();
115:                                 String reductionType = comboReductionType.getText();
116:
117:                                 displayState = new TraceOptionsDisplayState(subset, seed, reductionType);
118:                         }
119:                 });
120:
121:                 restorePreferences = new Button(this, SWT.NONE);
122:                 restorePreferences.setText("Restore preferences");
123:                 restorePreferences.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
124:                 restorePreferences.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter()
125:                 {
126:                         public void widgetSelected(org.eclipse.swt.events.SelectionEvent e)
127:                         {
128:                                 selectComboReductionItem(readTraceReductionPrefStr());
129:                                 seedSpinner.setSelection(readSeedPref());
130:                                 subsetSpinner.setSelection(readSubsetPref());
131:                         }
132:                 });
133:         }
134:
135:         private void selectComboReductionItem(String toSelect)
136:         {
137:                 String[] reductions = comboReductionType.getItems();
138:•                if (reductions.length > 0)
139:                 {
140:                         comboReductionType.select(0);
141:
142:•                        for (int i = 0; i < reductions.length; i++)
143:                         {
144:•                                if (reductions[i].equals(toSelect))
145:                                 {
146:                                         comboReductionType.select(i);
147:                                         break;
148:                                 }
149:                         }
150:                 }
151:         }
152:
153:         /**
154:          * This method initializes comboReductionType
155:          */
156:         private void createComboReductionType()
157:         {
158:
159:                 comboReductionType = new Combo(this, SWT.READ_ONLY);
160:
161:                 String[] reductions = new String[TraceReductionType.values().length - 1];
162:                 int i = 0;
163:•                for (TraceReductionType r : TraceReductionType.values())
164:                 {
165:•                        if (r != TraceReductionType.NONE) // Removed NONE at Nicks request
166:                         {
167:                                 reductions[i] = r.getDisplayName();
168:                                 i++;
169:                         }
170:
171:                 }
172:
173:                 comboReductionType.setItems(reductions);
174:                 String reductionStr = readTraceReductionPrefStr();
175:                 selectComboReductionItem(reductionStr);
176:                 comboReductionType.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
177:         }
178:
179:         private IPreferenceStore getPreferenceStore()
180:         {
181:                 return new ScopedPreferenceStore(InstanceScope.INSTANCE, ITracesConstants.PLUGIN_ID);
182:         }
183:
184:         private String readTraceReductionPrefStr()
185:         {
186:                 int ordinal = getPreferenceStore().getInt(ITracesConstants.TRACE_REDUCTION_TYPE);
187:
188:                 return TraceReductionType.values()[ordinal].getDisplayName();
189:         }
190:
191:         private int readSeedPref()
192:         {
193:                 return getPreferenceStore().getInt(ITracesConstants.TRACE_SEED);
194:         }
195:
196:         private int readSubsetPref()
197:         {
198:                 return getPreferenceStore().getInt(ITracesConstants.TRACE_SUBSET_LIMITATION);
199:         }
200:
201:         private void createSeedSpinner()
202:         {
203:                 seedSpinner = new Spinner(this, SWT.None);
204:                 seedSpinner.setMinimum(Integer.MIN_VALUE);
205:                 seedSpinner.setMaximum(Integer.MAX_VALUE);
206:                 seedSpinner.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
207:                 seedSpinner.setSelection(readSeedPref());
208:         }
209:
210:         private void createSubsetSpinner()
211:         {
212:                 subsetSpinner = new Spinner(this, SWT.None);
213:                 subsetSpinner.setMinimum(1);
214:                 subsetSpinner.setMaximum(100);
215:                 subsetSpinner.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
216:                 subsetSpinner.setSelection(readSubsetPref());
217:         }
218:
219:         private float subset = -1;
220:         private long seed = -1;
221:         private TraceReductionType reductionType;
222:
223:         public float getSubset()
224:         {
225:                 return subset;
226:         }
227:
228:         public long getSeed()
229:         {
230:                 return seed;
231:         }
232:
233:         public TraceReductionType getTraceReductionType()
234:         {
235:                 return reductionType;
236:         }
237:
238:         private void loadDisplayState()
239:         {
240:                 // The previously typed data have higher priority than what is contained in the preference store
241:•                if (displayState != null)
242:                 {
243:                         subsetSpinner.setSelection(displayState.getSubset());
244:                         seedSpinner.setSelection(displayState.getSeed());
245:
246:                         String previousReductionType = displayState.getReductionType();
247:                         final int ITEM_COUNT = comboReductionType.getItemCount();
248:•                        for (int i = 0; i < ITEM_COUNT; i++)
249:                         {
250:                                 String currentItem = comboReductionType.getItem(i);
251:
252:•                                if (currentItem.equals(previousReductionType))
253:                                 {
254:                                         comboReductionType.select(i);
255:                                         break;
256:                                 }
257:
258:                         }
259:                 }
260:         }
261: }