How to change the icon of tab host once setup? (Android) - android-widget

I am trying to change the Icon of one of the tabs of tab host at run
time. I am not able to figure out hwo to do with the widget. could
some one let me know how its done ?
spec = tabHost.newTabSpec("hello").setIndicator("hello",
res.getDrawable(R.drawable.tab1)).setContent(intent);
tabHost.addTab(spec)
The xml file is as below
selector xmlns:android="http://schemas.android.com/apk/res/android"
-- When selected, use grey --
item android:drawable="#drawable/icon1"
android:state_selected="true" />
-- When not selected, use white-
item android:drawable="#drawable/icon1"
/selector
Thanks ,
Titus

Here is how to change the icon after the TabHost (tab child) was created. This solution is not using the XML selector, this code will change the icon permanently.
View ic = (View) tabHost.getTabWidget().getChildTabViewAt(0).findViewById(android.R.id.icon);
ic.setBackgroundResource(R.drawable.icon_public);
This example will change the icon of first tab.

Related

Change menus and menu items programmatically in Eclipse E4

I am having trouble removing existing menus from the model, in a running app.
For example:
MMenu menu = modelService.findElements(app, "idMenuFoo", MMenu.class,
Collections.<String>emptyList(), EModelService.IN_MAIN_MENU).get(0);
menu.setLabel("X");
menu.setVisible(false);
menu.setToBeRendered(false);
After this code gets executed:
The label has been changed to 'X'
But the menu entry is still visible/rendered
If I start the app without clearPersistedState, then restart it, the menu has disappeared. This leads me to be believe the the visibility and rendering attributes were set in the first place, but not applied to the model (unlike the label attribute).
How can I programmatically trigger a main menu bar "refresh" after such changes?
As a Greg in the comment above posted, there is an open bug filed to address this issue. An easy to implement a workaround involves manually refreshing the underlying SWT menu. See https://bugs.eclipse.org/bugs/show_bug.cgi?id=365724#c9 for details. In a gist:
// retrieve the main menu, containing the top-level menu element that needs to be refreshed
MMenu mainMenu = ...
// org.eclipse.e4.ui.workbench.renderers.swt.MenuManagerRenderer
MenuManagerRender renderer = (MenuManagerRenderer)mainMenu.getRenderer();
renderer.getManager(mainMenu).update(true);

How to Create Tabgroup on smartface app studio

I have tried to create a tab-view or tab-group like control on smartface.io but I can't find any solution on the website.
Please any one have idea on how to create tab group. I can't find any tab-view on their the view pallet of IDE. thanks
You can use textbuttons, place them at the top of the page, use as many as you need. And place container objects under these buttons. When you press a button, make the related container's visibility true and other's false. For example, when pressed button1, let
cont1.visible = true;
cont2.visible = false;
cont3.visible = false;
and so on.
Also you should check Smartface in Action project. You can find project in Welcome page, for example in pgListView.

WCM - How to display content item elements from a Menu Component pointing elsewhere?

In IBM's Web Content Manager I have a page in the path:
TopArea > MainContent > SiteArea > content
which uses a Menu Component to pull items from a slightly different path, such as
TopArea > OtherContent > OtherSiteArea > othercontent
So, in the Menu Component, when I use [Property], [Placeholder], or [Element] tags, it pulls the data from othercontent. However, I need to use some kind of tag to pull data from the page that the menu component is being displayed on content.
Anyone know how to do this?
Here is a more specific example:
othercontent has Name: 3ee5fc.
content has Name: Home Page.
When using [Property context="autofill" type="content" field="name"] it displays 3ee5fc.
What kind of tag could I use (or what could I do) so that it would display Home Page instead?
Please note that there are multiple content items that are using this menu component, so I can't hard code (select) the content item, I need a tag that will find it based on what item is calling the menu component.
You need to change the context attribute. "autofill" will display from the items the menu has selected, where "current" will display the field from the item the menu is placed in.

How to show a view programmably in a position defined in plugin.xml?

