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

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.

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 jump from an event handler in story board to the code

I have a "Hello" button in the main view. I have set its Touch Up Inside handler to changeGreeting() in HelloWorldViewController.m. From the Connections Inspector, I can clear see this association:
My question is, how to jump to changeGreeting() function in the .m file from here (the story board view)?
I would expect simply clicking on that "Hello World View Controller changeGreeting:" button would bring me to the source code. But it turns out not the case.
There is no way (as far as I can tell) to jump directly from that panel to the changeGreeting: method.
You can press Command-Shift-O (or choose File > Open Quickly…) and type changeGreeting: (or some prefix of it) to jump to the definition.
If you want Apple to add a better way, go to https://bugreport.apple.com/ and file a feature request.
You could go to the 'Jump Bar' which is the horizontal bar at the top of the main viewer. Here change the file to the .m file and then start typing 'change' or 'greeting' to see all the methods in this file that match the filter.

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

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.

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/

Removing a view from Eclipse Window -> Show views

We have an application in which some views only work when attached to certain perspectives.
We want to remove those views from the Window -> Show View dialog so that users cannot add them to perspectives where they don't work.
Any ideas on how to do this either programmatically or declaratively?
I have tried using <visibleWhen />, but the views are still showing in the dialog:
<view class="com.mycompany.ViewClass"
id="com.mycompany.ViewId"
name="View Name"
restorable="true">
<visibleWhen>
<with variable="activeWorkbenchWindow.activePerspective">
<equals value="com.mycompany.MyPerspective"/>
</with>
</visibleWhen>
</view>
I don't think there is any problem with the <visibleWhen /> clause, so I'm wondering if it can be used with a View?
It should be treated as a menu contribution, using the <visibleWhen/> to only display that option when a certain condition is met.
See the wiki article "Menu Contribution" for more.
Unfortunately, it seems that Eclipse already does this for the Introduction view by calling the private ViewContentProvider.removeIntroView on the content provider for the Show Views dialog. A way to get around this limitation is to define activities by adding to the org.eclipse.ui.activities extension point (see activityPatternBinding on how activities can be mapped to UI contributions). Doing this will not only remove the views from the Show Views dialog, but it will also prevent them from showing in the perspectives themselves. The views can then be shown programmatically. I had to also enable the activities in the ApplicationWorkbenchAdvisor.preStartup method because of limitations in our application:
Set<String> activityIds = new HashSet<String>();
activityIds.add("com.my.activity.id");
IWorkbenchActivitySupport activitySupport = PlatformUI.getWorkbench().getActivitySupport();
activitySupport.setEnabledActivityIds(activityIds);
In this case, the activity has to be disabled before showing the dialog, so the Show Views menu contribution has to be modified to do this as well.
Hopefully an extension point will be added to the next version of Eclipse to provide the option for developers to remove views from the dialog declaratively.