Permalink
Browse files

Support opening multiple request views with unique filters.

  • Loading branch information...
Cade Cairns
Cade Cairns committed Nov 19, 2011
1 parent b775b1b commit d3741484207a0e0e240a8db365aa3d1bf908e67f
Binary file not shown.
@@ -36,6 +36,7 @@
restorable="false">
</view>
<view
+ allowMultiple="false"
class="com.subgraph.vega.ui.http.identities.IdentitiesView"
id="com.subgraph.vega.views.http.identities"
name="Identities"
@@ -72,6 +73,10 @@
class="com.subgraph.vega.ui.http.commands.SendRequest"
commandId="com.subgraph.vega.commands.sendRequest">
</handler>
+ <handler
+ class="com.subgraph.vega.ui.http.commands.OpenRequestView"
+ commandId="com.subgraph.vega.commands.openRequestView">
+ </handler>
<handler
class="com.subgraph.vega.ui.http.commands.OpenRequestViewFilter"
commandId="com.subgraph.vega.commands.openRequestFilter">
@@ -160,14 +165,6 @@
id="com.subgraph.vega.commands.sendRequest"
name="Send Request">
</command>
- <command
- id="com.subgraph.vega.commands.openRequestFilter"
- name="Open Request View Filters">
- </command>
- <command
- id="com.subgraph.vega.commands.resetRequestFilter"
- name="Reset Request View Filter">
- </command>
<category
id="com.subgraph.vega.commands.interceptQueueViewPopupCategory"
name="Interception Queue View Popup">
@@ -182,6 +179,25 @@
id="com.subgraph.vega.commands.popup.dropTransaction"
name="Drop pending transaction">
</command>
+ <category
+ id="com.subgraph.vega.commands.requestViewCategory"
+ name="Commands for controlling the Request View">
+ </category>
+ <command
+ categoryId="com.subgraph.vega.commands.requestViewCategory"
+ id="com.subgraph.vega.commands.openRequestView"
+ name="Open New Request Viewer">
+ </command>
+ <command
+ categoryId="com.subgraph.vega.commands.requestViewCategory"
+ id="com.subgraph.vega.commands.openRequestFilter"
+ name="Open Request View Filter">
+ </command>
+ <command
+ categoryId="com.subgraph.vega.commands.requestViewCategory"
+ id="com.subgraph.vega.commands.resetRequestFilter"
+ name="Reset Request View Filter">
+ </command>
</extension>
<extension
point="org.eclipse.ui.menus">
@@ -296,22 +312,24 @@
allPopups="false"
locationURI="toolbar:com.subgraph.vega.views.http">
<command
- commandId="com.subgraph.vega.commands.openRequestFilter"
- icon="icons/filter.gif"
- id="openfilter"
- label="Open Request Filter"
+ commandId="com.subgraph.vega.commands.openRequestView"
+ icon="icons/new_request_view.png"
+ label="Open New Request Viewer"
style="push">
</command>
- </menuContribution>
- <menuContribution
- allPopups="false"
- locationURI="toolbar:com.subgraph.vega.views.http?before=openfilter">
<command
commandId="com.subgraph.vega.commands.resetRequestFilter"
icon="icons/reset_filter.png"
label="Reset Request Filter"
style="push">
</command>
+ <command
+ commandId="com.subgraph.vega.commands.openRequestFilter"
+ icon="icons/filter.gif"
+ id="openfilter"
+ label="Open Request Filter"
+ style="push">
+ </command>
</menuContribution>
<menuContribution
allPopups="false"
@@ -26,13 +26,13 @@
@Override
public void createInitialLayout(IPageLayout layout) {
IFolderLayout proxyFolder = layout.createFolder(PROXY_FOLDER, IPageLayout.TOP, 0f, layout.getEditorArea());
- proxyFolder.addView(HttpRequestView.ID);
+ proxyFolder.addView(HttpRequestView.ID_PROXY);
proxyFolder.addView(InterceptView.ID);
proxyFolder.addView(InterceptQueueView.ID);
proxyFolder.addView(IdentitiesView.ID);
layout.addView(WEBSITE_VIEW, IPageLayout.LEFT, 0.25f, PROXY_FOLDER);
layout.setEditorAreaVisible(false);
- layout.getViewLayout(HttpRequestView.ID).setCloseable(false);
+ layout.getViewLayout(HttpRequestView.ID_PROXY).setCloseable(false);
layout.getViewLayout(InterceptView.ID).setCloseable(false);
layout.getViewLayout(InterceptQueueView.ID).setCloseable(false);
layout.getViewLayout(WEBSITE_VIEW).setCloseable(false);
@@ -41,6 +41,7 @@
private IWorkspace currentWorkspace;
private TableViewer tableViewer;
private List<IRequestLogRecord> records;
+ private final String conditionSetId;
private final IRequestLogUpdateListener callback;
private final IEventHandler conditionSetListener;
@@ -50,7 +51,15 @@
private int currentCount;
private IHttpConditionSet filterCondition;
- public HttpViewContentProviderLazy() {
+ /**
+ * @param instanceId A unique ID to differentiate between condition filter sets.
+ */
+ public HttpViewContentProviderLazy(String instanceId) {
+ if (instanceId != null) {
+ conditionSetId = IHttpConditionManager.CONDITION_SET_FILTER + "." + instanceId;
+ } else {
+ conditionSetId = IHttpConditionManager.CONDITION_SET_FILTER;
+ }
callback = createUpdateListener();
conditionSetListener = createConditionSetListener();
}
@@ -61,7 +70,6 @@ public void dispose() {
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
-
if(updateTask != null)
updateTask.cancel();
@@ -91,7 +99,7 @@ private void setNewInput(IModel model) {
return;
}
- filterCondition = model.addConditionSetTracker(IHttpConditionManager.CONDITION_SET_FILTER, conditionSetListener);
+ filterCondition = model.addConditionSetTracker(conditionSetId, conditionSetListener);
filterCondition.setMatchOnEmptySet(true);
currentWorkspace = model.addWorkspaceListener(createWorkspaceListener());
@@ -0,0 +1,42 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Subgraph.
+ * All rights reserved. This program and the accompanying materials
+ * are 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:
+ * Subgraph - initial API and implementation
+ ******************************************************************************/
+package com.subgraph.vega.ui.http.commands;
+
+import java.util.UUID;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.commands.IHandler;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+import com.subgraph.vega.ui.http.request.view.HttpRequestView;
+import com.subgraph.vega.ui.util.dialogs.ErrorDialog;
+
+public class OpenRequestView extends AbstractHandler implements IHandler {
+
+ @Override
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ final String secondaryId = UUID.randomUUID().toString();
+ try {
+ HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().showView(HttpRequestView.ID, secondaryId, IWorkbenchPage.VIEW_ACTIVATE);
+ } catch (PartInitException e) {
+ Shell shell = HandlerUtil.getActiveWorkbenchWindow(event).getShell();
+ ErrorDialog.displayExceptionError(shell, e);
+ return null;
+ }
+ return null;
+ }
+
+}
@@ -10,12 +10,18 @@
******************************************************************************/
package com.subgraph.vega.ui.http.commands;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.IHandler;
import org.eclipse.jface.window.Window;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.handlers.HandlerUtil;
+import com.subgraph.vega.ui.http.request.view.HttpRequestView;
import com.subgraph.vega.ui.http.requestfilters.RequestFilterConfigContent;
import com.subgraph.vega.ui.util.dialogs.ConfigDialogCreator;
@@ -24,13 +30,20 @@
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
- if(dialog != null && dialog.getShell() != null) {
- dialog.close();
- dialog = null;
- return null;
+ final IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
+ if (activePart instanceof HttpRequestView) {
+ if (dialog != null && dialog.getShell() != null) {
+ dialog.close();
+ dialog = null;
+ return null;
+ }
+ final String secondaryId = ((HttpRequestView) activePart).getViewSite().getSecondaryId();
+ dialog = ConfigDialogCreator.createDialog(event, new RequestFilterConfigContent(secondaryId));
+ dialog.open();
+ } else {
+ final Logger logger = Logger.getLogger("proxy");
+ logger.log(Level.WARNING, "OpenRequestViewFilter command occurred from unexpected origin");
}
- dialog = ConfigDialogCreator.createDialog(event, new RequestFilterConfigContent());
- dialog.open();
return null;
}
}
@@ -10,29 +10,49 @@
******************************************************************************/
package com.subgraph.vega.ui.http.commands;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.IHandler;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.handlers.HandlerUtil;
import com.subgraph.vega.api.model.IModel;
import com.subgraph.vega.api.model.IWorkspace;
import com.subgraph.vega.api.model.conditions.IHttpConditionManager;
import com.subgraph.vega.api.model.conditions.IHttpConditionSet;
import com.subgraph.vega.ui.http.Activator;
+import com.subgraph.vega.ui.http.request.view.HttpRequestView;
public class ResetRequestFilter extends AbstractHandler implements IHandler {
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
- final IModel model = Activator.getDefault().getModel();
- final IWorkspace workspace = model.getCurrentWorkspace();
- if(workspace != null) {
- final IHttpConditionManager conditionManager = workspace.getHttpConditionMananger();
- final IHttpConditionSet filterSet = conditionManager.getConditionSet("filter");
- filterSet.clearConditions();
- conditionManager.saveConditionSet("filter", filterSet);
- }
+ final IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
+ if (activePart instanceof HttpRequestView) {
+ final IModel model = Activator.getDefault().getModel();
+ final IWorkspace workspace = model.getCurrentWorkspace();
+ if(workspace != null) {
+ final String secondaryId = ((HttpRequestView) activePart).getViewSite().getSecondaryId();
+ final String conditionSetId;
+ if (secondaryId != null) {
+ conditionSetId = IHttpConditionManager.CONDITION_SET_FILTER + "." + secondaryId;
+ } else {
+ conditionSetId = IHttpConditionManager.CONDITION_SET_FILTER;
+ }
+ final IHttpConditionManager conditionManager = workspace.getHttpConditionMananger();
+ final IHttpConditionSet filterSet = conditionManager.getConditionSet(conditionSetId);
+ filterSet.clearConditions();
+ conditionManager.saveConditionSet(conditionSetId, filterSet);
+ }
+ } else {
+ final Logger logger = Logger.getLogger("proxy");
+ logger.log(Level.WARNING, "ResetRequestFilter command occurred from unexpected origin");
+ }
return null;
}
+
}
@@ -19,8 +19,14 @@
import com.subgraph.vega.ui.http.requestlogviewer.RequestLogViewer;
import com.subgraph.vega.ui.http.requestlogviewer.RequestResponseViewer;
+/**
+ * When multiple instances of this view are opened, the secondary view ID must be set to a unique value. The value is
+ * used to differentiate between condition filter sets.
+ */
public class HttpRequestView extends ViewPart {
public final static String ID = "com.subgraph.vega.views.http";
+ public final static String ID_PROXY_SECONDARY = "proxy";
+ public final static String ID_PROXY = ID + ":" + ID_PROXY_SECONDARY; /** Compound ID identifying the non-closable base view in the proxy perspective */
private RequestLogViewer requestLogViewer;
private RequestResponseViewer requestResponseViewer;
@@ -32,7 +38,7 @@ public void createPartControl(Composite parent) {
parent.setLayout(new FillLayout());
final SashForm form = new SashForm(parent, SWT.VERTICAL);
- requestLogViewer = new RequestLogViewer(form);
+ requestLogViewer = new RequestLogViewer(form, getViewSite().getSecondaryId());
requestLogViewer.registerContextMenu(getSite());
requestResponseViewer = new RequestResponseViewer(form);
@@ -10,7 +10,6 @@
******************************************************************************/
package com.subgraph.vega.ui.http.requestfilters;
-
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.SWT;
@@ -33,11 +32,23 @@
import com.subgraph.vega.ui.util.dialogs.IConfigDialogContent;
public class RequestFilterConfigContent implements IConfigDialogContent {
+ private final String conditionSetId;
private Composite composite;
private TreeViewer treeViewer;
private IHttpConditionManager conditionManager;
private IHttpConditionSet conditionSet;
private boolean conditionSetDirty;
+
+ /**
+ * @param instanceId A unique ID to differentiate between condition filter sets.
+ */
+ public RequestFilterConfigContent(String instanceId) {
+ if (instanceId != null) {
+ conditionSetId = IHttpConditionManager.CONDITION_SET_FILTER + "." + instanceId;
+ } else {
+ conditionSetId = IHttpConditionManager.CONDITION_SET_FILTER;
+ }
+ }
@Override
public String getTitle() {
@@ -61,12 +72,11 @@ public void onClose() {
@Override
public void onOk() {
if(conditionSetDirty) {
- conditionManager.saveConditionSet("filter", conditionSet);
+ conditionManager.saveConditionSet(conditionSetId, conditionSet);
conditionSetDirty = false;
}
}
-
@Override
public Composite createContents(Composite parent) {
composite = new Composite(parent, SWT.NONE);
@@ -91,7 +101,7 @@ public Composite createContents(Composite parent) {
final IWorkspace workspace = Activator.getDefault().getModel().getCurrentWorkspace();
if(workspace != null) {
conditionManager = workspace.getHttpConditionMananger();
- conditionSet = conditionManager.getConditionSetCopy("filter");
+ conditionSet = conditionManager.getConditionSetCopy(conditionSetId);
} else {
conditionManager = null;
Oops, something went wrong.

0 comments on commit d374148

Please sign in to comment.