Package: OpenVdmToolsProjectCommandHandler

OpenVdmToolsProjectCommandHandler

nameinstructionbranchcomplexitylinemethod
OpenVdmToolsProjectCommandHandler()
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%
execute(ExecutionEvent)
M: 56 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 13 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * #%~
3: * org.overture.ide.plugins.csk
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.csk.handlers;
23:
24: import java.io.File;
25: import java.io.IOException;
26: import java.util.List;
27: import java.util.Vector;
28:
29: import org.eclipse.core.commands.AbstractHandler;
30: import org.eclipse.core.commands.ExecutionEvent;
31: import org.eclipse.core.commands.ExecutionException;
32: import org.eclipse.core.resources.IContainer;
33: import org.eclipse.core.resources.IProject;
34: import org.eclipse.core.resources.IResource;
35: import org.eclipse.core.runtime.CoreException;
36: import org.eclipse.core.runtime.IProgressMonitor;
37: import org.eclipse.core.runtime.IStatus;
38: import org.eclipse.core.runtime.Status;
39: import org.eclipse.jface.viewers.IStructuredSelection;
40: import org.eclipse.ui.handlers.HandlerUtil;
41: import org.eclipse.ui.progress.UIJob;
42: import org.overture.ide.core.resources.IVdmProject;
43: import org.overture.ide.core.resources.IVdmSourceUnit;
44: import org.overture.ide.plugins.csk.Activator;
45: import org.overture.ide.plugins.csk.internal.VdmTools;
46:
47: public class OpenVdmToolsProjectCommandHandler extends AbstractHandler
48: {
49:
50:         public Object execute(ExecutionEvent event) throws ExecutionException
51:         {
52:                 IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getCurrentSelectionChecked(event);
53:                 final IContainer c = (IContainer) selection.getFirstElement();
54:
55:                 final IProject project = c.getProject();
56:                 
57:                 final IVdmProject vdmProject = (IVdmProject) project.getAdapter(IVdmProject.class);
58:                 
59:•                if (vdmProject != null)
60:                 {
61:                         final List<File> files = new Vector<File>();
62:
63:                         try
64:                         {
65:•                                for (IVdmSourceUnit source : vdmProject.getSpecFiles())
66:                                 {
67:                                         files.add(source.getSystemFile());
68:                                 }
69:
70:                                 UIJob job = new UIJob("Create VDM Tools Project")
71:                                 {
72:                                         
73:                                         @Override
74:                                         public IStatus runInUIThread(IProgressMonitor monitor)
75:                                         {
76:                                                 try
77:                                                 {
78:                                                         new VdmTools().createProject(this.getDisplay().getActiveShell(), vdmProject, files);
79:                                                         project.refreshLocal(IResource.DEPTH_INFINITE, null);
80:                                                 } catch (IOException e)
81:                                                 {
82:                                                         return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Failed to open VDM Tools",e);
83:                                                 } catch (CoreException e)
84:                                                 {
85:                                                         return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Failed to open VDM Tools",e);
86:                                                 }
87:                                                 return Status.OK_STATUS;
88:                                         }
89:                                 };
90:                                 job.schedule();
91:                                                                 
92:                                 
93:
94:                         } catch (CoreException e)
95:                         {
96:                                 // TODO Auto-generated catch block
97:                                 e.printStackTrace();
98:                         }
99:                 }
100:                 
101:                 return null;
102:         }
103:
104: }