Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordstadnik2005-11-22 05:48:27 -0500
committerdstadnik2005-11-22 05:48:27 -0500
commit981c34290253f36a7ae749e99ac09b20d249c7bd (patch)
treee06a378f6e5630b24146777acfff55623e282ae6 /devtools
parent37fca5281999a627ba8eb96ae095f8c5c37c9807 (diff)
downloadorg.eclipse.gmf-tooling-981c34290253f36a7ae749e99ac09b20d249c7bd.tar.gz
org.eclipse.gmf-tooling-981c34290253f36a7ae749e99ac09b20d249c7bd.tar.xz
org.eclipse.gmf-tooling-981c34290253f36a7ae749e99ac09b20d249c7bd.zip
#116837 add filter capability to edit part tracer
Diffstat (limited to 'devtools')
-rw-r--r--devtools/org.eclipse.gmf.dev/.options1
-rw-r--r--devtools/org.eclipse.gmf.dev/src/org/eclipse/gmf/dev/DevPlugin.java1
-rw-r--r--devtools/org.eclipse.gmf.dev/src/org/eclipse/gmf/dev/EditPartTraceRequestFilters.java277
-rw-r--r--devtools/org.eclipse.gmf.dev/src/org/eclipse/gmf/dev/EditPartTraceView.java71
4 files changed, 331 insertions, 19 deletions
diff --git a/devtools/org.eclipse.gmf.dev/.options b/devtools/org.eclipse.gmf.dev/.options
index b2426c9b8..f845caaeb 100644
--- a/devtools/org.eclipse.gmf.dev/.options
+++ b/devtools/org.eclipse.gmf.dev/.options
@@ -1,3 +1,2 @@
org.eclipse.gmf.dev/debug=false
org.eclipse.gmf.dev/debug/trace=false
-org.eclipse.gmf.dev/debug/requests/ignored=insert_semantic,property_change,autosize
diff --git a/devtools/org.eclipse.gmf.dev/src/org/eclipse/gmf/dev/DevPlugin.java b/devtools/org.eclipse.gmf.dev/src/org/eclipse/gmf/dev/DevPlugin.java
index 6086a9ac5..0033872ce 100644
--- a/devtools/org.eclipse.gmf.dev/src/org/eclipse/gmf/dev/DevPlugin.java
+++ b/devtools/org.eclipse.gmf.dev/src/org/eclipse/gmf/dev/DevPlugin.java
@@ -25,7 +25,6 @@ import org.osgi.framework.BundleContext;
public class DevPlugin extends AbstractUIPlugin {
public static final String TRACE_OPTION = "/debug/trace";
- public static final String IGNORED_REQUESTS_OPTION = "/debug/requests/ignored";
public static final String COMMAND_IMAGE = "/icons/command.gif";
public static final String COMMANDX_IMAGE = "/icons/commandx.gif";
diff --git a/devtools/org.eclipse.gmf.dev/src/org/eclipse/gmf/dev/EditPartTraceRequestFilters.java b/devtools/org.eclipse.gmf.dev/src/org/eclipse/gmf/dev/EditPartTraceRequestFilters.java
new file mode 100644
index 000000000..8e63967be
--- /dev/null
+++ b/devtools/org.eclipse.gmf.dev/src/org/eclipse/gmf/dev/EditPartTraceRequestFilters.java
@@ -0,0 +1,277 @@
+/*
+ * Copyright (c) 2005 Borland Software Corporation
+ *
+ * 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:
+ * Dmitri Stadnik (Borland) - initial API and implementation
+ */
+package org.eclipse.gmf.dev;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerSorter;
+import org.eclipse.jface.window.Window;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IMemento;
+import org.eclipse.ui.dialogs.CheckedTreeSelectionDialog;
+
+/**
+ * @author dstadnik
+ */
+public class EditPartTraceRequestFilters {
+
+ private static final Object[] NONE = new Object[0];
+ private static final String REQUEST_FILTERS_TAG = "request_filters"; //$NON-NLS-1$
+ private static final String CATEGORY_TAG = "category"; //$NON-NLS-1$
+ private static final String CATEGORY_NAME_ATTR = "name"; //$NON-NLS-1$
+ private static final String FILTER_TAG = "filter"; //$NON-NLS-1$
+ private static final String REQUEST_TYPE_ATTR = "request_type"; //$NON-NLS-1$
+ private static final String ENABLED_ATTR = "enabled"; //$NON-NLS-1$
+
+ private List<Category> categories;
+
+ public EditPartTraceRequestFilters() {
+ categories = new ArrayList<Category>();
+ categories.add(new Category("GEF", getRequestFilters(org.eclipse.gef.RequestConstants.class)));
+ categories.add(new Category("GMF",
+ getRequestFilters(org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants.class)));
+ }
+
+ public boolean isEnabled(String requestType) {
+ for (Category category : categories) {
+ Filter filter = category.filters.get(requestType);
+ if (filter != null && filter.enabled) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public void readState(IMemento memento) {
+ if (memento == null) {
+ return;
+ }
+ IMemento requestFiltersMemento = memento.getChild(REQUEST_FILTERS_TAG);
+ if (requestFiltersMemento == null) {
+ return;
+ }
+ for (IMemento categoryMemento : requestFiltersMemento.getChildren(CATEGORY_TAG)) {
+ String categoryName = categoryMemento.getString(CATEGORY_NAME_ATTR);
+ if (categoryName == null) {
+ continue;
+ }
+ for (Category category : categories) {
+ if (!categoryName.equals(category.name)) {
+ continue;
+ }
+ for (IMemento filterMemento : categoryMemento.getChildren(FILTER_TAG)) {
+ String requestType = filterMemento.getString(REQUEST_TYPE_ATTR);
+ if (requestType == null) {
+ continue;
+ }
+ String enabled = filterMemento.getString(ENABLED_ATTR);
+ if (!Boolean.parseBoolean(enabled)) {
+ continue;
+ }
+ Filter filter = category.filters.get(requestType);
+ if (filter != null) {
+ filter.enabled = true;
+ }
+ }
+ }
+ }
+ }
+
+ public void writeState(IMemento memento) {
+ if (memento == null) {
+ return;
+ }
+ IMemento requestFiltersMemento = memento.getChild(REQUEST_FILTERS_TAG);
+ if (requestFiltersMemento == null) {
+ requestFiltersMemento = memento.createChild(REQUEST_FILTERS_TAG);
+ }
+ for (Category category : categories) {
+ IMemento categoryMemento = null;
+ for (IMemento existingCategoryMemento : requestFiltersMemento.getChildren(CATEGORY_TAG)) {
+ String categoryName = existingCategoryMemento.getString(CATEGORY_NAME_ATTR);
+ if (category.name.equals(categoryName)) {
+ categoryMemento = existingCategoryMemento;
+ break;
+ }
+ }
+ if (categoryMemento == null) {
+ categoryMemento = requestFiltersMemento.createChild(CATEGORY_TAG);
+ categoryMemento.putString(CATEGORY_NAME_ATTR, category.name);
+ }
+ for (Filter filter : category.filters.values()) {
+ IMemento filterMemento = null;
+ for (IMemento existingFilterMemento : categoryMemento.getChildren(FILTER_TAG)) {
+ String requestType = existingFilterMemento.getString(REQUEST_TYPE_ATTR);
+ if (filter.type.equals(requestType)) {
+ filterMemento = existingFilterMemento;
+ break;
+ }
+ }
+ if (filterMemento == null) {
+ if (!filter.enabled) {
+ continue;
+ }
+ filterMemento = categoryMemento.createChild(FILTER_TAG);
+ filterMemento.putString(REQUEST_TYPE_ATTR, filter.type);
+ }
+ filterMemento.putString(ENABLED_ATTR, String.valueOf(filter.enabled));
+ }
+ }
+ }
+
+ public void edit(Shell shell) {
+ CheckedTreeSelectionDialog dialog = new CheckedTreeSelectionDialog(shell, new RequestFiltersLabelProvider(),
+ new RequestFiltersContentProvider());
+ dialog.setContainerMode(true);
+ dialog.setInput(categories);
+ //dialog.setExpandedElements(categories.toArray(new Category[categories.size()]));
+ dialog.setInitialElementSelections(getEnabledRequestFilters());
+ dialog.setSorter(new ViewerSorter());
+ dialog.setTitle("Filtered Requests");
+ dialog.setMessage("Select requests that should be filtered out:");
+ if (dialog.open() == Window.OK) {
+ setEnabledRequestFilters(dialog.getResult());
+ }
+ }
+
+ private List<Filter> getEnabledRequestFilters() {
+ List<Filter> filters = new ArrayList<Filter>();
+ for (Category category : categories) {
+ for (Filter filter : category.filters.values()) {
+ if (filter.enabled) {
+ filters.add(filter);
+ }
+ }
+ }
+ return filters;
+ }
+
+ private void setEnabledRequestFilters(Object[] selection) {
+ for (Category category : categories) {
+ for (Filter filter : category.filters.values()) {
+ boolean enabled = false;
+ for (Object selected : selection) {
+ if (selected == filter) {
+ enabled = true;
+ break;
+ }
+ }
+ filter.enabled = enabled;
+ }
+ }
+ }
+
+ protected Map<String, Filter> getRequestFilters(Class clazz) {
+ Map<String, Filter> filters = new HashMap<String, Filter>();
+ try {
+ for (Field field : clazz.getDeclaredFields()) {
+ if (Modifier.isStatic(field.getModifiers()) && Modifier.isFinal(field.getModifiers())
+ && String.class.equals(field.getType()) && !field.isSynthetic()) {
+ // possibly name should start with 'REQ_'
+ String requestType = (String) field.get(null);
+ if (requestType != null) {
+ filters.put(requestType, new Filter(requestType, false));
+ }
+ }
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return filters;
+ }
+
+ private static class Filter {
+
+ public Category category;
+ public String type;
+ public boolean enabled;
+
+ public Filter(String type, boolean enabled) {
+ this.type = type;
+ this.enabled = enabled;
+ }
+ }
+
+ private static class Category {
+
+ public String name;
+ private Map<String, Filter> filters; // request type -> filter
+
+ public Category(String name, Map<String, Filter> filters) {
+ this.name = name;
+ this.filters = filters;
+ for (Filter filter : filters.values()) {
+ filter.category = this;
+ }
+ }
+ }
+
+ private static class RequestFiltersLabelProvider extends LabelProvider {
+
+ public String getText(Object element) {
+ if (element instanceof Filter) {
+ return ((Filter) element).type;
+ } else if (element instanceof Category) {
+ return ((Category) element).name;
+ }
+ return super.getText(element);
+ }
+ }
+
+ private class RequestFiltersContentProvider implements ITreeContentProvider {
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {}
+
+ public Object getParent(Object element) {
+ if (element instanceof Filter) {
+ return ((Filter) element).category;
+ } else if (element instanceof Category) {
+ return categories;
+ }
+ return null;
+ }
+
+ public boolean hasChildren(Object element) {
+ if (element instanceof Category) {
+ return !((Category) element).filters.isEmpty();
+ } else if (element == categories) {
+ return !categories.isEmpty();
+ }
+ return false;
+ }
+
+ public Object[] getChildren(Object parentElement) {
+ if (parentElement instanceof Category) {
+ Collection<Filter> filters = ((Category) parentElement).filters.values();
+ return filters.toArray(new Filter[filters.size()]);
+ } else if (parentElement == categories) {
+ return categories.toArray(new Category[categories.size()]);
+ }
+ return NONE;
+ }
+
+ public Object[] getElements(Object inputElement) {
+ return getChildren(inputElement);
+ }
+
+ public void dispose() {}
+ }
+}
diff --git a/devtools/org.eclipse.gmf.dev/src/org/eclipse/gmf/dev/EditPartTraceView.java b/devtools/org.eclipse.gmf.dev/src/org/eclipse/gmf/dev/EditPartTraceView.java
index ece5a924a..035c40db6 100644
--- a/devtools/org.eclipse.gmf.dev/src/org/eclipse/gmf/dev/EditPartTraceView.java
+++ b/devtools/org.eclipse.gmf.dev/src/org/eclipse/gmf/dev/EditPartTraceView.java
@@ -33,12 +33,16 @@ import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerFilter;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
+import org.eclipse.ui.IMemento;
import org.eclipse.ui.IPartListener;
+import org.eclipse.ui.IViewSite;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchPartSite;
+import org.eclipse.ui.PartInitException;
import org.eclipse.ui.part.ViewPart;
/**
@@ -48,6 +52,7 @@ public class EditPartTraceView extends ViewPart {
private TreeViewer viewer;
private List<IAction> actions;
+ private EditPartTraceRequestFilters requestFilters = new EditPartTraceRequestFilters();
private IWorkbenchPart part;
private Stack<CommandCreatedEvent> history = new Stack<CommandCreatedEvent>();
@@ -91,6 +96,16 @@ public class EditPartTraceView extends ViewPart {
return (TopEditPartTraceRecord) records.get(records.size() - 1);
}
+ public void init(IViewSite site, IMemento memento) throws PartInitException {
+ super.init(site, memento);
+ requestFilters.readState(memento);
+ }
+
+ public void saveState(IMemento memento) {
+ super.saveState(memento);
+ requestFilters.writeState(memento);
+ }
+
protected void setSite(IWorkbenchPartSite site) {
super.setSite(site);
site.getWorkbenchWindow().getPartService().addPartListener(partListener);
@@ -98,6 +113,7 @@ public class EditPartTraceView extends ViewPart {
public void createPartControl(Composite parent) {
viewer = new TreeViewer(parent);
+ viewer.addFilter(new TraceViewerFilter());
viewer.setLabelProvider(new TraceLabelProvider());
viewer.setContentProvider(new TraceContentProvider());
viewer.setInput(new ArrayList());
@@ -107,6 +123,13 @@ public class EditPartTraceView extends ViewPart {
protected void makeActions() {
actions = new ArrayList<IAction>();
+ actions.add(new Action("Flush") {
+
+ public void run() {
+ getRecords().clear();
+ viewer.refresh(true);
+ }
+ });
actions.add(new Action("Expand") {
public void run() {
@@ -116,10 +139,10 @@ public class EditPartTraceView extends ViewPart {
}
}
});
- actions.add(new Action("Flush") {
+ actions.add(new Action("Filters") {
public void run() {
- getRecords().clear();
+ requestFilters.edit(getSite().getShell());
viewer.refresh(true);
}
});
@@ -211,14 +234,15 @@ public class EditPartTraceView extends ViewPart {
}
protected EditPartTraceRecord trace(CommandCreatedEvent event, boolean top) {
- if (event.request != null && isIgnored(event.request)) {
- return null;
- }
StringBuffer text = new StringBuffer();
text.append(DevUtils.getSimpleClassName(event.editPart));
text.append(" : ");
+ String requestType;
if (event.request != null) {
- text.append(String.valueOf(event.request.getType()));
+ requestType = String.valueOf(event.request.getType());
+ text.append(requestType);
+ } else {
+ requestType = null;
}
text.append(" -> ");
text.append(DevUtils.getSimpleClassName(event.command));
@@ -241,16 +265,8 @@ public class EditPartTraceView extends ViewPart {
}
}
EditPartTraceRecord[] akids = (EditPartTraceRecord[]) kids.toArray(new EditPartTraceRecord[kids.size()]);
- return top ? new TopEditPartTraceRecord(text.toString(), DevPlugin.EVENT_IMAGE, akids) : new EditPartTraceRecord(text.toString(), DevPlugin.EVENT_IMAGE, akids);
- }
-
- protected boolean isIgnored(Request request) {
- String ignored = DevPlugin.getOption(DevPlugin.IGNORED_REQUESTS_OPTION);
- if (ignored == null) {
- return false;
- }
- String type = String.valueOf(request.getType());
- return ignored.indexOf(type) >= 0;
+ return top ? new TopEditPartTraceRecord(text.toString(), DevPlugin.EVENT_IMAGE, akids, requestType)
+ : new EditPartTraceRecord(text.toString(), DevPlugin.EVENT_IMAGE, akids);
}
private class TraceContentProvider implements ITreeContentProvider {
@@ -319,12 +335,33 @@ public class EditPartTraceView extends ViewPart {
}
}
+ private class TraceViewerFilter extends ViewerFilter {
+
+ public TraceViewerFilter() {}
+
+ public boolean select(Viewer viewer, Object parentElement, Object element) {
+ if (element instanceof TopEditPartTraceRecord) {
+ String requestType = ((TopEditPartTraceRecord) element).getRequestType();
+ if (requestType != null) {
+ return !requestFilters.isEnabled(requestType);
+ }
+ }
+ return true;
+ }
+ }
+
private class TopEditPartTraceRecord extends EditPartTraceRecord {
+ private String requestType;
private int timesRequested = 1;
- public TopEditPartTraceRecord(String label, String imageId, EditPartTraceRecord[] kids) {
+ public TopEditPartTraceRecord(String label, String imageId, EditPartTraceRecord[] kids, String requestType) {
super(label, imageId, kids);
+ this.requestType = requestType;
+ }
+
+ public String getRequestType() {
+ return requestType;
}
public int getTimesRequested() {

Back to the top