I want to show views (multiple) in my plugin source code using:
showView(id, id2, IWorkbenchPage.VIEW_ACTIVATE)
This view is first closed, shown after my proccess completed.
I defined the view and its positon in plugin.xml as below:
name="..."
icon="..."
category="..."
class="..."
allowMultiple="true"
id="myid"
extension
point="org.eclipse.ui.perspectiveExtensions"
perspectiveExtension
targetID="org.eclipse.jdt.ui.JavaPerspective"
view
ratio="0.5"
relative="org.eclipse.ui.views.ContentOutline"
relationship="stack"
visible="false"
id="myid"
I want to show them top right area of perspective (the same as Outline view).
If I set visible true or open my view manually in GUI, it appears top right as I expected,
but when I use "showView()" above, views always appears at the bottom (console, problems, etc.)
How can I show my views always top right programmably?
You need to add placeholders for the rest of your views, that have a secondary ID. Another entry in your perspectiveExtension with a compound ID and a wildcard should work: myid:*. See IPageLayout javadoc for more information.

Fast views in eclipse rcp application

How to add a fast view to my eclipse rcp applicatio?
You can add the right button, as in this thread:
that can be done by adding a button to fast view bar and by opening a standard view in button event
Button button =
new Button ((Composite)((WorkbenchWindow) window).getFastViewBar ().getControl (), SWT.PUSH);
to avoid overlapping in button event first create folder layout for this view with reference to initial view and then call the action to add view.
IFolderLayout ViewLayout1 = layout.createFolder ( "ViewLayout1",
IPageLayout.BOTTOM,
0.50f, initalView.ID);
OpenViewAction ov = new OpenViewAction (window, "label", secondview.ID);
ov.run ();
Showing and minimizing a fast view programmatically should be done through command "org.eclipse.ui.views.showView" with the parameter "org.eclipse.ui.views.showView.makeFast".
See Eclipse RCP: open a view via standard command org.eclipse.ui.handlers.ShowViewHandler:
Eclipse provides the standard command org.eclipse.ui.views.showView to open an arbitrary view.
The default handler is org.eclipse.ui.handlers.ShowViewHandler. This handler is a nice example how you could add your own command with arguments. It takes two parameters:
The first has the ID org.eclipse.ui.views.showView.viewId and identifies the view ID which should be opened,
the next one has the ID org.eclipse.ui.views.showView.makeFast and determines if the view should be open as a fast view.
Without parameters the command will let the user choose which view to open.
See Parameter for commands for some examples
Lets see the real world example: "Show View" command. The command is generic and can show any view. The view id is given to the command as a parameter:
<command
name="%command.showView.name"
description="%command.showView.description"
categoryId="org.eclipse.ui.category.views"
id="org.eclipse.ui.views.showView"
defaultHandler="org.eclipse.ui.handlers.ShowViewHandler">
<commandParameter
id="org.eclipse.ui.views.showView.viewId"
name="%command.showView.viewIdParameter"
values="org.eclipse.ui.internal.registry.ViewParameterValues" />
<commandParameter
id="org.eclipse.ui.views.showView.makeFast"
name="%command.showView.makeFastParameter"
optional="true"/>
</command>
The list of all possible values of the parameter is given by the class ViewParameterValues. The class would iterate through the view registry and return it.
Note: just to be complete, in theory (this thread)
RCP apps can disable fast views by calling WorkbenchWindowConfigurer.setShowFastViewBar(false) from their
WorkbenchAdvisor's preWindowOpen() method.
This not only hides the fast view bar, but also hides the Fast View menu item on views.
The simple way to add a fast view to an Eclipse RCP or RAP application begins with creating a normal view. In the plugins xml, add a new extension for the view (I'll call it fast.view), with the correct attributes.
<view
closable="true"
id="fast.view"
minimized="true"
ratio=".30f"
relationship="fast" <--- This attribute tells the view to be a fast view.
relative="other.view"
</view>
After adding this extension, we must also show the fast view bar in the workspace. To do this, edit the ApplicationWorkbenhWindowAdvisor (or other advisor that launches your workbench window), and add the following lines to your preWindowOpen() method:
IWorkbenchWindowConfigurer configurer = getWindowConfigurer();
configurer.setShowFastViewBars(true);
If you already have an IWorkbenchWindowsConfigurer, you don't need to make a new one. This method tells the workbench to display the fast bar, and your new fast view perspective extension should be there when it starts.
I got this information from an Eclipse Papercuts article written by Lars Vogel: http://www.vogella.de/blog/2009/09/15/fastview-eclipse-rcp/