How can I navigate the view menu using SWTBot? - java

Is it possible to the view menu using SWTBot? An example of an view menu is the one of Problems view (see screenshot). For example how can I change the grouping to Type using SWTBot? I've tried:
for (final SWTBotViewMenu a : this.bot.viewById("org.eclipse.ui.views.ProblemView").menus()) {
System.out.println(a.getText());
}
this.bot.viewById("org.eclipse.ui.views.ProblemView").toolbarDropDownButton("View Menu").menuItem("Group By").menu("None").click();
The for loop doesn't give anything at all, and the second one gives an error, that the "View Menu" cannot be found. I have no idea how to navigate this menu ?

It's probably too late for the OP, but here goes:
For some reason, the straight-forward way to activate a view like "Problems" doesn't work. You can use this workaround:
this.bot.menu("Window").menu("Show View").menu("Problems").click();
SWTBotView problemsView = bot.activeView();
This will only help with the first part, though. You now have access to the toolbar buttons via:
List<SWTBotToolbarButton> toolbarButtons = problemsView.getToolbarButtons();
For the Problems view, this gives you access to the "Focus on active task" button, but the three buttons in the cornern, "view menu", "minimize" and "maximize" do not appear in this list. Unfortunately, I have no solution for this as of now.
[Edit]
You can bring up the view menu like that:
this.bot.menu("Window").menu("Navigation").menu("Show View Menu").click();
but I don't know how to select an item from it afterwards. Maybe someone else will know...

try this:
SWTBotView view = bot.viewByTitle("MyView");
view.show();
view.viewMenu().menu("MyContextOption").click();

The problem come from the fact that this menu is populated with dynamic entries. SWTBot doesn't handle this kind of entry.
See ViewMenuFinder.getMenuItem(). Different kind of IContributionItem are handled but in the situation of the Problems View, the items are of type DynamicMenuContributionItem.

I think you can try with:
theView.viewMenu().menu("Group By").menu("Type").click();
I am able to do the same thing with SWTBot 2.8.0 for Project Explorer view

Related

Validate CTabFolder before switching tabs

In a CTabFolder, I'd like to check the content for unsaved data before the user can switch from one tab to another. SWT does not provide a PreSelection event, as stated here.
I found a workaround, suggesting to switch back to the old tab when a selection is triggered, validate the data and then perform the desired switch again, if data is valid.
I do understand the general idea of this workaround, however, it is not working for me. oldPageIndex and newPageIndex do always have the same value, though I did not click on the same tab.
this.tabContainer.addSelectionListener(new SelectionAdapter() {
#Override
public void widgetSelected(SelectionEvent event) {
int oldPageIndex = tabContainer.getSelectionIndex();
int newPageIndex = tabContainer.indexOf((CTabItem)event.item);
// Here: oldPageIndex == newPageIndex
...
}
});
Is this workaround still working or is there anything I could possibly be doing wrong? Or maybe, has there been any fix for a real PreSelection event in the meantime? I tried using event.doit, but the SelectionEvent is fired, when the tabs have been switched already.
You can use the selection listener but as you have found the getSelectionIndex() does not give you the old tab. So you will have to maintain the old tab index yourself.
This is the technique used by the Eclipse FormEditor.

Android AccessibilityDelegate force reading of ViewGroup not children

I'm using a viewpager which is made up of some number of relative layout siblings which are quite complex.
If I click on the relative layout, it will highlight the entire page and read the title and a few textviews one after the other as expected.
If I scroll the viewpager I'd like talkback to read the next page in the same way it reads the first if I click. Secondly, if I scroll to the second, third, etc. pages and click on those layouts, talkback will read as expected.
I am trying to achieve the click behavior after the scroll event has completed.
Here is what I have for the accessibilityDelegate.
viewPager.setAccessibilityDelegate(new AccessibilityDelegate () {
#Override
public boolean onRequestSendAccessibilityEvent(ViewGroup host, View child, AccessibilityEvent event) {
if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_SCROLLED) {
View page = viewPager.getCurrentPageView();
performAccessibilityAction(page, AccessibilityNodeInfo.ACTION_CLICK, Bundle.EMPTY);
}
return super.onRequestSendAccessibilityEvent(host, child, event);
}
});
I've verified that 'page' is the RelativeLayout parent that I think it is. I've also confirmed that the onRequestSendAccessibilityEvent is being fired, but it doesn't read the contents of its children. Am I missing something?
Updated
I've also tried using
viewpager.getCurrentPageView().sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED);
The above worked for another example when I needed to force talkback to reread a single item but does not have any affect if I try it on the page.
Thanks
Some background -- When you tap on the relative layout, TalkBack generates speech based on the layout's contents. On ICS, this is triggered by a HOVER_ENTER event. On Jelly Bean, it's triggered by an ACCESSIBILITY_FOCUS event. These events are sent automatically by the framework and should, generally speaking, never be sent manually from an app. The same goes for FOCUS events, except in the special case of custom views (see Accessibility talk from Google I/O 2013 for more details).
So, back on topic.
You can control the speech for SCROLLED events by populating the outgoing event with the text you want read. The down side of this is that you'll need to manually generate the text you want read, and it's very likely that this text will differ from what TalkBack will read if the user touches the layout.
viewPager.setAccessibilityDelegate(new AccessibilityDelegate () {
#Override
public void onPopulateAccessibilityEvent(View host, AccessibilityEvent event) {
super.onPopulateAccessibilityEvent(host, event);
if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_SCROLLED) {
event.setContentDescription(/** your text */);
}
}
});
Another option is to do nothing and let the user explore the view on their own. This is the preferred interaction model for Android accessibility.
Edit: Video URL is broken, Changed.
This issue was reported on google check
where ViewPager does not set AccessibilityEvent parameters properly
when scrolling.
But after releas of Android Support Library, revision 23.2.1 (March 2016) This issue has been resolved.
update Support Library to Android Support Library to 23.2.1
I had the same issue before. And now I add android:focusable="true" to the ViewGroup, the TalkBalk will read the ViewGroup, instead of its children

