Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordstadnik2005-11-10 14:51:22 +0000
committerdstadnik2005-11-10 14:51:22 +0000
commitf19a4a673f284993bc4dba4767c0f998debed716 (patch)
treea599452c1f7f62fe26c37a4a65a2f8a82a212924 /devtools
parente786483cf14049ac8fd5091cf475f3c4784730ae (diff)
downloadorg.eclipse.gmf-tooling-f19a4a673f284993bc4dba4767c0f998debed716.tar.gz
org.eclipse.gmf-tooling-f19a4a673f284993bc4dba4767c0f998debed716.tar.xz
org.eclipse.gmf-tooling-f19a4a673f284993bc4dba4767c0f998debed716.zip
initial
Diffstat (limited to 'devtools')
-rw-r--r--devtools/org.eclipse.gmf.dev.hook/.classpath7
-rw-r--r--devtools/org.eclipse.gmf.dev.hook/.cvsignore1
-rw-r--r--devtools/org.eclipse.gmf.dev.hook/.project28
-rw-r--r--devtools/org.eclipse.gmf.dev.hook/META-INF/MANIFEST.MF14
-rw-r--r--devtools/org.eclipse.gmf.dev.hook/build.properties4
-rw-r--r--devtools/org.eclipse.gmf.dev.hook/src/org/eclipse/gmf/dev/hook/DevHookPlugin.java40
-rw-r--r--devtools/org.eclipse.gmf.dev.hook/src/org/eclipse/gmf/dev/hook/EditPartTraceListener.java36
-rw-r--r--devtools/org.eclipse.gmf.dev.hook/src/org/eclipse/gmf/dev/hook/EditPartTracer.java123
-rw-r--r--devtools/org.eclipse.gmf.dev/.classpath7
-rw-r--r--devtools/org.eclipse.gmf.dev/.cvsignore1
-rw-r--r--devtools/org.eclipse.gmf.dev/.options3
-rw-r--r--devtools/org.eclipse.gmf.dev/.project28
-rw-r--r--devtools/org.eclipse.gmf.dev/META-INF/MANIFEST.MF15
-rw-r--r--devtools/org.eclipse.gmf.dev/build.properties4
-rw-r--r--devtools/org.eclipse.gmf.dev/icons/command.gifbin0 -> 379 bytes
-rw-r--r--devtools/org.eclipse.gmf.dev/icons/commandx.gifbin0 -> 191 bytes
-rw-r--r--devtools/org.eclipse.gmf.dev/icons/editpart.gifbin0 -> 323 bytes
-rw-r--r--devtools/org.eclipse.gmf.dev/icons/event.gifbin0 -> 351 bytes
-rw-r--r--devtools/org.eclipse.gmf.dev/icons/info.gifbin0 -> 121 bytes
-rw-r--r--devtools/org.eclipse.gmf.dev/icons/model.gifbin0 -> 368 bytes
-rw-r--r--devtools/org.eclipse.gmf.dev/icons/parameter.gifbin0 -> 376 bytes
-rw-r--r--devtools/org.eclipse.gmf.dev/icons/request.gifbin0 -> 618 bytes
-rw-r--r--devtools/org.eclipse.gmf.dev/plugin.xml38
-rw-r--r--devtools/org.eclipse.gmf.dev/src/org/eclipse/gmf/dev/CommandCreatedEvent.java47
-rw-r--r--devtools/org.eclipse.gmf.dev/src/org/eclipse/gmf/dev/DevPlugin.java144
-rw-r--r--devtools/org.eclipse.gmf.dev/src/org/eclipse/gmf/dev/DevUtils.java68
-rw-r--r--devtools/org.eclipse.gmf.dev/src/org/eclipse/gmf/dev/EditPartTraceConstructor.java238
-rw-r--r--devtools/org.eclipse.gmf.dev/src/org/eclipse/gmf/dev/EditPartTraceRecord.java85
-rw-r--r--devtools/org.eclipse.gmf.dev/src/org/eclipse/gmf/dev/EditPartTraceView.java338
-rw-r--r--devtools/org.eclipse.gmf.dev/src/org/eclipse/gmf/dev/PartTrackerView.java193
30 files changed, 1462 insertions, 0 deletions
diff --git a/devtools/org.eclipse.gmf.dev.hook/.classpath b/devtools/org.eclipse.gmf.dev.hook/.classpath
new file mode 100644
index 000000000..751c8f2e5
--- /dev/null
+++ b/devtools/org.eclipse.gmf.dev.hook/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/devtools/org.eclipse.gmf.dev.hook/.cvsignore b/devtools/org.eclipse.gmf.dev.hook/.cvsignore
new file mode 100644
index 000000000..ba077a403
--- /dev/null
+++ b/devtools/org.eclipse.gmf.dev.hook/.cvsignore
@@ -0,0 +1 @@
+bin
diff --git a/devtools/org.eclipse.gmf.dev.hook/.project b/devtools/org.eclipse.gmf.dev.hook/.project
new file mode 100644
index 000000000..4e47f75b1
--- /dev/null
+++ b/devtools/org.eclipse.gmf.dev.hook/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.gmf.dev.hook</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/devtools/org.eclipse.gmf.dev.hook/META-INF/MANIFEST.MF b/devtools/org.eclipse.gmf.dev.hook/META-INF/MANIFEST.MF
new file mode 100644
index 000000000..affbf9aa0
--- /dev/null
+++ b/devtools/org.eclipse.gmf.dev.hook/META-INF/MANIFEST.MF
@@ -0,0 +1,14 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: GMF Dev Hook
+Bundle-SymbolicName: org.eclipse.gmf.dev.hook; singleton:=true
+Bundle-Version: 1.0.0
+Bundle-Activator: org.eclipse.gmf.dev.hook.DevHookPlugin
+Bundle-Vendor: eclipse.org
+Bundle-Localization: plugin
+Require-Bundle: org.eclipse.core.runtime,
+ org.eclipse.ui,
+ org.eclipse.draw2d,
+ org.eclipse.gef
+Eclipse-AutoStart: true
+Export-Package: org.eclipse.gmf.dev.hook
diff --git a/devtools/org.eclipse.gmf.dev.hook/build.properties b/devtools/org.eclipse.gmf.dev.hook/build.properties
new file mode 100644
index 000000000..34d2e4d2d
--- /dev/null
+++ b/devtools/org.eclipse.gmf.dev.hook/build.properties
@@ -0,0 +1,4 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .
diff --git a/devtools/org.eclipse.gmf.dev.hook/src/org/eclipse/gmf/dev/hook/DevHookPlugin.java b/devtools/org.eclipse.gmf.dev.hook/src/org/eclipse/gmf/dev/hook/DevHookPlugin.java
new file mode 100644
index 000000000..4b8973742
--- /dev/null
+++ b/devtools/org.eclipse.gmf.dev.hook/src/org/eclipse/gmf/dev/hook/DevHookPlugin.java
@@ -0,0 +1,40 @@
+/*
+ * 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.hook;
+
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * @author dstadnik
+ */
+public class DevHookPlugin extends AbstractUIPlugin {
+
+ private static DevHookPlugin instance;
+
+ public DevHookPlugin() {
+ instance = this;
+ }
+
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ }
+
+ public void stop(BundleContext context) throws Exception {
+ super.stop(context);
+ instance = null;
+ }
+
+ public static DevHookPlugin getInstance() {
+ return instance;
+ }
+}
diff --git a/devtools/org.eclipse.gmf.dev.hook/src/org/eclipse/gmf/dev/hook/EditPartTraceListener.java b/devtools/org.eclipse.gmf.dev.hook/src/org/eclipse/gmf/dev/hook/EditPartTraceListener.java
new file mode 100644
index 000000000..08ecca811
--- /dev/null
+++ b/devtools/org.eclipse.gmf.dev.hook/src/org/eclipse/gmf/dev/hook/EditPartTraceListener.java
@@ -0,0 +1,36 @@
+/*
+ * 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.hook;
+
+import java.util.Map;
+
+import org.eclipse.gef.EditPart;
+import org.eclipse.gef.Request;
+import org.eclipse.gef.commands.Command;
+
+/**
+ * Traces editparts notifications.
+ *
+ * @author dstadnik
+ */
+public interface EditPartTraceListener {
+
+ /**
+ * Called when command was requested but before it was created.
+ */
+ public void commandRequested(EditPart editPart, Request request);
+
+ /**
+ * Edit part created command in response to the request.
+ */
+ public void commandCreated(EditPart editPart, Request request, Command command, Map sources);
+}
diff --git a/devtools/org.eclipse.gmf.dev.hook/src/org/eclipse/gmf/dev/hook/EditPartTracer.java b/devtools/org.eclipse.gmf.dev.hook/src/org/eclipse/gmf/dev/hook/EditPartTracer.java
new file mode 100644
index 000000000..50c20607b
--- /dev/null
+++ b/devtools/org.eclipse.gmf.dev.hook/src/org/eclipse/gmf/dev/hook/EditPartTracer.java
@@ -0,0 +1,123 @@
+/*
+ * 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.hook;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gef.EditPartViewer;
+import org.eclipse.gef.EditPolicy;
+import org.eclipse.gef.Request;
+import org.eclipse.gef.commands.Command;
+import org.eclipse.gef.editparts.AbstractGraphicalEditPart;
+
+/**
+ * @author dstadnik
+ */
+public class EditPartTracer {
+
+ private List listeners;
+
+ private EditPartTracer() {}
+
+ public static EditPartTracer getInstance(EditPartViewer viewer) {
+ if (viewer == null) {
+ return null;
+ }
+ return (EditPartTracer) viewer.getProperty(EditPartTracer.class.getName());
+ }
+
+ public static EditPartTracer install(EditPartViewer viewer) {
+ EditPartTracer tracer = getInstance(viewer);
+ if (tracer == null && viewer != null) {
+ tracer = new EditPartTracer();
+ viewer.setProperty(EditPartTracer.class.getName(), tracer);
+ }
+ return tracer;
+ }
+
+ public void addTraceListener(EditPartTraceListener listener) {
+ if (listener == null) {
+ throw new IllegalArgumentException();
+ }
+ if (listeners == null) {
+ listeners = new ArrayList();
+ }
+ listeners.add(listener);
+ }
+
+ public void removeTraceListener(EditPartTraceListener listener) {
+ if (listener == null) {
+ throw new IllegalArgumentException();
+ }
+ if (listeners == null) {
+ return;
+ }
+ listeners.remove(listener);
+ }
+
+ public void fireCommandRequested(EditPart editPart, Request request) {
+ if (listeners == null) {
+ return;
+ }
+ for (int i = 0; i < listeners.size(); i++) {
+ try {
+ ((EditPartTraceListener) listeners.get(i)).commandRequested(editPart, request);
+ } catch (Throwable t) {
+ t.printStackTrace();
+ }
+ }
+ }
+
+ public void fireCommandCreated(EditPart editPart, Request request, Command command, Map sources) {
+ if (listeners == null) {
+ return;
+ }
+ for (int i = 0; i < listeners.size(); i++) {
+ try {
+ ((EditPartTraceListener) listeners.get(i)).commandCreated(editPart, request, command, sources);
+ } catch (Throwable t) {
+ t.printStackTrace();
+ }
+ }
+ }
+
+ public static class Insider extends AbstractGraphicalEditPart {
+
+ /**
+ * Standard implementation of getCommand(Request) method
+ * from AbstractEditPart that also traces edit policies
+ * that created particular commands.
+ */
+ public static Command getCommand(EditPolicyIterator editPolicies, Request request, Map sources) {
+ Command command = null;
+ while (editPolicies.hasNext()) {
+ EditPolicy nextPolicy = editPolicies.next();
+ Command nextCommand = nextPolicy.getCommand(request);
+ if (nextCommand != null) {
+ sources.put(nextCommand, nextPolicy);
+ }
+ command = command == null ? nextCommand : command.chain(nextCommand);
+ }
+ return command;
+ }
+
+ protected IFigure createFigure() {
+ return null;
+ }
+
+ protected void createEditPolicies() {}
+ }
+}
diff --git a/devtools/org.eclipse.gmf.dev/.classpath b/devtools/org.eclipse.gmf.dev/.classpath
new file mode 100644
index 000000000..751c8f2e5
--- /dev/null
+++ b/devtools/org.eclipse.gmf.dev/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/devtools/org.eclipse.gmf.dev/.cvsignore b/devtools/org.eclipse.gmf.dev/.cvsignore
new file mode 100644
index 000000000..ba077a403
--- /dev/null
+++ b/devtools/org.eclipse.gmf.dev/.cvsignore
@@ -0,0 +1 @@
+bin
diff --git a/devtools/org.eclipse.gmf.dev/.options b/devtools/org.eclipse.gmf.dev/.options
new file mode 100644
index 000000000..e40ce79d8
--- /dev/null
+++ b/devtools/org.eclipse.gmf.dev/.options
@@ -0,0 +1,3 @@
+org.eclipse.gmf.dev/debug=false
+org.eclipse.gmf.dev/debug/trace=false
+org.eclipse.gmf.dev/debug/requests/ignored=insert_semantic
diff --git a/devtools/org.eclipse.gmf.dev/.project b/devtools/org.eclipse.gmf.dev/.project
new file mode 100644
index 000000000..696b62e37
--- /dev/null
+++ b/devtools/org.eclipse.gmf.dev/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.gmf.dev</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/devtools/org.eclipse.gmf.dev/META-INF/MANIFEST.MF b/devtools/org.eclipse.gmf.dev/META-INF/MANIFEST.MF
new file mode 100644
index 000000000..b5d90e250
--- /dev/null
+++ b/devtools/org.eclipse.gmf.dev/META-INF/MANIFEST.MF
@@ -0,0 +1,15 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: GMF Dev
+Bundle-SymbolicName: org.eclipse.gmf.dev; singleton:=true
+Bundle-Version: 1.0.0
+Bundle-Activator: org.eclipse.gmf.dev.DevPlugin
+Bundle-Vendor: eclipse.org
+Bundle-Localization: plugin
+Require-Bundle: org.eclipse.core.runtime,
+ org.eclipse.ui,
+ org.eclipse.draw2d,
+ org.eclipse.gef,
+ org.eclipse.gmf.dev.hook,
+ org.eclipse.gmf.runtime.diagram.ui
+Eclipse-AutoStart: true
diff --git a/devtools/org.eclipse.gmf.dev/build.properties b/devtools/org.eclipse.gmf.dev/build.properties
new file mode 100644
index 000000000..34d2e4d2d
--- /dev/null
+++ b/devtools/org.eclipse.gmf.dev/build.properties
@@ -0,0 +1,4 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .
diff --git a/devtools/org.eclipse.gmf.dev/icons/command.gif b/devtools/org.eclipse.gmf.dev/icons/command.gif
new file mode 100644
index 000000000..57f410224
--- /dev/null
+++ b/devtools/org.eclipse.gmf.dev/icons/command.gif
Binary files differ
diff --git a/devtools/org.eclipse.gmf.dev/icons/commandx.gif b/devtools/org.eclipse.gmf.dev/icons/commandx.gif
new file mode 100644
index 000000000..50db6946d
--- /dev/null
+++ b/devtools/org.eclipse.gmf.dev/icons/commandx.gif
Binary files differ
diff --git a/devtools/org.eclipse.gmf.dev/icons/editpart.gif b/devtools/org.eclipse.gmf.dev/icons/editpart.gif
new file mode 100644
index 000000000..6514f7bb7
--- /dev/null
+++ b/devtools/org.eclipse.gmf.dev/icons/editpart.gif
Binary files differ
diff --git a/devtools/org.eclipse.gmf.dev/icons/event.gif b/devtools/org.eclipse.gmf.dev/icons/event.gif
new file mode 100644
index 000000000..dd45f08fb
--- /dev/null
+++ b/devtools/org.eclipse.gmf.dev/icons/event.gif
Binary files differ
diff --git a/devtools/org.eclipse.gmf.dev/icons/info.gif b/devtools/org.eclipse.gmf.dev/icons/info.gif
new file mode 100644
index 000000000..2da001e3e
--- /dev/null
+++ b/devtools/org.eclipse.gmf.dev/icons/info.gif
Binary files differ
diff --git a/devtools/org.eclipse.gmf.dev/icons/model.gif b/devtools/org.eclipse.gmf.dev/icons/model.gif
new file mode 100644
index 000000000..049cac696
--- /dev/null
+++ b/devtools/org.eclipse.gmf.dev/icons/model.gif
Binary files differ
diff --git a/devtools/org.eclipse.gmf.dev/icons/parameter.gif b/devtools/org.eclipse.gmf.dev/icons/parameter.gif
new file mode 100644
index 000000000..a16ac8314
--- /dev/null
+++ b/devtools/org.eclipse.gmf.dev/icons/parameter.gif
Binary files differ
diff --git a/devtools/org.eclipse.gmf.dev/icons/request.gif b/devtools/org.eclipse.gmf.dev/icons/request.gif
new file mode 100644
index 000000000..86550fe9f
--- /dev/null
+++ b/devtools/org.eclipse.gmf.dev/icons/request.gif
Binary files differ
diff --git a/devtools/org.eclipse.gmf.dev/plugin.xml b/devtools/org.eclipse.gmf.dev/plugin.xml
new file mode 100644
index 000000000..6306d28b9
--- /dev/null
+++ b/devtools/org.eclipse.gmf.dev/plugin.xml
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.0"?>
+
+<plugin>
+
+ <extension
+ point="org.eclipse.ui.views">
+ <category
+ name="GMF Dev"
+ id="org.eclipse.gmf.dev">
+ </category>
+ <view
+ name="GEF Console"
+ category="org.eclipse.gmf.dev"
+ class="org.eclipse.gef.ui.console.DebugGEF"
+ id="org.eclipse.gmf.dev.DebugGEF">
+ </view>
+ <view
+ name="Command Stack"
+ category="org.eclipse.gmf.dev"
+ class="org.eclipse.gef.ui.stackview.CommandStackInspector"
+ id="org.eclipse.gmf.dev.CommandStackInspector">
+ </view>
+ <view
+ name="Edit Parts Tracer"
+ category="org.eclipse.gmf.dev"
+ class="org.eclipse.gmf.dev.EditPartTraceView"
+ id="org.eclipse.gmf.dev.EditPartTraceView">
+ </view>
+ <view
+ name="Workbench Parts Tracker"
+ category="org.eclipse.gmf.dev"
+ class="org.eclipse.gmf.dev.PartTrackerView"
+ id="org.eclipse.gmf.dev.PartTrackerView">
+ </view>
+ </extension>
+
+</plugin>
diff --git a/devtools/org.eclipse.gmf.dev/src/org/eclipse/gmf/dev/CommandCreatedEvent.java b/devtools/org.eclipse.gmf.dev/src/org/eclipse/gmf/dev/CommandCreatedEvent.java
new file mode 100644
index 000000000..4df020bc5
--- /dev/null
+++ b/devtools/org.eclipse.gmf.dev/src/org/eclipse/gmf/dev/CommandCreatedEvent.java
@@ -0,0 +1,47 @@
+/*
+ * 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.List;
+import java.util.Map;
+
+import org.eclipse.gef.EditPart;
+import org.eclipse.gef.Request;
+import org.eclipse.gef.commands.Command;
+
+/**
+ * @author dstadnik
+ */
+public class CommandCreatedEvent {
+
+ EditPart editPart;
+ Request request;
+ Command command;
+ Map sources;
+ List<CommandCreatedEvent> siblings;
+
+ public Object getSource(Object object) {
+ Object source = null;
+ if (sources != null) {
+ source = sources.get(object);
+ }
+ if (source == null && siblings != null) {
+ for (CommandCreatedEvent sibling : siblings) {
+ source = sibling.getSource(object);
+ if (source != null) {
+ break;
+ }
+ }
+ }
+ return source;
+ }
+}
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
new file mode 100644
index 000000000..6086a9ac5
--- /dev/null
+++ b/devtools/org.eclipse.gmf.dev/src/org/eclipse/gmf/dev/DevPlugin.java
@@ -0,0 +1,144 @@
+/*
+ * 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 org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * @author dstadnik
+ */
+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";
+ public static final String EDITPART_IMAGE = "/icons/editpart.gif";
+ public static final String EVENT_IMAGE = "/icons/event.gif";
+ public static final String INFO_IMAGE = "/icons/info.gif";
+ public static final String MODEL_IMAGE = "/icons/model.gif";
+ public static final String PARAMETER_IMAGE = "/icons/parameter.gif";
+ public static final String REQUEST_IMAGE = "/icons/request.gif";
+
+ private static DevPlugin instance;
+
+ public DevPlugin() {
+ instance = this;
+ }
+
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ getImageRegistry().put(COMMAND_IMAGE, getImageDescriptor(COMMAND_IMAGE));
+ getImageRegistry().put(COMMANDX_IMAGE, getImageDescriptor(COMMANDX_IMAGE));
+ getImageRegistry().put(EDITPART_IMAGE, getImageDescriptor(EDITPART_IMAGE));
+ getImageRegistry().put(EVENT_IMAGE, getImageDescriptor(EVENT_IMAGE));
+ getImageRegistry().put(INFO_IMAGE, getImageDescriptor(INFO_IMAGE));
+ getImageRegistry().put(MODEL_IMAGE, getImageDescriptor(MODEL_IMAGE));
+ getImageRegistry().put(PARAMETER_IMAGE, getImageDescriptor(PARAMETER_IMAGE));
+ getImageRegistry().put(REQUEST_IMAGE, getImageDescriptor(REQUEST_IMAGE));
+ }
+
+ public void stop(BundleContext context) throws Exception {
+ super.stop(context);
+ instance = null;
+ }
+
+ public static DevPlugin getInstance() {
+ return instance;
+ }
+
+ /**
+ * Returns an image descriptor for the image file at the given
+ * plug-in relative path.
+ *
+ * @param path the path
+ * @return the image descriptor
+ */
+ public static ImageDescriptor getImageDescriptor(String path) {
+ return AbstractUIPlugin.imageDescriptorFromPlugin("org.eclipse.gmf.dev", path);
+ }
+
+ public static Image getImage(String name) {
+ return instance.getImageRegistry().get(name);
+ }
+
+ public static String getOption(String name) {
+ if (instance == null) {
+ return null;
+ }
+ String key = instance.getBundle().getSymbolicName() + name;
+ return Platform.getDebugOption(key);
+ }
+
+ public static boolean isOptionEnabled(String name) {
+ return Boolean.valueOf(getOption(name)).booleanValue();
+ }
+
+ public boolean isTracing() {
+ return isOptionEnabled(TRACE_OPTION);
+ }
+
+ public static void logInfo(String text) {
+ DevPlugin instance = getInstance();
+ if (instance == null) {
+ return;
+ }
+ if (!instance.isDebugging()) {
+ return;
+ }
+ log(IStatus.INFO, text);
+ }
+
+ public static void logError(String text) {
+ log(IStatus.ERROR, text);
+ }
+
+ public static void logError(String text, Throwable cause) {
+ log(IStatus.ERROR, text, cause);
+ }
+
+ public static void logWarning(String text) {
+ log(IStatus.WARNING, text);
+ }
+
+ public static void logWarning(String text, Throwable cause) {
+ log(IStatus.WARNING, text, cause);
+ }
+
+ protected static void log(int type, String text) {
+ if (instance != null && instance.isTracing()) {
+ log(type, text, new Throwable());
+ } else {
+ log(type, text, null);
+ }
+ }
+
+ protected static void log(int type, String text, Throwable cause) {
+ if (instance == null) {
+ System.err.println(text);
+ if (cause != null) {
+ cause.printStackTrace(System.err);
+ }
+ } else {
+ String id = instance.getBundle().getSymbolicName();
+ IStatus status = new Status(type, id, 0, text, cause);
+ instance.getLog().log(status);
+ }
+ }
+}
diff --git a/devtools/org.eclipse.gmf.dev/src/org/eclipse/gmf/dev/DevUtils.java b/devtools/org.eclipse.gmf.dev/src/org/eclipse/gmf/dev/DevUtils.java
new file mode 100644
index 000000000..ae0267954
--- /dev/null
+++ b/devtools/org.eclipse.gmf.dev/src/org/eclipse/gmf/dev/DevUtils.java
@@ -0,0 +1,68 @@
+/*
+ * 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;
+
+/**
+ * @author dstadnik
+ */
+public class DevUtils {
+
+ private DevUtils() {}
+
+ public static String getFullClassName(Object obj) {
+ if (obj == null) {
+ return null;
+ }
+ return obj.getClass().getName();
+ }
+
+ public static String getSimpleClassName(Object obj) {
+ if (obj == null) {
+ return null;
+ }
+ return getSimpleName(obj.getClass().getName());
+ }
+
+ public static String getSimpleName(String fqn) {
+ return fqn.substring(fqn.lastIndexOf('.') + 1);
+ }
+
+ /**
+ * Returns <code>null</code> if field does not exist.
+ */
+ public static Object getFieldValue(Object obj, String name) {
+ try {
+ Field f = obj.getClass().getDeclaredField(name);
+ f.setAccessible(true);
+ return f.get(obj);
+ } catch (Throwable t) {
+ DevPlugin.logError("Unable to retrieve field value : " + name, t);
+ }
+ return null;
+ }
+
+ /**
+ * Returns <code>null</code> if field does not exist.
+ */
+ public static Object getStaticFieldValue(Class clazz, String name) {
+ try {
+ Field f = clazz.getDeclaredField(name);
+ f.setAccessible(true);
+ return f.get(null);
+ } catch (Throwable t) {
+ DevPlugin.logError("Unable to retrieve static field value : " + name, t);
+ }
+ return null;
+ }
+}
diff --git a/devtools/org.eclipse.gmf.dev/src/org/eclipse/gmf/dev/EditPartTraceConstructor.java b/devtools/org.eclipse.gmf.dev/src/org/eclipse/gmf/dev/EditPartTraceConstructor.java
new file mode 100644
index 000000000..9d6b9d326
--- /dev/null
+++ b/devtools/org.eclipse.gmf.dev/src/org/eclipse/gmf/dev/EditPartTraceConstructor.java
@@ -0,0 +1,238 @@
+/*
+ * 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.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gef.GraphicalEditPart;
+import org.eclipse.gef.Request;
+import org.eclipse.gef.commands.Command;
+import org.eclipse.gef.commands.CompoundCommand;
+import org.eclipse.gef.requests.ChangeBoundsRequest;
+import org.eclipse.gef.requests.GroupRequest;
+import org.eclipse.gmf.runtime.common.core.command.CompositeCommand;
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.diagram.ui.commands.EtoolsProxyCommand;
+import org.eclipse.gmf.runtime.diagram.ui.commands.SemanticCreateCommand;
+import org.eclipse.gmf.runtime.diagram.ui.commands.XtoolsProxyCommand;
+import org.eclipse.gmf.runtime.diagram.ui.requests.EditCommandRequestWrapper;
+import org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest;
+
+/**
+ * @author dstadnik
+ */
+class EditPartTraceConstructor {
+
+ private EditPartTraceConstructor() {
+ }
+
+ public static EditPartTraceRecord createEditPartNode(EditPart editPart) {
+ List<EditPartTraceRecord> kids = new ArrayList<EditPartTraceRecord>();
+ kids.add(new EditPartTraceRecord(String.valueOf(editPart.getModel()), DevPlugin.MODEL_IMAGE));
+ if (editPart instanceof GraphicalEditPart) {
+ GraphicalEditPart gEditPart = (GraphicalEditPart) editPart;
+ kids.add(new EditPartTraceRecord("figure bounds " + gEditPart.getFigure().getBounds()));
+ }
+ return new EditPartTraceRecord(DevUtils.getFullClassName(editPart), DevPlugin.EDITPART_IMAGE, (EditPartTraceRecord[]) kids.toArray(new EditPartTraceRecord[kids.size()]));
+ }
+
+ public static EditPartTraceRecord createRequestNode(Request request) {
+ List<EditPartTraceRecord> kids = new ArrayList<EditPartTraceRecord>();
+ if (request instanceof ChangeBoundsRequest) {
+ ChangeBoundsRequest cbRequest = (ChangeBoundsRequest) request;
+ kids.add(new EditPartTraceRecord("location " + cbRequest.getLocation()));
+ kids.add(new EditPartTraceRecord("move delta " + cbRequest.getMoveDelta()));
+ kids.add(new EditPartTraceRecord("resize delta " + cbRequest.getSizeDelta()));
+ kids.add(new EditPartTraceRecord("resize direction " + cbRequest.getResizeDirection()));
+ }
+ if (request instanceof GroupRequest) {
+ List<? extends EditPart> editParts = (List<? extends EditPart>) ((GroupRequest) request).getEditParts();
+ if (editParts != null) {
+ for (EditPart editPart : editParts) {
+ kids.add(createEditPartNode(editPart));
+ }
+ }
+ }
+ if (request instanceof EditCommandRequestWrapper) {
+ IEditCommandRequest realRequest = ((EditCommandRequestWrapper) request).getEditCommandRequest();
+ if (realRequest != null) {
+ kids.add(createRequestNode(realRequest));
+ }
+ }
+ return new EditPartTraceRecord(DevUtils.getFullClassName(request), DevPlugin.REQUEST_IMAGE, (EditPartTraceRecord[]) kids.toArray(new EditPartTraceRecord[kids.size()]));
+ }
+
+ private static String getLabel(IEditCommandRequest request) {
+ String label = DevUtils.getFullClassName(request);
+ if (request.getLabel() != null) {
+ label += '<' + request.getLabel() + '>';
+ }
+ return label;
+ }
+
+ public static EditPartTraceRecord createRequestNode(IEditCommandRequest request) {
+ List<EditPartTraceRecord> kids = new ArrayList<EditPartTraceRecord>();
+ //kids.add(new EditPartTraceRecord("edit helper context " + request.getEditHelperContext()));
+ List elementsToEdit = request.getElementsToEdit();
+ if (elementsToEdit != null) {
+ for (Object elementToEdit : elementsToEdit) {
+ kids.add(new EditPartTraceRecord("element to edit " + elementToEdit));
+ }
+ }
+ Map parameters = request.getParameters();
+ if (parameters != null) {
+ for (Object key : parameters.keySet()) {
+ if ("org.eclipse.gmf.dev.sources".equals(key)) {
+ continue;
+ }
+ kids.add(new EditPartTraceRecord(String.valueOf(key) + '=' + parameters.get(key), DevPlugin.PARAMETER_IMAGE));
+ }
+ }
+ return new EditPartTraceRecord(getLabel(request), DevPlugin.REQUEST_IMAGE, (EditPartTraceRecord[]) kids.toArray(new EditPartTraceRecord[kids.size()]));
+ }
+
+ private static String getLabel(org.eclipse.emf.common.command.Command command) {
+ String label = DevUtils.getFullClassName(command);
+ if (command.getLabel() != null) {
+ label += '<' + command.getLabel() + '>';
+ }
+ return label;
+ }
+
+ private static String getImage(org.eclipse.emf.common.command.Command command) {
+ String id = DevPlugin.COMMANDX_IMAGE;
+ try {
+ if (command.canExecute()) {
+ id = DevPlugin.COMMAND_IMAGE;
+ }
+ } catch (Exception e) {
+ // ignore
+ }
+ return id;
+ }
+
+ public static EditPartTraceRecord createCommandNode(org.eclipse.emf.common.command.Command command, CommandCreatedEvent event) {
+ List<EditPartTraceRecord> kids = new ArrayList<EditPartTraceRecord>();
+ Object source = event.getSource(command);
+ if (source != null) {
+ kids.add(new EditPartTraceRecord("from " + DevUtils.getFullClassName(source)));
+ }
+ if (command instanceof org.eclipse.emf.common.command.CompoundCommand) {
+ for (org.eclipse.emf.common.command.Command subCommand : (List<? extends org.eclipse.emf.common.command.Command>) ((org.eclipse.emf.common.command.CompoundCommand) command).getCommandList()) {
+ kids.add(createCommandNode(subCommand, event));
+ }
+ }
+ return new EditPartTraceRecord(getLabel(command), getImage(command), (EditPartTraceRecord[]) kids.toArray(new EditPartTraceRecord[kids.size()]));
+ }
+
+ private static String getLabel(Command command) {
+ String label = DevUtils.getFullClassName(command);
+ if (command.getDebugLabel() != null) {
+ label += '<' + command.getDebugLabel() + '>';
+ }
+ return label;
+ }
+
+ private static String getImage(Command command) {
+ String id = DevPlugin.COMMANDX_IMAGE;
+ try {
+ if (command.canExecute()) {
+ id = DevPlugin.COMMAND_IMAGE;
+ }
+ } catch (Exception e) {
+ // ignore
+ }
+ return id;
+ }
+
+ public static EditPartTraceRecord createCommandNode(Command command, CommandCreatedEvent event) {
+ List<EditPartTraceRecord> kids = new ArrayList<EditPartTraceRecord>();
+ Object source = event.getSource(command);
+ if (source != null) {
+ kids.add(new EditPartTraceRecord("from " + DevUtils.getFullClassName(source)));
+ }
+ if (command instanceof CompoundCommand) {
+ for (Command subCommand : (List<? extends Command>) ((CompoundCommand) command).getCommands()) {
+ kids.add(createCommandNode(subCommand, event));
+ }
+ }
+ if (command instanceof EtoolsProxyCommand) {
+ ICommand realCommand = ((EtoolsProxyCommand) command).getICommand();
+ if (realCommand != null) {
+ kids.add(createCommandNode(realCommand, event));
+ }
+ }
+ if (command instanceof IAdaptable) {
+ org.eclipse.emf.common.command.Command delegate = (org.eclipse.emf.common.command.Command) ((IAdaptable) command).getAdapter(org.eclipse.emf.common.command.Command.class);
+ if (delegate != null) {
+ kids.add(createCommandNode(delegate, event));
+ }
+ }
+ return new EditPartTraceRecord(getLabel(command), getImage(command), (EditPartTraceRecord[]) kids.toArray(new EditPartTraceRecord[kids.size()]));
+ }
+
+ private static String getLabel(ICommand command) {
+ String label = DevUtils.getFullClassName(command);
+ if (command.getLabel() != null) {
+ label += '<' + command.getLabel() + '>';
+ }
+ return label;
+ }
+
+ private static String getImage(ICommand command) {
+ String id = DevPlugin.COMMANDX_IMAGE;
+ try {
+ if (command.isExecutable()) {
+ id = DevPlugin.COMMAND_IMAGE;
+ }
+ } catch (Exception e) {
+ // ignore
+ }
+ return id;
+ }
+
+ public static EditPartTraceRecord createCommandNode(ICommand command, CommandCreatedEvent event) {
+ List<EditPartTraceRecord> kids = new ArrayList<EditPartTraceRecord>();
+ Object source = event.getSource(command);
+ if (source != null) {
+ kids.add(new EditPartTraceRecord("from " + DevUtils.getFullClassName(source)));
+ }
+ if (command instanceof CompositeCommand) {
+ for (ICommand subCommand : (List<? extends ICommand>) ((CompositeCommand) command).getCommands()) {
+ kids.add(createCommandNode(subCommand, event));
+ }
+ }
+ if (command instanceof XtoolsProxyCommand) {
+ Command realCommand = ((XtoolsProxyCommand) command).getCommand();
+ if (realCommand != null) {
+ kids.add(createCommandNode(realCommand, event));
+ }
+ }
+ if (command instanceof SemanticCreateCommand) {
+ ICommand realCommand = (ICommand) DevUtils.getFieldValue(command, "realSemanticCommand");
+ if (realCommand != null) {
+ kids.add(createCommandNode(realCommand, event));
+ }
+ }
+ if (command instanceof IAdaptable) {
+ org.eclipse.emf.common.command.Command delegate = (org.eclipse.emf.common.command.Command) ((IAdaptable) command).getAdapter(org.eclipse.emf.common.command.Command.class);
+ if (delegate != null) {
+ kids.add(createCommandNode(delegate, event));
+ }
+ }
+ return new EditPartTraceRecord(getLabel(command), getImage(command), (EditPartTraceRecord[]) kids.toArray(new EditPartTraceRecord[kids.size()]));
+ }
+} \ No newline at end of file
diff --git a/devtools/org.eclipse.gmf.dev/src/org/eclipse/gmf/dev/EditPartTraceRecord.java b/devtools/org.eclipse.gmf.dev/src/org/eclipse/gmf/dev/EditPartTraceRecord.java
new file mode 100644
index 000000000..daf797f2c
--- /dev/null
+++ b/devtools/org.eclipse.gmf.dev/src/org/eclipse/gmf/dev/EditPartTraceRecord.java
@@ -0,0 +1,85 @@
+/*
+ * 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;
+
+/**
+ * @author dstadnik
+ */
+public class EditPartTraceRecord {
+
+ public static final EditPartTraceRecord[] NO_KIDS = new EditPartTraceRecord[0];
+
+ private transient EditPartTraceRecord parent;
+ private String label;
+ private String imageId;
+ private EditPartTraceRecord[] kids;
+
+ public EditPartTraceRecord(String label) {
+ this(label, null, NO_KIDS);
+ }
+
+ public EditPartTraceRecord(String label, String imageId) {
+ this(label, imageId, NO_KIDS);
+ }
+
+ public EditPartTraceRecord(String label, String imageId, EditPartTraceRecord[] kids) {
+ this.label = label;
+ this.imageId = imageId;
+ this.kids = kids;
+ if (this.kids == null) {
+ this.kids = NO_KIDS;
+ }
+ for (EditPartTraceRecord kid : this.kids) {
+ kid.parent = this;
+ }
+ }
+
+ public EditPartTraceRecord getParent() {
+ return parent;
+ }
+
+ public String getLabel() {
+ return label;
+ }
+
+ public String getImageId() {
+ return imageId;
+ }
+
+ public EditPartTraceRecord[] getKids() {
+ return kids;
+ }
+
+ public boolean equalTree(EditPartTraceRecord another) {
+ if (another == null) {
+ return false;
+ }
+ if (another == this) {
+ return true;
+ }
+ if (label == null ? another.label != null : !label.equals(another.label)) {
+ return false;
+ }
+ if (imageId == null ? another.imageId != null : !imageId.equals(another.imageId)) {
+ return false;
+ }
+ if (kids.length != another.kids.length) {
+ return false;
+ }
+ for (int i = 0; i < kids.length; i++) {
+ if (kids[i] == null ? another.kids[i] != null : !kids[i].equalTree(another.kids[i])) {
+ return false;
+ }
+ }
+ return true;
+ }
+}
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
new file mode 100644
index 000000000..ece5a924a
--- /dev/null
+++ b/devtools/org.eclipse.gmf.dev/src/org/eclipse/gmf/dev/EditPartTraceView.java
@@ -0,0 +1,338 @@
+/*
+ * 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.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;
+import org.eclipse.gef.GraphicalViewer;
+import org.eclipse.gef.Request;
+import org.eclipse.gef.commands.Command;
+import org.eclipse.gmf.dev.hook.EditPartTraceListener;
+import org.eclipse.gmf.dev.hook.EditPartTracer;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.action.IToolBarManager;
+import org.eclipse.jface.viewers.AbstractTreeViewer;
+import org.eclipse.jface.viewers.IStructuredSelection;
+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.swt.graphics.Image;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.ui.IPartListener;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.IWorkbenchPartSite;
+import org.eclipse.ui.part.ViewPart;
+
+/**
+ * @author dstadnik
+ */
+public class EditPartTraceView extends ViewPart {
+
+ private TreeViewer viewer;
+ private List<IAction> actions;
+ private IWorkbenchPart part;
+ private Stack<CommandCreatedEvent> history = new Stack<CommandCreatedEvent>();
+
+ private IPartListener partListener = new IPartListener() {
+
+ public void partActivated(IWorkbenchPart part) {
+ install(part);
+ }
+
+ public void partDeactivated(IWorkbenchPart part) {
+ install(null);
+ }
+
+ public void partBroughtToTop(IWorkbenchPart part) {}
+
+ public void partOpened(IWorkbenchPart part) {}
+
+ public void partClosed(IWorkbenchPart part) {}
+ };
+
+ private EditPartTraceListener traceListener = new EditPartTraceListener() {
+
+ public void commandRequested(EditPart editPart, Request request) {
+ traceCommandRequested(editPart, request);
+ }
+
+ public void commandCreated(EditPart editPart, Request request, Command command, Map sources) {
+ traceCommandCreated(editPart, request, command, sources);
+ }
+ };
+
+ private List<EditPartTraceRecord> getRecords() {
+ return (List<EditPartTraceRecord>) viewer.getInput();
+ }
+
+ private TopEditPartTraceRecord getLastRecord() {
+ List<EditPartTraceRecord> records = getRecords();
+ if (records.isEmpty()) {
+ return null;
+ }
+ return (TopEditPartTraceRecord) records.get(records.size() - 1);
+ }
+
+ protected void setSite(IWorkbenchPartSite site) {
+ super.setSite(site);
+ site.getWorkbenchWindow().getPartService().addPartListener(partListener);
+ }
+
+ public void createPartControl(Composite parent) {
+ viewer = new TreeViewer(parent);
+ viewer.setLabelProvider(new TraceLabelProvider());
+ viewer.setContentProvider(new TraceContentProvider());
+ viewer.setInput(new ArrayList());
+ makeActions();
+ fillActions();
+ }
+
+ protected void makeActions() {
+ actions = new ArrayList<IAction>();
+ actions.add(new Action("Expand") {
+
+ public void run() {
+ Iterator selection = ((IStructuredSelection) viewer.getSelection()).iterator();
+ while (selection.hasNext()) {
+ viewer.expandToLevel(selection.next(), AbstractTreeViewer.ALL_LEVELS);
+ }
+ }
+ });
+ actions.add(new Action("Flush") {
+
+ public void run() {
+ getRecords().clear();
+ viewer.refresh(true);
+ }
+ });
+ }
+
+ protected void fillActions() {
+ IToolBarManager mgr = getViewSite().getActionBars().getToolBarManager();
+ for (IAction action : actions) {
+ mgr.add(action);
+ }
+ }
+
+ public void setFocus() {
+ if (viewer == null) {
+ return;
+ }
+ Control control = viewer.getControl();
+ if (control != null && !control.isDisposed()) {
+ control.setFocus();
+ }
+ }
+
+ public void dispose() {
+ getSite().getWorkbenchWindow().getPartService().removePartListener(partListener);
+ install(null);
+ super.dispose();
+ }
+
+ protected void install(IWorkbenchPart part) {
+ EditPartTracer tracer = getTracer(this.part, false);
+ if (tracer != null) {
+ tracer.removeTraceListener(traceListener);
+ this.part = null;
+ }
+ tracer = getTracer(part, true);
+ if (tracer != null) {
+ tracer.addTraceListener(traceListener);
+ this.part = part;
+ }
+ }
+
+ protected static EditPartTracer getTracer(IWorkbenchPart part, boolean hook) {
+ if (part == null) {
+ return null;
+ }
+ GraphicalViewer viewer = (GraphicalViewer) part.getAdapter(GraphicalViewer.class);
+ EditPartTracer tracer = EditPartTracer.getInstance(viewer);
+ if (tracer == null && hook) {
+ tracer = EditPartTracer.install(viewer);
+ }
+ return tracer;
+ }
+
+ protected void traceCommandRequested(EditPart editPart, Request request) {
+ CommandCreatedEvent event = new CommandCreatedEvent();
+ event.editPart = editPart;
+ event.request = request;
+ history.push(event);
+ }
+
+ protected void traceCommandCreated(EditPart editPart, Request request, Command command, Map sources) {
+ if (history.isEmpty()) {
+ throw new IllegalStateException("Command requested event was not received.");
+ }
+ CommandCreatedEvent event = (CommandCreatedEvent) history.pop();
+ event.editPart = editPart;
+ event.request = request;
+ event.command = command;
+ event.sources = sources;
+ if (history.isEmpty()) {
+ EditPartTraceRecord record = trace(event, true);
+ if (record != null) {
+ TopEditPartTraceRecord lastRecord = getLastRecord();
+ if (lastRecord != null && lastRecord.equalTree(record)) {
+ lastRecord.requested();
+ viewer.refresh(lastRecord, true);
+ } else {
+ getRecords().add(record);
+ viewer.add(getRecords(), record);
+ }
+ }
+ } else {
+ CommandCreatedEvent parent = (CommandCreatedEvent) history.peek();
+ if (parent.siblings == null) {
+ parent.siblings = new ArrayList<CommandCreatedEvent>();
+ }
+ parent.siblings.add(event);
+ }
+ }
+
+ 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(" : ");
+ if (event.request != null) {
+ text.append(String.valueOf(event.request.getType()));
+ }
+ text.append(" -> ");
+ text.append(DevUtils.getSimpleClassName(event.command));
+ List<EditPartTraceRecord> kids = new ArrayList<EditPartTraceRecord>();
+ if (event.editPart != null) {
+ kids.add(EditPartTraceConstructor.createEditPartNode(event.editPart));
+ }
+ if (event.request != null) {
+ kids.add(EditPartTraceConstructor.createRequestNode(event.request));
+ }
+ if (event.command != null) {
+ kids.add(EditPartTraceConstructor.createCommandNode(event.command, event));
+ }
+ if (event.siblings != null) {
+ for (CommandCreatedEvent sibling : event.siblings) {
+ EditPartTraceRecord kid = trace(sibling, false);
+ if (kid != null) {
+ kids.add(kid);
+ }
+ }
+ }
+ 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;
+ }
+
+ private class TraceContentProvider implements ITreeContentProvider {
+
+ public void dispose() {}
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {}
+
+ public Object getParent(Object element) {
+ if (element instanceof TopEditPartTraceRecord) {
+ return getRecords();
+ } else if (element instanceof EditPartTraceRecord) {
+ return ((EditPartTraceRecord) element).getParent();
+ }
+ return null;
+ }
+
+ public boolean hasChildren(Object element) {
+ if (element instanceof Collection) {
+ return !((Collection) element).isEmpty();
+ } else if (element instanceof EditPartTraceRecord) {
+ return ((EditPartTraceRecord) element).getKids().length > 0;
+ }
+ return false;
+ }
+
+ public Object[] getChildren(Object parentElement) {
+ if (parentElement instanceof Collection) {
+ return ((Collection) parentElement).toArray();
+ } else if (parentElement instanceof EditPartTraceRecord) {
+ return ((EditPartTraceRecord) parentElement).getKids();
+ }
+ return null;
+ }
+
+ public Object[] getElements(Object inputElement) {
+ return getChildren(inputElement);
+ }
+ }
+
+ private static class TraceLabelProvider extends LabelProvider {
+
+ public String getText(Object element) {
+ String text = null;
+ if (element instanceof EditPartTraceRecord) {
+ text = ((EditPartTraceRecord) element).getLabel();
+ }
+ if (text == null) {
+ return "<unspecified>";
+ }
+ if (element instanceof TopEditPartTraceRecord) {
+ text += " (" + ((TopEditPartTraceRecord) element).getTimesRequested() + ")";
+ }
+ return text;
+ }
+
+ public Image getImage(Object element) {
+ String imageId = null;
+ if (element instanceof EditPartTraceRecord) {
+ imageId = ((EditPartTraceRecord) element).getImageId();
+ }
+ if (imageId == null) {
+ imageId = DevPlugin.INFO_IMAGE;
+ }
+ return DevPlugin.getImage(imageId);
+ }
+ }
+
+ private class TopEditPartTraceRecord extends EditPartTraceRecord {
+
+ private int timesRequested = 1;
+
+ public TopEditPartTraceRecord(String label, String imageId, EditPartTraceRecord[] kids) {
+ super(label, imageId, kids);
+ }
+
+ public int getTimesRequested() {
+ return timesRequested;
+ }
+
+ public void requested() {
+ timesRequested++;
+ }
+ }
+}
diff --git a/devtools/org.eclipse.gmf.dev/src/org/eclipse/gmf/dev/PartTrackerView.java b/devtools/org.eclipse.gmf.dev/src/org/eclipse/gmf/dev/PartTrackerView.java
new file mode 100644
index 000000000..d14a9056e
--- /dev/null
+++ b/devtools/org.eclipse.gmf.dev/src/org/eclipse/gmf/dev/PartTrackerView.java
@@ -0,0 +1,193 @@
+/*
+ * 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.Iterator;
+
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Tree;
+import org.eclipse.swt.widgets.TreeItem;
+import org.eclipse.ui.IPartListener;
+import org.eclipse.ui.ISelectionListener;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.part.ViewPart;
+
+/**
+ * @author dstadnik
+ */
+public class PartTrackerView extends ViewPart {
+
+ private Tree control;
+ private PartTracker tracker;
+
+ public void createPartControl(Composite parent) {
+ control = new Tree(parent, SWT.SINGLE);
+ tracker = new PartTracker(getViewSite().getPage());
+
+ IAction clearAction = new Action("Clear") { //$NON-NLS-1$
+
+ public void run() {
+ if (control != null && !control.isDisposed()) {
+ control.removeAll();
+ }
+ }
+ };
+ getViewSite().getActionBars().getToolBarManager().add(clearAction);
+ }
+
+ public void setFocus() {
+ if (control != null && !control.isDisposed()) {
+ control.setFocus();
+ }
+ }
+
+ public void dispose() {
+ if (tracker != null) {
+ tracker.dispose();
+ tracker = null;
+ }
+ }
+
+ public TreeItem addItem(String text) {
+ TreeItem item = new TreeItem(control, SWT.NONE);
+ if (text != null) {
+ item.setText(text);
+ }
+ scrollDown(item);
+ return item;
+ }
+
+ public TreeItem addItem(String text, IWorkbenchPart part) {
+ if (part == this) {
+ return null;
+ }
+ TreeItem item = new TreeItem(control, SWT.NONE);
+ Image image = part.getTitleImage();
+ if (image != null && !image.isDisposed()) {
+ item.setImage(image);
+ }
+ if (text != null) {
+ text = text + ' ' + part.getTitle();
+ } else {
+ text = part.getTitle();
+ }
+ item.setText(text);
+ scrollDown(item);
+ return item;
+ }
+
+ public TreeItem addItem(String text, ISelection selection) {
+ TreeItem item = new TreeItem(control, SWT.NONE);
+ addItem(item, text, selection);
+ scrollDown(item);
+ return item;
+ }
+
+ private TreeItem addItem(TreeItem item, String text, ISelection selection) {
+ if (selection == null) {
+ if (text != null) {
+ item.setText(text);
+ }
+ return null;
+ }
+ String value;
+ if (selection instanceof IStructuredSelection) {
+ value = "structured selection"; //$NON-NLS-1$
+ IStructuredSelection elements = (IStructuredSelection) selection;
+ if (elements.isEmpty()) {
+ value += " : empty"; //$NON-NLS-1$
+ } else {
+ Iterator i = elements.iterator();
+ while (i.hasNext()) {
+ Object element = i.next();
+ TreeItem elementItem = new TreeItem(item, SWT.NONE);
+ elementItem.setText(getClassName(element, false) + ':' + String.valueOf(element));
+ }
+ }
+ } else {
+ value = selection.toString();
+ }
+ if (text != null) {
+ value = text + ' ' + value;
+ }
+ item.setText(value);
+ item.setExpanded(true);
+ return item;
+ }
+
+ private void scrollDown(TreeItem item) {
+ control.showItem(item);
+ }
+
+ public Object getAdapter(Class adapter) {
+ if (Control.class.isAssignableFrom(adapter)) {
+ return control;
+ }
+ return super.getAdapter(adapter);
+ }
+
+ public static String getClassName(Object obj, boolean fqn) {
+ if (obj == null) {
+ return null;
+ }
+ String name = obj.getClass().getName();
+ return fqn ? name : name.substring(name.lastIndexOf('.') + 1);
+ }
+
+ private class PartTracker implements IPartListener, ISelectionListener {
+
+ private IWorkbenchPage page;
+
+ public PartTracker(IWorkbenchPage page) {
+ this.page = page;
+ page.addPartListener(this);
+ page.addSelectionListener(this);
+ }
+
+ public void partActivated(IWorkbenchPart part) {
+ addItem("[actv]", part); //$NON-NLS-1$
+ }
+
+ public void partDeactivated(IWorkbenchPart part) {
+ addItem("[deac]", part); //$NON-NLS-1$
+ }
+
+ public void partBroughtToTop(IWorkbenchPart part) {
+ addItem("[btop]", part); //$NON-NLS-1$
+ }
+
+ public void partOpened(IWorkbenchPart part) {
+ addItem("[opnd]", part); //$NON-NLS-1$
+ }
+
+ public void partClosed(IWorkbenchPart part) {
+ addItem("[clsd]", part); //$NON-NLS-1$
+ }
+
+ public void selectionChanged(IWorkbenchPart part, ISelection selection) {
+ addItem("[selc]", selection); //$NON-NLS-1$
+ }
+
+ public void dispose() {
+ page.removeSelectionListener(this);
+ page.removePartListener(this);
+ }
+ }
+}

Back to the top