Package: VdmLanguagePropertyPage

VdmLanguagePropertyPage

nameinstructionbranchcomplexitylinemethod
VdmLanguagePropertyPage()
M: 15 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
createContents(Composite)
M: 39 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 10 C: 0
0%
M: 1 C: 0
0%
createGroup(String, Composite)
M: 32 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 9 C: 0
0%
M: 1 C: 0
0%
createLanguagePanel(Composite)
M: 95 C: 0
0%
M: 8 C: 0
0%
M: 5 C: 0
0%
M: 19 C: 0
0%
M: 1 C: 0
0%
createTypeCheckGroup(Composite)
M: 43 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 8 C: 0
0%
M: 1 C: 0
0%
getSelectedProject()
M: 47 C: 0
0%
M: 10 C: 0
0%
M: 6 C: 0
0%
M: 13 C: 0
0%
M: 1 C: 0
0%
performOk()
M: 34 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * #%~
3: * org.overture.ide.ui
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.ui.property;
23:
24: import org.eclipse.core.resources.IProject;
25: import org.eclipse.core.runtime.Assert;
26: import org.eclipse.core.runtime.CoreException;
27: import org.eclipse.jface.viewers.ISelection;
28: import org.eclipse.jface.viewers.IStructuredSelection;
29: import org.eclipse.jface.viewers.ITreeSelection;
30: import org.eclipse.swt.SWT;
31: import org.eclipse.swt.layout.GridData;
32: import org.eclipse.swt.layout.GridLayout;
33: import org.eclipse.swt.widgets.Button;
34: import org.eclipse.swt.widgets.Combo;
35: import org.eclipse.swt.widgets.Composite;
36: import org.eclipse.swt.widgets.Control;
37: import org.eclipse.swt.widgets.Group;
38: import org.eclipse.swt.widgets.Label;
39: import org.eclipse.ui.IWorkbenchPropertyPage;
40: import org.eclipse.ui.dialogs.PropertyPage;
41: import org.eclipse.ui.internal.WorkbenchPlugin;
42: import org.overture.config.Release;
43: import org.overture.ide.core.resources.IVdmProject;
44: import org.overture.ide.ui.utility.VdmTypeCheckerUi;
45:
46: @SuppressWarnings("restriction")
47: public class VdmLanguagePropertyPage extends PropertyPage implements
48:                 IWorkbenchPropertyPage
49: {
50:         private Combo comboBoxLanguageVersion = null;
51:         private Button checkBoxSuppressWarnings = null;
52:         private Button checkBoxUseStrictLetDef = null;
53:
54:         private IVdmProject project = null;
55:
56:         private Group typeGroup;
57:
58:         public VdmLanguagePropertyPage()
59:         {
60:                 super();
61:         }
62:
63:         @Override
64:         protected Control createContents(Composite parent)
65:         {
66:                 Composite comp = new Composite(parent, SWT.NONE);
67:
68:                 comp.setLayout(new GridLayout(1, true));
69:                 comp.setFont(parent.getFont());
70:
71:                 IProject p = getSelectedProject();
72:
73:•                if (p != null)
74:                 {
75:                         this.project = (IVdmProject) p.getAdapter(IVdmProject.class);
76:                         Assert.isNotNull(this.project, "Project could not be adapted");
77:
78:                         createLanguagePanel(comp);
79:                         createTypeCheckGroup(comp);
80:                 }
81:                 return comp;
82:         }
83:
84:         private Group createGroup(String name, Composite comp)
85:         {
86:                 Group group = new Group(comp, SWT.NONE);
87:                 group.setText(name);
88:                 GridData gd = new GridData(GridData.FILL_HORIZONTAL);
89:
90:                 group.setLayoutData(gd);
91:
92:                 GridLayout layout = new GridLayout();
93:                 layout.makeColumnsEqualWidth = false;
94:                 layout.numColumns = 3;
95:                 group.setLayout(layout);
96:                 return group;
97:         }
98:
99:         void createLanguagePanel(Composite composite)
100:         {
101:                 Group languageOptionsGroup = createGroup("Language options", composite);
102:
103:                 Label mylabel = new Label(languageOptionsGroup, SWT.NONE);
104:                 mylabel.setLayoutData(new GridData());
105:                 mylabel.setText("Language version");
106:                 comboBoxLanguageVersion = new Combo(languageOptionsGroup, SWT.READ_ONLY);
107:
108:                 String[] languageTypes = new String[Release.values().length];
109:                 int i = 0;
110:•                for (Release r : Release.values())
111:                 {
112:                         languageTypes[i] = r.toString();
113:                         i++;
114:                 }
115:
116:                 comboBoxLanguageVersion.setItems(languageTypes);
117:                 comboBoxLanguageVersion.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
118:                 try
119:                 {
120:•                        if (project.getLanguageVersion() != null)
121:•                                for (int j = 0; j < languageTypes.length; j++)
122:                                 {
123:•                                        if (project.getLanguageVersion().toString().equals(languageTypes[j]))
124:                                                 comboBoxLanguageVersion.select(j);
125:                                 }
126:                 } catch (CoreException e)
127:                 {
128:                         // TODO Auto-generated catch block
129:                         e.printStackTrace();
130:                 }
131:         }
132:
133:         void createTypeCheckGroup(Composite comp)
134:         {
135:                 typeGroup = createGroup("Type checking", comp);
136:
137:                 checkBoxSuppressWarnings = new Button(typeGroup, SWT.CHECK);
138:                 checkBoxSuppressWarnings.setText("Suppress warnings");
139:                 checkBoxSuppressWarnings.setSelection(project.hasSuppressWarnings());
140:                 
141:                 checkBoxUseStrictLetDef = new Button(typeGroup, SWT.CHECK);
142:                 checkBoxUseStrictLetDef.setText("Strict type checking");
143:                 checkBoxUseStrictLetDef.setSelection(project.hasUseStrictLetDef());
144:
145:         }
146:
147:         @SuppressWarnings( { "deprecation" })
148:         public static IProject getSelectedProject()
149:         {
150:                 ISelection selectedItem = WorkbenchPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage().getSelection();
151:                 IProject selectedProject = null;
152:
153:•                if (selectedItem instanceof ITreeSelection)
154:                 {
155:                         ITreeSelection selection = (ITreeSelection) selectedItem;
156:•                        if (selection.getPaths().length > 0)
157:                         {
158:                                 Object project = selection.getPaths()[0].getLastSegment();
159:•                                if (project instanceof IProject)
160:                                         selectedProject = (IProject) project;
161:
162:                         }
163:•                } else if (selectedItem instanceof IStructuredSelection)
164:                 {
165:                         IStructuredSelection selection = (IStructuredSelection) selectedItem;
166:•                        if (selection.getFirstElement() instanceof IProject)
167:                                 selectedProject = (IProject) selection.getFirstElement();
168:                 }
169:
170:                 return selectedProject;
171:         }
172:
173:         @Override
174:         public boolean performOk()
175:         {
176:                 try
177:                 {
178:                         project.setBuilder(Release.lookup(comboBoxLanguageVersion.getText()));
179:                         project.setSuppressWarnings(checkBoxSuppressWarnings.getSelection());
180:                         project.setUseStrictLetDef(checkBoxUseStrictLetDef.getSelection());
181:
182:                         VdmTypeCheckerUi.typeCheck(getShell(), project);
183:                 } catch (CoreException e)
184:                 {
185:                         // TODO Auto-generated catch block
186:                         e.printStackTrace();
187:                 }
188:                 return super.performOk();
189:         }
190: }