Package: VdmNewProjectWizard

VdmNewProjectWizard

nameinstructionbranchcomplexitylinemethod
VdmNewProjectWizard()
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%
addNature(IProject, String)
M: 38 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 10 C: 0
0%
M: 1 C: 0
0%
addPages()
M: 43 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%
performFinish()
M: 29 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 10 C: 0
0%
M: 1 C: 0
0%
setVdmBuilder(IProject)
M: 16 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 5 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.wizard;
23:
24: import org.eclipse.core.resources.IProject;
25: import org.eclipse.core.resources.IProjectDescription;
26: import org.eclipse.core.runtime.Assert;
27: import org.eclipse.core.runtime.CoreException;
28: import org.eclipse.core.runtime.IProgressMonitor;
29: import org.eclipse.ui.wizards.newresource.BasicNewProjectResourceWizard;
30: import org.overture.ast.lex.Dialect;
31: import org.overture.config.Release;
32: import org.overture.ide.core.resources.IVdmProject;
33: import org.overture.ide.core.utility.LanguageManager;
34: import org.overture.ide.ui.wizard.pages.LibraryIncludePage;
35: import org.overture.ide.ui.wizard.pages.LibraryUtil;
36:
37: /*
38: * Abstract wizard for creating a VDM project
39: */
40: public abstract class VdmNewProjectWizard extends BasicNewProjectResourceWizard
41: {
42:
43:         private LibraryIncludePage _pageTwo;
44:         private static final String WIZARD_NAME = "VDM New Project Wizard";
45:
46:         public VdmNewProjectWizard()
47:         {
48:                 setWindowTitle(WIZARD_NAME);
49:                 getPageName();
50:                 getPageTitle();
51:                 getPageDescription();
52:         }
53:
54:         @Override
55:         public void addPages()
56:         {
57:                 super.addPages();
58:                 getPages()[0].setTitle(getPageTitle());
59:                 getPages()[0].setDescription(getPageDescription());
60:                 Dialect d = LanguageManager.getInstance().getLanguage(getNature()).getDialect();
61:•                _pageTwo = new LibraryIncludePage("Library Include",d == Dialect.VDM_PP || d==Dialect.VDM_RT,null);
62:                 addPage(_pageTwo);
63:         }
64:
65:         @Override
66:         public boolean performFinish()
67:         {
68:
69:                 boolean ok = super.performFinish();
70:                 
71:                 IProject prj = getNewProject();
72:
73:•                if (prj != null)
74:                 {
75:                         try
76:                         {
77:                                 setVdmBuilder(prj);
78:                                 IVdmProject p = (IVdmProject) prj.getAdapter(IVdmProject.class);
79:                                 LibraryUtil.createSelectedLibraries(p,_pageTwo.getLibrarySelection());
80:
81:                         } catch (CoreException e)
82:                         {
83:                                 // TODO Auto-generated catch block
84:                                 e.printStackTrace();
85:                                 return false;
86:                         }
87:                 }
88:
89:                 return ok;
90:         }
91:
92:         private void setVdmBuilder(IProject prj) throws CoreException
93:         {
94:
95:                 addNature(prj, getNature());
96:                 IVdmProject p = (IVdmProject) prj.getAdapter(IVdmProject.class);
97:                 Assert.isNotNull(p, "Project could not be adapted");
98:                 p.setBuilder(Release.DEFAULT);
99:         }
100:
101:         private static void addNature(IProject project, String nature)
102:                         throws CoreException
103:         {
104:•                if (!project.hasNature(nature))
105:                 {
106:                         IProjectDescription description = project.getDescription();
107:                         String[] prevNatures = description.getNatureIds();
108:                         String[] newNatures = new String[prevNatures.length + 1];
109:                         System.arraycopy(prevNatures, 0, newNatures, 0, prevNatures.length);
110:                         newNatures[prevNatures.length] = nature;
111:                         description.setNatureIds(newNatures);
112:
113:                         IProgressMonitor monitor = null;
114:                         project.setDescription(description, monitor);
115:                 }
116:         }
117:
118:         protected abstract String getPageName();
119:
120:         protected abstract String getPageTitle();
121:
122:         protected abstract String getPageDescription();
123:
124:         protected abstract String getNature();
125:
126: }