Skip to content

Commit

Permalink
Support opening multiple request views with unique filters.
Browse files Browse the repository at this point in the history
  • Loading branch information
Cade Cairns committed Nov 19, 2011
1 parent b775b1b commit d374148
Show file tree
Hide file tree
Showing 10 changed files with 166 additions and 42 deletions.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
50 changes: 34 additions & 16 deletions platform/com.subgraph.vega.ui.http/plugin.xml
Expand Up @@ -36,6 +36,7 @@
restorable="false"> restorable="false">
</view> </view>
<view <view
allowMultiple="false"
class="com.subgraph.vega.ui.http.identities.IdentitiesView" class="com.subgraph.vega.ui.http.identities.IdentitiesView"
id="com.subgraph.vega.views.http.identities" id="com.subgraph.vega.views.http.identities"
name="Identities" name="Identities"
Expand Down Expand Up @@ -72,6 +73,10 @@
class="com.subgraph.vega.ui.http.commands.SendRequest" class="com.subgraph.vega.ui.http.commands.SendRequest"
commandId="com.subgraph.vega.commands.sendRequest"> commandId="com.subgraph.vega.commands.sendRequest">
</handler> </handler>
<handler
class="com.subgraph.vega.ui.http.commands.OpenRequestView"
commandId="com.subgraph.vega.commands.openRequestView">
</handler>
<handler <handler
class="com.subgraph.vega.ui.http.commands.OpenRequestViewFilter" class="com.subgraph.vega.ui.http.commands.OpenRequestViewFilter"
commandId="com.subgraph.vega.commands.openRequestFilter"> commandId="com.subgraph.vega.commands.openRequestFilter">
Expand Down Expand Up @@ -160,14 +165,6 @@
id="com.subgraph.vega.commands.sendRequest" id="com.subgraph.vega.commands.sendRequest"
name="Send Request"> name="Send Request">
</command> </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 <category
id="com.subgraph.vega.commands.interceptQueueViewPopupCategory" id="com.subgraph.vega.commands.interceptQueueViewPopupCategory"
name="Interception Queue View Popup"> name="Interception Queue View Popup">
Expand All @@ -182,6 +179,25 @@
id="com.subgraph.vega.commands.popup.dropTransaction" id="com.subgraph.vega.commands.popup.dropTransaction"
name="Drop pending transaction"> name="Drop pending transaction">
</command> </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>
<extension <extension
point="org.eclipse.ui.menus"> point="org.eclipse.ui.menus">
Expand Down Expand Up @@ -296,22 +312,24 @@
allPopups="false" allPopups="false"
locationURI="toolbar:com.subgraph.vega.views.http"> locationURI="toolbar:com.subgraph.vega.views.http">
<command <command
commandId="com.subgraph.vega.commands.openRequestFilter" commandId="com.subgraph.vega.commands.openRequestView"
icon="icons/filter.gif" icon="icons/new_request_view.png"
id="openfilter" label="Open New Request Viewer"
label="Open Request Filter"
style="push"> style="push">
</command> </command>
</menuContribution>
<menuContribution
allPopups="false"
locationURI="toolbar:com.subgraph.vega.views.http?before=openfilter">
<command <command
commandId="com.subgraph.vega.commands.resetRequestFilter" commandId="com.subgraph.vega.commands.resetRequestFilter"
icon="icons/reset_filter.png" icon="icons/reset_filter.png"
label="Reset Request Filter" label="Reset Request Filter"
style="push"> style="push">
</command> </command>
<command
commandId="com.subgraph.vega.commands.openRequestFilter"
icon="icons/filter.gif"
id="openfilter"
label="Open Request Filter"
style="push">
</command>
</menuContribution> </menuContribution>
<menuContribution <menuContribution
allPopups="false" allPopups="false"
Expand Down
Expand Up @@ -26,13 +26,13 @@ public class ProxyPerspectiveFactory implements IPerspectiveFactory {
@Override @Override
public void createInitialLayout(IPageLayout layout) { public void createInitialLayout(IPageLayout layout) {
IFolderLayout proxyFolder = layout.createFolder(PROXY_FOLDER, IPageLayout.TOP, 0f, layout.getEditorArea()); 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(InterceptView.ID);
proxyFolder.addView(InterceptQueueView.ID); proxyFolder.addView(InterceptQueueView.ID);
proxyFolder.addView(IdentitiesView.ID); proxyFolder.addView(IdentitiesView.ID);
layout.addView(WEBSITE_VIEW, IPageLayout.LEFT, 0.25f, PROXY_FOLDER); layout.addView(WEBSITE_VIEW, IPageLayout.LEFT, 0.25f, PROXY_FOLDER);
layout.setEditorAreaVisible(false); layout.setEditorAreaVisible(false);
layout.getViewLayout(HttpRequestView.ID).setCloseable(false); layout.getViewLayout(HttpRequestView.ID_PROXY).setCloseable(false);
layout.getViewLayout(InterceptView.ID).setCloseable(false); layout.getViewLayout(InterceptView.ID).setCloseable(false);
layout.getViewLayout(InterceptQueueView.ID).setCloseable(false); layout.getViewLayout(InterceptQueueView.ID).setCloseable(false);
layout.getViewLayout(WEBSITE_VIEW).setCloseable(false); layout.getViewLayout(WEBSITE_VIEW).setCloseable(false);
Expand Down
Expand Up @@ -41,6 +41,7 @@ public class HttpViewContentProviderLazy implements ILazyContentProvider {
private IWorkspace currentWorkspace; private IWorkspace currentWorkspace;
private TableViewer tableViewer; private TableViewer tableViewer;
private List<IRequestLogRecord> records; private List<IRequestLogRecord> records;
private final String conditionSetId;
private final IRequestLogUpdateListener callback; private final IRequestLogUpdateListener callback;
private final IEventHandler conditionSetListener; private final IEventHandler conditionSetListener;


Expand All @@ -50,7 +51,15 @@ public class HttpViewContentProviderLazy implements ILazyContentProvider {
private int currentCount; private int currentCount;
private IHttpConditionSet filterCondition; 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(); callback = createUpdateListener();
conditionSetListener = createConditionSetListener(); conditionSetListener = createConditionSetListener();
} }
Expand All @@ -61,7 +70,6 @@ public void dispose() {


@Override @Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {

if(updateTask != null) if(updateTask != null)
updateTask.cancel(); updateTask.cancel();


Expand Down Expand Up @@ -91,7 +99,7 @@ private void setNewInput(IModel model) {
return; return;
} }


filterCondition = model.addConditionSetTracker(IHttpConditionManager.CONDITION_SET_FILTER, conditionSetListener); filterCondition = model.addConditionSetTracker(conditionSetId, conditionSetListener);
filterCondition.setMatchOnEmptySet(true); filterCondition.setMatchOnEmptySet(true);


currentWorkspace = model.addWorkspaceListener(createWorkspaceListener()); currentWorkspace = model.addWorkspaceListener(createWorkspaceListener());
Expand Down
@@ -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;
}

}
Expand Up @@ -10,12 +10,18 @@
******************************************************************************/ ******************************************************************************/
package com.subgraph.vega.ui.http.commands; 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.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException; import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.IHandler; import org.eclipse.core.commands.IHandler;
import org.eclipse.jface.window.Window; 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.http.requestfilters.RequestFilterConfigContent;
import com.subgraph.vega.ui.util.dialogs.ConfigDialogCreator; import com.subgraph.vega.ui.util.dialogs.ConfigDialogCreator;


Expand All @@ -24,13 +30,20 @@ public class OpenRequestViewFilter extends AbstractHandler implements IHandler {


@Override @Override
public Object execute(ExecutionEvent event) throws ExecutionException { public Object execute(ExecutionEvent event) throws ExecutionException {
if(dialog != null && dialog.getShell() != null) { final IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
dialog.close(); if (activePart instanceof HttpRequestView) {
dialog = null; if (dialog != null && dialog.getShell() != null) {
return 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; return null;
} }
} }
Expand Up @@ -10,29 +10,49 @@
******************************************************************************/ ******************************************************************************/
package com.subgraph.vega.ui.http.commands; 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.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException; import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.IHandler; 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.IModel;
import com.subgraph.vega.api.model.IWorkspace; import com.subgraph.vega.api.model.IWorkspace;
import com.subgraph.vega.api.model.conditions.IHttpConditionManager; import com.subgraph.vega.api.model.conditions.IHttpConditionManager;
import com.subgraph.vega.api.model.conditions.IHttpConditionSet; import com.subgraph.vega.api.model.conditions.IHttpConditionSet;
import com.subgraph.vega.ui.http.Activator; import com.subgraph.vega.ui.http.Activator;
import com.subgraph.vega.ui.http.request.view.HttpRequestView;


public class ResetRequestFilter extends AbstractHandler implements IHandler { public class ResetRequestFilter extends AbstractHandler implements IHandler {


@Override @Override
public Object execute(ExecutionEvent event) throws ExecutionException { public Object execute(ExecutionEvent event) throws ExecutionException {
final IModel model = Activator.getDefault().getModel(); final IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
final IWorkspace workspace = model.getCurrentWorkspace(); if (activePart instanceof HttpRequestView) {
if(workspace != null) { final IModel model = Activator.getDefault().getModel();
final IHttpConditionManager conditionManager = workspace.getHttpConditionMananger(); final IWorkspace workspace = model.getCurrentWorkspace();
final IHttpConditionSet filterSet = conditionManager.getConditionSet("filter"); if(workspace != null) {
filterSet.clearConditions(); final String secondaryId = ((HttpRequestView) activePart).getViewSite().getSecondaryId();
conditionManager.saveConditionSet("filter", filterSet); 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; return null;
} }

} }
Expand Up @@ -19,8 +19,14 @@
import com.subgraph.vega.ui.http.requestlogviewer.RequestLogViewer; import com.subgraph.vega.ui.http.requestlogviewer.RequestLogViewer;
import com.subgraph.vega.ui.http.requestlogviewer.RequestResponseViewer; 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 class HttpRequestView extends ViewPart {
public final static String ID = "com.subgraph.vega.views.http"; 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 RequestLogViewer requestLogViewer;
private RequestResponseViewer requestResponseViewer; private RequestResponseViewer requestResponseViewer;


Expand All @@ -32,7 +38,7 @@ public void createPartControl(Composite parent) {
parent.setLayout(new FillLayout()); parent.setLayout(new FillLayout());
final SashForm form = new SashForm(parent, SWT.VERTICAL); final SashForm form = new SashForm(parent, SWT.VERTICAL);


requestLogViewer = new RequestLogViewer(form); requestLogViewer = new RequestLogViewer(form, getViewSite().getSecondaryId());
requestLogViewer.registerContextMenu(getSite()); requestLogViewer.registerContextMenu(getSite());


requestResponseViewer = new RequestResponseViewer(form); requestResponseViewer = new RequestResponseViewer(form);
Expand Down
Expand Up @@ -10,7 +10,6 @@
******************************************************************************/ ******************************************************************************/
package com.subgraph.vega.ui.http.requestfilters; package com.subgraph.vega.ui.http.requestfilters;



import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
Expand All @@ -33,11 +32,23 @@
import com.subgraph.vega.ui.util.dialogs.IConfigDialogContent; import com.subgraph.vega.ui.util.dialogs.IConfigDialogContent;


public class RequestFilterConfigContent implements IConfigDialogContent { public class RequestFilterConfigContent implements IConfigDialogContent {
private final String conditionSetId;
private Composite composite; private Composite composite;
private TreeViewer treeViewer; private TreeViewer treeViewer;
private IHttpConditionManager conditionManager; private IHttpConditionManager conditionManager;
private IHttpConditionSet conditionSet; private IHttpConditionSet conditionSet;
private boolean conditionSetDirty; 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 @Override
public String getTitle() { public String getTitle() {
Expand All @@ -61,12 +72,11 @@ public void onClose() {
@Override @Override
public void onOk() { public void onOk() {
if(conditionSetDirty) { if(conditionSetDirty) {
conditionManager.saveConditionSet("filter", conditionSet); conditionManager.saveConditionSet(conditionSetId, conditionSet);
conditionSetDirty = false; conditionSetDirty = false;
} }
} }



@Override @Override
public Composite createContents(Composite parent) { public Composite createContents(Composite parent) {
composite = new Composite(parent, SWT.NONE); composite = new Composite(parent, SWT.NONE);
Expand All @@ -91,7 +101,7 @@ public Composite createContents(Composite parent) {
final IWorkspace workspace = Activator.getDefault().getModel().getCurrentWorkspace(); final IWorkspace workspace = Activator.getDefault().getModel().getCurrentWorkspace();
if(workspace != null) { if(workspace != null) {
conditionManager = workspace.getHttpConditionMananger(); conditionManager = workspace.getHttpConditionMananger();
conditionSet = conditionManager.getConditionSetCopy("filter"); conditionSet = conditionManager.getConditionSetCopy(conditionSetId);


} else { } else {
conditionManager = null; conditionManager = null;
Expand Down

0 comments on commit d374148

Please sign in to comment.