Author: xcoulon
Date: 2012-02-08 16:53:41 -0500 (Wed, 08 Feb 2012)
New Revision: 38525
Added:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/action/OpenInWSTesterAction.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/action/OpenInWSTesterActionProvider.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/internal/utils/JaxrsPathModuleArtifactAdapter.java
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/META-INF/MANIFEST.MF
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/plugin.xml
Log:
patches applied -
https://issues.jboss.org/browse/JBIDE-10609 and
https://issues.jboss.org/browse/JBIDE-10285
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/META-INF/MANIFEST.MF
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/META-INF/MANIFEST.MF 2012-02-08 21:06:10
UTC (rev 38524)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/META-INF/MANIFEST.MF 2012-02-08 21:53:41
UTC (rev 38525)
@@ -33,7 +33,8 @@
org.eclipse.ui.editors;bundle-version="3.7.0",
org.eclipse.core.commands;bundle-version="3.6.0",
org.eclipse.ltk.core.refactoring;bundle-version="3.5.200",
- org.eclipse.wst.validation;bundle-version="1.2.300"
+ org.eclipse.wst.validation;bundle-version="1.2.300",
+ org.eclipse.wst.server.core
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ClassPath: .
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/plugin.xml
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/plugin.xml 2012-02-08 21:06:10 UTC (rev
38524)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/plugin.xml 2012-02-08 21:53:41 UTC (rev
38525)
@@ -203,6 +203,24 @@
</or>
</enablement>
</actionProvider>
+ <actionProvider
+
class="org.jboss.tools.ws.jaxrs.ui.cnf.action.OpenInWSTesterActionProvider"
+ id="org.jboss.tools.ws.jaxrs.ui.cnf.openWSTesterActionProvider"
+ priority="normal">
+ <enablement>
+ <or>
+ <instanceof
+
value="org.jboss.tools.ws.jaxrs.ui.cnf.UriPathTemplateElement">
+ </instanceof>
+ <instanceof
+
value="org.jboss.tools.ws.jaxrs.ui.cnf.UriPathTemplateMethodMappingElement">
+ </instanceof>
+ <instanceof
+
value="org.jboss.tools.ws.jaxrs.ui.cnf.UriPathTemplateMediaTypeMappingElement">
+ </instanceof>
+ </or>
+ </enablement>
+ </actionProvider>
</navigatorContent>
</extension>
Added:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/action/OpenInWSTesterAction.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/action/OpenInWSTesterAction.java
(rev 0)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/action/OpenInWSTesterAction.java 2012-02-08
21:53:41 UTC (rev 38525)
@@ -0,0 +1,108 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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:
+ * Brian Fitzpatrick - Initial API and implementation
+ ******************************************************************************/
+
+package org.jboss.tools.ws.jaxrs.ui.cnf.action;
+
+import java.lang.reflect.Method;
+import java.util.List;
+
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.ITreeSelection;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.ui.IViewPart;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.navigator.CommonViewer;
+import org.jboss.tools.ws.jaxrs.ui.cnf.UriPathTemplateElement;
+import org.jboss.tools.ws.jaxrs.ui.internal.utils.Logger;
+
+/**
+ * @author bfitzpat
+ *
+ */
+public class OpenInWSTesterAction extends Action implements ISelectionChangedListener {
+
+ private ISelection selection = null;
+
+ public OpenInWSTesterAction() {
+ super("Open in JBoss WS Tester");
+ }
+
+ /**
+ * (non-Javadoc)
+ * @see org.eclipse.jface.action.Action#run()
+ */
+ @Override
+ public void run() {
+ ITreeSelection treeSelection = ((ITreeSelection) selection);
+ @SuppressWarnings("rawtypes")
+ List selections = treeSelection.toList();
+ if (selections.isEmpty()) {
+ return;
+ }
+ Object selectedObject = selections.get(0);
+ try {
+ if (selectedObject instanceof UriPathTemplateElement) {
+ UriPathTemplateElement element = (UriPathTemplateElement) selectedObject;
+ String uriPathTemplate = element.getEndpoint().getUriPathTemplate();
+ String uriPrefix = "http://[domain]:[port]"; //$NON-NLS-1$
+
+ // Now we call the WS Tester through Reflection so there's no direct plug-in
dependency
+ IWorkbench wb = PlatformUI.getWorkbench();
+ IWorkbenchWindow win = wb.getActiveWorkbenchWindow();
+ IWorkbenchPage page = win.getActivePage();
+ String id = "org.jboss.tools.ws.ui.tester.views.TestWSView"; //$NON-NLS-1$
+ try {
+ IViewPart part = page.showView(id);
+ if (part != null &&
+ part.getClass().getName().equalsIgnoreCase(
+ "org.jboss.tools.ws.ui.views.JAXRSWSTestView2")) { //$NON-NLS-1$
+ Class<?> c = part.getClass();
+ Class<?> parmtypes[] = new Class[2];
+ parmtypes[0] = String.class;
+ parmtypes[1] = String.class;
+ Method setURL = c.getDeclaredMethod("setJAXRS", parmtypes);
//$NON-NLS-1$
+ if (setURL != null) {
+ Object arglist[] = new Object[2];
+ arglist[0] = uriPrefix + uriPathTemplate;
+ arglist[1] = element.getEndpoint().getHttpMethod().getHttpVerb();
+ setURL.invoke(part, arglist);
+ }
+ }
+ } catch (PartInitException e) {
+ e.printStackTrace();
+ Logger.error("Failed to open WS Tester", e);
+ }
+ }
+ } catch (Exception e) {
+ Logger.error("Failed to open WS Tester", e);
+ }
+ }
+
+ @Override
+ public void selectionChanged(SelectionChangedEvent event) {
+ Object source = event.getSource();
+ if (source instanceof CommonViewer) {
+ this.selection = ((CommonViewer) source).getSelection();
+ }
+ }
+
+ public void setSelection(ISelection selection) {
+ this.selection = selection;
+
+ }
+
+}
Property changes on:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/action/OpenInWSTesterAction.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/action/OpenInWSTesterActionProvider.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/action/OpenInWSTesterActionProvider.java
(rev 0)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/action/OpenInWSTesterActionProvider.java 2012-02-08
21:53:41 UTC (rev 38525)
@@ -0,0 +1,75 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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:
+ * Brian Fitzpatrick - Initial API and implementation
+ ******************************************************************************/
+
+package org.jboss.tools.ws.jaxrs.ui.cnf.action;
+
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.ui.IActionBars;
+import org.eclipse.ui.actions.ActionFactory;
+import org.eclipse.ui.navigator.CommonActionProvider;
+import org.eclipse.ui.navigator.ICommonActionExtensionSite;
+import org.eclipse.ui.navigator.ICommonMenuConstants;
+import org.eclipse.ui.navigator.ICommonViewerSite;
+import org.eclipse.ui.navigator.ICommonViewerWorkbenchSite;
+
+/**
+ * @author bfitzpat
+ *
+ */
+public class OpenInWSTesterActionProvider extends CommonActionProvider {
+
+ private OpenInWSTesterAction openInWSTesterAction = null;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.ui.navigator.CommonActionProvider#init(org.eclipse.ui.navigator
+ * .ICommonActionExtensionSite)
+ */
+ @Override
+ public void init(ICommonActionExtensionSite aSite) {
+ ICommonViewerSite viewSite = aSite.getViewSite();
+ if (viewSite instanceof ICommonViewerWorkbenchSite) {
+ openInWSTesterAction = new OpenInWSTesterAction();
+ openInWSTesterAction.setSelection(aSite.getStructuredViewer().getSelection());
+ aSite.getStructuredViewer().addSelectionChangedListener(openInWSTesterAction);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.ui.actions.ActionGroup#fillActionBars(org.eclipse.ui.IActionBars
+ * )
+ */
+ @Override
+ public void fillActionBars(IActionBars actionBars) {
+ super.fillActionBars(actionBars);
+ actionBars.setGlobalActionHandler(ActionFactory.COPY.getId(), openInWSTesterAction);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.ui.actions.ActionGroup#fillContextMenu(org.eclipse.jface.
+ * action.IMenuManager)
+ */
+ @Override
+ public void fillContextMenu(IMenuManager menu) {
+ if (openInWSTesterAction != null && openInWSTesterAction.isEnabled()) {
+ menu.appendToGroup(ICommonMenuConstants.GROUP_EDIT, openInWSTesterAction);
+ }
+ }
+
+}
Property changes on:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/cnf/action/OpenInWSTesterActionProvider.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/internal/utils/JaxrsPathModuleArtifactAdapter.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/internal/utils/JaxrsPathModuleArtifactAdapter.java
(rev 0)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/internal/utils/JaxrsPathModuleArtifactAdapter.java 2012-02-08
21:53:41 UTC (rev 38525)
@@ -0,0 +1,49 @@
+package org.jboss.tools.ws.jaxrs.ui.internal.utils;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.wst.server.core.IModule;
+import org.eclipse.wst.server.core.IModuleArtifact;
+import org.eclipse.wst.server.core.ServerUtil;
+import org.eclipse.wst.server.core.model.ModuleArtifactAdapterDelegate;
+import org.eclipse.wst.server.core.util.WebResource;
+import org.jboss.tools.ws.jaxrs.ui.cnf.UriPathTemplateElement;
+
+/**
+ * This class adapts {@link UriPathTemplateElement} into WebResources that Eclipse
Run|Debug On Server functionallity can handle.
+ *
+ * This allows you to use the Run As functionality on the JAX-RS node elements which
represent a path.
+ *
+ * @TODO currently only shows up for paths without "{" in them.
+ * @author max
+ *
+ */
+public class JaxrsPathModuleArtifactAdapter extends ModuleArtifactAdapterDelegate {
+
+ @Override
+ public IModuleArtifact getModuleArtifact(Object obj) {
+ if (obj instanceof UriPathTemplateElement) {
+ UriPathTemplateElement element = (UriPathTemplateElement) obj;
+
+ //TODO: NPE check this
+ IProject project = element.getEndpoint().getJavaProject().getProject();
+
+ IModule module = ServerUtil.getModule(project);
+
+ if(plainUrl(element)) {
+ Path path = new Path(element.getEndpoint().getUriPathTemplate());
+ //TODO: need to take possible @Application context path into consideration!
+ return new WebResource(module, path); //$NON-NLS-1$
+ }
+ }
+
+ return null;
+ }
+
+ // @return true when the path is directly viewable in a browser and its a GET request.
+ private boolean plainUrl(UriPathTemplateElement element) {
+ //TODO: NPE check this
+ return
element.getEndpoint().getHttpMethod().getHttpVerb().equalsIgnoreCase("GET")
&& !element.getEndpoint().getUriPathTemplate().contains("{");
+ }
+
+}
Property changes on:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/internal/utils/JaxrsPathModuleArtifactAdapter.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain