Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » SWTBot » How to access the JDT "quick outline" pop-up?
How to access the JDT "quick outline" pop-up? [message #507896] Thu, 14 January 2010 21:16 Go to next message
Robert M. Fuhrer is currently offline Robert M. Fuhrer
Messages: 294
Registered: July 2009
Senior Member
I'm working out how to test IDEs for IMP.

My current question is how to access information pop-ups, like the
"Quick Outline" view in the JDT, accessible (on Mac OS) via Cmd-O.

I tried the following:

srcEditor.pressShortcut(Keystrokes.COMMAND, KeyStroke.getInstance("o"));
bot.waitUntil(Conditions.waitForShell(new BaseMatcher<Shell>() {
public boolean matches(Object item) {
return (item instanceof JavaOutlineInformationControl);
}
public void describeTo(Description description) {
description.appendText("Shell of type " + JavaOutlineInformationControl.class);
}
}));
bot.tree().select("main(String[]) : void"); // hopefully gets the tree in the 'quick outline' view

but this doesn't work (times out, never finding the shell).

[BTW, JavaOutlineInformationControl is the active shell for the "Quick
Outline" pop-up view, according to EclipseSpy.]

This code runs when the variable 'srcEditor' refers to a Java source
editor, which presently has focus.

N.B.: I don't actually see the pop-up appear, so presumably the Cmd-O
shortcut I'm trying to invoke just isn't working, as opposed to the
waitForShell() call being wrong.

Any hints?

--
Cheers,
-- Bob

--------------------------------
Robert M. Fuhrer
Research Staff Member
Programming Technologies Dept.
IBM T.J. Watson Research Center

IDE Meta-tooling Platform Project Lead (http://www.eclipse.org/imp)
X10: Productive High-Performance Parallel Programming (http://x10.sf.net)
Re: How to access the JDT "quick outline" pop-up? [message #508031 is a reply to message #507896] Fri, 15 January 2010 15:44 Go to previous messageGo to next message
Pascal G is currently offline Pascal G
Messages: 157
Registered: July 2009
Senior Member
Robert M. Fuhrer wrote:
> I'm working out how to test IDEs for IMP.
>
> My current question is how to access information pop-ups, like the
> "Quick Outline" view in the JDT, accessible (on Mac OS) via Cmd-O.
>
> I tried the following:
>
> srcEditor.pressShortcut(Keystrokes.COMMAND,
> KeyStroke.getInstance("o"));
> bot.waitUntil(Conditions.waitForShell(new BaseMatcher<Shell>() {
> public boolean matches(Object item) {
> return (item instanceof JavaOutlineInformationControl);
> }
> public void describeTo(Description description) {
> description.appendText("Shell of type " +
> JavaOutlineInformationControl.class);
> }
> }));
> bot.tree().select("main(String[]) : void"); // hopefully gets the
> tree in the 'quick outline' view
>
> but this doesn't work (times out, never finding the shell).
>
> [BTW, JavaOutlineInformationControl is the active shell for the "Quick
> Outline" pop-up view, according to EclipseSpy.]
>
> This code runs when the variable 'srcEditor' refers to a Java source
> editor, which presently has focus.
>
> N.B.: I don't actually see the pop-up appear, so presumably the Cmd-O
> shortcut I'm trying to invoke just isn't working, as opposed to the
> waitForShell() call being wrong.
>
> Any hints?
>

I suspect that it is effectively the pressShortcut call that doesn't
work. I would suggest you try something like this:

String commandId = IJavaEditorActionDefinitionIds.SHOW_OUTLINE;
IWorkbenchPart part = srcEditor.getReference();
IHandlerService adapter = (IHandlerService)
part.getSite().getService(IHandlerService.class);
Object commandResult = adapter.executeCommand(commandId, null);

This little snippet shows how to activate a command programmatically.
The only thing I am not sure about is the commandId, but I think it's
the one you need in this case [1]. And make sure you run this inside the
UI thread, with a syncExec().

This should activate your pop-up, so watch the test execution to confirm.

[1] I have traced this using the handy "get reference in workspace"
action in Eclipse. First I looked for JavaOutlineInformationControl,
then I saw that the constructor requires a commandId. I then traced the
calls to
JavaSourceViewerConfiguration#getOutlinePresenterControlCrea tor, which
is called by JavaSourceViewerConfiguration#getOutlinePresenter with
IJavaEditorActionDefinitionIds.SHOW_OUTLINE as the commandId.

Hope this helps.
--
Pascal Gélinas | Software Developer
*Nu Echo Inc.*
http://www.nuecho.com/ | http://blog.nuecho.com/

*Because performance matters.*
Re: How to access the JDT "quick outline" pop-up? [message #508099 is a reply to message #508031] Fri, 15 January 2010 16:46 Go to previous messageGo to next message
Robert M. Fuhrer is currently offline Robert M. Fuhrer
Messages: 294
Registered: July 2009
Senior Member
On 1/15/10 10:44 AM, Pascal Gelinas wrote:
> Robert M. Fuhrer wrote:
>> I'm working out how to test IDEs for IMP.
>>
>> My current question is how to access information pop-ups, like the
>> "Quick Outline" view in the JDT, accessible (on Mac OS) via Cmd-O.
>>
>> I tried the following:
>>
>> srcEditor.pressShortcut(Keystrokes.COMMAND, KeyStroke.getInstance("o"));
>> bot.waitUntil(Conditions.waitForShell(new BaseMatcher<Shell>() {
>> public boolean matches(Object item) {
>> return (item instanceof JavaOutlineInformationControl);
>> }
>> public void describeTo(Description description) {
>> description.appendText("Shell of type " +
>> JavaOutlineInformationControl.class);
>> }
>> }));
>> bot.tree().select("main(String[]) : void"); // hopefully gets the tree
>> in the 'quick outline' view
>>
>> but this doesn't work (times out, never finding the shell).
>>
>> [BTW, JavaOutlineInformationControl is the active shell for the "Quick
>> Outline" pop-up view, according to EclipseSpy.]
>>
>> This code runs when the variable 'srcEditor' refers to a Java source
>> editor, which presently has focus.
>>
>> N.B.: I don't actually see the pop-up appear, so presumably the Cmd-O
>> shortcut I'm trying to invoke just isn't working, as opposed to the
>> waitForShell() call being wrong.
>>
>> Any hints?
>>
>
> I suspect that it is effectively the pressShortcut call that doesn't
> work. I would suggest you try something like this:
>
> String commandId = IJavaEditorActionDefinitionIds.SHOW_OUTLINE;
> IWorkbenchPart part = srcEditor.getReference();
> IHandlerService adapter = (IHandlerService)
> part.getSite().getService(IHandlerService.class);
> Object commandResult = adapter.executeCommand(commandId, null);
>
> This little snippet shows how to activate a command programmatically.
> The only thing I am not sure about is the commandId, but I think it's
> the one you need in this case [1]. And make sure you run this inside the
> UI thread, with a syncExec().
>
> This should activate your pop-up, so watch the test execution to confirm.

Thanks!

I'll certainly try this out, but I'd really like to test that the shortcut
keystroke works as well. Is there any reason why the shortcut shouldn't
work?

--
Cheers,
-- Bob

--------------------------------
Robert M. Fuhrer
Research Staff Member
Programming Technologies Dept.
IBM T.J. Watson Research Center

IDE Meta-tooling Platform Project Lead (http://www.eclipse.org/imp)
X10: Productive High-Performance Parallel Programming (http://x10.sf.net)
Re: How to access the JDT "quick outline" pop-up? [message #508106 is a reply to message #508099] Fri, 15 January 2010 17:46 Go to previous messageGo to next message
Pascal G is currently offline Pascal G
Messages: 157
Registered: July 2009
Senior Member
Robert M. Fuhrer wrote:
>
> I'll certainly try this out, but I'd really like to test that the shortcut
> keystroke works as well. Is there any reason why the shortcut shouldn't
> work?
>

There is some funky stuff going one when you use the pressShortcut()
methods. Depending on your configuration, SWTBot uses SWT's
Display#post() or AWT's Robot class (default is AWT). Might be that AWT
doesn't properly handle the Command key stroke, so one bet is to try to
use SWT mechanism instead [1]. If it still doesn't work, it might be
related to bug 280562, but with the Command key instead of AltGr. I
don't have a mac so I can't really try this...

[1] You need to set SWTBotPreferences#KEYBOARD_STRATEGY to
org.eclipse.swtbot.swt.finder.keyboard.SWTKeyboardStrategy

Hope this helps.
--
Pascal Gélinas | Software Developer
*Nu Echo Inc.*
http://www.nuecho.com/ | http://blog.nuecho.com/

*Because performance matters.*
Re: How to access the JDT "quick outline" pop-up? [message #508108 is a reply to message #508106] Fri, 15 January 2010 23:40 Go to previous message
Robert M. Fuhrer is currently offline Robert M. Fuhrer
Messages: 294
Registered: July 2009
Senior Member
On 1/15/10 5:42 PM, Pascal Gelinas wrote:
> Robert M. Fuhrer wrote:
>>
>> I'll certainly try this out, but I'd really like to test that the
>> shortcut
>> keystroke works as well. Is there any reason why the shortcut shouldn't
>> work?
>>
>
> There is some funky stuff going one when you use the pressShortcut()
> methods. Depending on your configuration, SWTBot uses SWT's
> Display#post() or AWT's Robot class (default is AWT). Might be that AWT
> doesn't properly handle the Command key stroke, so one bet is to try to
> use SWT mechanism instead [1]. If it still doesn't work, it might be
> related to bug 280562, but with the Command key instead of AltGr. I
> don't have a mac so I can't really try this...
>
> [1] You need to set SWTBotPreferences#KEYBOARD_STRATEGY to
> org.eclipse.swtbot.swt.finder.keyboard.SWTKeyboardStrategy
>
> Hope this helps.

That fixes the problem, as long as I set it early enough. (I set it
before creating the SWTWorkbenchBot; not sure whether setting it any
later would work properly.)

Thanks again!

--
Cheers,
-- Bob

--------------------------------
Robert M. Fuhrer
Research Staff Member
Programming Technologies Dept.
IBM T.J. Watson Research Center

IDE Meta-tooling Platform Project Lead (http://www.eclipse.org/imp)
X10: Productive High-Performance Parallel Programming (http://x10.sf.net)
Previous Topic:WidgetNotFound when looking for menu item?
Next Topic:Combination of SWTBot und TPTP
Goto Forum:
  


Current Time: Thu Oct 23 01:45:38 GMT 2014

Powered by FUDForum. Page generated in 0.01695 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software