Author: Grid.Qian
Date: 2010-01-28 05:56:25 -0500 (Thu, 28 Jan 2010)
New Revision: 19980
Modified:
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/commands/MergeWebXMLCommand.java
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/messages/JBossWSCreationCore.properties
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/messages/JBossWSCreationCoreMessages.java
trunk/ws/plugins/org.jboss.tools.ws.ui/META-INF/MANIFEST.MF
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/JBossWSUIMessages.java
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/utils/UIUtils.java
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/wizards/JBossWSGenerateSampleClassWizardPage.java
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/wizards/JBossWSGenerateWebXmlWizardPage.java
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/wizards/JBossWSGenerateWizard.java
Log:
JBIDE-5715: create a wizard for generating a sample web service class in a dynamic
project
Modified:
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/commands/MergeWebXMLCommand.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/commands/MergeWebXMLCommand.java 2010-01-28
07:44:11 UTC (rev 19979)
+++
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/commands/MergeWebXMLCommand.java 2010-01-28
10:56:25 UTC (rev 19980)
@@ -28,8 +28,8 @@
import org.eclipse.jst.javaee.web.ServletMapping;
import org.eclipse.jst.javaee.web.WebApp;
import org.eclipse.jst.javaee.web.WebFactory;
-import org.eclipse.wst.common.environment.IEnvironment;
import org.eclipse.wst.common.frameworks.datamodel.AbstractDataModelOperation;
+import org.jboss.tools.ws.core.utils.StatusUtils;
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;
@@ -40,6 +40,7 @@
public class MergeWebXMLCommand extends AbstractDataModelOperation {
private ServiceModel model;
+ IStatus status;
public MergeWebXMLCommand(ServiceModel model) {
this.model = model;
@@ -48,12 +49,11 @@
@Override
public IStatus execute(IProgressMonitor monitor, IAdaptable info)
throws ExecutionException {
+ status = Status.OK_STATUS;
if (!model.isUpdateWebxml()) {
- return Status.OK_STATUS;
+ return status;
}
- IEnvironment environment = getEnvironment();
- IStatus status = null;
ServletDescriptor[] servletDescriptors = new ServletDescriptor[model
.getServiceClasses().size()];
List<String> serviceClasses = model.getServiceClasses();
@@ -61,16 +61,11 @@
servletDescriptors[i] = getServletDescriptor(serviceClasses.get(i));
}
- status = mergeWebXML(servletDescriptors);
- if (status.getSeverity() == Status.ERROR) {
- environment.getStatusHandler().reportError(status);
- return status;
- }
- return Status.OK_STATUS;
+ mergeWebXML(servletDescriptors);
+ return status;
}
- private IStatus mergeWebXML(final ServletDescriptor[] servletDescriptors) {
- IStatus status = Status.OK_STATUS;
+ private void mergeWebXML(final ServletDescriptor[] servletDescriptors) {
final IModelProvider provider = ModelProviderManager
.getModelProvider(JBossWSCreationUtils.getProjectByName(model
.getWebProjectName()));
@@ -96,7 +91,6 @@
}
}, null);
- return status;
}
@SuppressWarnings("unchecked")
@@ -108,9 +102,21 @@
org.eclipse.jst.j2ee.webapplication.Servlet aServlet =
(org.eclipse.jst.j2ee.webapplication.Servlet) theServlets
.get(i);
if (aServlet.getServletName().equals(servletDescriptor._name)) {
+ status =
StatusUtils.errorStatus(JBossWSCreationCoreMessages.Error_JBossWS_GenerateWizard_WSName_Same);
return;
}
}
+ List theServletMapplings = webapp.getServletMappings();
+ for (int i = 0; i < theServletMapplings.size(); i++) {
+ org.eclipse.jst.j2ee.webapplication.ServletMapping aServletMapping =
(org.eclipse.jst.j2ee.webapplication.ServletMapping) theServletMapplings
+ .get(i);
+ if (aServletMapping.getName().equals(servletDescriptor._name)
+ || aServletMapping.getUrlPattern().equals(
+ servletDescriptor._mappings)) {
+ status =
StatusUtils.errorStatus(JBossWSCreationCoreMessages.Error_JBossWS_GenerateWizard_WSName_Same);
+ return;
+ }
+ }
org.eclipse.jst.j2ee.webapplication.WebapplicationFactory factory =
org.eclipse.jst.j2ee.webapplication.WebapplicationFactory.eINSTANCE;
org.eclipse.jst.j2ee.webapplication.Servlet servlet = factory
.createServlet();
@@ -131,7 +137,6 @@
servletMapping.setUrlPattern(servletDescriptor._mappings);
webapp.getServletMappings().add(servletMapping);
}
-
}
private ServletDescriptor getServletDescriptor(String clsName) {
@@ -155,12 +160,36 @@
public void addjeeServlet(IProject webProject,
ServletDescriptor servletDescriptor, WebApp webapp) {
List theServlets = webapp.getServlets();
+
for (int i = 0; i < theServlets.size(); i++) {
Servlet aServlet = (Servlet) theServlets.get(i);
if (aServlet.getServletName().equals(servletDescriptor._name)) {
+ status =
StatusUtils.errorStatus(JBossWSCreationCoreMessages.Error_JBossWS_GenerateWizard_WSName_Same);
return;
}
}
+
+ List theServletMapplings = webapp.getServletMappings();
+ for (int i = 0; i < theServletMapplings.size(); i++) {
+ ServletMapping aServletMapping = (ServletMapping) theServletMapplings
+ .get(i);
+ if (aServletMapping.getServletName()
+ .equals(servletDescriptor._name)) {
+ status =
StatusUtils.errorStatus(JBossWSCreationCoreMessages.Error_JBossWS_GenerateWizard_WSName_Same);
+ return;
+ }
+ List list = aServletMapping.getUrlPatterns();
+ if (list != null) {
+ for (int j = 0; j < list.size(); j++) {
+ UrlPatternType url = (UrlPatternType) list.get(j);
+ if (url.getValue().equals(servletDescriptor._mappings)) {
+ status =
StatusUtils.errorStatus(JBossWSCreationCoreMessages.Error_JBossWS_GenerateWizard_WSName_Same);
+ return;
+ }
+ }
+ }
+ }
+
WebFactory factory = WebFactory.eINSTANCE;
Servlet servlet = factory.createServlet();
servlet.setServletName(servletDescriptor._name);
Modified:
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/messages/JBossWSCreationCore.properties
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/messages/JBossWSCreationCore.properties 2010-01-28
07:44:11 UTC (rev 19979)
+++
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/messages/JBossWSCreationCore.properties 2010-01-28
10:56:25 UTC (rev 19980)
@@ -53,3 +53,4 @@
Command=wsconsume.sh
Bin=bin
+Error_JBossWS_GenerateWizard_WSName_Same=The Web Service Name has been used in the
web.xml of the web project.
Modified:
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/messages/JBossWSCreationCoreMessages.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/messages/JBossWSCreationCoreMessages.java 2010-01-28
07:44:11 UTC (rev 19979)
+++
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/messages/JBossWSCreationCoreMessages.java 2010-01-28
10:56:25 UTC (rev 19980)
@@ -64,6 +64,7 @@
public static String Command;
public static String Bin;
+ public static String Error_JBossWS_GenerateWizard_WSName_Same;
private JBossWSCreationCoreMessages() {
}
Modified: trunk/ws/plugins/org.jboss.tools.ws.ui/META-INF/MANIFEST.MF
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.ui/META-INF/MANIFEST.MF 2010-01-28 07:44:11 UTC
(rev 19979)
+++ trunk/ws/plugins/org.jboss.tools.ws.ui/META-INF/MANIFEST.MF 2010-01-28 10:56:25 UTC
(rev 19980)
@@ -15,7 +15,8 @@
org.eclipse.jst.j2ee,
org.eclipse.jem.util,
org.jboss.tools.ws.creation.core,
- org.eclipse.wst.common.frameworks
+ org.eclipse.wst.common.frameworks,
+ org.eclipse.wst.common.emfworkbench.integration
Bundle-ActivationPolicy: lazy
Export-Package: org.jboss.tools.ws.ui,
org.jboss.tools.ws.ui.messages,
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-01-28
07:44:11 UTC (rev 19979)
+++
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/messages/JBossWSUI.properties 2010-01-28
10:56:25 UTC (rev 19980)
@@ -52,4 +52,6 @@
JBossWS_GenerateWizard_WizardPage_CheckButton_Label=Use the default value
JBossWS_GenerateWizard_GenerateSampleClassPage_Package_Label=Package
JBossWS_GenerateWizard_GenerateSampleClassPage_ClassName_Label=Class
-JBossWS_GenerateWizard_NotDynamicWebProject_Error=This wizard may only be used on Dynamic
Web Projects.
+Error_JBossWS_GenerateWizard_NotDynamicWebProject=The project must be a Dynamic Web
Project and contain a web.xml in a right Location
+Error_JBossWS_GenerateWizard_ClassName_Same=The class name has been used in the web
project.
+JBossWS_GenerateWizard_MessageDialog_Title=Error
Modified:
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/messages/JBossWSUIMessages.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/messages/JBossWSUIMessages.java 2010-01-28
07:44:11 UTC (rev 19979)
+++
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/messages/JBossWSUIMessages.java 2010-01-28
10:56:25 UTC (rev 19980)
@@ -86,7 +86,9 @@
public static String JBossWS_GenerateWizard_WizardPage_CheckButton_Label;
public static String JBossWS_GenerateWizard_GenerateSampleClassPage_Package_Label;
public static String JBossWS_GenerateWizard_GenerateSampleClassPage_ClassName_Label;
- public static String JBossWS_GenerateWizard_NotDynamicWebProject_Error;
+ public static String Error_JBossWS_GenerateWizard_NotDynamicWebProject;
+ public static String Error_JBossWS_GenerateWizard_ClassName_Same;
+ public static String JBossWS_GenerateWizard_MessageDialog_Title;
static {
Modified:
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/utils/UIUtils.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/utils/UIUtils.java 2010-01-28
07:44:11 UTC (rev 19979)
+++
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/utils/UIUtils.java 2010-01-28
10:56:25 UTC (rev 19980)
@@ -23,6 +23,8 @@
import java.util.ArrayList;
import java.util.List;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.IPath;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
@@ -37,6 +39,9 @@
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.ui.PlatformUI;
+import org.eclipse.wst.common.componentcore.ComponentCore;
+import org.eclipse.wst.common.componentcore.ModuleCoreNature;
+import org.eclipse.wst.common.componentcore.resources.IVirtualComponent;
/**
* @author Grid Qian
@@ -498,5 +503,21 @@
matchingFilePath.delete();
}
}
+
+ public static IPath getWebContentRootPath(IProject project) {
+ if (project == null)
+ return null;
+
+ if (!ModuleCoreNature.isFlexibleProject(project))
+ return null;
+
+ IPath path = null;
+ IVirtualComponent component = ComponentCore.createComponent(project);
+ if (component != null && component.exists()) {
+ path = component.getRootFolder().getWorkspaceRelativePath();
+ }
+ return path;
+ }
+
}
\ No newline at end of file
Modified:
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/wizards/JBossWSGenerateSampleClassWizardPage.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/wizards/JBossWSGenerateSampleClassWizardPage.java 2010-01-28
07:44:11 UTC (rev 19979)
+++
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/wizards/JBossWSGenerateSampleClassWizardPage.java 2010-01-28
10:56:25 UTC (rev 19980)
@@ -7,7 +7,7 @@
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
+ ******************************************************************************/
package org.jboss.tools.ws.ui.wizards;
import org.eclipse.jface.wizard.WizardPage;
@@ -41,40 +41,42 @@
public void createControl(Composite parent) {
Composite composite = createDialogArea(parent);
this.wizard = (JBossWSGenerateWizard) this.getWizard();
- new Label(composite,
SWT.NONE).setText(JBossWSUIMessages.JBossWS_GenerateWizard_GenerateSampleClassPage_Package_Label);
+ new Label(composite, SWT.NONE)
+ .setText(JBossWSUIMessages.JBossWS_GenerateWizard_GenerateSampleClassPage_Package_Label);
packageName = new Text(composite, SWT.BORDER);
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
packageName.setLayoutData(gd);
packageName.setText(wizard.getPackageName());
packageName.setEnabled(!wizard.isUseDefaultClassName());
- packageName.addModifyListener(new ModifyListener(){
+ packageName.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
- if
(!"".equals(packageName.getText())&&!"".equals(className.getText())){
//$NON-NLS-1$ //$NON-NLS-2$
+ if (!"".equals(packageName.getText()) &&
!"".equals(className.getText())) { //$NON-NLS-1$ //$NON-NLS-2$
setPageComplete(true);
- }else {
+ } else {
setPageComplete(false);
}
}
-
+
});
-
- new Label(composite,
SWT.NONE).setText(JBossWSUIMessages.JBossWS_GenerateWizard_GenerateSampleClassPage_ClassName_Label);
+
+ new Label(composite, SWT.NONE)
+ .setText(JBossWSUIMessages.JBossWS_GenerateWizard_GenerateSampleClassPage_ClassName_Label);
className = new Text(composite, SWT.BORDER);
gd = new GridData(GridData.FILL_HORIZONTAL);
className.setLayoutData(gd);
className.setText(wizard.getClassName());
className.setEnabled(!wizard.isUseDefaultClassName());
- className.addModifyListener(new ModifyListener(){
+ className.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
- if
(!"".equals(packageName.getText())&&!"".equals(className.getText())){
//$NON-NLS-1$ //$NON-NLS-2$
+ if (!"".equals(packageName.getText()) &&
!"".equals(className.getText())) { //$NON-NLS-1$ //$NON-NLS-2$
setPageComplete(true);
- }else {
+ } else {
setPageComplete(false);
}
}
-
+
});
checkDefault = new Button(composite, SWT.CHECK);
@@ -82,7 +84,8 @@
gd.horizontalSpan = 2;
checkDefault.setLayoutData(gd);
checkDefault.setSelection(wizard.isUseDefaultClassName());
- checkDefault.setText(JBossWSUIMessages.JBossWS_GenerateWizard_WizardPage_CheckButton_Label);
+ checkDefault
+ .setText(JBossWSUIMessages.JBossWS_GenerateWizard_WizardPage_CheckButton_Label);
checkDefault.addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent e) {
@@ -107,11 +110,11 @@
}
public boolean isPageComplete() {
-
if(!"".equals(packageName.getText())&&!"".equals(className.getText())){
//$NON-NLS-1$//$NON-NLS-2$
- wizard.setPackageName(packageName.getText());
- wizard.setClassName(className.getText());
- return true;
- }
+ if (!"".equals(packageName.getText()) &&
!"".equals(className.getText())) { //$NON-NLS-1$//$NON-NLS-2$
+ wizard.setPackageName(packageName.getText());
+ wizard.setClassName(className.getText());
+ return true;
+ }
return false;
}
Modified:
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/wizards/JBossWSGenerateWebXmlWizardPage.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/wizards/JBossWSGenerateWebXmlWizardPage.java 2010-01-28
07:44:11 UTC (rev 19979)
+++
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/wizards/JBossWSGenerateWebXmlWizardPage.java 2010-01-28
10:56:25 UTC (rev 19980)
@@ -7,7 +7,7 @@
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
+ ******************************************************************************/
package org.jboss.tools.ws.ui.wizards;
import org.eclipse.jface.wizard.IWizardPage;
@@ -27,51 +27,53 @@
public class JBossWSGenerateWebXmlWizardPage extends WizardPage {
private JBossWSGenerateWizard wizard;
- private Text name;
- private Button checkDefault;
-
-
+ private Text name;
+ private Button checkDefault;
+
protected JBossWSGenerateWebXmlWizardPage(String pageName) {
super(pageName);
- this.setTitle(JBossWSUIMessages.JBossWS_GenerateWizard_GenerateWebXmlPage_Title);
- this.setDescription(JBossWSUIMessages.JBossWS_GenerateWizard_GenerateWebXmlPage_Description);
+ this
+ .setTitle(JBossWSUIMessages.JBossWS_GenerateWizard_GenerateWebXmlPage_Title);
+ this
+ .setDescription(JBossWSUIMessages.JBossWS_GenerateWizard_GenerateWebXmlPage_Description);
}
public void createControl(Composite parent) {
Composite composite = createDialogArea(parent);
- this.wizard = (JBossWSGenerateWizard)this.getWizard();
- new Label (composite,
SWT.NONE).setText(JBossWSUIMessages.JBossWS_GenerateWizard_GenerateWebXmlPage_ServiceName_Label);
+ this.wizard = (JBossWSGenerateWizard) this.getWizard();
+ new Label(composite, SWT.NONE)
+ .setText(JBossWSUIMessages.JBossWS_GenerateWizard_GenerateWebXmlPage_ServiceName_Label);
name = new Text(composite, SWT.BORDER);
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
name.setLayoutData(gd);
name.setText(wizard.getServiceName());
name.setEnabled(!wizard.isUseDefaultServiceName());
- name.addModifyListener(new ModifyListener(){
+ name.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
- if (!"".equals(name.getText())){ //$NON-NLS-1$
+ if (!"".equals(name.getText())) { //$NON-NLS-1$
setPageComplete(true);
} else {
setPageComplete(false);
}
}
-
+
});
-
-
+
checkDefault = new Button(composite, SWT.CHECK);
gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = 2;
checkDefault.setLayoutData(gd);
checkDefault.setSelection(wizard.isUseDefaultServiceName());
- checkDefault.setText(JBossWSUIMessages.JBossWS_GenerateWizard_WizardPage_CheckButton_Label);
- checkDefault.addSelectionListener(new SelectionListener(){
+ checkDefault
+ .setText(JBossWSUIMessages.JBossWS_GenerateWizard_WizardPage_CheckButton_Label);
+ checkDefault.addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent e) {
}
public void widgetSelected(SelectionEvent e) {
- if (checkDefault.getSelection()){
+ if (checkDefault.getSelection()) {
checkDefault.setSelection(true);
name.setText(wizard.NAMEDEFAULT);
} else {
@@ -80,19 +82,18 @@
name.setEnabled(!checkDefault.getSelection());
wizard.setUseDefaultServiceName(!checkDefault.getSelection());
}
-
+
});
-
+
setControl(composite);
-
}
-
- public IWizardPage getNextPage(){
+
+ public IWizardPage getNextPage() {
wizard.setServiceName(name.getText());
return super.getNextPage();
}
-
+
private Composite createDialogArea(Composite parent) {
// create a composite with standard margins and spacing
Composite composite = new Composite(parent, SWT.NONE);
Modified:
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/wizards/JBossWSGenerateWizard.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/wizards/JBossWSGenerateWizard.java 2010-01-28
07:44:11 UTC (rev 19979)
+++
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/wizards/JBossWSGenerateWizard.java 2010-01-28
10:56:25 UTC (rev 19980)
@@ -7,15 +7,17 @@
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
+ ******************************************************************************/
package org.jboss.tools.ws.ui.wizards;
import java.io.File;
import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
-import org.eclipse.jdt.internal.core.JavaProject;
-import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.core.runtime.IStatus;
+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;
@@ -25,6 +27,7 @@
import org.jboss.tools.ws.creation.core.commands.ServiceSampleCreationCommand;
import org.jboss.tools.ws.creation.core.data.ServiceModel;
import org.jboss.tools.ws.ui.messages.JBossWSUIMessages;
+import org.jboss.tools.ws.ui.utils.UIUtils;
public class JBossWSGenerateWizard extends Wizard implements INewWizard {
@@ -40,11 +43,13 @@
private String className = CLASSDEFAULT;
private boolean useDefaultServiceName = true;
private boolean useDefaultClassName = true;
-
+
private IStructuredSelection selection;
private IProject project;
private static String WEB = "web.xml"; //$NON-NLS-1$
- private File webFile;
+ private static String JAVA = ".java"; //$NON-NLS-1$
+ private static String WEBINF = "WEB-INF"; //$NON-NLS-1$
+ private IFile webFile;
private boolean hasInited = false;
public JBossWSGenerateWizard() {
@@ -66,14 +71,39 @@
if (canFinish()) {
ServiceModel model = new ServiceModel();
model.setWebProjectName(project.getName());
- model.addServiceClasses(new StringBuffer().append(
- getPackageName())
+ model.addServiceClasses(new StringBuffer().append(getPackageName())
.append(".").append(getClassName()).toString()); //$NON-NLS-1$
model.setServiceName(getServiceName());
model.setUpdateWebxml(true);
model.setCustomPackage(getPackageName());
+
+ File file = findFileByPath(getClassName() + JAVA, project
+ .getLocation().toOSString());
+ if (file != null) {
+ MessageDialog
+ .openError(
+ this.getShell(),
+ JBossWSUIMessages.JBossWS_GenerateWizard_MessageDialog_Title,
+ JBossWSUIMessages.Error_JBossWS_GenerateWizard_ClassName_Same);
+ return false;
+ }
+
+ IStatus status = null;
try {
- new MergeWebXMLCommand(model).execute(null, null);
+ MergeWebXMLCommand mergeCommand = new MergeWebXMLCommand(model);
+ status = mergeCommand.execute(null, null);
+ } catch (ExecutionException e) {
+ e.printStackTrace();
+ }
+ if (status != null && status.getSeverity() == Status.ERROR) {
+ MessageDialog
+ .openError(
+ this.getShell(),
+ JBossWSUIMessages.JBossWS_GenerateWizard_MessageDialog_Title,
+ status.getMessage());
+ return false;
+ }
+ try {
new ServiceSampleCreationCommand(model).execute(null, null);
} catch (ExecutionException e) {
e.printStackTrace();
@@ -82,6 +112,51 @@
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(
+ UIUtils.getWebContentRootPath(project).append(WEBINF))
+ .getFile(WEB);
+ }
+ hasInited = true;
+ }
+
+ @Override
+ public boolean canFinish() {
+ if (hasInited && (webFile == null || !webFile.exists())) {
+ if (firstPage != null && !firstPage.getControl().isDisposed()) {
+ firstPage
+ .setErrorMessage(JBossWSUIMessages.Error_JBossWS_GenerateWizard_NotDynamicWebProject);
+ }
+ return false;
+ }
+ return super.canFinish();
+ }
+
+ private File findFileByPath(String name, String path) {
+ File ret = null;
+ File folder = new File(path);
+ if (folder.isDirectory()) {
+ File[] files = folder.listFiles();
+ for (File file : files) {
+ ret = findFileByPath(name, file.getAbsolutePath());
+ if (ret != null) {
+ break;
+ }
+ }
+ } else {
+ if (name.equals(folder.getName())) {
+ ret = folder;
+ }
+ }
+ return ret;
+ }
+
public String getServiceName() {
return serviceName;
}
@@ -121,54 +196,4 @@
public void setUseDefaultClassName(boolean useDefaultClassName) {
this.useDefaultClassName = useDefaultClassName;
}
-
- public void init(IWorkbench workbench, IStructuredSelection selection) {
- this.selection = selection;
-
- if (this.selection.getFirstElement() instanceof JavaProject) {
- project = ((JavaProject)this.selection.getFirstElement()).getProject();
- }
- else if (this.selection.getFirstElement() instanceof IProject) {
- project = (IProject) this.selection.getFirstElement();
- }
- if (project != null
- && JavaEEProjectUtilities.isDynamicWebProject(project)) {
- webFile = findFileByPath(project.getLocation().toOSString());
- if (webFile != null) {
- // TODO: if this is valid, we can finish
- }
- }
- hasInited = true;
- }
-
- @Override
- public boolean canFinish() {
- if (hasInited && webFile == null ) {
- if (firstPage != null && !firstPage.getControl().isDisposed()) {
- firstPage.setErrorMessage(JBossWSUIMessages.JBossWS_GenerateWizard_NotDynamicWebProject_Error);
- }
- return false;
- }
- return super.canFinish();
- }
-
- private File findFileByPath(String path) {
- File ret = null;
- File folder = new File(path);
- if (folder.isDirectory()) {
- File[] files = folder.listFiles();
- for (File file : files) {
- ret = findFileByPath(file.getAbsolutePath());
- if (ret != null) {
- break;
- }
- }
- } else {
- if (WEB.equals(folder.getName())) {
- ret = folder;
- }
- }
- return ret;
- }
-
}