Package: WizardProjectsImportPageProxy

WizardProjectsImportPageProxy

nameinstructionbranchcomplexitylinemethod
WizardProjectsImportPageProxy()
M: 22 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 10 C: 0
0%
M: 1 C: 0
0%
createPageControlsPostconfig()
M: 64 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 17 C: 0
0%
M: 1 C: 0
0%
createProjects()
M: 30 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 12 C: 0
0%
M: 1 C: 0
0%
getMainPageButton(String)
M: 15 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
getMainPageField(String)
M: 15 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
getPage()
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%
getResource(String, String)
M: 25 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 9 C: 0
0%
M: 1 C: 0
0%
invokeMainPageMethod(String)
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%
invokeMainPageMethod(String, Object[])
M: 84 C: 0
0%
M: 8 C: 0
0%
M: 5 C: 0
0%
M: 19 C: 0
0%
M: 1 C: 0
0%
performCancel()
M: 30 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 12 C: 0
0%
M: 1 C: 0
0%
performFinish()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
setBundleRelativeInputPath(String, String)
M: 26 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 6 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.pages;
23:
24: import java.io.IOException;
25: import java.lang.reflect.Field;
26: import java.lang.reflect.InvocationTargetException;
27: import java.lang.reflect.Method;
28: import java.net.MalformedURLException;
29: import java.net.URL;
30: import java.util.List;
31: import java.util.Vector;
32:
33: import org.eclipse.core.runtime.FileLocator;
34: import org.eclipse.core.runtime.Platform;
35: import org.eclipse.jface.wizard.IWizardPage;
36: import org.eclipse.swt.widgets.Button;
37: import org.eclipse.swt.widgets.Combo;
38: import org.eclipse.swt.widgets.Control;
39: import org.eclipse.swt.widgets.Text;
40: import org.eclipse.ui.internal.util.BundleUtility;
41: import org.osgi.framework.Bundle;
42: import org.overture.ide.ui.VdmUIPlugin;
43:
44: @SuppressWarnings("restriction")
45: public class WizardProjectsImportPageProxy {
46:         String inputPath = "";
47:         private IWizardPage mainPage = null;
48:
49:         public WizardProjectsImportPageProxy() {
50:                 try {
51:                         @SuppressWarnings("rawtypes")
52:                         Class theClass = Class
53:                                         .forName("org.eclipse.ui.internal.wizards.datatransfer.WizardProjectsImportPage");
54:                         mainPage = (IWizardPage) theClass.newInstance();
55:                 } catch (Exception e) {
56:                         VdmUIPlugin
57:                                         .log("Failed to create instance: org.eclipse.ui.internal.wizards.datatransfer.WizardProjectsImportPage",
58:                                                         e);
59:                 }
60:         }
61:
62:         public IWizardPage getPage() {
63:                 return this.mainPage;
64:         }
65:
66:         public void performCancel() {
67:                 try {
68:                         invokeMainPageMethod("performCancel");
69:                 } catch (NoSuchMethodException e) {
70:                         VdmUIPlugin.log("Failed to invoke performCancel on WizardProjectsImportPage", e);
71:                 } catch (SecurityException e) {
72:                         VdmUIPlugin.log("Failed to invoke performCancel on WizardProjectsImportPage", e);
73:                 } catch (IllegalAccessException e) {
74:                         VdmUIPlugin.log("Failed to invoke performCancel on WizardProjectsImportPage", e);
75:                 } catch (IllegalArgumentException e) {
76:                         VdmUIPlugin.log("Failed to invoke performCancel on WizardProjectsImportPage", e);
77:                 } catch (InvocationTargetException e) {
78:                         VdmUIPlugin.log("Failed to invoke performCancel on WizardProjectsImportPage", e);
79:                 }
80:         }
81:
82:         public void performFinish() {
83:                 this.createProjects();
84:         }
85:
86:         public void createProjects() {
87:                 try {
88:                         invokeMainPageMethod("createProjects");
89:                 } catch (NoSuchMethodException e) {
90:                         VdmUIPlugin.log("Failed to invoke createProjects on WizardProjectsImportPage", e);
91:                 } catch (SecurityException e) {
92:                         VdmUIPlugin.log("Failed to invoke createProjects on WizardProjectsImportPage", e);
93:                 } catch (IllegalAccessException e) {
94:                         VdmUIPlugin.log("Failed to invoke createProjects on WizardProjectsImportPage", e);
95:                 } catch (IllegalArgumentException e) {
96:                         VdmUIPlugin.log("Failed to invoke createProjects on WizardProjectsImportPage", e);
97:                 } catch (InvocationTargetException e) {
98:                         VdmUIPlugin.log("Failed to invoke createProjects on WizardProjectsImportPage", e);
99:                 }
100:         }
101:
102:         /**
103:          * This initializes the page with the graphical selection and sets the input
104:          * path. The input path must be set prior to the call to this method
105:          */
106:         public void createPageControlsPostconfig() {
107:                 try {
108:                         getMainPageButton("projectFromArchiveRadio").setSelection(true);
109:                         getMainPageButton("projectFromArchiveRadio").setEnabled(false);
110:                         getMainPageButton("projectFromDirectoryRadio").setSelection(false);
111:                         getMainPageButton("projectFromDirectoryRadio").setEnabled(false);
112:
113:                         getMainPageButton("browseDirectoriesButton").setEnabled(false);
114:                         getMainPageButton("browseArchivesButton").setEnabled(false);
115:
116:                         invokeMainPageMethod("archiveRadioSelected");
117:
118:                         Control pathfield = getMainPageField("archivePathField");
119:•                        if (pathfield instanceof Text) {
120:                                 ((Text) pathfield).setText(this.inputPath);
121:•                        } else if (pathfield instanceof Combo) {
122:                                 ((Combo) pathfield).setText(this.inputPath);
123:                         }
124:
125:                         pathfield.setEnabled(false);
126:                 } catch (Exception e) {
127:                         VdmUIPlugin
128:                                         .log("Failed to configure throug reflection WizardProjectsImportPage",
129:                                                         e);
130:                 }
131:         }
132:
133:         public void setBundleRelativeInputPath(String bundleId, String relativePath)
134:                         throws IOException {
135:                 URL examplesUrl = getResource(bundleId, relativePath);
136:                 this.inputPath = FileLocator.resolve(examplesUrl).getPath();
137:                 try
138:                 {
139:                         invokeMainPageMethod("updateProjectsList",this.inputPath);
140:                 } catch (Exception e)
141:                 {
142:                         VdmUIPlugin.log("Failed to update project list from path",        e);
143:                 }
144:         }
145:
146:         public static URL getResource(String pluginId, String path) {
147:                 // if the bundle is not ready then there is no image
148:                 Bundle bundle = Platform.getBundle(pluginId);
149:•                if (!BundleUtility.isReady(bundle)) {
150:                         return null;
151:                 }
152:
153:                 // look for the image (this will check both the plugin and fragment
154:                 // folders
155:                 URL fullPathString = BundleUtility.find(bundle, path);
156:•                if (fullPathString == null) {
157:                         try {
158:                                 fullPathString = new URL(path);
159:                         } catch (MalformedURLException e) {
160:                                 return null;
161:                         }
162:                 }
163:
164:                 return fullPathString;
165:
166:         }
167:
168:         // utils
169:         private Button getMainPageButton(String field) throws NoSuchFieldException,
170:                         SecurityException, IllegalArgumentException, IllegalAccessException {
171:                 Field f = mainPage.getClass().getDeclaredField(field);
172:                 f.setAccessible(true);
173:                 return (Button) f.get(mainPage);
174:         }
175:
176:         private Control getMainPageField(String field) throws NoSuchFieldException,
177:                         SecurityException, IllegalArgumentException, IllegalAccessException {
178:                 Field f = mainPage.getClass().getDeclaredField(field);
179:                 f.setAccessible(true);
180:                 return (Control) f.get(mainPage);
181:         }
182:
183:         private Object invokeMainPageMethod(String method, Object... args)
184:                         throws NoSuchMethodException, SecurityException,
185:                         IllegalAccessException, IllegalArgumentException,
186:                         InvocationTargetException {
187:                 Method m = null;
188:
189:•                if (args.length == 0) {
190:                         m = mainPage.getClass().getDeclaredMethod(method);
191:                         args = null;
192:                 } else {
193:                         List<Class<?>> parameterTypes = new Vector<Class<?>>();
194:•                        for (Object object : args) {
195:•                                if(object instanceof Boolean)
196:                                 {
197:                                         parameterTypes.add(boolean.class);
198:                                 }else{
199:                                 parameterTypes.add(object.getClass());
200:                                 }
201:                         }
202:                         try{
203:                                 m = mainPage.getClass().getMethod(method,
204:                                                 parameterTypes.toArray(new Class<?>[] {}));
205:                         }catch(NoSuchMethodException e)
206:                         {;}
207:•                        if(m==null)
208:                         {
209:                         m = mainPage.getClass().getDeclaredMethod(method,
210:                                         parameterTypes.toArray(new Class<?>[] {}));
211:                         }
212:                 }
213:                 m.setAccessible(true);
214:                 return m.invoke(mainPage, args);
215:         }
216:
217:         private Object invokeMainPageMethod(String method)
218:                         throws NoSuchMethodException, SecurityException,
219:                         IllegalAccessException, IllegalArgumentException,
220:                         InvocationTargetException {
221:                 return invokeMainPageMethod(method, new Object[] {});
222:         }
223: }