Package: SelectDialectWizardPage$1

SelectDialectWizardPage$1

nameinstructionbranchcomplexitylinemethod
widgetDefaultSelected(SelectionEvent)
M: 1 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
widgetSelected(SelectionEvent)
M: 72 C: 0
0%
M: 10 C: 0
0%
M: 6 C: 0
0%
M: 9 C: 0
0%
M: 1 C: 0
0%
{...}
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%

Coverage

1: /*
2: * #%~
3: * org.overture.ide.help
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.help.wizard;
23:
24: import java.util.Arrays;
25: import java.util.HashSet;
26: import java.util.Set;
27:
28: import org.eclipse.jface.wizard.WizardPage;
29: import org.eclipse.swt.SWT;
30: import org.eclipse.swt.events.SelectionEvent;
31: import org.eclipse.swt.events.SelectionListener;
32: import org.eclipse.swt.graphics.Point;
33: import org.eclipse.swt.layout.GridLayout;
34: import org.eclipse.swt.widgets.Button;
35: import org.eclipse.swt.widgets.Composite;
36: import org.eclipse.swt.widgets.Label;
37:
38: public class SelectDialectWizardPage extends WizardPage
39: {
40:         public interface DialectSelectedHandler
41:         {
42:                 public void dialectSelected(String dialect);
43:         }
44:
45:         private DialectSelectedHandler handler;
46:         private Button vdmslbuttonRadio;
47:         private Button vdmppbuttonRadio;
48:         private Button vdmrtbuttonRadio;
49:         private Set<Button> radioButtons;
50:
51:         protected SelectDialectWizardPage(DialectSelectedHandler handler)
52:         {
53:                 super("Dialect Selectio");
54:                 this.handler = handler;
55:         }
56:
57:         @Override
58:         public void createControl(Composite parent)
59:         {
60:                 SelectionListener selectionChangeListner = new SelectionListener()
61:                 {
62:
63:                         @Override
64:                         public void widgetSelected(SelectionEvent e)
65:                         {
66:•                                for (Button b : new Button[] { vdmslbuttonRadio,
67:                                                 vdmppbuttonRadio, vdmrtbuttonRadio })
68:                                 {
69:•                                        if (radioButtons.contains(e.widget) && !e.widget.equals(b))
70:                                         {
71:                                                 b.setSelection(false);
72:                                         } else
73:                                         {
74:                                                 b.setSelection(true);
75:                                         }
76:                                 }
77:•                                if(e.widget instanceof Button &&((Button)e.widget).getSelection())
78:                                 {
79:                                         handler.dialectSelected(((Button)e.widget).getText());
80:                                 }
81:                         }
82:
83:                         @Override
84:                         public void widgetDefaultSelected(SelectionEvent e)
85:                         {
86:
87:                         }
88:                 };
89:
90:                 Composite c = new Composite(parent, SWT.NONE);
91:                 Label label = new Label(c, SWT.NONE);
92:                 label.setText("Select dialect");
93:                 vdmslbuttonRadio = new Button(c, SWT.RADIO);
94:                 vdmslbuttonRadio.setText("VDM-SL");
95:                 vdmslbuttonRadio.addSelectionListener(selectionChangeListner);
96:                 vdmslbuttonRadio.setSelection(true);
97:
98:                 vdmppbuttonRadio = new Button(c, SWT.RADIO);
99:                 vdmppbuttonRadio.setText("VDM-PP");
100:                 vdmppbuttonRadio.addSelectionListener(selectionChangeListner);
101:
102:                 vdmrtbuttonRadio = new Button(c, SWT.RADIO);
103:                 vdmrtbuttonRadio.setText("VDM-RT");
104:                 vdmrtbuttonRadio.addSelectionListener(selectionChangeListner);
105:                 radioButtons = new HashSet<Button>(Arrays.asList(new Button[] {
106:                                 vdmslbuttonRadio, vdmppbuttonRadio, vdmrtbuttonRadio }));
107:                 c.setSize(new Point(300, 200));
108:                 c.setLayout(new GridLayout());
109:                 setControl(c);
110:         }
111:
112:         @Override
113:         public String getTitle()
114:         {
115:                 return "Select Dialect";
116:         }
117:
118:         public String getSelectedDialect()
119:         {
120:                 for (Button b : this.radioButtons)
121:                 {
122:                         if (b.getSelection())
123:                         {
124:                                 return b.getText();
125:                         }
126:                 }
127:                 return null;
128:         }
129:
130:         @Override
131:         public boolean isPageComplete()
132:         {
133:                 if (handler != null)
134:                 {
135:                         handler.dialectSelected(getSelectedDialect());
136:                 }
137:                 return super.isPageComplete();
138:         }
139:
140: }