diff options
author | dstadnik | 2006-05-12 14:49:07 +0000 |
---|---|---|
committer | dstadnik | 2006-05-12 14:49:07 +0000 |
commit | d6b0a34c8e4f188c12459c0bca2acbaeeb463303 (patch) | |
tree | 5dc67c9edace540e8d1a589022a0dde15d3dcd17 /devtools | |
parent | 500c0e8a7b75195cdd000826797f79d31394a862 (diff) | |
download | org.eclipse.gmf-tooling-d6b0a34c8e4f188c12459c0bca2acbaeeb463303.tar.gz org.eclipse.gmf-tooling-d6b0a34c8e4f188c12459c0bca2acbaeeb463303.tar.xz org.eclipse.gmf-tooling-d6b0a34c8e4f188c12459c0bca2acbaeeb463303.zip |
use sources
Diffstat (limited to 'devtools')
3 files changed, 94 insertions, 52 deletions
diff --git a/devtools/org.eclipse.gmf.dev/src/org/eclipse/gmf/dev/EditPartTraceUtil.java b/devtools/org.eclipse.gmf.dev/src/org/eclipse/gmf/dev/EditPartTraceUtil.java new file mode 100644 index 000000000..145c0a974 --- /dev/null +++ b/devtools/org.eclipse.gmf.dev/src/org/eclipse/gmf/dev/EditPartTraceUtil.java @@ -0,0 +1,81 @@ +/* + * 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.util.IdentityHashMap; + +import org.eclipse.gef.EditPart; +import org.eclipse.gef.Request; +import org.eclipse.gef.commands.Command; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PlatformUI; + +/** + * @author dstadnik + */ +public class EditPartTraceUtil { + + private EditPartTraceUtil() { + } + + public static EditPartTraceView getTraceView() { + IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); + if (window == null) { + return null; + } + IWorkbenchPage page = window.getActivePage(); + if (page == null) { + return null; + } + return (EditPartTraceView) page.findView("org.eclipse.gmf.dev.EditPartTraceView"); + } + + public static void fireCommandRequested(EditPart editPart, Request request) { + EditPartTraceView view = getTraceView(); + if (view == null) { + return; + } + try { + view.traceCommandRequested(editPart, request); + } catch (Throwable t) { + t.printStackTrace(); + } + } + + public static void fireCommandCreated(EditPart editPart, Request request, Command command) { + EditPartTraceView view = getTraceView(); + if (view == null) { + return; + } + try { + view.traceCommandCreated(editPart, request, command); + } catch (Throwable t) { + t.printStackTrace(); + } + } + + public static void addSource(Object command, Object source) { + EditPartTraceView view = getTraceView(); + if (view == null) { + return; + } + CommandCreatedEvent event = view.getCurrentEvent(); + if (event == null) { + return; + } + if (event.sources == null) { + event.sources = new IdentityHashMap(); + } + event.sources.put(command, source); + } +} 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 0d5cef67c..7f1f83442 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 @@ -15,7 +15,6 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; import java.util.List; -import java.util.Map; import java.util.Stack; import org.eclipse.gef.EditPart; @@ -135,7 +134,7 @@ public class EditPartTraceView extends ViewPart { history.push(event); } - public void traceCommandCreated(EditPart editPart, Request request, Command command, Map sources) { + public void traceCommandCreated(EditPart editPart, Request request, Command command) { if (history.isEmpty()) { throw new IllegalStateException("Command requested event was not received."); } @@ -143,7 +142,6 @@ public class EditPartTraceView extends ViewPart { event.editPart = editPart; event.request = request; event.command = command; - event.sources = sources; if (history.isEmpty()) { EditPartTraceRecord record = trace(event, true); if (record != null) { @@ -200,6 +198,13 @@ public class EditPartTraceView extends ViewPart { return top ? new TopEditPartTraceRecord(text.toString(), DevPlugin.EVENT_IMAGE, akids, requestType) : new EditPartTraceRecord(text.toString(), DevPlugin.EVENT_IMAGE, akids); } + public CommandCreatedEvent getCurrentEvent() { + if (history.isEmpty()) { + return null; + } + return history.peek(); + } + private class TraceContentProvider implements ITreeContentProvider { public void dispose() { diff --git a/devtools/org.eclipse.gmf.dev/src/org/eclipse/gmf/dev/EditPartTracer.aj b/devtools/org.eclipse.gmf.dev/src/org/eclipse/gmf/dev/EditPartTracer.aj index 1f4811d3d..8c23e636b 100644 --- a/devtools/org.eclipse.gmf.dev/src/org/eclipse/gmf/dev/EditPartTracer.aj +++ b/devtools/org.eclipse.gmf.dev/src/org/eclipse/gmf/dev/EditPartTracer.aj @@ -11,16 +11,10 @@ */ package org.eclipse.gmf.dev; -import java.util.HashMap; -import java.util.Map; - import org.eclipse.gef.EditPart; import org.eclipse.gef.EditPolicy; import org.eclipse.gef.Request; import org.eclipse.gef.commands.Command; -import org.eclipse.ui.IWorkbenchPage; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.PlatformUI; /** * @author dstadnik @@ -30,13 +24,12 @@ public aspect EditPartTracer { pointcut makingCommandInEditPart(EditPart editPart, Request request) : execution(Command EditPart.getCommand(Request)) && target(editPart) && args(request); Command around(EditPart editPart, Request request) : makingCommandInEditPart(editPart, request) { - fireCommandRequested(editPart, request); - Map sources = new HashMap(); + EditPartTraceUtil.fireCommandRequested(editPart, request); Command command = null; try { command = proceed(editPart, request); } finally { - fireCommandCreated(editPart, request, command, sources); + EditPartTraceUtil.fireCommandCreated(editPart, request, command); } return command; } @@ -44,47 +37,10 @@ public aspect EditPartTracer { pointcut makingCommandInEditPolicy(EditPolicy editPolicy, Request request) : execution(Command EditPolicy.getCommand(Request)) && target(editPolicy) && args(request); Command around(EditPolicy editPolicy, Request request) : makingCommandInEditPolicy(editPolicy, request) { - Command command = null; - try { - command = proceed(editPolicy, request); - } finally { + Command command = proceed(editPolicy, request); + if (command != null) { + EditPartTraceUtil.addSource(command, editPolicy); } return command; } - - private static Object getTraceView() { - IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); - if (window == null) { - return null; - } - IWorkbenchPage page = window.getActivePage(); - if (page == null) { - return null; - } - return page.findView("org.eclipse.gmf.dev.EditPartTraceView"); - } - - private void fireCommandRequested(EditPart editPart, Request request) { - Object view = getTraceView(); - if (view == null) { - return; - } - try { - view.getClass().getDeclaredMethod("traceCommandRequested", EditPart.class, Request.class).invoke(view, editPart, request); - } catch (Throwable t) { - t.printStackTrace(); - } - } - - private void fireCommandCreated(EditPart editPart, Request request, Command command, Map sources) { - Object view = getTraceView(); - if (view == null) { - return; - } - try { - view.getClass().getDeclaredMethod("traceCommandCreated", EditPart.class, Request.class, Command.class, Map.class).invoke(view, editPart, request, command, sources); - } catch (Throwable t) { - t.printStackTrace(); - } - } } |