Author: bfitzpat
Date: 2010-09-08 15:11:58 -0400 (Wed, 08 Sep 2010)
New Revision: 24821
Added:
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/commands/RSServiceCreationCommand.java
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/commands/ServiceCreationCommand.java
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/wizards/JBossWSAnnotatedClassWizard.java
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/wizards/JBossWSAnnotatedClassWizardPage.java
Modified:
trunk/ws/plugins/org.jboss.tools.ws.ui/plugin.properties
trunk/ws/plugins/org.jboss.tools.ws.ui/plugin.xml
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/messages/JBossWSUI.properties
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/wizards/JBossRSGenerateWizard.java
Log:
OPEN - issue JBIDE-6904: Provide simple wizard for creating JAX-WS and JAX-RS services
from annotated class files
https://jira.jboss.org/browse/JBIDE-6904
Adds the new "Simple Web Service" wizard that users can use to both create
samples and create service projects from their own annotated classes.
Added:
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/commands/RSServiceCreationCommand.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/commands/RSServiceCreationCommand.java
(rev 0)
+++
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/commands/RSServiceCreationCommand.java 2010-09-08
19:11:58 UTC (rev 24821)
@@ -0,0 +1,248 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.ws.creation.core.commands;
+
+import java.io.File;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.IPackageFragment;
+import org.eclipse.jdt.core.IPackageFragmentRoot;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.wst.common.frameworks.datamodel.AbstractDataModelOperation;
+import org.jboss.tools.ws.core.utils.StatusUtils;
+import org.jboss.tools.ws.creation.core.JBossWSCreationCorePlugin;
+import org.jboss.tools.ws.creation.core.data.ServiceModel;
+import org.jboss.tools.ws.creation.core.messages.JBossWSCreationCoreMessages;
+import org.jboss.tools.ws.creation.core.utils.JBossWSCreationUtils;
+
+/**
+ * @author Brian Fitzpatrick
+ *
+ */
+public class RSServiceCreationCommand extends AbstractDataModelOperation {
+
+ private ServiceModel model;
+ private IResource annotatedClassResource;
+ private IResource applicationClassResource;
+ private static String JAVA = ".java"; //$NON-NLS-1$
+
+ public static final String LINE_SEPARATOR = System
+ .getProperty("line.separator"); //$NON-NLS-1$
+
+ public RSServiceCreationCommand(ServiceModel model) {
+ this.model = model;
+ }
+
+ public IResource getAnnotatedClassResource() {
+ return this.annotatedClassResource;
+ }
+
+ public IResource getApplicationClassResource() {
+ return this.applicationClassResource;
+ }
+
+ @Override
+ public IStatus execute(IProgressMonitor monitor, IAdaptable info)
+ throws ExecutionException {
+ IJavaProject project = null;
+ try {
+ project = JBossWSCreationUtils.getJavaProjectByName(model
+ .getWebProjectName());
+ } catch (JavaModelException e) {
+ JBossWSCreationCorePlugin.getDefault().logError(e);
+ return StatusUtils
+ .errorStatus(JBossWSCreationCoreMessages.Error_Create_Client_Sample);
+ }
+
+ // find the class, make sure it's in the project and open if we find it
+ if (model.getServiceClasses() != null && model.getServiceClasses().size() == 1)
{
+ String clazzName = model.getServiceClasses().get(0);
+ File file = JBossWSCreationUtils.findFileByPath(clazzName + JAVA,
project.getProject()
+ .getLocation().toOSString());
+ if (file == null) {
+ ICompilationUnit rsAnnotatedClass =
+ createRESTAnnotatedJavaClass (model.getCustomPackage(), JBossWSCreationUtils
+ .classNameFromQualifiedName(model.getServiceClasses().get(0)),
+ project);
+ if (rsAnnotatedClass != null) {
+ this.annotatedClassResource = rsAnnotatedClass.getResource();
+ }
+ } else {
+ IResource test = findClass(project, clazzName);
+ if (test != null) {
+ this.annotatedClassResource = test;
+ }
+ }
+ }
+
+ File file = JBossWSCreationUtils.findFileByPath(model.getApplicationClassName() + JAVA,
project.getProject()
+ .getLocation().toOSString());
+
+ if (file == null) {
+ ICompilationUnit appClass = createRESTApplicationClass (model.getCustomPackage(),
model.getApplicationClassName(),
+ project);
+ if (appClass != null) {
+ this.applicationClassResource = appClass.getResource();
+ } else {
+ IResource test = findClass(project, model.getApplicationClassName());
+ if (test != null) {
+ this.applicationClassResource = test;
+ }
+ }
+ }
+
+ return null;
+ }
+
+ public IResource findClass(IJavaProject project, String className) {
+ try {
+ IType type = project.findType(className);
+ if (type != null) {
+ final IPackageFragment fragment = type.getPackageFragment();
+ return fragment.getResource();
+ }
+ } catch (JavaModelException e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ private ICompilationUnit createRESTApplicationClass(String packageName,
+ String className, IJavaProject project) {
+ try {
+ IPath srcPath = new Path(JBossWSCreationUtils
+ .getJavaProjectSrcLocation(project.getProject()));
+ srcPath = project.getPath().append(
+ srcPath.makeRelativeTo(project.getProject()
+ .getLocation()));
+ IPackageFragmentRoot root = project
+ .findPackageFragmentRoot(srcPath);
+ if (packageName == null) {
+ packageName = ""; //$NON-NLS-1$
+ }
+ IPackageFragment pkg = root.createPackageFragment(packageName,
+ false, null);
+ ICompilationUnit wrapperCls = pkg.createCompilationUnit(className
+ + ".java", "", true, null); //$NON-NLS-1$//$NON-NLS-2$
+ if (!packageName.equals("")) { //$NON-NLS-1$
+ wrapperCls.createPackageDeclaration(packageName, null);
+ }
+
+ StringBuffer clsContent = new StringBuffer();
+ clsContent.append("public class ").append(className).append(" extends
Application").append(" {" + LINE_SEPARATOR); //$NON-NLS-1$ //$NON-NLS-2$
//$NON-NLS-3$
+ clsContent.append("}").append(LINE_SEPARATOR); //$NON-NLS-1$
+ wrapperCls.createType(clsContent.toString(), null, true, null);
+
+ wrapperCls.createImport("java.util.Set", null,null); //$NON-NLS-1$
+ wrapperCls.createImport("java.util.HashSet", null,null); //$NON-NLS-1$
+ wrapperCls.createImport("javax.ws.rs.core.Application", null,null);
//$NON-NLS-1$
+
+ IType serviceClsType = wrapperCls.findPrimaryType();
+ clsContent = new StringBuffer();
+ clsContent.append("private Set<Object> singletons = new
HashSet<Object>();" + LINE_SEPARATOR); //$NON-NLS-1$
+ serviceClsType.createField(clsContent.toString(), null, false, null);
+
+ clsContent = new StringBuffer();
+ clsContent.append("private Set<Class<?>> empty = new
HashSet<Class<?>>();" + LINE_SEPARATOR); //$NON-NLS-1$
+ serviceClsType.createField(clsContent.toString(), null, false, null);
+
+ clsContent = new StringBuffer();
+ clsContent.append(LINE_SEPARATOR);
+ clsContent.append("public " + className + "(){" + LINE_SEPARATOR);
//$NON-NLS-1$ //$NON-NLS-2$
+ clsContent.append(" singletons.add(new " + JBossWSCreationUtils
//$NON-NLS-1$
+ .classNameFromQualifiedName(model.getServiceClasses().get(0)) + "());" +
LINE_SEPARATOR); //$NON-NLS-1$
+ clsContent.append("}" + LINE_SEPARATOR); //$NON-NLS-1$
+ serviceClsType.createMethod(clsContent.toString(), null, true, null);
+
+ clsContent = new StringBuffer();
+ clsContent.append(LINE_SEPARATOR);
+ clsContent.append("@Override" + LINE_SEPARATOR); //$NON-NLS-1$
+ clsContent.append("public Set<Class<?>> getClasses() {" +
LINE_SEPARATOR); //$NON-NLS-1$
+ clsContent.append(" return empty;" + LINE_SEPARATOR); //$NON-NLS-1$
+ clsContent.append("}" + LINE_SEPARATOR); //$NON-NLS-1$
+ serviceClsType.createMethod(clsContent.toString(), null, true, null);
+
+ clsContent = new StringBuffer();
+ clsContent.append(LINE_SEPARATOR);
+ clsContent.append("@Override" + LINE_SEPARATOR); //$NON-NLS-1$
+ clsContent.append("public Set<Object> getSingletons() {" +
LINE_SEPARATOR); //$NON-NLS-1$
+ clsContent.append(" return singletons;" + LINE_SEPARATOR);
//$NON-NLS-1$
+ clsContent.append("}" + LINE_SEPARATOR); //$NON-NLS-1$
+ serviceClsType.createMethod(clsContent.toString(), null, true, null);
+
+ wrapperCls.save(null, true);
+ return wrapperCls;
+ } catch (Exception e) {
+ JBossWSCreationCorePlugin.getDefault().logError(e);
+ return null;
+ }
+ }
+
+ private ICompilationUnit createRESTAnnotatedJavaClass(String packageName,
+ String className, IJavaProject project) {
+ try {
+ IPath srcPath = new Path(JBossWSCreationUtils
+ .getJavaProjectSrcLocation(project.getProject()));
+ srcPath = project.getPath().append(
+ srcPath.makeRelativeTo(project.getProject()
+ .getLocation()));
+ IPackageFragmentRoot root = project
+ .findPackageFragmentRoot(srcPath);
+ if (packageName == null) {
+ packageName = ""; //$NON-NLS-1$
+ }
+ IPackageFragment pkg = root.createPackageFragment(packageName,
+ false, null);
+ ICompilationUnit wrapperCls = pkg.createCompilationUnit(className
+ + ".java", "", true, null); //$NON-NLS-1$//$NON-NLS-2$
+ if (!packageName.equals("")) { //$NON-NLS-1$
+ wrapperCls.createPackageDeclaration(packageName, null);
+ }
+
+ StringBuffer clsContent = new StringBuffer();
+ clsContent.append("@Path(\"/" + model.getServiceName() +
"\")").append(LINE_SEPARATOR); //$NON-NLS-1$ //$NON-NLS-2$
+ clsContent.append("public class ").append(className).append(" {" +
LINE_SEPARATOR); //$NON-NLS-1$ //$NON-NLS-2$
+ clsContent.append("}").append(LINE_SEPARATOR); //$NON-NLS-1$
+ wrapperCls.createType(clsContent.toString(), null, true, null);
+
+ wrapperCls.createImport("javax.ws.rs.Produces", null,null); //$NON-NLS-1$
+ wrapperCls.createImport("javax.ws.rs.GET", null,null); //$NON-NLS-1$
+ wrapperCls.createImport("javax.ws.rs.Path", null,null); //$NON-NLS-1$
+
+ IType serviceClsType = wrapperCls.findPrimaryType();
+ clsContent = new StringBuffer();
+ clsContent.append("@GET()"); //$NON-NLS-1$
+ clsContent.append(LINE_SEPARATOR);
+ clsContent.append("@Produces(\"text/plain\")"); //$NON-NLS-1$
+ clsContent.append(LINE_SEPARATOR);
+ clsContent.append("public String sayHello() {"); //$NON-NLS-1$
+ clsContent.append(LINE_SEPARATOR);
+ clsContent.append(" return \"Hello World!\";"); //$NON-NLS-1$
+ clsContent.append(LINE_SEPARATOR);
+ clsContent.append("}"); //$NON-NLS-1$
+ serviceClsType.createMethod(clsContent.toString(), null, true, null);
+ wrapperCls.save(null, true);
+ return wrapperCls;
+ } catch (Exception e) {
+ JBossWSCreationCorePlugin.getDefault().logError(e);
+ return null;
+ }
+ }
+}
Property changes on:
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/commands/RSServiceCreationCommand.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/commands/ServiceCreationCommand.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/commands/ServiceCreationCommand.java
(rev 0)
+++
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/commands/ServiceCreationCommand.java 2010-09-08
19:11:58 UTC (rev 24821)
@@ -0,0 +1,134 @@
+package org.jboss.tools.ws.creation.core.commands;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.IPackageFragment;
+import org.eclipse.jdt.core.IPackageFragmentRoot;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.wst.common.frameworks.datamodel.AbstractDataModelOperation;
+import org.jboss.tools.ws.core.utils.StatusUtils;
+import org.jboss.tools.ws.creation.core.JBossWSCreationCorePlugin;
+import org.jboss.tools.ws.creation.core.data.ServiceModel;
+import org.jboss.tools.ws.creation.core.messages.JBossWSCreationCoreMessages;
+import org.jboss.tools.ws.creation.core.utils.JBossWSCreationUtils;
+
+public class ServiceCreationCommand extends AbstractDataModelOperation {
+
+ private ServiceModel model;
+ private IResource resource;
+
+ public static final String LINE_SEPARATOR = System
+ .getProperty("line.separator"); //$NON-NLS-1$
+
+ public ServiceCreationCommand(ServiceModel model) {
+ this.model = model;
+ }
+
+ public IResource getResource() {
+ return this.resource;
+ }
+
+ @Override
+ public IStatus execute(IProgressMonitor monitor, IAdaptable info)
+ throws ExecutionException {
+ IJavaProject project = null;
+ try {
+ project = JBossWSCreationUtils.getJavaProjectByName(model
+ .getWebProjectName());
+ } catch (JavaModelException e) {
+ JBossWSCreationCorePlugin.getDefault().logError(e);
+ return StatusUtils
+ .errorStatus(JBossWSCreationCoreMessages.Error_Create_Client_Sample);
+ }
+
+ // find the class, make sure it's in the project and open if we find it
+ if (model.getServiceClasses() != null && model.getServiceClasses().size() == 1)
{
+ String clazzName = model.getServiceClasses().get(0);
+ IResource test = findClass(project, clazzName);
+ if (test != null) {
+ this.resource = test;
+ } else {
+ ICompilationUnit createdClass =
+ createJavaClass(model.getCustomPackage(), JBossWSCreationUtils
+ .classNameFromQualifiedName(model.getServiceClasses().get(0)),
+ project);
+ if (createdClass != null) {
+ this.resource = createdClass.getResource();
+ }
+ }
+ }
+
+ return null;
+ }
+
+ public IResource findClass(IJavaProject project, String className) {
+ try {
+ IType type = project.findType(className);
+ if (type != null) {
+ if (type.getResource() != null)
+ return type.getResource();
+ }
+ } catch (JavaModelException e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ private ICompilationUnit createJavaClass(String packageName,
+ String className, IJavaProject project) {
+ try {
+ IPath srcPath = new Path(JBossWSCreationUtils
+ .getJavaProjectSrcLocation(project.getProject()));
+ srcPath = project.getPath().append(
+ srcPath.makeRelativeTo(project.getProject()
+ .getLocation()));
+ IPackageFragmentRoot root = project
+ .findPackageFragmentRoot(srcPath);
+ if (packageName == null) {
+ packageName = ""; //$NON-NLS-1$
+ }
+ IPackageFragment pkg = root.createPackageFragment(packageName,
+ false, null);
+ ICompilationUnit wrapperCls = pkg.createCompilationUnit(className
+ + ".java", "", true, null); //$NON-NLS-1$//$NON-NLS-2$
+ if (!packageName.equals("")) { //$NON-NLS-1$
+ wrapperCls.createPackageDeclaration(packageName, null);
+ }
+
+ StringBuffer clsContent = new StringBuffer();
+ clsContent.append("(a)WebService()").append(LINE_SEPARATOR); //$NON-NLS-1$
+ clsContent.append("public class ").append(className).append(" {" +
LINE_SEPARATOR); //$NON-NLS-1$ //$NON-NLS-2$
+ clsContent.append("}").append(LINE_SEPARATOR); //$NON-NLS-1$
+ wrapperCls.createType(clsContent.toString(), null, true, null);
+
+ wrapperCls.createImport("javax.jws.WebMethod", null,null); //$NON-NLS-1$
+ wrapperCls.createImport("javax.jws.WebService", null,null); //$NON-NLS-1$
+
+ IType serviceClsType = wrapperCls.findPrimaryType();
+ clsContent = new StringBuffer();
+ clsContent.append("@WebMethod()"); //$NON-NLS-1$
+ clsContent.append(LINE_SEPARATOR);
+ clsContent.append("public String sayHello(String name) {"); //$NON-NLS-1$
+ clsContent.append(LINE_SEPARATOR);
+ clsContent.append(" System.out.println(\"Hello: \" + name);");
//$NON-NLS-1$
+ clsContent.append(LINE_SEPARATOR);
+ clsContent.append(" return \"Hello \" + name +
\"!\";"); //$NON-NLS-1$
+ clsContent.append(LINE_SEPARATOR);
+ clsContent.append("}"); //$NON-NLS-1$
+ serviceClsType.createMethod(clsContent.toString(), null, true, null);
+ wrapperCls.save(null, true);
+ return wrapperCls;
+ } catch (Exception e) {
+ JBossWSCreationCorePlugin.getDefault().logError(e);
+ return null;
+ }
+ }
+}
Property changes on:
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/commands/ServiceCreationCommand.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/ws/plugins/org.jboss.tools.ws.ui/plugin.properties
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.ui/plugin.properties 2010-09-08 18:09:18 UTC (rev
24820)
+++ trunk/ws/plugins/org.jboss.tools.ws.ui/plugin.properties 2010-09-08 19:11:58 UTC (rev
24821)
@@ -5,4 +5,9 @@
PLUGIN_PROVIDER=JBoss by Red Hat
JBOSSWS_WIZARD_DESC=Create a sample web service
test.view.category.name = JBoss Tools Web Services
-test.view.name = Web Service Tester
\ No newline at end of file
+test.view.name = Web Service Tester
+restful.wizard.name = Create a Sample RESTful Web Service
+restful.wizard.description = Create a Sample RESTful Web Service
+ws_bottom_up.wizard.name = Simple Web Service
+ws_bottom_up.wizard.description = Create a Sample RESTful Web Service
+jbossws.page.name = JBossWS Runtime
\ No newline at end of file
Modified: trunk/ws/plugins/org.jboss.tools.ws.ui/plugin.xml
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.ui/plugin.xml 2010-09-08 18:09:18 UTC (rev 24820)
+++ trunk/ws/plugins/org.jboss.tools.ws.ui/plugin.xml 2010-09-08 19:11:58 UTC (rev 24821)
@@ -43,12 +43,12 @@
hasPages="true"
icon="icons/obj16/new_webserv_wiz.gif"
id="org.jboss.tools.ws.ui.wizard.rsgenerate"
- name="Create a Sample RESTful Web Service">
+ name="%restful.wizard.name">
<selection
class="org.eclipse.core.resources.IProject">
</selection>
<description>
- Create a Sample RESTful Web Service
+ %restful.wizard.description
</description>
</wizard>
<wizard
@@ -57,14 +57,42 @@
hasPages="true"
icon="icons/obj16/new_webserv_wiz.gif"
id="org.jboss.tools.ws.ui.wizard.rsgenerate2"
- name="Create a Sample RESTful Web Service">
+ name="%restful.wizard.name">
<selection
class="org.eclipse.core.resources.IProject">
</selection>
<description>
- Create a Sample RESTful Web Service
+ %restful.wizard.description
</description>
</wizard>
+ <wizard
+ category="org.eclipse.jst.ws.ui.new"
+ class="org.jboss.tools.ws.ui.wizards.JBossWSAnnotatedClassWizard"
+ hasPages="true"
+ icon="icons/obj16/new_webserv_wiz.gif"
+ id="org.jboss.tools.ws.ui.wizard.wsclass2"
+ name="%ws_bottom_up.wizard.name">
+ <selection
+ class="org.eclipse.core.resources.IProject">
+ </selection>
+ <description>
+ %ws_bottom_up.wizard.description
+ </description>
+ </wizard>
+ <wizard
+ category="org.jboss.ide.eclipse.ui.wizards"
+ class="org.jboss.tools.ws.ui.wizards.JBossWSAnnotatedClassWizard"
+ hasPages="true"
+ icon="icons/obj16/new_webserv_wiz.gif"
+ id="org.jboss.tools.ws.ui.wizard.wsclass"
+ name="%ws_bottom_up.wizard.name">
+ <selection
+ class="org.eclipse.core.resources.IProject">
+ </selection>
+ <description>
+ %ws_bottom_up.wizard.description
+ </description>
+ </wizard>
</extension>
<extension point="org.eclipse.wst.common.project.facet.ui.images">
<image facet="jbossws.core"
path="icons/obj16/new_webserv_wiz.gif"/>
@@ -83,7 +111,7 @@
<page
class="org.jboss.tools.ws.ui.project.facet.JBossWSPropertyPage"
id="org.jboss.tools.ws.ui.page"
- name="JBossWS Runtime">
+ name="%jbossws.page.name">
<enabledWhen>
<adapt
type="org.eclipse.core.resources.IProject">
Modified:
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/messages/JBossWSUI.properties
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/messages/JBossWSUI.properties 2010-09-08
18:09:18 UTC (rev 24820)
+++
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/messages/JBossWSUI.properties 2010-09-08
19:11:58 UTC (rev 24821)
@@ -82,24 +82,24 @@
JBossWS_DelimitedStringList_EditValue_Dialog_Title=Edit Value
JBossWS_DelimitedStringList_EditValue_Dialog_Message=Specify the updated value below.
-JBossWSAnnotatedClassWizard_Annotated_Class_WS_Wizard_Title=Create a Web Service
(Botom-up)
+JBossWSAnnotatedClassWizard_Annotated_Class_WS_Wizard_Title=Simple Web Service
JBossWSAnnotatedClassWizardPage_Application_Class_Browse_btn=...
-JBossWSAnnotatedClassWizardPage_Application_Class_field=Application class (JAX-RS only)
+JBossWSAnnotatedClassWizardPage_Application_Class_field=Application class
JBossWSAnnotatedClassWizardPage_JAXRS_Button=JAX-RS (REST)
JBossWSAnnotatedClassWizardPage_JAXWS_Button=JAX-WS (WSDL-based)
JBossWSAnnotatedClassWizardPage_package_browse_btn=...
-JBossWSAnnotatedClassWizardPage_package_name_field=Package name
+JBossWSAnnotatedClassWizardPage_package_name_field=Package
JBossWSAnnotatedClassWizardPage_PageDescription=Select the details for the new web
service below. If a class does not yet exist, a sample will be created.
JBossWSAnnotatedClassWizardPage_PageTitle=Project and Web Service Details
JBossWSAnnotatedClassWizardPage_Project_Group=Dynamic web project
JBossWSAnnotatedClassWizardPage_Projects_Combo_Tooltip=If no Dynamic Web Project exists,
you must create one before creating your web service.
JBossWSAnnotatedClassWizardPage_Service_class_Browse_btn=...
-JBossWSAnnotatedClassWizardPage_Service_class_field=Service class
+JBossWSAnnotatedClassWizardPage_Service_class_field=Class
JBossWSAnnotatedClassWizardPage_Service_implementation_group=Service implementation
JBossWSAnnotatedClassWizardPage_Service_Name_field=Service name
JBossWSAnnotatedClassWizardPage_Update_Web_xml_checkbox=Update web.xml
-JBossWSAnnotatedClassWizardPage_Web_Service_Group=Web service
-JBossWSAnnotatedClassWizardPage_WS_Tech_Group=Web service technology:
+JBossWSAnnotatedClassWizardPage_Web_Service_Group=Service details
+JBossWSAnnotatedClassWizardPage_WS_Tech_Group=Technology
JAXRSWSTestView_Action_URL_Label=Action URL:
JAXRSWSTestView_Button_Get_From_WSDL=Get from WSDL...
Modified:
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/wizards/JBossRSGenerateWizard.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/wizards/JBossRSGenerateWizard.java 2010-09-08
18:09:18 UTC (rev 24820)
+++
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/wizards/JBossRSGenerateWizard.java 2010-09-08
19:11:58 UTC (rev 24821)
@@ -91,10 +91,8 @@
model.setWebProjectName(project.getName());
model.addServiceClasses(new StringBuffer().append(getPackageName())
.append(".").append(getClassName()).toString()); //$NON-NLS-1$
-// model.addServiceClasses(new StringBuffer().append(getPackageName())
-// .append(".").append(getAppClassName()).toString()); //$NON-NLS-1$
model.setServiceName(getServiceName());
- model.setUpdateWebxml(true);
+ model.setUpdateWebxml(getUpdateWebXML());
model.setCustomPackage(getPackageName());
model.setApplicationClassName( getAppClassName());
Added:
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/wizards/JBossWSAnnotatedClassWizard.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/wizards/JBossWSAnnotatedClassWizard.java
(rev 0)
+++
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/wizards/JBossWSAnnotatedClassWizard.java 2010-09-08
19:11:58 UTC (rev 24821)
@@ -0,0 +1,334 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.ws.ui.wizards;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.jst.j2ee.project.JavaEEProjectUtilities;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.INewWizard;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.ide.IDE;
+import org.eclipse.ui.wizards.newresource.BasicNewResourceWizard;
+import org.eclipse.wst.common.frameworks.datamodel.AbstractDataModelOperation;
+import org.jboss.tools.ws.creation.core.commands.AddRestEasyJarsCommand;
+import org.jboss.tools.ws.creation.core.commands.MergeWebXMLCommand;
+import org.jboss.tools.ws.creation.core.commands.RSMergeWebXMLCommand;
+import org.jboss.tools.ws.creation.core.commands.RSServiceCreationCommand;
+import org.jboss.tools.ws.creation.core.commands.ServiceCreationCommand;
+import org.jboss.tools.ws.creation.core.data.ServiceModel;
+import org.jboss.tools.ws.creation.core.utils.JBossWSCreationUtils;
+import org.jboss.tools.ws.ui.JBossWSUIPlugin;
+import org.jboss.tools.ws.ui.messages.JBossWSUIMessages;
+
+/**
+ * @author Brian Fitzpatrick
+ *
+ */
+public class JBossWSAnnotatedClassWizard extends Wizard implements INewWizard {
+
+ private static final String JDT_EDITOR =
+ "org.eclipse.jdt.ui.CompilationUnitEditor"; //$NON-NLS-1$
+
+ public static String WSNAMEDEFAULT = "HelloWorld"; //$NON-NLS-1$
+ public static String PACKAGEDEFAULT = "org.jboss.samples.webservices";
//$NON-NLS-1$
+ public static String WSCLASSDEFAULT = "HelloWorld"; //$NON-NLS-1$
+
+ public static String RSNAMEDEFAULT = "MyRESTApplication"; //$NON-NLS-1$
+ public static String RSCLASSDEFAULT = "HelloWorldResource"; //$NON-NLS-1$
+ public static String RSAPPCLASSDEFAULT = "MyRESTApplication"; //$NON-NLS-1$
+
+ private String serviceName = WSNAMEDEFAULT;
+ private String packageName = PACKAGEDEFAULT;
+ private String className = WSCLASSDEFAULT;
+ private String appClassName = ""; //$NON-NLS-1$
+ private boolean useDefaultServiceName = true;
+ private boolean useDefaultClassName = true;
+ private boolean updateWebXML = true;
+ private boolean isJAXWS = true;
+
+ private IStructuredSelection selection;
+ private IProject project;
+
+ private static String WEB = "web.xml"; //$NON-NLS-1$
+ private static String WEBINF = "WEB-INF"; //$NON-NLS-1$
+ private IFile webFile;
+
+ public JBossWSAnnotatedClassWizard() {
+ super();
+ super.setWindowTitle(JBossWSUIMessages.JBossWSAnnotatedClassWizard_Annotated_Class_WS_Wizard_Title);
+ super.setHelpAvailable(false);
+ }
+
+ public void addPages() {
+ super.addPages();
+ JBossWSAnnotatedClassWizardPage onePage =
+ new JBossWSAnnotatedClassWizardPage("onePage"); //$NON-NLS-1$
+ addPage(onePage);
+ }
+
+ @Override
+ public boolean performFinish() {
+ if (canFinish()) {
+ ServiceModel model = new ServiceModel();
+ model.setWebProjectName(project.getName());
+ model.addServiceClasses(new StringBuffer().append(getPackageName())
+ .append(".").append(getClassName()).toString()); //$NON-NLS-1$
+ model.setServiceName(getServiceName());
+ model.setUpdateWebxml(getUpdateWebXML());
+ model.setCustomPackage(getPackageName());
+ model.setApplicationClassName( getAppClassName());
+
+ AbstractDataModelOperation mergeCommand = null;
+ if (isJAXWS()) {
+ mergeCommand = new MergeWebXMLCommand(model);
+ } else {
+ mergeCommand = new RSMergeWebXMLCommand(model);
+ }
+
+ IStatus status = null;
+ if (getUpdateWebXML()) {
+ try {
+ status = mergeCommand.execute(null, null);
+ } catch (ExecutionException e) {
+ JBossWSUIPlugin.log(e);
+ }
+ if (status != null && status.getSeverity() == Status.ERROR) {
+ MessageDialog
+ .openError(
+ this.getShell(),
+ JBossWSUIMessages.JBossWS_GenerateWizard_MessageDialog_Title,
+ status.getMessage());
+ return false;
+ }
+ }
+
+ AbstractDataModelOperation addJarsCommand = null;
+ AbstractDataModelOperation addClassesCommand = null;
+ if (!isJAXWS()) {
+ addJarsCommand = new AddRestEasyJarsCommand(model);
+ addClassesCommand = new RSServiceCreationCommand(model);
+ } else {
+ addClassesCommand = new ServiceCreationCommand(model);
+ }
+ try {
+ if (addJarsCommand != null) {
+ addJarsCommand.execute(null, null);
+ }
+ if (addClassesCommand != null) {
+ addClassesCommand.execute(null, null);
+ }
+ getProject().refreshLocal(IProject.DEPTH_INFINITE, new NullProgressMonitor());
+ IFile openFile1 = null;
+ IFile openFile2 = null;
+ if (addClassesCommand instanceof ServiceCreationCommand) {
+ ServiceCreationCommand cmd = (ServiceCreationCommand) addClassesCommand;
+ if (cmd.getResource() != null && cmd.getResource() instanceof IFile) {
+ openFile1 = (IFile) cmd.getResource();
+ }
+ } else if (addClassesCommand instanceof RSServiceCreationCommand) {
+ RSServiceCreationCommand cmd = (RSServiceCreationCommand) addClassesCommand;
+ if (cmd.getAnnotatedClassResource() != null &&
cmd.getAnnotatedClassResource() instanceof IFile) {
+ openFile1 = (IFile) cmd.getAnnotatedClassResource();
+ }
+ if (cmd.getApplicationClassResource() != null &&
cmd.getApplicationClassResource() instanceof IFile) {
+ openFile2 = (IFile) cmd.getApplicationClassResource();
+ }
+ }
+ if (openFile1 != null) {
+ openResource(openFile1);
+ }
+ if (openFile2 != null) {
+ openResource(openFile2);
+ }
+ } catch (ExecutionException e) {
+ JBossWSUIPlugin.log(e);
+ MessageDialog
+ .openError(
+ this.getShell(),
+ JBossWSUIMessages.JBossWS_GenerateWizard_MessageDialog_Title,
+ e.getMessage());
+ } catch (CoreException e) {
+ JBossWSUIPlugin.log(e);
+ MessageDialog
+ .openError(
+ this.getShell(),
+ JBossWSUIMessages.JBossWS_GenerateWizard_MessageDialog_Title,
+ e.getMessage());
+ }
+ }
+ return true;
+ }
+
+ public void init(IWorkbench workbench, IStructuredSelection selection) {
+ this.selection = selection;
+ if (this.selection.getFirstElement() instanceof IProject) {
+ project = (IProject) this.selection.getFirstElement();
+ }
+ if (project != null
+ && JavaEEProjectUtilities.isDynamicWebProject(project)) {
+ webFile = project.getParent().getFolder(
+ JBossWSCreationUtils.getWebContentRootPath(project).append(WEBINF))
+ .getFile(WEB);
+ }
+ }
+
+ @Override
+ public boolean canFinish() {
+ return super.canFinish();
+ }
+
+ public String getServiceName() {
+ return serviceName;
+ }
+
+ public void setServiceName(String serviceName) {
+ this.serviceName = serviceName;
+ }
+
+ public String getPackageName() {
+ return packageName;
+ }
+
+ public void setPackageName(String packageName) {
+ this.packageName = packageName;
+ }
+
+ public String getClassName() {
+ return className;
+ }
+
+ public void setClassName(String className) {
+ this.className = className;
+ }
+
+ public String getAppClassName() {
+ return appClassName;
+ }
+
+ public void setAppClassName(String className) {
+ this.appClassName = className;
+ }
+
+ public boolean isUseDefaultServiceName() {
+ return useDefaultServiceName;
+ }
+
+ public void setUseDefaultServiceName(boolean useDefaultServiceName) {
+ this.useDefaultServiceName = useDefaultServiceName;
+ }
+
+ public boolean isUseDefaultClassName() {
+ return useDefaultClassName;
+ }
+
+ public void setUseDefaultClassName(boolean useDefaultClassName) {
+ this.useDefaultClassName = useDefaultClassName;
+ }
+
+ public void setUpdateWebXML(boolean updateWebXML) {
+ this.updateWebXML = updateWebXML;
+ }
+
+ public boolean getUpdateWebXML() {
+ return updateWebXML;
+ }
+
+ public void setJAXWS(boolean isJAXWS) {
+ this.isJAXWS = isJAXWS;
+ }
+
+ public boolean isJAXWS() {
+ return isJAXWS;
+ }
+
+ public IProject getProject() {
+ return project;
+ }
+
+ public ServiceModel getServiceModel() {
+ ServiceModel model = new ServiceModel();
+ if (project != null) {
+ model.setWebProjectName(project.getName());
+ }
+ if (getPackageName() != null) {
+ model.addServiceClasses(new StringBuffer().append(getPackageName())
+ .append(".").append(getClassName()).toString()); //$NON-NLS-1$
+ }
+ model.setServiceName(getServiceName());
+ model.setUpdateWebxml(true);
+ model.setCustomPackage(getPackageName());
+ model.setCustomClassName(getClassName());
+ return model;
+ }
+
+ public void setProject (String projectName) {
+ if (projectName != null && projectName.trim().length() > 0) {
+ IProject test =
+ ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
+ if (test != null) {
+ this.project = test;
+ if (project != null
+ && JavaEEProjectUtilities.isDynamicWebProject(project)) {
+ webFile = project.getParent().getFolder(
+ JBossWSCreationUtils.getWebContentRootPath(project).append(WEBINF))
+ .getFile(WEB);
+ }
+ }
+ }
+ }
+
+
+ public IFile getWebFile() {
+ return webFile;
+ }
+
+ protected void openResource(final IFile resource) {
+ if (resource.getType() != IResource.FILE) {
+ return;
+ }
+
+ IWorkbenchWindow window = JBossWSUIPlugin.getActiveWorkbenchWindow();
+ if (window == null) {
+ return;
+ }
+
+ final IWorkbenchPage activePage = window.getActivePage();
+ if (activePage != null) {
+ final Display display = getShell().getDisplay();
+ display.asyncExec(new Runnable() {
+ public void run() {
+ try {
+ IDE.openEditor(activePage, resource, JDT_EDITOR, true);
+ } catch (PartInitException e) {
+ JBossWSUIPlugin.log(e);
+ }
+ }
+ });
+ BasicNewResourceWizard.selectAndReveal(resource, activePage
+ .getWorkbenchWindow());
+ }
+ }
+
+}
Property changes on:
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/wizards/JBossWSAnnotatedClassWizard.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/wizards/JBossWSAnnotatedClassWizardPage.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/wizards/JBossWSAnnotatedClassWizardPage.java
(rev 0)
+++
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/wizards/JBossWSAnnotatedClassWizardPage.java 2010-09-08
19:11:58 UTC (rev 24821)
@@ -0,0 +1,707 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.ws.ui.wizards;
+
+import java.util.ArrayList;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.internal.core.PackageFragment;
+import org.eclipse.jdt.ui.IJavaElementSearchConstants;
+import org.eclipse.jdt.ui.JavaUI;
+import org.eclipse.jface.dialogs.DialogPage;
+import org.eclipse.jface.window.Window;
+import org.eclipse.jface.wizard.IWizardPage;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.jst.j2ee.project.JavaEEProjectUtilities;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.dialogs.SelectionDialog;
+import org.jboss.tools.ws.creation.core.data.ServiceModel;
+import org.jboss.tools.ws.creation.core.utils.JBossWSCreationUtils;
+import org.jboss.tools.ws.creation.core.utils.RestEasyLibUtils;
+import org.jboss.tools.ws.ui.messages.JBossWSUIMessages;
+
+@SuppressWarnings("restriction")
+public class JBossWSAnnotatedClassWizardPage extends WizardPage {
+
+ private JBossWSAnnotatedClassWizard wizard;
+ private Combo projects;
+ private boolean bHasChanged = false;
+ private Button optJAXWS;
+ private Button optJAXRS;
+ private Text packageName;
+ private Text className;
+ private Text appClassName;
+ private Text name;
+ private Button updateWebXML;
+ private Button btnPackageBrowse;
+ private Button btnServiceClassBrowse;
+ private Button btnAppClassBrowse;
+
+ protected JBossWSAnnotatedClassWizardPage(String pageName) {
+ super(pageName);
+ this
+ .setTitle(JBossWSUIMessages.JBossWSAnnotatedClassWizardPage_PageTitle);
+ this
+ .setDescription(JBossWSUIMessages.JBossWSAnnotatedClassWizardPage_PageDescription);
+ }
+
+ private void createWsTechComposite(Composite parent) {
+ Group wsTechGroup = new Group(parent, SWT.NONE);
+ wsTechGroup
+ .setText(JBossWSUIMessages.JBossWSAnnotatedClassWizardPage_WS_Tech_Group);
+ GridData gd = new GridData(GridData.FILL_HORIZONTAL);
+ gd.horizontalSpan = 2;
+ wsTechGroup.setLayout(new GridLayout(2, false));
+ wsTechGroup.setLayoutData(gd);
+
+ Composite wsTechComposite = new Composite (wsTechGroup, SWT.NONE);
+ GridLayout gl = new GridLayout(2, true);
+ gl.marginTop = -5;
+ gl.marginBottom = -5;
+ wsTechComposite.setLayout(gl);
+ GridData gridData = new GridData();
+ gridData.horizontalIndent = -5;
+ gridData.grabExcessHorizontalSpace = true;
+ gridData.horizontalAlignment = org.eclipse.swt.layout.GridData.FILL;
+ wsTechComposite.setLayoutData(gridData);
+
+ optJAXWS = new Button(wsTechComposite, SWT.RADIO);
+ optJAXWS.setText(JBossWSUIMessages.JBossWSAnnotatedClassWizardPage_JAXWS_Button);
+ optJAXWS.setLayoutData(new GridData(SWT.FILL, SWT.NULL, true, false));
+
+ optJAXRS = new Button(wsTechComposite, SWT.RADIO);
+ optJAXRS.setText(JBossWSUIMessages.JBossWSAnnotatedClassWizardPage_JAXRS_Button);
+ optJAXRS.setLayoutData(new GridData(SWT.FILL, SWT.NULL, true, false));
+
+ //default
+ optJAXWS.setSelection(true);
+
+ optJAXWS.addSelectionListener(new SelectionListener(){
+ public void widgetSelected(SelectionEvent e) {
+ wizard.setJAXWS(true);
+ appClassName.setEnabled(!wizard.isJAXWS());
+ btnAppClassBrowse.setEnabled(!wizard.isJAXWS());
+ updateDefaultValues();
+ setPageComplete(isPageComplete());
+ }
+ public void widgetDefaultSelected(SelectionEvent e) {
+ widgetSelected(e);
+ }
+ });
+ optJAXRS.addSelectionListener(new SelectionListener(){
+ public void widgetSelected(SelectionEvent e) {
+ wizard.setJAXWS(false);
+ appClassName.setEnabled(!wizard.isJAXWS());
+ btnAppClassBrowse.setEnabled(!wizard.isJAXWS());
+ updateDefaultValues();
+ setPageComplete(isPageComplete());
+ }
+ public void widgetDefaultSelected(SelectionEvent e) {
+ widgetSelected(e);
+ }
+ });
+ }
+
+ private String testDefaultServiceName( String currentName) {
+ ServiceModel model = wizard.getServiceModel();
+ JBossWSGenerateWizardValidator.setServiceModel(model);
+ IStatus status = JBossWSGenerateWizardValidator.isWSNameValid();
+ try {
+ if (status.getSeverity() == IStatus.ERROR
+ && !JavaEEProjectUtilities.isDynamicWebProject(wizard
+ .getProject())) {
+ return currentName;
+ }
+ } catch (NullPointerException npe) {
+ return currentName;
+ }
+ String testName = currentName;
+ int i = 1;
+ while (status != null) {
+ testName = currentName + i;
+ wizard.setServiceName(testName);
+ model = wizard.getServiceModel();
+ JBossWSGenerateWizardValidator.setServiceModel(model);
+ status = JBossWSGenerateWizardValidator.isWSNameValid();
+ i++;
+ }
+ return testName;
+ }
+
+ private String testDefaultAppClassName(String currentName) {
+ ServiceModel model = wizard.getServiceModel();
+ JBossRSGenerateWizardValidator.setServiceModel(model);
+ if (wizard.getProject() == null) {
+ return currentName;
+ } else {
+ boolean isDynamicWebProject = false;
+ try {
+ if (wizard.getProject().getNature(
+ "org.eclipse.wst.common.project.facet.core.nature") != null) {
//$NON-NLS-1$
+ isDynamicWebProject = true;
+ }
+ } catch (CoreException e) {
+ // ignore
+ }
+ if (!isDynamicWebProject) {
+ return currentName;
+ }
+ }
+ String testName = currentName;
+ IStatus status = JBossRSGenerateWizardValidator.isAppClassNameValid(
+ model.getCustomPackage() + '.' + currentName);
+ int i = 1;
+ while (status != null && status.getSeverity() == IStatus.ERROR) {
+ testName = currentName + i;
+ wizard.setClassName(testName);
+ model = wizard.getServiceModel();
+ JBossWSGenerateWizardValidator.setServiceModel(model);
+ status = JBossWSGenerateWizardValidator.isWSClassValid(testName,
+ wizard.getProject());
+ i++;
+ }
+ return testName;
+ }
+
+ private String testDefaultClassName(String currentName) {
+ ServiceModel model = wizard.getServiceModel();
+ JBossWSGenerateWizardValidator.setServiceModel(model);
+ if (wizard.getProject() == null) {
+ return currentName;
+ } else {
+ boolean isDynamicWebProject = false;
+ try {
+ if (wizard.getProject().getNature(
+ "org.eclipse.wst.common.project.facet.core.nature") != null) {
//$NON-NLS-1$
+ isDynamicWebProject = true;
+ }
+ } catch (CoreException e) {
+ // ignore
+ }
+ if (!isDynamicWebProject) {
+ return currentName;
+ }
+ }
+ String testName = currentName;
+ IStatus status = JBossWSGenerateWizardValidator.isWSClassValid(
+ testName, wizard.getProject());
+ int i = 1;
+ while (status != null && status.getSeverity() == IStatus.ERROR) {
+ testName = currentName + i;
+ wizard.setClassName(testName);
+ model = wizard.getServiceModel();
+ JBossWSGenerateWizardValidator.setServiceModel(model);
+ status = JBossWSGenerateWizardValidator.isWSClassValid(testName,
+ wizard.getProject());
+ i++;
+ }
+ return testName;
+ }
+
+ private void updateDefaultValues() {
+
+ String testName = null;
+ if (wizard.isJAXWS()) {
+ if (className != null && className.getText().trim().length() == 0) {
+ testName = testDefaultClassName(JBossWSAnnotatedClassWizard.WSCLASSDEFAULT);
+ className.setText(testName);
+ wizard.setClassName(testName);
+ }
+
+ if (name != null && name.getText().trim().length() == 0) {
+ testName = testDefaultServiceName(JBossWSAnnotatedClassWizard.WSNAMEDEFAULT);
+ name.setText(testName);
+ wizard.setServiceName(testName);
+ }
+ appClassName.setText(""); //$NON-NLS-1$
+ wizard.setAppClassName(""); //$NON-NLS-1$
+ } else {
+ if (className != null && className.getText().trim().length() == 0) {
+ testName = testDefaultClassName(JBossWSAnnotatedClassWizard.RSCLASSDEFAULT);
+ className.setText(testName);
+ wizard.setClassName(testName);
+ }
+ if (name != null && name.getText().trim().length() == 0) {
+ testName = testDefaultServiceName(JBossWSAnnotatedClassWizard.RSNAMEDEFAULT);
+ name.setText(testName);
+ wizard.setServiceName(testName);
+ }
+ if (appClassName != null && appClassName.getText().trim().length() == 0) {
+ testName = testDefaultAppClassName(JBossWSAnnotatedClassWizard.RSAPPCLASSDEFAULT);
+ appClassName.setText(testName);
+ wizard.setAppClassName(testName);
+ }
+ }
+ if (packageName != null && packageName.getText().trim().length() == 0) {
+ packageName.setText(JBossWSAnnotatedClassWizard.PACKAGEDEFAULT);
+ wizard.setPackageName(packageName.getText());
+ }
+ }
+
+ private void createProjectGroup ( Composite parent ) {
+ Group group = new Group(parent, SWT.NONE);
+ group
+ .setText(JBossWSUIMessages.JBossWSAnnotatedClassWizardPage_Project_Group);
+ GridData gd = new GridData(GridData.FILL_HORIZONTAL);
+ gd.horizontalSpan = 2;
+ group.setLayout(new GridLayout(2, false));
+ group.setLayoutData(gd);
+
+ projects = new Combo(group, SWT.BORDER | SWT.DROP_DOWN);
+ projects
+ .setToolTipText(JBossWSUIMessages.JBossWSAnnotatedClassWizardPage_Projects_Combo_Tooltip);
+ gd = new GridData(GridData.FILL_HORIZONTAL);
+ gd.horizontalSpan = 2;
+ projects.setLayoutData(gd);
+ refreshProjectList(wizard.getServiceModel().getWebProjectName());
+
+ projects.addSelectionListener(new SelectionListener() {
+ public void widgetSelected(SelectionEvent e) {
+ wizard.setProject(projects.getText());
+ bHasChanged = true;
+ setPageComplete(isPageComplete());
+ }
+ public void widgetDefaultSelected(SelectionEvent e) {
+ widgetSelected(e);
+ }
+ });
+
+ }
+
+ private void createApplicationGroup(Composite parent) {
+ GridData gd = new GridData();
+ gd.grabExcessHorizontalSpace = true;
+ gd.horizontalSpan = 2;
+ gd.horizontalIndent = -5;
+ gd.horizontalAlignment = org.eclipse.swt.layout.GridData.FILL;
+ Group group = new Group(parent, SWT.NONE);
+ group.setLayout(new GridLayout(2, false));
+ group.setText(JBossWSUIMessages.JBossWSAnnotatedClassWizardPage_Web_Service_Group);
+ group.setLayoutData(gd);
+
+ new Label(group, SWT.NONE)
+ .setText(JBossWSUIMessages.JBossWSAnnotatedClassWizardPage_Service_Name_field);
+ name = new Text(group, SWT.BORDER);
+ gd = new GridData(GridData.FILL_HORIZONTAL);
+ name.setLayoutData(gd);
+// name.setText(wizard.getServiceName());
+ name.addModifyListener(new ModifyListener() {
+
+ public void modifyText(ModifyEvent e) {
+ wizard.setServiceName(name.getText());
+ bHasChanged = true;
+ setPageComplete(isPageComplete());
+ }
+
+ });
+
+ updateWebXML = new Button(group, SWT.CHECK);
+ updateWebXML.setText(JBossWSUIMessages.JBossWSAnnotatedClassWizardPage_Update_Web_xml_checkbox);
+ gd = new GridData(GridData.FILL_HORIZONTAL);
+ gd.horizontalSpan = 2;
+ updateWebXML.setLayoutData(gd);
+ updateWebXML.setSelection(wizard.getUpdateWebXML());
+ updateWebXML.addSelectionListener(new SelectionListener() {
+ public void widgetSelected(SelectionEvent e) {
+ wizard.setUpdateWebXML(updateWebXML.getSelection());
+ name.setEnabled(wizard.getUpdateWebXML());
+ setPageComplete(isPageComplete());
+ }
+ public void widgetDefaultSelected(SelectionEvent e) {
+ widgetSelected(e);
+ }
+ });
+
+ }
+
+ private void createImplementationGroup(Composite parent) {
+ GridData gd = new GridData();
+ gd.grabExcessHorizontalSpace = true;
+ gd.horizontalSpan = 2;
+ gd.horizontalIndent = -5;
+ gd.horizontalAlignment = org.eclipse.swt.layout.GridData.FILL;
+ Group group = new Group(parent, SWT.NONE);
+ group.setLayout(new GridLayout(3, false));
+ group.setText(JBossWSUIMessages.JBossWSAnnotatedClassWizardPage_Service_implementation_group);
+ group.setLayoutData(gd);
+
+ new Label(group, SWT.NONE)
+ .setText(JBossWSUIMessages.JBossWSAnnotatedClassWizardPage_package_name_field);
+ packageName = new Text(group, SWT.BORDER);
+ gd = new GridData(GridData.FILL_HORIZONTAL);
+ packageName.setLayoutData(gd);
+ packageName.setText(wizard.getPackageName());
+ packageName.addModifyListener(new ModifyListener() {
+
+ public void modifyText(ModifyEvent e) {
+ wizard.setPackageName(packageName.getText());
+ setPageComplete(isPageComplete());
+ }
+
+ });
+
+ btnPackageBrowse = new Button(group, SWT.PUSH);
+ btnPackageBrowse.setText(JBossWSUIMessages.JBossWSAnnotatedClassWizardPage_package_browse_btn);
+ btnPackageBrowse.addSelectionListener(new SelectionListener(){
+ public void widgetSelected(SelectionEvent e) {
+ if (wizard.getProject() == null) {
+ return;
+ }
+
+ IJavaProject project = JavaCore.create( wizard.getProject());
+ if (project == null) {
+ return;
+ }
+
+ try {
+ SelectionDialog dialog =
+ JavaUI.createPackageDialog(
+ getShell(),
+ project,
+ IJavaElementSearchConstants.CONSIDER_REQUIRED_PROJECTS);
+ if (dialog.open() == Window.OK) {
+ if (dialog.getResult() != null && dialog.getResult().length == 1) {
+ String fqClassName = ((PackageFragment) dialog.getResult()[0]).getElementName();
+ packageName.setText(fqClassName);
+ setPageComplete(isPageComplete());
+ }
+ }
+ } catch (JavaModelException e1) {
+ e1.printStackTrace();
+ }
+ }
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+ });
+
+ new Label(group, SWT.NONE)
+ .setText(JBossWSUIMessages.JBossWSAnnotatedClassWizardPage_Service_class_field);
+ className = new Text(group, SWT.BORDER);
+ gd = new GridData(GridData.FILL_HORIZONTAL);
+ className.setLayoutData(gd);
+// className.setText(wizard.getClassName());
+ className.addModifyListener(new ModifyListener() {
+
+ public void modifyText(ModifyEvent e) {
+ wizard.setClassName(className.getText());
+ setPageComplete(isPageComplete());
+ }
+
+ });
+
+ btnServiceClassBrowse = new Button(group, SWT.PUSH);
+ btnServiceClassBrowse.setText(JBossWSUIMessages.JBossWSAnnotatedClassWizardPage_Service_class_Browse_btn);
+ btnServiceClassBrowse.addSelectionListener(new SelectionListener(){
+ public void widgetSelected(SelectionEvent e) {
+ if (wizard.getProject() == null) {
+ return;
+ }
+
+ try {
+ SelectionDialog dialog =
+ JavaUI.createTypeDialog(
+ getShell(),
+ null,
+ wizard.getProject(),
+ IJavaElementSearchConstants.CONSIDER_CLASSES,
+ false);
+ if (dialog.open() == Window.OK) {
+ if (dialog.getResult() != null && dialog.getResult().length == 1) {
+ String fqClassName = ((IType) dialog.getResult()[0]).getElementName();
+ className.setText(fqClassName);
+ setPageComplete(isPageComplete());
+ }
+ }
+ } catch (JavaModelException e1) {
+ e1.printStackTrace();
+ }
+ }
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+ });
+
+ new Label(group, SWT.NONE)
+ .setText(JBossWSUIMessages.JBossWSAnnotatedClassWizardPage_Application_Class_field);
+ appClassName = new Text(group, SWT.BORDER);
+ gd = new GridData(GridData.FILL_HORIZONTAL);
+ appClassName.setLayoutData(gd);
+// appClassName.setText(wizard.getAppClassName());
+ appClassName.addModifyListener(new ModifyListener() {
+
+ public void modifyText(ModifyEvent e) {
+ wizard.setAppClassName(appClassName.getText());
+ setPageComplete(isPageComplete());
+ }
+
+ });
+
+ btnAppClassBrowse = new Button(group, SWT.PUSH);
+ btnAppClassBrowse.setText(JBossWSUIMessages.JBossWSAnnotatedClassWizardPage_Application_Class_Browse_btn);
+ btnAppClassBrowse.addSelectionListener(new SelectionListener(){
+ public void widgetSelected(SelectionEvent e) {
+ if (wizard.getProject() == null) {
+ return;
+ }
+
+ try {
+ SelectionDialog dialog =
+ JavaUI.createTypeDialog(
+ getShell(),
+ null,
+ wizard.getProject(),
+ IJavaElementSearchConstants.CONSIDER_CLASSES,
+ false);
+ if (dialog.open() == Window.OK) {
+ if (dialog.getResult() != null && dialog.getResult().length == 1) {
+ String fqClassName = ((IType) dialog.getResult()[0]).getElementName();
+ appClassName.setText(fqClassName);
+ setPageComplete(isPageComplete());
+ }
+ }
+ } catch (JavaModelException e1) {
+ e1.printStackTrace();
+ }
+ }
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+ });
+ }
+
+ public void createControl(Composite parent) {
+ Composite composite = createDialogArea(parent);
+ this.wizard = (JBossWSAnnotatedClassWizard) this.getWizard();
+
+ createWsTechComposite(composite);
+ createProjectGroup(composite);
+ createApplicationGroup(composite);
+ createImplementationGroup(composite);
+ appClassName.setEnabled(!wizard.isJAXWS());
+ btnAppClassBrowse.setEnabled(!wizard.isJAXWS());
+ updateDefaultValues();
+
+ setControl(composite);
+ }
+
+ private void refreshProjectList(String projectName) {
+ String[] projectNames = getProjects();
+ boolean foundInitialProject = false;
+ projects.removeAll();
+ for (int i = 0; i < projectNames.length; i++) {
+ projects.add(projectNames[i]);
+ if (projectNames[i].equals(projectName)) {
+ foundInitialProject = true;
+ }
+ }
+ if (foundInitialProject)
+ projects.setText(projectName);
+ }
+
+ public IWizardPage getNextPage() {
+ return super.getNextPage();
+ }
+
+ private Composite createDialogArea(Composite parent) {
+ // create a composite with standard margins and spacing
+ Composite composite = new Composite(parent, SWT.NONE);
+ GridLayout layout = new GridLayout();
+ layout.marginHeight = 7;
+ layout.marginWidth = 7;
+ layout.verticalSpacing = 4;
+ layout.horizontalSpacing = 4;
+ layout.numColumns = 2;
+ composite.setLayout(layout);
+ composite.setLayoutData(new GridData(GridData.FILL_BOTH));
+ return composite;
+ }
+
+ @Override
+ public boolean isPageComplete() {
+ return validate();
+ }
+
+ private boolean validate() {
+ ServiceModel model = wizard.getServiceModel();
+ if (wizard.isJAXWS()) {
+ setMessage(JBossWSUIMessages.JBossWS_GenerateWizard_GenerateWizardPage_Description);
+ setErrorMessage(null);
+
+ JBossWSGenerateWizardValidator.setServiceModel(model);
+
+ if (!projects.isDisposed() && projects.getText().length() > 0) {
+ model.setWebProjectName(projects.getText());
+ }
+
+ if (((JBossWSAnnotatedClassWizard) this.getWizard()).getProject() == null) {
+ setErrorMessage(JBossWSUIMessages.Error_JBossWS_GenerateWizard_NoProjectSelected);
+ return false;
+ }
+
+ IFile web = ((JBossWSAnnotatedClassWizard) this.getWizard()).getWebFile();
+ if (web == null || !web.exists()) {
+ setErrorMessage(JBossWSUIMessages.Error_JBossWS_GenerateWizard_NotDynamicWebProject);
+ return false;
+ }
+
+ try {
+ if
("" .equals(JBossWSCreationUtils.getJavaProjectSrcLocation(((JBossWSAnnotatedClassWizard)
this.getWizard()).getProject()))) { //$NON-NLS-1$
+ setErrorMessage(JBossWSUIMessages.Error_JBossWS_GenerateWizard_NoSrcInProject);
+ return false;
+ }
+ } catch (JavaModelException e) {
+ e.printStackTrace();
+ }
+
+ IStatus status = JBossWSGenerateWizardValidator.isWSNameValid();
+ if (status != null) {
+ setErrorMessage(status.getMessage());
+ return false;
+ }
+
+ IStatus classNameStatus = JBossWSGenerateWizardValidator.isWSClassValid(model
+ .getCustomClassName(), wizard.getProject());
+ if (classNameStatus != null) {
+ if (classNameStatus.getSeverity() == IStatus.ERROR) {
+ setErrorMessage(classNameStatus.getMessage());
+ return false;
+ } else if (classNameStatus.getSeverity() == IStatus.WARNING) {
+ setMessage(classNameStatus.getMessage(), DialogPage.WARNING);
+ setErrorMessage(null);
+ return true;
+ }
+ }
+
+ setMessage(JBossWSUIMessages.JBossWS_GenerateWizard_GenerateWizardPage_Description);
+ setErrorMessage(null);
+ return true;
+ } else {
+ setMessage(JBossWSUIMessages.JBossWS_GenerateWizard_GenerateWizardPage_Description);
+ setErrorMessage(null);
+
+ JBossRSGenerateWizardValidator.setServiceModel(model);
+ if (!projects.isDisposed() && projects.getText().length() > 0) {
+ model.setWebProjectName(projects.getText());
+ }
+
+ // no project selected
+ if (((JBossWSAnnotatedClassWizard) this.getWizard()).getProject() == null) {
+ setErrorMessage(JBossWSUIMessages.Error_JBossWS_GenerateWizard_NoProjectSelected);
+ return false;
+ }
+
+ // project not a dynamic web project
+ IFile web = ((JBossWSAnnotatedClassWizard) this.getWizard()).getWebFile();
+ if (web == null || !web.exists()) {
+ setErrorMessage(JBossWSUIMessages.Error_JBossWS_GenerateWizard_NotDynamicWebProject);
+ return false;
+ }
+
+ IStatus reInstalledStatus =
+ RestEasyLibUtils.doesRuntimeSupportRestEasy(((JBossWSAnnotatedClassWizard)
this.getWizard()).getProject());
+ if (reInstalledStatus.getSeverity() != IStatus.OK){
+ setErrorMessage(JBossWSUIMessages.JBossRSGenerateWizardPage_Error_RestEasyJarsNotFoundInRuntime);
+ return false;
+ }
+
+ // no source folder in web project
+ try {
+ if
("" .equals(JBossWSCreationUtils.getJavaProjectSrcLocation(((JBossWSAnnotatedClassWizard)
this.getWizard()).getProject()))) { //$NON-NLS-1$
+ setErrorMessage(JBossWSUIMessages.Error_JBossWS_GenerateWizard_NoSrcInProject);
+ return false;
+ }
+ } catch (JavaModelException e) {
+ e.printStackTrace();
+ }
+
+ // already has a REST sample installed - can't use wizard again
+ if (wizard.getUpdateWebXML()) {
+ IStatus alreadyHasREST = JBossRSGenerateWizardValidator.RESTAppExists();
+ if (alreadyHasREST != null) {
+ if (alreadyHasREST.getSeverity() == IStatus.ERROR) {
+ setErrorMessage(alreadyHasREST.getMessage());
+ return false;
+ } else if (alreadyHasREST.getSeverity() == IStatus.WARNING) {
+ setMessage(alreadyHasREST.getMessage(), DialogPage.WARNING);
+ setErrorMessage(null);
+ return true;
+ }
+ }
+ }
+
+ // Check the service class name
+ IStatus classNameStatus = JBossRSGenerateWizardValidator.isWSClassValid(model
+ .getCustomClassName(), wizard.getProject());
+ if (classNameStatus != null) {
+ if (classNameStatus.getSeverity() == IStatus.ERROR) {
+ setErrorMessage(classNameStatus.getMessage());
+ return false;
+ } else if (classNameStatus.getSeverity() == IStatus.WARNING) {
+ setMessage(classNameStatus.getMessage(), DialogPage.WARNING);
+ setErrorMessage(null);
+ return true;
+ }
+ }
+
+ // check the application class name
+ IStatus appClassNameStatus = JBossRSGenerateWizardValidator.isAppClassNameValid(
+ model.getCustomPackage() + '.' + model.getApplicationClassName());
+ if (appClassNameStatus != null) {
+ if (appClassNameStatus.getSeverity() == IStatus.ERROR) {
+ setMessage(appClassNameStatus.getMessage(), DialogPage.ERROR);
+ return false;
+ } else if (appClassNameStatus.getSeverity() == IStatus.WARNING) {
+ setMessage(appClassNameStatus.getMessage(), DialogPage.WARNING);
+ return true;
+ }
+ }
+ }
+ setMessage(JBossWSUIMessages.JBossWSAnnotatedClassWizardPage_PageDescription);
+ setErrorMessage(null);
+ return true;
+ }
+
+ private String[] getProjects() {
+ IProject[] projects = ResourcesPlugin.getWorkspace().getRoot()
+ .getProjects();
+ ArrayList<String> dynamicProjects = new ArrayList<String>();
+ for (int i = 0; i < projects.length; i++) {
+ boolean isDynamicWebProject = JavaEEProjectUtilities
+ .isDynamicWebProject(projects[i]);
+ if (isDynamicWebProject) {
+ dynamicProjects.add(projects[i].getName());
+ }
+ }
+ return dynamicProjects.toArray(new String[dynamicProjects.size()]);
+ }
+
+ protected boolean hasChanged() {
+ return bHasChanged;
+ }
+}
Property changes on:
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/wizards/JBossWSAnnotatedClassWizardPage.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain