### Eclipse Workspace Patch 1.0 #P org.jboss.tools.ws.ui Index: src/org/jboss/tools/ws/ui/JBossWSUIPlugin.java =================================================================== --- src/org/jboss/tools/ws/ui/JBossWSUIPlugin.java (revision 24019) +++ src/org/jboss/tools/ws/ui/JBossWSUIPlugin.java (working copy) @@ -13,6 +13,8 @@ import org.eclipse.core.runtime.Status; import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.plugin.AbstractUIPlugin; import org.jboss.tools.ws.ui.messages.JBossWSUIMessages; import org.osgi.framework.BundleContext; @@ -69,4 +71,26 @@ public static void log(Throwable ex) { plugin.getLog().log(new Status(Status.ERROR, PLUGIN_ID, Status.OK, JBossWSUIMessages.JBossWS_UI_PLUGIN_NO_MESSAGES, ex)); } + + private IWorkbenchPage internalGetActivePage() { + IWorkbenchWindow window= getWorkbench().getActiveWorkbenchWindow(); + if (window == null) + return null; + return window.getActivePage(); + } + + private IWorkbenchWindow internalGetActiveWorkbenchWindow() { + IWorkbenchWindow window= getWorkbench().getActiveWorkbenchWindow(); + if (window == null) + return null; + return window; + } + + public static IWorkbenchPage getActivePage() { + return getDefault().internalGetActivePage(); + } + + public static IWorkbenchWindow getActiveWorkbenchWindow() { + return getDefault().internalGetActiveWorkbenchWindow(); + } } Index: src/org/jboss/tools/ws/ui/wizards/JBossWSGenerateWizard.java =================================================================== --- src/org/jboss/tools/ws/ui/wizards/JBossWSGenerateWizard.java (revision 24019) +++ src/org/jboss/tools/ws/ui/wizards/JBossWSGenerateWizard.java (working copy) @@ -15,6 +15,7 @@ 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; @@ -24,8 +25,14 @@ 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.jboss.tools.ws.creation.core.commands.MergeWebXMLCommand; import org.jboss.tools.ws.creation.core.commands.ServiceSampleCreationCommand; import org.jboss.tools.ws.creation.core.data.ServiceModel; @@ -35,6 +42,9 @@ public class JBossWSGenerateWizard extends Wizard implements INewWizard { + private static final String JDT_EDITOR = + "org.eclipse.jdt.ui.CompilationUnitEditor"; //$NON-NLS-1$ + String NAMEDEFAULT = "HelloWorld"; //$NON-NLS-1$ String PACKAGEDEFAULT = "org.jboss.samples.webservices"; //$NON-NLS-1$ String CLASSDEFAULT = "HelloWorld"; //$NON-NLS-1$ @@ -104,8 +114,13 @@ return false; } try { - new ServiceSampleCreationCommand(model).execute(null, null); + ServiceSampleCreationCommand cmd = + new ServiceSampleCreationCommand(model); + cmd.execute(null, null); getProject().refreshLocal(IProject.DEPTH_INFINITE, new NullProgressMonitor()); + if (cmd.getResource() != null && cmd.getResource() instanceof IFile) { + openResource((IFile) cmd.getResource()); + } } catch (ExecutionException e) { JBossWSUIPlugin.log(e); MessageDialog @@ -223,4 +238,32 @@ 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()); + } + } + } Index: src/org/jboss/tools/ws/ui/wizards/JBossRSGenerateWizard.java =================================================================== --- src/org/jboss/tools/ws/ui/wizards/JBossRSGenerateWizard.java (revision 24019) +++ src/org/jboss/tools/ws/ui/wizards/JBossRSGenerateWizard.java (working copy) @@ -15,6 +15,7 @@ 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; @@ -24,8 +25,14 @@ 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.jboss.tools.ws.creation.core.commands.AddRestEasyJarsCommand; import org.jboss.tools.ws.creation.core.commands.RSMergeWebXMLCommand; import org.jboss.tools.ws.creation.core.commands.RSServiceSampleCreationCommand; @@ -40,6 +47,9 @@ */ public class JBossRSGenerateWizard extends Wizard implements INewWizard { + private static final String JDT_EDITOR = + "org.eclipse.jdt.ui.CompilationUnitEditor"; //$NON-NLS-1$ + String NAMEDEFAULT = "MyRESTApplication"; //$NON-NLS-1$ String PACKAGEDEFAULT = "org.jboss.samples.rs.webservices"; //$NON-NLS-1$ String CLASSDEFAULT = "HelloWorldResource"; //$NON-NLS-1$ @@ -115,8 +125,13 @@ } try { new AddRestEasyJarsCommand(model).execute(null, null); - new RSServiceSampleCreationCommand(model).execute(null, null); + RSServiceSampleCreationCommand createCommand = + new RSServiceSampleCreationCommand(model); + createCommand.execute(null, null); getProject().refreshLocal(IProject.DEPTH_INFINITE, new NullProgressMonitor()); + if (createCommand.getResource() != null && createCommand.getResource() instanceof IFile) { + openResource((IFile) createCommand.getResource()); + } } catch (ExecutionException e) { JBossWSUIPlugin.log(e); MessageDialog @@ -242,4 +257,32 @@ 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()); + } + } + } #P org.jboss.tools.ws.creation.core Index: src/org/jboss/tools/ws/creation/core/commands/RSServiceSampleCreationCommand.java =================================================================== --- src/org/jboss/tools/ws/creation/core/commands/RSServiceSampleCreationCommand.java (revision 24184) +++ src/org/jboss/tools/ws/creation/core/commands/RSServiceSampleCreationCommand.java (working copy) @@ -11,6 +11,7 @@ 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; @@ -36,6 +37,8 @@ public class RSServiceSampleCreationCommand extends AbstractDataModelOperation { private ServiceModel model; + private IResource resource; + public static final String LINE_SEPARATOR = System .getProperty("line.separator"); //$NON-NLS-1$ @@ -43,6 +46,10 @@ this.model = model; } + public IResource getResource() { + return this.resource; + } + @Override public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException { @@ -56,11 +63,15 @@ .errorStatus(JBossWSCreationCoreMessages.Error_Create_Client_Sample); } - createRESTAnnotatedJavaClass (model.getCustomPackage(), JBossWSCreationUtils + ICompilationUnit rsAnnotatedClass = + createRESTAnnotatedJavaClass (model.getCustomPackage(), JBossWSCreationUtils .classNameFromQualifiedName(model.getServiceClasses().get(0)), project); createRESTApplicationClass (model.getCustomPackage(), model.getApplicationClassName(), project); + if (rsAnnotatedClass != null) { + this.resource = rsAnnotatedClass.getResource(); + } return null; } Index: src/org/jboss/tools/ws/creation/core/commands/ServiceSampleCreationCommand.java =================================================================== --- src/org/jboss/tools/ws/creation/core/commands/ServiceSampleCreationCommand.java (revision 24184) +++ src/org/jboss/tools/ws/creation/core/commands/ServiceSampleCreationCommand.java (working copy) @@ -1,6 +1,7 @@ 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; @@ -22,12 +23,18 @@ public class ServiceSampleCreationCommand extends AbstractDataModelOperation { private ServiceModel model; + private IResource resource; + public static final String LINE_SEPARATOR = System .getProperty("line.separator"); //$NON-NLS-1$ public ServiceSampleCreationCommand(ServiceModel model) { this.model = model; } + + public IResource getResource() { + return this.resource; + } @Override public IStatus execute(IProgressMonitor monitor, IAdaptable info) @@ -42,9 +49,13 @@ .errorStatus(JBossWSCreationCoreMessages.Error_Create_Client_Sample); } - createJavaClass(model.getCustomPackage(), JBossWSCreationUtils + ICompilationUnit createdClass = + createJavaClass(model.getCustomPackage(), JBossWSCreationUtils .classNameFromQualifiedName(model.getServiceClasses().get(0)), project); + if (createdClass != null) { + this.resource = createdClass.getResource(); + } return null; }