Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 1f4811d3df60d4131aa5669977b2fd972e5282f2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
 * 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.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
 */
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();
		Command command = null;
		try {
			command = proceed(editPart, request);
		} finally {
			fireCommandCreated(editPart, request, command, sources);
		}
		return command;
	}

	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 {
		}
		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();
		}
	}
}

Back to the top