|
Lines 12-26
Link Here
|
| 12 |
|
12 |
|
| 13 |
import java.io.StringWriter; |
13 |
import java.io.StringWriter; |
| 14 |
import java.lang.reflect.InvocationTargetException; |
14 |
import java.lang.reflect.InvocationTargetException; |
|
|
15 |
import java.util.ArrayList; |
| 16 |
import java.util.Iterator; |
| 17 |
import java.util.List; |
| 15 |
|
18 |
|
| 16 |
import org.eclipse.core.resources.IFile; |
19 |
import org.eclipse.core.resources.IFile; |
| 17 |
import org.eclipse.core.resources.IResource; |
20 |
import org.eclipse.core.resources.IResource; |
| 18 |
import org.eclipse.core.resources.ResourcesPlugin; |
21 |
import org.eclipse.core.resources.ResourcesPlugin; |
|
|
22 |
import org.eclipse.core.runtime.CoreException; |
| 23 |
import org.eclipse.core.runtime.IProgressMonitor; |
| 19 |
import org.eclipse.core.runtime.IStatus; |
24 |
import org.eclipse.core.runtime.IStatus; |
| 20 |
import org.eclipse.core.runtime.Status; |
25 |
import org.eclipse.core.runtime.Status; |
| 21 |
import org.eclipse.jdt.core.IJavaProject; |
26 |
import org.eclipse.jdt.core.IJavaProject; |
|
|
27 |
import org.eclipse.jdt.core.IMethod; |
| 28 |
import org.eclipse.jdt.core.IPackageFragment; |
| 22 |
import org.eclipse.jdt.core.IPackageFragmentRoot; |
29 |
import org.eclipse.jdt.core.IPackageFragmentRoot; |
| 23 |
import org.eclipse.jdt.core.IType; |
30 |
import org.eclipse.jdt.core.IType; |
|
|
31 |
import org.eclipse.jdt.core.ITypeHierarchy; |
| 24 |
import org.eclipse.jdt.core.JavaModelException; |
32 |
import org.eclipse.jdt.core.JavaModelException; |
| 25 |
import org.eclipse.jdt.junit.wizards.NewTestCaseWizardPageOne; |
33 |
import org.eclipse.jdt.junit.wizards.NewTestCaseWizardPageOne; |
| 26 |
import org.eclipse.jdt.junit.wizards.NewTestCaseWizardPageTwo; |
34 |
import org.eclipse.jdt.junit.wizards.NewTestCaseWizardPageTwo; |
|
Lines 32-44
Link Here
|
| 32 |
import org.eclipse.jst.server.ui.internal.JavaServerUIPlugin; |
40 |
import org.eclipse.jst.server.ui.internal.JavaServerUIPlugin; |
| 33 |
import org.eclipse.jst.server.ui.internal.Messages; |
41 |
import org.eclipse.jst.server.ui.internal.Messages; |
| 34 |
import org.eclipse.osgi.util.NLS; |
42 |
import org.eclipse.osgi.util.NLS; |
|
|
43 |
import org.eclipse.swt.SWT; |
| 44 |
import org.eclipse.swt.layout.GridData; |
| 45 |
import org.eclipse.swt.layout.GridLayout; |
| 46 |
import org.eclipse.swt.widgets.Button; |
| 35 |
import org.eclipse.swt.widgets.Composite; |
47 |
import org.eclipse.swt.widgets.Composite; |
|
|
48 |
import org.eclipse.swt.widgets.Control; |
| 36 |
import org.eclipse.swt.widgets.Display; |
49 |
import org.eclipse.swt.widgets.Display; |
|
|
50 |
import org.eclipse.swt.widgets.Label; |
| 37 |
import org.eclipse.swt.widgets.Shell; |
51 |
import org.eclipse.swt.widgets.Shell; |
| 38 |
import org.eclipse.ui.*; |
52 |
import org.eclipse.ui.INewWizard; |
|
|
53 |
import org.eclipse.ui.IWorkbench; |
| 54 |
import org.eclipse.ui.IWorkbenchPage; |
| 55 |
import org.eclipse.ui.IWorkbenchWindow; |
| 56 |
import org.eclipse.ui.PartInitException; |
| 57 |
import org.eclipse.ui.PlatformUI; |
| 39 |
import org.eclipse.ui.actions.WorkspaceModifyDelegatingOperation; |
58 |
import org.eclipse.ui.actions.WorkspaceModifyDelegatingOperation; |
| 40 |
import org.eclipse.ui.ide.IDE; |
59 |
import org.eclipse.ui.ide.IDE; |
| 41 |
import org.eclipse.ui.wizards.newresource.BasicNewResourceWizard; |
60 |
import org.eclipse.ui.wizards.newresource.BasicNewResourceWizard; |
|
|
61 |
import org.eclipse.wst.common.project.facet.core.IFacetedProject; |
| 62 |
import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion; |
| 63 |
import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager; |
| 64 |
|
| 42 |
/** |
65 |
/** |
| 43 |
* |
66 |
* |
| 44 |
*/ |
67 |
*/ |
|
Lines 46-68
Link Here
|
| 46 |
private static final String SUPERCLASS_NAME = "org.apache.cactus.ServletTestCase"; //$NON-NLS-1$ |
69 |
private static final String SUPERCLASS_NAME = "org.apache.cactus.ServletTestCase"; //$NON-NLS-1$ |
| 47 |
|
70 |
|
| 48 |
protected static final String[] CLASSES_TO_CHECK = { |
71 |
protected static final String[] CLASSES_TO_CHECK = { |
| 49 |
"org.apache.cactus.ServletTestCase", "junit.framework.TestCase", |
72 |
"org.apache.cactus.ServletTestCase", "junit.framework.TestCase", //$NON-NLS-1$ //$NON-NLS-2$ |
| 50 |
"org.apache.commons.logging.Log", "org.aspectj.lang.JoinPoint", |
73 |
"org.apache.commons.logging.Log", "org.aspectj.lang.JoinPoint", //$NON-NLS-1$ //$NON-NLS-2$ |
| 51 |
"org.apache.commons.httpclient.HttpClient" }; |
74 |
"org.apache.commons.httpclient.HttpClient" }; //$NON-NLS-1$ |
| 52 |
|
75 |
|
| 53 |
protected static final String[] REQUIRED_LIBRARIES = { |
76 |
protected static final String[] REQUIRED_LIBRARIES = { |
| 54 |
"cactus-1.7.jar", "junit-3.8.1.jar", "aspectjrt-1.2.1.jar", |
77 |
"cactus-1.7.2.jar", "junit-3.8.1.jar", "aspectjrt-1.2.1.jar", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
| 55 |
"commons-logging-1.0.4.jar", "commons-httpclient-2.0.2.jar" }; |
78 |
"commons-logging-1.0.4.jar", "commons-httpclient-2.0.2.jar" }; //$NON-NLS-1$ //$NON-NLS-2$ |
| 56 |
|
79 |
|
| 57 |
private IWorkbench fWorkbench; |
80 |
private IWorkbench fWorkbench; |
| 58 |
private IStructuredSelection fSelection; |
81 |
private IStructuredSelection fSelection; |
| 59 |
private NewTestCaseWizardPageTwo fPage2; |
82 |
private NewTestCaseWizardPageTwo fPage2; |
| 60 |
private NewTestCaseWizardPageOne fPage1; |
83 |
private NewTestCaseWizardPageOne fPage1; |
| 61 |
|
84 |
|
| 62 |
public NewServletTestCaseWizard() { |
85 |
public NewServletTestCaseWizard() { |
| 63 |
super(); |
86 |
super(); |
| 64 |
setWindowTitle(Messages.NewServletTestCaseWizard_WindowTitle); |
87 |
setWindowTitle(Messages.NewServletTestCaseWizard_WindowTitle); |
| 65 |
setDefaultPageImageDescriptor(ImageResource.getImageDescriptor(ImageResource.IMG_WIZ_CACTUS_TEST)); |
88 |
setDefaultPageImageDescriptor(ImageResource.getImageDescriptor(ImageResource.IMG_WIZ_CACTUS_TEST)); |
|
|
89 |
|
| 90 |
|
| 66 |
} |
91 |
} |
| 67 |
|
92 |
|
| 68 |
public void init(IWorkbench workbench, IStructuredSelection selection) { |
93 |
public void init(IWorkbench workbench, IStructuredSelection selection) { |
|
Lines 73-118
Link Here
|
| 73 |
public void addPages() { |
98 |
public void addPages() { |
| 74 |
super.addPages(); |
99 |
super.addPages(); |
| 75 |
fPage2 = new NewTestCaseWizardPageTwo(); |
100 |
fPage2 = new NewTestCaseWizardPageTwo(); |
| 76 |
fPage1 = new NewTestCaseWizardPageOne(fPage2) { |
101 |
fPage1 = new CactusPage1(fPage2); |
| 77 |
public void createControl(Composite parent) { |
|
|
| 78 |
super.createControl(parent); |
| 79 |
setSuperClass(SUPERCLASS_NAME, true); |
| 80 |
} |
| 81 |
|
| 82 |
protected IStatus validateIfJUnitProject() { |
| 83 |
IPackageFragmentRoot root = getPackageFragmentRoot(); |
| 84 |
if (root == null) |
| 85 |
return Status.OK_STATUS; |
| 86 |
|
| 87 |
IJavaProject project = root.getJavaProject(); |
| 88 |
try { |
| 89 |
for (int i = 0; i < CLASSES_TO_CHECK.length; i++) { |
| 90 |
IType type = project.findType(CLASSES_TO_CHECK[i]); |
| 91 |
if (type == null) { |
| 92 |
MessageDialog.openError(getShell(), |
| 93 |
Messages.NewServletTestCaseWizard_ErrorMessageTitleMissingLibrary, |
| 94 |
NLS.bind(Messages.NewServletTestCaseWizard_ErrorMessageMissingLibrary, REQUIRED_LIBRARIES)); |
| 95 |
return Status.OK_STATUS; |
| 96 |
} |
| 97 |
} |
| 98 |
} catch (JavaModelException e) { |
| 99 |
JavaServerUIPlugin.log(e); |
| 100 |
} |
| 101 |
return Status.OK_STATUS; |
| 102 |
} |
| 103 |
}; |
| 104 |
addPage(fPage1); |
102 |
addPage(fPage1); |
| 105 |
fPage1.init(getSelection()); |
103 |
fPage1.init(getSelection()); |
| 106 |
addPage(fPage2); |
104 |
addPage(fPage2); |
| 107 |
|
105 |
|
| 108 |
} |
106 |
} |
|
|
107 |
|
| 108 |
private class CactusPage1 extends NewTestCaseWizardPageOne |
| 109 |
{ |
| 110 |
|
| 111 |
private Button fBeginButton; |
| 112 |
private Button fEndButton; |
| 113 |
private Button fBeginXXXButton; |
| 114 |
private Button fEndXXXButton; |
| 115 |
private Composite fCactusButtonComposite; |
| 116 |
|
| 117 |
public CactusPage1(NewTestCaseWizardPageTwo page2) { |
| 118 |
super(page2); |
| 119 |
|
| 120 |
} |
| 121 |
|
| 122 |
public void init(IStructuredSelection selection) { |
| 123 |
super.init(selection); |
| 124 |
} |
| 125 |
|
| 126 |
public void createControl(Composite parent) { |
| 127 |
super.createControl(parent); |
| 128 |
setSuperClass(SUPERCLASS_NAME, true); |
| 129 |
|
| 130 |
|
| 131 |
} |
| 132 |
|
| 133 |
protected IStatus superClassChanged() { |
| 134 |
String superClassName= getSuperClass(); |
| 135 |
if (superClassName == null || superClassName.trim().equals("")) { //$NON-NLS-1$ |
| 136 |
Status status = new Status(IStatus.ERROR, JavaServerUIPlugin.PLUGIN_ID, IStatus.ERROR, Messages.NewServletTestCaseWizard_WarningMessageSuperclassIsEmpty, null); |
| 137 |
return status; |
| 138 |
} |
| 139 |
|
| 140 |
if (superClassName.equals("org.apache.cactus.ServletTestCase")){ |
| 141 |
//Short-circuit if this IS ServletTestCase |
| 142 |
return Status.OK_STATUS; |
| 143 |
} |
| 144 |
|
| 145 |
if (getPackageFragmentRoot() != null) |
| 146 |
{ |
| 147 |
IType type; |
| 148 |
try { |
| 149 |
type = resolveClassNameToType(getPackageFragmentRoot().getJavaProject(), getPackageFragment(), superClassName); |
| 150 |
if (type == null) { |
| 151 |
Status status = new Status(IStatus.WARNING, JavaServerUIPlugin.PLUGIN_ID, IStatus.WARNING, Messages.NewServletTestCaseWizard_WarningMessageSuperclassDoesNotExist, null); |
| 152 |
return status; |
| 153 |
} |
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
if (type.isInterface()) { |
| 158 |
Status status = new Status(IStatus.WARNING, JavaServerUIPlugin.PLUGIN_ID, IStatus.WARNING, Messages.NewServletTestCaseWizard_WarningMessageSuperclassIsInterface, null); |
| 159 |
return status; |
| 160 |
} |
| 161 |
|
| 162 |
ITypeHierarchy hierarchy = type.newTypeHierarchy(null); |
| 163 |
IType [] superTypes = hierarchy.getAllSuperclasses(type); |
| 164 |
for (int i=0; i<superTypes.length; i++) |
| 165 |
{ |
| 166 |
if (superTypes[i].getFullyQualifiedName().equals("org.apache.cactus.ServletTestCase")) |
| 167 |
{ |
| 168 |
return Status.OK_STATUS; |
| 169 |
} |
| 170 |
} |
| 171 |
|
| 172 |
Status status = new Status(IStatus.WARNING, JavaServerUIPlugin.PLUGIN_ID, IStatus.WARNING, Messages.NewServletTestCaseWizard_WarningMessageSuperclassNotServletTestCase, null); |
| 173 |
return status; |
| 174 |
|
| 175 |
} catch (JavaModelException e) { |
| 176 |
JavaServerUIPlugin.log(e); |
| 177 |
} |
| 178 |
|
| 179 |
} |
| 180 |
|
| 181 |
return Status.OK_STATUS; |
| 182 |
} |
| 183 |
|
| 184 |
private IType resolveClassNameToType(IJavaProject jproject, IPackageFragment pack, String classToTestName) throws JavaModelException { |
| 185 |
|
| 186 |
IType type= jproject.findType(classToTestName); |
| 187 |
|
| 188 |
// search in current package |
| 189 |
if (type == null && pack != null && !pack.isDefaultPackage()) { |
| 190 |
type= jproject.findType(pack.getElementName(), classToTestName); |
| 191 |
} |
| 192 |
|
| 193 |
// search in java.lang |
| 194 |
if (type == null) { |
| 195 |
type= jproject.findType("java.lang", classToTestName); //$NON-NLS-1$ |
| 196 |
} |
| 197 |
return type; |
| 198 |
} |
| 199 |
|
| 200 |
protected IStatus validateIfJUnitProject() { |
| 201 |
try { |
| 202 |
if (checkForWebProject()) |
| 203 |
{ |
| 204 |
checkForCactusLibraries(); |
| 205 |
} |
| 206 |
else |
| 207 |
{ |
| 208 |
String msg = Messages.NewServletTestCaseWizard_WarningMessageSelectAWebProject; |
| 209 |
MessageDialog.openWarning(getShell(), Messages.NewServletTestCaseWizard_WarningTitleWebProjectRequired, msg); |
| 210 |
return new Status(IStatus.WARNING, JavaServerUIPlugin.PLUGIN_ID, IStatus.ERROR, msg, null); |
| 211 |
} |
| 212 |
} catch (CoreException e) { |
| 213 |
return new Status(Status.ERROR, JavaServerUIPlugin.PLUGIN_ID, IStatus.ERROR, "Failed to check for cactus libraries." ,e); |
| 214 |
} |
| 215 |
|
| 216 |
return Status.OK_STATUS; |
| 217 |
} |
| 218 |
|
| 219 |
protected void createTypeMembers(IType type, ImportsManager imports, IProgressMonitor monitor) throws CoreException { |
| 220 |
super.createTypeMembers(type, imports, monitor); |
| 221 |
if (fBeginButton.getSelection()) |
| 222 |
{ |
| 223 |
generateBeginMethod(type, imports); |
| 224 |
} |
| 225 |
|
| 226 |
if (fEndButton.getSelection()) |
| 227 |
{ |
| 228 |
generateEndMethod(type, imports); |
| 229 |
} |
| 230 |
|
| 231 |
if (fBeginXXXButton.getSelection()) |
| 232 |
{ |
| 233 |
generateBeginXXXMethods(type, imports); |
| 234 |
} |
| 235 |
|
| 236 |
if (fEndXXXButton.getSelection()) |
| 237 |
{ |
| 238 |
generateEndXXXMethods(type, imports); |
| 239 |
} |
| 240 |
|
| 241 |
} |
| 242 |
|
| 243 |
private void generateBeginMethod(IType type, ImportsManager imports) |
| 244 |
throws JavaModelException |
| 245 |
{ |
| 246 |
StringBuilder methodBuffer = new StringBuilder(); |
| 247 |
methodBuffer.append("public void begin("); //$NON-NLS-1$ |
| 248 |
methodBuffer.append(imports.addImport("org.apache.cactus.WebRequest")); //$NON-NLS-1$ |
| 249 |
methodBuffer.append(" request) throws "); //$NON-NLS-1$ |
| 250 |
methodBuffer.append(imports.addImport("java.lang.Exception")); //$NON-NLS-1$ |
| 251 |
methodBuffer.append(" {\n\n\t} "); //$NON-NLS-1$ |
| 252 |
type.createMethod(methodBuffer.toString(), null, false, null); |
| 253 |
} |
| 254 |
|
| 255 |
private void generateEndMethod(IType type, ImportsManager imports) |
| 256 |
throws JavaModelException |
| 257 |
{ |
| 258 |
StringBuilder methodBuffer = new StringBuilder(); |
| 259 |
methodBuffer.append("public void end("); //$NON-NLS-1$ |
| 260 |
methodBuffer.append(imports.addImport("org.apache.cactus.WebRequest")); //$NON-NLS-1$ |
| 261 |
methodBuffer.append(" request) throws "); //$NON-NLS-1$ |
| 262 |
methodBuffer.append(imports.addImport("java.lang.Exception")); //$NON-NLS-1$ |
| 263 |
methodBuffer.append(" {\n\n\t} "); //$NON-NLS-1$ |
| 264 |
type.createMethod(methodBuffer.toString(), null, false, null); |
| 265 |
} |
| 266 |
|
| 267 |
private void generateBeginXXXMethods(IType type, ImportsManager imports) |
| 268 |
throws JavaModelException |
| 269 |
{ |
| 270 |
generateXXXMethods(type, imports, "begin"); //$NON-NLS-1$ |
| 271 |
} |
| 272 |
|
| 273 |
private void generateXXXMethods(IType type, ImportsManager imports, String prefix) throws JavaModelException |
| 274 |
{ |
| 275 |
IMethod [] testMethods = type.getMethods(); |
| 276 |
for (int i=0; i<testMethods.length; i++) |
| 277 |
{ |
| 278 |
IMethod testMethod = testMethods[i]; |
| 279 |
String testMethodName = testMethod.getElementName(); |
| 280 |
if (testMethodName.startsWith("test")) //$NON-NLS-1$ |
| 281 |
{ |
| 282 |
String newMethodName = prefix + testMethodName.substring(4); |
| 283 |
StringBuilder methodBuffer = new StringBuilder(); |
| 284 |
methodBuffer.append("public void "); //$NON-NLS-1$ |
| 285 |
methodBuffer.append(newMethodName); |
| 286 |
methodBuffer.append("("); //$NON-NLS-1$ |
| 287 |
methodBuffer.append(imports.addImport("org.apache.cactus.WebRequest")); //$NON-NLS-1$ |
| 288 |
methodBuffer.append(" request) throws "); //$NON-NLS-1$ |
| 289 |
methodBuffer.append(imports.addImport("java.lang.Exception")); //$NON-NLS-1$ |
| 290 |
methodBuffer.append(" {\n\n\t} "); //$NON-NLS-1$ |
| 291 |
type.createMethod(methodBuffer.toString(), testMethod, false, null); |
| 292 |
|
| 293 |
} |
| 294 |
|
| 295 |
} |
| 296 |
} |
| 297 |
|
| 298 |
private void generateEndXXXMethods(IType type, ImportsManager imports) |
| 299 |
throws JavaModelException |
| 300 |
{ |
| 301 |
generateXXXMethods(type, imports, "end"); //$NON-NLS-1$ |
| 302 |
} |
| 303 |
|
| 304 |
protected void createMethodStubSelectionControls(Composite composite, int nColumns) { |
| 305 |
super.createMethodStubSelectionControls(composite, nColumns); |
| 306 |
createEmptySpace(composite); |
| 307 |
fCactusButtonComposite = new Composite(composite, SWT.NONE); |
| 308 |
GridData gd = new GridData(); |
| 309 |
gd.horizontalSpan = 3; |
| 310 |
fCactusButtonComposite.setLayoutData(gd); |
| 311 |
GridLayout layout = new GridLayout(); |
| 312 |
layout.numColumns = 1; |
| 313 |
layout.marginWidth = layout.marginHeight = 0; |
| 314 |
layout.makeColumnsEqualWidth = true; |
| 315 |
fCactusButtonComposite.setLayout(layout); |
| 316 |
|
| 317 |
fBeginButton = createSelectionButton("begin()", fCactusButtonComposite); //$NON-NLS-1$ |
| 318 |
fEndButton = createSelectionButton("end()", fCactusButtonComposite); //$NON-NLS-1$ |
| 319 |
fBeginXXXButton = createSelectionButton("beginXXX() methods", fCactusButtonComposite); //$NON-NLS-1$ |
| 320 |
fEndXXXButton = createSelectionButton("endXXX() methods", fCactusButtonComposite); //$NON-NLS-1$ |
| 321 |
|
| 322 |
} |
| 323 |
|
| 324 |
private Button createSelectionButton(String text, Composite group) { |
| 325 |
Button button= new Button(group, SWT.CHECK | SWT.LEFT); |
| 326 |
button.setFont(group.getFont()); |
| 327 |
button.setText(text); |
| 328 |
GridData data = new GridData(); |
| 329 |
data.horizontalAlignment = SWT.BEGINNING; |
| 330 |
data.verticalAlignment = GridData.CENTER; |
| 331 |
button.setLayoutData(data); |
| 332 |
return button; |
| 333 |
} |
| 334 |
|
| 335 |
} |
| 336 |
|
| 337 |
private static Control createEmptySpace(Composite parent) { |
| 338 |
return createEmptySpace(parent, 1); |
| 339 |
} |
| 340 |
|
| 341 |
private static Control createEmptySpace(Composite parent, int span) { |
| 342 |
Label label= new Label(parent, SWT.LEFT); |
| 343 |
GridData gd= new GridData(); |
| 344 |
gd.horizontalAlignment= GridData.BEGINNING; |
| 345 |
gd.grabExcessHorizontalSpace= false; |
| 346 |
gd.horizontalSpan= span; |
| 347 |
gd.horizontalIndent= 0; |
| 348 |
gd.widthHint= 0; |
| 349 |
gd.heightHint= 0; |
| 350 |
label.setLayoutData(gd); |
| 351 |
return label; |
| 352 |
} |
| 353 |
|
| 109 |
|
354 |
|
| 110 |
private IStructuredSelection getSelection() { |
355 |
private IStructuredSelection getSelection() { |
| 111 |
return fSelection; |
356 |
return fSelection; |
| 112 |
} |
357 |
} |
|
|
358 |
|
| 359 |
private boolean checkForWebProject() throws CoreException |
| 360 |
{ |
| 361 |
IPackageFragmentRoot root = fPage1.getPackageFragmentRoot(); |
| 362 |
if (root == null) |
| 363 |
return false; |
| 364 |
|
| 365 |
IJavaProject project = root.getJavaProject(); |
| 366 |
IFacetedProject facetedProject = ProjectFacetsManager.create(project.getProject()); |
| 367 |
if (facetedProject != null) |
| 368 |
{ |
| 369 |
Iterator facets = facetedProject.getProjectFacets().iterator(); |
| 370 |
while(facets.hasNext()) |
| 371 |
{ |
| 372 |
IProjectFacetVersion facet = (IProjectFacetVersion) facets.next(); |
| 373 |
if (facet.getProjectFacet().getId().equals("jst.web")) //$NON-NLS-1$ |
| 374 |
{ |
| 375 |
return true; |
| 376 |
} |
| 377 |
|
| 378 |
} |
| 379 |
} |
| 380 |
|
| 381 |
return false; |
| 382 |
} |
| 383 |
|
| 384 |
private void checkForCactusLibraries() |
| 385 |
{ |
| 386 |
IPackageFragmentRoot root = fPage1.getPackageFragmentRoot(); |
| 387 |
if (root == null) |
| 388 |
return; |
| 389 |
|
| 390 |
IJavaProject project = root.getJavaProject(); |
| 391 |
|
| 392 |
List missingLibraries = new ArrayList(); |
| 393 |
try { |
| 394 |
for (int i = 0; i < CLASSES_TO_CHECK.length; i++) { |
| 395 |
IType type = project.findType(CLASSES_TO_CHECK[i]); |
| 396 |
if (type == null) { |
| 397 |
missingLibraries.add(REQUIRED_LIBRARIES[i]); |
| 398 |
} |
| 399 |
} |
| 400 |
|
| 401 |
if (missingLibraries.size() > 0) |
| 402 |
{ |
| 403 |
if (MessageDialog.openQuestion(getShell(), Messages.NewServletTestCaseWizard_ErrorMessageTitleMissingLibrary, |
| 404 |
NLS.bind(Messages.NewServletTestCaseWizard_ErrorMessageMissingLibrary, missingLibraries.toArray()))) |
| 405 |
{ |
| 406 |
CactusAddLibrariesProposal.installLibraries(project.getProject()); |
| 407 |
} |
| 408 |
} |
| 409 |
|
| 410 |
|
| 411 |
} catch (JavaModelException e) { |
| 412 |
JavaServerUIPlugin.log(e); |
| 413 |
} |
| 414 |
} |
| 113 |
|
415 |
|
| 114 |
public boolean performFinish() { |
416 |
public boolean performFinish() { |
| 115 |
if (finishPage(fPage1.getRunnable())) { |
417 |
if (finishPage(fPage1.getRunnable())) { |
|
|
418 |
|
| 116 |
IType newClass = fPage1.getCreatedType(); |
419 |
IType newClass = fPage1.getCreatedType(); |
| 117 |
|
420 |
|
| 118 |
IResource resource = newClass.getCompilationUnit().getResource(); |
421 |
IResource resource = newClass.getCompilationUnit().getResource(); |
|
Lines 120-145
Link Here
|
| 120 |
BasicNewResourceWizard.selectAndReveal(resource, fWorkbench |
423 |
BasicNewResourceWizard.selectAndReveal(resource, fWorkbench |
| 121 |
.getActiveWorkbenchWindow()); |
424 |
.getActiveWorkbenchWindow()); |
| 122 |
openResource(resource); |
425 |
openResource(resource); |
| 123 |
// checkLibraryMissing(); |
|
|
| 124 |
} |
426 |
} |
| 125 |
return true; |
427 |
return true; |
| 126 |
} |
428 |
} |
| 127 |
return false; |
429 |
return false; |
| 128 |
} |
430 |
} |
| 129 |
|
431 |
|
| 130 |
/*private void checkLibraryMissing() { |
|
|
| 131 |
IType newClass = fPage1.getCreatedType(); |
| 132 |
IJavaProject project = newClass.getJavaProject(); |
| 133 |
try { |
| 134 |
IType type = project.findType(SUPERCLASS_NAME); |
| 135 |
MessageDialog.openError(getShell(), NLS.bind( |
| 136 |
Messages.NewServletTestCaseWizard_ErrorMessageMissingLibrary, REQUIRED_LIBRARIES), |
| 137 |
Messages.NewServletTestCaseWizard_ErrorMessageMissingType); |
| 138 |
} catch (JavaModelException e) { |
| 139 |
JavaServerUIPlugin.log(e); |
| 140 |
} |
| 141 |
}*/ |
| 142 |
|
| 143 |
protected boolean finishPage(IRunnableWithProgress runnable) { |
432 |
protected boolean finishPage(IRunnableWithProgress runnable) { |
| 144 |
IRunnableWithProgress op = new WorkspaceModifyDelegatingOperation(runnable); |
433 |
IRunnableWithProgress op = new WorkspaceModifyDelegatingOperation(runnable); |
| 145 |
try { |
434 |
try { |
|
Lines 148-154
Link Here
|
| 148 |
} catch (InvocationTargetException e) { |
437 |
} catch (InvocationTargetException e) { |
| 149 |
String title = Messages.NewServletTestCaseWizard_ErrorTitleNew; // NewJUnitWizard_op_error_title |
438 |
String title = Messages.NewServletTestCaseWizard_ErrorTitleNew; // NewJUnitWizard_op_error_title |
| 150 |
String message = Messages.NewServletTestCaseWizard_ErrorTitleCreateOfElementFailed; // NewJUnitWizard_op_error_message |
439 |
String message = Messages.NewServletTestCaseWizard_ErrorTitleCreateOfElementFailed; // NewJUnitWizard_op_error_message |
| 151 |
// ExceptionHandler.handle(e, shell, title, message); |
|
|
| 152 |
displayMessageDialog(e, e.getMessage(), getShell(), title, message); |
440 |
displayMessageDialog(e, e.getMessage(), getShell(), title, message); |
| 153 |
return false; |
441 |
return false; |
| 154 |
} catch (InterruptedException e) { |
442 |
} catch (InterruptedException e) { |
|
Lines 191-204
Link Here
|
| 191 |
} |
479 |
} |
| 192 |
} |
480 |
} |
| 193 |
|
481 |
|
| 194 |
public static IWorkbenchPage getActivePage() { |
482 |
private static IWorkbenchPage getActivePage() { |
| 195 |
IWorkbenchWindow activeWorkbenchWindow = getActiveWorkbenchWindow(); |
483 |
IWorkbenchWindow activeWorkbenchWindow = getActiveWorkbenchWindow(); |
| 196 |
if (activeWorkbenchWindow == null) |
484 |
if (activeWorkbenchWindow == null) |
| 197 |
return null; |
485 |
return null; |
| 198 |
return activeWorkbenchWindow.getActivePage(); |
486 |
return activeWorkbenchWindow.getActivePage(); |
| 199 |
} |
487 |
} |
| 200 |
|
488 |
|
| 201 |
public static IWorkbenchWindow getActiveWorkbenchWindow() { |
489 |
private static IWorkbenchWindow getActiveWorkbenchWindow() { |
| 202 |
IWorkbench workbench = JavaServerUIPlugin.getInstance().getWorkbench(); |
490 |
IWorkbench workbench = JavaServerUIPlugin.getInstance().getWorkbench(); |
| 203 |
if (workbench != null) |
491 |
if (workbench != null) |
| 204 |
return workbench.getActiveWorkbenchWindow(); |
492 |
return workbench.getActiveWorkbenchWindow(); |