### Eclipse Workspace Patch 1.0 #P org.eclipse.pde.runtime Index: plugin.properties =================================================================== RCS file: /cvsroot/eclipse/pde/ui/org.eclipse.pde.runtime/plugin.properties,v retrieving revision 1.21 diff -u -r1.21 plugin.properties --- plugin.properties 13 Nov 2008 14:41:21 -0000 1.21 +++ plugin.properties 15 Mar 2009 20:29:11 -0000 @@ -1,5 +1,5 @@ ############################################################################### -# Copyright (c) 2000, 2008 IBM Corporation and others. +# Copyright (c) 2000, 2009 IBM Corporation and others. # 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 Index: plugin.xml =================================================================== RCS file: /cvsroot/eclipse/pde/ui/org.eclipse.pde.runtime/plugin.xml,v retrieving revision 1.49 diff -u -r1.49 plugin.xml --- plugin.xml 13 Nov 2008 14:41:21 -0000 1.49 +++ plugin.xml 15 Mar 2009 20:29:11 -0000 @@ -2,7 +2,6 @@ - @@ -30,6 +29,23 @@ id="org.eclipse.pde.runtime.spy.commands.spyCommand" name="%spy-command.name"> + + + + + + + + @@ -54,6 +70,12 @@ schemeId="org.eclipse.ui.defaultAcceleratorConfiguration" sequence="M1+M3+F1"> + + @@ -61,6 +83,10 @@ class="org.eclipse.pde.internal.runtime.spy.handlers.SpyHandler" commandId="org.eclipse.pde.runtime.spy.commands.spyCommand"> + + Index: src/org/eclipse/pde/internal/runtime/spy/SpyFormToolkit.java =================================================================== RCS file: /cvsroot/eclipse/pde/ui/org.eclipse.pde.runtime/src/org/eclipse/pde/internal/runtime/spy/SpyFormToolkit.java,v retrieving revision 1.10 diff -u -r1.10 SpyFormToolkit.java --- src/org/eclipse/pde/internal/runtime/spy/SpyFormToolkit.java 24 Apr 2008 21:50:45 -0000 1.10 +++ src/org/eclipse/pde/internal/runtime/spy/SpyFormToolkit.java 15 Mar 2009 20:29:11 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. + * Copyright (c) 2007, 2009 IBM Corporation and others. * 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 @@ -14,43 +14,21 @@ import java.util.HashMap; import java.util.Map; - import org.eclipse.help.IContext; import org.eclipse.help.internal.context.Context; import org.eclipse.jface.action.Action; import org.eclipse.jface.action.ToolBarManager; +import org.eclipse.jface.dialogs.PopupDialog; import org.eclipse.osgi.util.NLS; -import org.eclipse.pde.internal.runtime.PDERuntimeMessages; -import org.eclipse.pde.internal.runtime.PDERuntimePlugin; -import org.eclipse.pde.internal.runtime.PDERuntimePluginImages; -import org.eclipse.pde.internal.runtime.spy.dialogs.SpyDialog; +import org.eclipse.pde.internal.runtime.*; import org.eclipse.swt.SWT; -import org.eclipse.swt.dnd.Clipboard; -import org.eclipse.swt.dnd.TextTransfer; -import org.eclipse.swt.dnd.Transfer; -import org.eclipse.swt.events.DisposeEvent; -import org.eclipse.swt.events.DisposeListener; -import org.eclipse.swt.events.MenuAdapter; -import org.eclipse.swt.events.MenuEvent; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; -import org.eclipse.swt.graphics.Cursor; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.graphics.ImageData; -import org.eclipse.swt.graphics.ImageLoader; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.FileDialog; -import org.eclipse.swt.widgets.Menu; -import org.eclipse.swt.widgets.MenuItem; -import org.eclipse.swt.widgets.ToolBar; -import org.eclipse.swt.widgets.Widget; +import org.eclipse.swt.dnd.*; +import org.eclipse.swt.events.*; +import org.eclipse.swt.graphics.*; +import org.eclipse.swt.widgets.*; import org.eclipse.ui.forms.events.HyperlinkAdapter; import org.eclipse.ui.forms.events.HyperlinkEvent; -import org.eclipse.ui.forms.widgets.FormText; -import org.eclipse.ui.forms.widgets.FormToolkit; -import org.eclipse.ui.forms.widgets.Section; +import org.eclipse.ui.forms.widgets.*; import org.osgi.framework.Bundle; /** @@ -64,9 +42,9 @@ private class SpyHyperlinkAdapter extends HyperlinkAdapter { - private SpyDialog dialog; + private PopupDialog dialog; - public SpyHyperlinkAdapter(SpyDialog dialog) { + public SpyHyperlinkAdapter(PopupDialog dialog) { this.dialog = dialog; } @@ -126,10 +104,10 @@ } private Map bundleClassByName = new HashMap(); - private SpyDialog dialog; + private PopupDialog dialog; private static String HELP_KEY = "org.eclipse.ui.help"; //$NON-NLS-1$ - public SpyFormToolkit(SpyDialog dialog) { + public SpyFormToolkit(PopupDialog dialog) { super(Display.getDefault()); this.dialog = dialog; } Index: src/org/eclipse/pde/internal/runtime/spy/sections/ActiveMenuSection.java =================================================================== RCS file: src/org/eclipse/pde/internal/runtime/spy/sections/ActiveMenuSection.java diff -N src/org/eclipse/pde/internal/runtime/spy/sections/ActiveMenuSection.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/pde/internal/runtime/spy/sections/ActiveMenuSection.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,139 @@ +/******************************************************************************* + * Copyright (c) 2009 EclipseSource Corporation and others. + * 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: + * EclipseSource Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.pde.internal.runtime.spy.sections; + +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import org.eclipse.core.commands.Command; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.jface.action.*; +import org.eclipse.pde.internal.runtime.PDERuntimeMessages; +import org.eclipse.pde.internal.runtime.PDERuntimePlugin; +import org.eclipse.pde.internal.runtime.spy.SpyFormToolkit; +import org.eclipse.swt.widgets.Event; +import org.eclipse.ui.IActionDelegate; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.commands.ICommandService; +import org.eclipse.ui.forms.widgets.*; +import org.eclipse.ui.internal.IActionSetContributionItem; +import org.eclipse.ui.internal.PluginAction; +import org.eclipse.ui.menus.CommandContributionItem; + +/** + * @since 3.5 + */ +public class ActiveMenuSection implements ISpySection { + + public void build(ScrolledForm form, SpyFormToolkit toolkit, Event event) { + + Object object = event.widget.getData(); + if (object != null) { + Section section = toolkit.createSection(form.getBody(), ExpandableComposite.TITLE_BAR); + section.clientVerticalSpacing = 9; + section.setText(PDERuntimeMessages.SpyDialog_activeSelection_title); + FormText text = toolkit.createFormText(section, true); + section.setClient(text); + + TableWrapData td = new TableWrapData(); + td.align = TableWrapData.FILL; + td.grabHorizontal = true; + section.setLayoutData(td); + + StringBuffer buffer = new StringBuffer(); + buffer.append("
"); //$NON-NLS-1$ + if (object instanceof IContributionItem) { + IContributionItem item = (IContributionItem) object; + String id = item.getId(); + if (id != null) { + buffer.append(toolkit.createIdentifierSection(text, "The active contribution item identifier", new String[] {id})); + } + scan(item, buffer, toolkit, text); + } + + buffer.append("
"); //$NON-NLS-1$ + text.setText(buffer.toString(), true, false); + } + } + + // FIXME this is a bit hackish but works... rearchitect + private void scan(IContributionItem item, StringBuffer buffer, SpyFormToolkit toolkit, FormText text) { + // check for action set information + if (item instanceof IActionSetContributionItem) { + IActionSetContributionItem actionItem = (IActionSetContributionItem) item; + buffer.append(toolkit.createIdentifierSection(text, "The active action set identifier", new String[] {actionItem.getActionSetId()})); + } else if (item instanceof ActionContributionItem) { + createActionContributionItemText(item, buffer, toolkit, text); + } else if (item instanceof SubContributionItem) { + SubContributionItem subItem = (SubContributionItem) item; + scan(subItem.getInnerItem(), buffer, toolkit, text); // recurse + } else if (item instanceof CommandContributionItem) { // TODO... this is hard... + CommandContributionItem contributionItem = (CommandContributionItem) item; + ICommandService service = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class); + Command command = service.getCommand(contributionItem.getCommand().getId()); + buffer.append(toolkit.createClassSection(text, "The active contribution item class:", new Class[] {command.getClass()})); + createContributionItemText(item, buffer, toolkit); + } + } + + private void createContributionItemText(Object object, StringBuffer buffer, SpyFormToolkit toolkit) { + IContributionItem item = (IContributionItem) object; + // TODO call ICommandService to get the actual command... + } + +// private void createPluginContributionText(Object object, StringBuffer buffer) { +// IPluginContribution item = (IPluginContribution) object; +// createActiveContributionItemText(item.getClass(), buffer); +// } + + private void createActionContributionItemText(Object object, StringBuffer buffer, SpyFormToolkit toolkit, FormText text) { + ActionContributionItem actionItem = (ActionContributionItem) object; + IAction action = actionItem.getAction(); + + if (action instanceof PluginAction) { + PluginAction pluginAction = (PluginAction) action; + Class clazz = pluginAction.getClass().getSuperclass(); + + // first attempt to get the delegate + try { + Field field = clazz.getDeclaredField("delegate"); //$NON-NLS-1$ + field.setAccessible(true); + IActionDelegate delegate = (IActionDelegate) field.get(pluginAction); + if (delegate == null) { // have to invoke createDelegate if we don't have one yet... + Method method = clazz.getDeclaredMethod("createDelegate", null); //$NON-NLS-1$ + method.setAccessible(true); + method.invoke(pluginAction, null); + delegate = (IActionDelegate) field.get(pluginAction); + } + + buffer.append(toolkit.createClassSection(text, "The active contribution item class", new Class[] {delegate.getClass()})); + + } catch (Exception e) { + PDERuntimePlugin.log(e); + } + + } else { + // normal JFace Actions + Class clazz = action.getClass(); + buffer.append(toolkit.createClassSection(text, "The active contribution item class:", new Class[] {clazz})); + } + + String id = action.getActionDefinitionId(); + if (id != null) { + buffer.append(toolkit.createIdentifierSection(text, "The active action definition identifier", new String[] {action.getActionDefinitionId()})); + } + } + + public void build(ScrolledForm form, SpyFormToolkit toolkit, ExecutionEvent event) { + // TODO Auto-generated method stub + + } + +} Index: src/org/eclipse/pde/internal/runtime/spy/handlers/MenuSpyHandler.java =================================================================== RCS file: src/org/eclipse/pde/internal/runtime/spy/handlers/MenuSpyHandler.java diff -N src/org/eclipse/pde/internal/runtime/spy/handlers/MenuSpyHandler.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/pde/internal/runtime/spy/handlers/MenuSpyHandler.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,96 @@ +/******************************************************************************* + * Copyright (c) 2009 EclipseSource Corporation and others. + * 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: + * EclipseSource Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.pde.internal.runtime.spy.handlers; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.jface.dialogs.PopupDialog; +import org.eclipse.pde.internal.runtime.PDERuntimePluginImages; +import org.eclipse.pde.internal.runtime.spy.dialogs.MenuSpyDialog; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Cursor; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.*; +import org.eclipse.ui.handlers.HandlerUtil; + +/** + * @since 3.5 + */ +public class MenuSpyHandler extends AbstractHandler implements Listener { + + private PopupDialog INSTANCE = null; + private Cursor defaultCursor; + private Cursor spyCursor; + + public MenuSpyHandler() { + // do nothing + } + + public Object execute(ExecutionEvent event) { + if (event != null) { + if (INSTANCE != null && INSTANCE.getShell() != null && !INSTANCE.getShell().isDisposed()) { + INSTANCE.close(); + } + + Shell shell = HandlerUtil.getActiveShell(event); + if (shell != null) { + Display display = shell.getDisplay(); + display.addFilter(SWT.Selection, this); + display.addFilter(SWT.KeyDown, this); + display.addFilter(SWT.Show, this); + if (display.getActiveShell() != null) { + defaultCursor = display.getActiveShell().getCursor(); + Image image = PDERuntimePluginImages.get(PDERuntimePluginImages.IMG_MENUSPY_OBJ); + spyCursor = new Cursor(display, image.getImageData(), 7, 7); + display.getActiveShell().setCursor(spyCursor); + } + } + } + return null; + } + + public void handleEvent(Event event) { + switch (event.type) { + case SWT.KeyDown : + if (event.keyCode == SWT.ESC) + break; + case SWT.Show : + if (spyCursor != null) { + Shell shell = event.display.getActiveShell(); + if (shell != null) { + shell.setCursor(spyCursor); + } + } + return; + } + event.display.removeFilter(SWT.Selection, this); + event.display.removeFilter(SWT.KeyDown, this); + event.display.removeFilter(SWT.Show, this); + if (spyCursor != null) { + if (event.display.getActiveShell() != null) { + event.display.getActiveShell().setCursor(defaultCursor); + defaultCursor = null; + spyCursor.dispose(); + spyCursor = null; + } + } + + if (event.type == SWT.Selection) { + Shell shell = event.display.getActiveShell(); + MenuSpyDialog dialog = new MenuSpyDialog(shell, event, shell.getDisplay().getCursorLocation()); + INSTANCE = dialog; + dialog.create(); + dialog.open(); + event.doit = false; + event.type = SWT.None; + } + } +} Index: src/org/eclipse/pde/internal/runtime/spy/dialogs/MenuSpyDialog.java =================================================================== RCS file: src/org/eclipse/pde/internal/runtime/spy/dialogs/MenuSpyDialog.java diff -N src/org/eclipse/pde/internal/runtime/spy/dialogs/MenuSpyDialog.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/pde/internal/runtime/spy/dialogs/MenuSpyDialog.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,128 @@ +/******************************************************************************* + * Copyright (c) 2009 EclipseSource Corporation and others. + * 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: + * EclipseSource - initial API and implementation + *******************************************************************************/ +package org.eclipse.pde.internal.runtime.spy.dialogs; + +import org.eclipse.jface.action.Action; +import org.eclipse.jface.dialogs.PopupDialog; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.pde.internal.runtime.*; +import org.eclipse.pde.internal.runtime.spy.SpyFormToolkit; +import org.eclipse.pde.internal.runtime.spy.sections.ActiveMenuSection; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.*; +import org.eclipse.swt.widgets.*; +import org.eclipse.ui.ISharedImages; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.forms.widgets.ScrolledForm; +import org.eclipse.ui.forms.widgets.TableWrapLayout; + +/** + * @since 3.5 + */ +public class MenuSpyDialog extends PopupDialog { + + private Event event; + private Point fAnchor; + private Composite composite; + private SpyFormToolkit toolkit; + + private class CloseAction extends Action { + public ImageDescriptor getImageDescriptor() { + return PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_DELETE); + } + + public String getToolTipText() { + return PDERuntimeMessages.SpyDialog_close; + } + + public void run() { + close(); + } + } + + public MenuSpyDialog(Shell parent, Event event, Point point) { + super(parent, SWT.NONE, true, true, false, false, false, null, null); + this.event = event; + this.fAnchor = point; + this.toolkit = new SpyFormToolkit(this); + } + + /* + * @see org.eclipse.jface.window.Window#configureShell(Shell) + */ + protected void configureShell(Shell shell) { + super.configureShell(shell); + PlatformUI.getWorkbench().getHelpSystem().setHelp(shell, IHelpContextIds.SPY_DIALOG); + } + + protected Control createContents(Composite parent) { + getShell().setBackground(getShell().getDisplay().getSystemColor(SWT.COLOR_DARK_GRAY)); + initializeBounds(); + return createDialogArea(parent); + } + + protected Control createDialogArea(Composite parent) { + this.composite = (Composite) super.createDialogArea(parent); + + ScrolledForm form = toolkit.createScrolledForm(composite); + toolkit.decorateFormHeading(form.getForm()); + + // set title and image + form.setText(PDERuntimeMessages.SpyDialog_title); + Image image = PDERuntimePluginImages.get(PDERuntimePluginImages.IMG_SPY_OBJ); + form.setImage(image); + + // add a Close button to the toolbar + form.getToolBarManager().add(new CloseAction()); + form.getToolBarManager().update(true); + + TableWrapLayout layout = new TableWrapLayout(); + layout.leftMargin = 10; + layout.rightMargin = 10; + layout.topMargin = 10; + layout.verticalSpacing = 10; + form.getBody().setLayout(layout); + + // TODO, make this so we use an extension point. + ActiveMenuSection section = new ActiveMenuSection(); + section.build(form, toolkit, event); + + parent.pack(); + return composite; + } + + protected Point getInitialLocation(Point size) { + if (fAnchor == null) { + return super.getInitialLocation(size); + } + Point point = fAnchor; + Rectangle monitor = getShell().getMonitor().getClientArea(); + if (monitor.width < point.x + size.x) { + point.x = Math.max(0, point.x - size.x); + } + if (monitor.height < point.y + size.y) { + point.y = Math.max(0, point.y - size.y); + } + return point; + } + + public boolean close() { + if (toolkit != null) + toolkit.dispose(); + toolkit = null; + return super.close(); + } + + protected Control getFocusControl() { + return this.composite; + } + +}