Eclipse RCP: getting the default perspective switcher button via id from SWTBot - eclipse-rcp

In an Eclipse 3.7 RCP app, I would like to get the Default perspective switcher button via id for SWTBot/unit testing purposes to get around this:
assertNotNull("PerspectiveBar not visisble", bot.toolbarButtonWithTooltip("Perspektive öffnen"));
How do I find out the id of the button to be able to use
assertNotNull("PerspectiveBar not visisble", bot.toolbarButtonWithId("somekey", "someid"));
Or: is there a better (internationalization-independent) way to do this, may setting key/id of this button by myself?
Thx.

If you want to find any widget with SWTBot by an id,
you have to set the id against key "org.eclipse.swtbot.widget.key".
widget.setData("org.eclipse.swtbot.widget.key", "my.widget.id");
Now you can get the widget like below
bot.widget(withId("my.widget.id"));
For your case it will be
bot.toolbarButtonWithId("someid");
But before that you must ensure you set the id against the key mentioned above.

Related

How to customize default SaveHandler of an e4 application?

In my e4 application, I am using the default ISaveHandler(which i have not defined explicitly anywhere) as shown in the image.
I just need to update the icon, title & text of this handler, rest works fine for me for single mPart save or multiple mPart save prompt.
I don't want to create my own save handler UI. Even if I could inherit the original one, that will work for me.
[
That dialog is an inner class of org.eclipse.e4.ui.workbench.renderers.swt.WBWRenderer so you can't get at it. I don't think you have any choice but to write your own ISaveHandler and the dialog.
You might be able to use org.eclipse.e4.ui.internal.workbench.PartServiceSaveHandler to do some of the work.
To use your save handler everywhere set it in the main window context. (see this question).

Programmatically open a specific tab of the Eclipse CDT project property page

I would like to open a specific tab of the Eclipse CDT project property page from code. For example the screenshot below shows the property page open on the Build Steps tab.
The following code opens the property page succesfully, but always the last accessed tab.
private void openProperties(IProject project) {
String ID = "org.eclipse.cdt.managedbuilder.ui.properties.Page_BuildSettings";
org.eclipse.swt.widgets.Shell shell = org.eclipse.swt.widgets.Display.getCurrent().getActiveShell();
org.eclipse.ui.dialogs.PreferencesUtil.createPropertyDialogOn(
shell, project,
ID, null, null, 0)
.open();
}
The thing I don't quite understand is the Settings page is declared using extension point="org.eclipse.ui.propertyPages" and has an ID. But the tabs are added using extension point="org.eclipse.cdt.ui.cPropertyTab" which does not include an ID. So how are the tabs addressed without an ID?
This is only a partial solution, but hopefully it helps:
Save the return value of createPropertyDialogOn(). It's a PreferenceDialog.
Call getSelectedPage() on it to get the IPreferencePage representing the page.
Most CDT preference pages, including the Build Settings page, extend from org.eclipse.cdt.ui.newui.AbstractPage. AbstractPage uses an SWT TabFolder widget to store the tabs.
Here's the fuzzy part: get a hold of the TabFolder widget for the page. Unfortunately, it's not exposed via any public API, so I think your options are:
Use reflection. The TabFolder is stored as a protected field of the AbstractPage named folder.
Search the SWT widget hierarchy rooted at page.getControl(), where page is the AbstractPage, for a TabFolder.
Once you have the tab control, you can use getItemCount() and getItem(index) on it to enumerate its items, which will be of type TabItem.
On each TabItem, call getData() to retrieve the associated ICPropertyTab.
Examine the ICPropertyTab object to see if it's the one you want to activate. In your case, that might be a check like tab instanceof org.eclipse.cdt.managedbuilder.ui.properties.BuildStepsTab.
Once you've found the right tab, activate it via folder.setSelection(item).

How to change the toolbar's icon dynamically in eclipse?

I am building a login part for a eclipse plugin project, but I am blocked by changing the icon of my toolbar after auto login. I use IElementUpdater to get the element when click the login button. But when it is auto login, I can not get the element, is there any way that I can change the icon like element.setIcon(). I start auto login by using IStartup extension point.
I tried ControlContribution, there's no exact example for me. So could some one help me to figure out this blocker? Thank you!
You can force the updateElements call using the command service:
ICommandService commandService = (ICommandService)window.getService(ICommandService.class);
commandService.refreshElements("command id", null);

gwt - history - how to "keep" UI state

I tried the example which is showing how to get data from history to re-generate UI; The thing I see mostly in all "history usage" examples are related to UI re-generation only so it is none-static way...
But what about "each UI state may have its unique url something like JSF does with flows"? For example I have app url like a
http://localhost:8080/myapp/MyApp.html
the app default UI contains main menu which is helping to navigate through my test catalog; I tried to make possible keep the UI dynamics in history by building url in this way
http://localhost:8080/myapp/MyApp.html#menu_testcategory_page1
but when I click internet browser "refresh" button the url keeps the same as http://localhost:8080/myapp/MyApp.html#menu_testcategory_page1 but the UI comes back to its default state :(
So my question is
is there an optimal way in pure gwt to stay in the same UI state even after browser's refresh button is clicked (I mean the unload/load window events occur)?
thanks
P.S. gwt 2.3
You should implement Activities and Places pattern: http://www.gwtproject.org/doc/latest/DevGuideMvpActivitiesAndPlaces.html
I am using it for 3 years, and it works very well.
Note, however, that when you reload a page, you lose all of your state, data, etc. If you need to preserve some of it, you can use a combination of a Place (#page1) and a token that tells the corresponding Activity the state of the View representing this Place, i.e. (#page1:item=5).
You probably just forgot to call
History.fireCurrentHistoryState();
from your entry point.

How to set id attribute of combo-box ITEMS in GWT (Google Web Toolkit) for Selenium

I've been looking for a clear way to set id in combobox items since GWT creates a for each combobox items without an id attribute..
I want to set an id attribute for my Selenium Test..
How can i do that?
Hope u can give me a clear steps because I am really stuck right now..
Thanks
You can set an id attribute on any widget's element, by calling
yourWidget.getElement().setId("yourId");