how to get the views listed in the WorkbenchWindow in RCP application?

In my RCP application there are two views.
I know how to get the active view. It's by using the following code:
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActivePart();
But I need the list of all the views, which are present in the Active Workbench Window.
Use
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getViewReferences()
for that matter.
The views are on the page rather than the window:
IViewReference [] viewRefs = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getViewReferences();
You can also get all pages (although there is usually only one)
IWorkbenchPage [] pages = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getPages();
and windows:
IWorkbenchWindow [] windows = PlatformUI.getWorkbench().getWorkbenchWindows();
To be sure you have everything iterate through all the pages on all the windows.
Hi Keerthi use below code to get views,
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getViewReferences()
This will return arry of views iterator over the array and you will get each view.
To get view id, execute below
for(IViewPart view :PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getViews()){
view.getViewSite().getId();//Get view id
}
I hope this will definitely work for you :)

Eclipse plug-in: bind data to a list and refresh view

I am working on an Eclipse plugin-project where I have multiple services which have to register themselves to the master-project (stored in a list). I have one view where I want to list each service (that successfully registered itself) and its status (if enabled/disabled -> from settings) which should be updated if the status changes.
What i tried:
The adding works as expected and the list in the master-project knows the single services. Now I have problems to show the details (service + it's status). I tried to add a new label for each service (with a for-each-loop). Basically this works, but I don't know how to refresh the view after I get the event (in the view) that a service was added. Moreover I don't know how to bind the propertychanged-event to such a label. (I know how to do it if the labels are hard coded, but that's not possible here).
How can I achieve what I want? (show label & status for each registered service and refresh status if it changes)
Thank you!!
For the sake of completeness, I add my answer/solution I found here:
Eclipse plug-in: bind data to a list and refresh view

eclipse listener for main menu bar selections

i am trying to capture user selections from the menu bar , for example if the user pressed File in the menu, my plug-in gonna print "File pressed".
i figured out how to listen to view selections by IselectionService , but still has no clue how to do it with the main menu bars(or toolbars).
thanx for help
More details :
I gonna explain my problem a little bit more precisely :
I would like capture top-level menus actions and toolbar, the problem is I really don't know how to create and attach the listener.
Here is the ISelectionListener of the plugin.
My purpose is to listen to the workbench top-level menu selections and toolbar.
Thanx for help
// the listener we register with the selection service
private ISelectionListener listener = new ISelectionListener() {
public void selectionChanged(IWorkbenchPart sourcepart, ISelection selection) {
// we ignore our own selections
if (sourcepart != SelectionView.this) {
showSelection(sourcepart, selection);
}
}
};
...
...
public void createPartControl(Composite parent) {
...
getSite().getWorkbenchWindow().getSelectionService().addSelectionListener(listener);
P.S : Most what I found about menu listener were SWT stuff for some view or windows I had created, thats not what I meant, I need listener to the main top level menu and toolbars in eclipse workbench.
If you know the location uri (which you can check with a PluginSpy), you can add an handler in order to react to that menu event.
Note: The Menu Contribution article mentions the locationURI for:
main menu is "org.eclipse.ui.main.menu"
main toolbor is "org.eclipse.ui.main.toolbar"
Yuo could try to use the ICommandService:
with this service you can register an IExecutionListener.
This way you can track all the commands wich are executed but I'm afraid that this way you can't track the menu item that activated the command itself.
Hope it helps
i just wanna tell you i got some help from guys who made Smarttutor plugin, which excatly what i need. captures all the actions on the menus. – amir farah 31 secs ago edit i just wanna tell you i got some help from guys who made Smarttutor plugin, which excatly what i need. captures all the actions on the menus.
here is the website:code.google.com/p/smarttutor

Categories

Resources