Eclipse 4 RCP Application (standalone!): Add "show view" in menu - eclipse

In my standalone RCP Application (which I start using a product configuration) I would like to add a menu entry "show view" that lists all views I have defined in my persistent application model (an application.e4xmi file) being closed.
Currently I do not have any Advisor Classes in use.
What I did was to manually add HandledMenuItems for each view and added a CoreExpression as Visible-When Expression.
This expression tests for a special key value pair in the application context. The problem here is that I would need a special expression for each view.
What would be a good pattern to solve this problem?
Or is there a way to parametrize the core expression?
Could I use any predefined eclipse plugins / commands / handlers?
Update: Instead it would also be okay to have the Window > Show View structure in my standalone RCP application - exactly like it exists in the Eclipse workbench. Is there a way to add this menu (entry) by using any predefined / available means?

I'm not sure if this helps you, because it's eclipse 3.7 code, but you can give it a try.
I added a dynamic menu contribution to the View menu like so:
<menu id="x.y.menu.views label="%menu.window.label">
<dynamic class="x.y.menu.ViewListMenuContribution" id="viewlist" />
</menu>
In that class, I used one of the the eclipse menu factories to actually fill the menu:
#Override
public void fill(Menu menu, int index)
{
super.fill(menu, index);
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
IContributionItem item = ContributionItemFactory.VIEWS_SHORTLIST.create(window);
if (item != null)
item.fill(menu, index);
}
This should show all views that are currently closed.

There is currently no way to do that, except keeping track of the parts yourself and reopening them with the EPartService

Related

Build a Perspective from Fragment with Eclipse e4

Is it possible to define a perspective stack and perspective in the fragment.e4xmi?
The Eclipse 4 model editor doesn't seem to allow it. Why?
I add a new Model Fragment and for Feature Name I click Find ....
When I want to add a Perspective or a Perspective Stack, the dialog greys out the OK-Button.
Also, I have a lack of understanding what this Dialog is showing in general. It lists certain UI Elements and a lot of items below them, like
children
handlers
menus
and so on.
But those are listed multiple times. For example children is listed under CompositePart and under Dialog. But it doesn't make any difference which one I chose.
I know I can define the Perspective in the plugin.xml using the extension point and implementing IPerspectiveFactory. Is there no way to do it with the fragment.e4xmi?
Not sure about that dialog as I don't usually use it.
What you want to add is a Model Fragment with the 'Extended Element-ID' set to the id of the TrimmedWindow you want to put the perspective in. The 'Feature Name' would be children.
The model editor should then let you add a "Perspective Stack" as a child.
You can add the Perspective to the stack.
Note: Using the plugin.xml and IPerspectiveFactory is for Eclipse 3.x compatability mode, not pure e4. If you are using compatability mode I'm not sure how defining a perspective in the model editor fits.

Eclipse neon: different behavior for context menus ? Possible bug in eclipse v4.6.0?

JMSToolBox is an eclipse-rcp v4.5.2 based application.
I tried to upgraded to eclipse v4.6.0 but found a problem with popups menu as follows:
A part is defined in the e4 model as a Part Descriptor (PD). A popup menu is defined inside that PD
On a certain action, the PD descriptor is instanciated and the part is added and displayed in a Part Stack. The body of this part is a TabFolder with multiple tabs corresponding to a JMS Q browsed. Each tab body is basically composed of a TableViewer/Table to display JMS messages.
Each time a new tab is created, a new TableViewer/Table is created and the popupmenu is registered on the Table of the TableViewer with the following line of code:
menuService.registerContextMenu(table,<id of the popup menu in the part>);
This works perfectly with eclipse v4.5.2 (Mars) but not with v4.6.0 (Neon) !
With neon, the popup is working only for the first tab: the context menu is visible and #CanExecute methods associated to the handlers/commands of the menu items are called . For subsequent tabs created, no popup is displayed and #CanExecute methods for the menu items are not called
If I register a different menu with a different Id (previously added to the PD) for each tab, it works! So I suspect this may be due to the fact that a menu with the same element id is added to multiple TableViever/Table even if it is coming from a different instance of a PD...
Is it a bug in neon? a regression? or do I benefit of a bug in mars that makes the application is working Ok with this version?
For now I have to downgrade (or not upgrade) to eclipse v4.5.2..
For reference, I pushed some code to correct the problem. It will be in eclipse v4.6.1+ bug #496695

How to add an e4 eclipse part into Show View dialog

I'm developing an eclipse plugin using e4 technologies intended to be run in Eclipse IDE.
How can I add my part (defined as 'PartDescriptor' in fragment.e4xmi file in my plugin) into the "Show View" dialog tree (main menu > Window > Show View > Other ...) ?
Based on examination of org.eclipse.e4.ui.workbench.swt.internal.copy.ViewContentProvider#createChildren source code and based on examination of PartDescriptors of other parts using Live Application Model part I tried to add following tags to my PartDescriptor on Supplementary tab:
View
categoryTag:MyGroup
However, it doesn't work for me. I use Eclipse 4.3 and e4 0.14.
It's not possible, says Thomas Schindl at
http://www.eclipse.org/forums/index.php/t/499424/
Hello.
How can I add my part (defined as 'PartDescriptor' in fragment.e4xmi
file in my plugin) into the "Show View" dialog tree (main menu >
Window > Show View > Other ...) ?
Based on examination of
org.eclipse.e4.ui.workbench.swt.internal.copy.ViewContentProvider#createChildren
source code and based on examination of PartDescriptors of other parts
using Live Application Model part I tried to add following tags to my
PartDescriptor on Supplementary tab:
View categoryTag:MyGroup
However, it doesn't work for me. I use Eclipse 4.3 and e4 0.14.
Thans for answers.
I don't think this is the class making up the Show View ... content in
the compat layer which is constructed from IViewDescriptors IIRC.
Hence if you contribute through a fragment it can't show up there.
Tom
It's possible in 4.6.3 (and possibly before that).
You still need the View tag, but categoryTag apparently has been deprecated. Instead, there now is a Category field in MPartDescriptor, which can be set via the Eclipse e4 model editor:

Programatically manipulating the Eclipse RCP EditorArea Sashes

I have an eclipse RCP application that uses and Editor Area. I have a few things that I would like to do programatically but cannot find any documentation:
1) Do not restore editor sash layout. I.e., I like to use rcp saveAndRestore functionality, but for my perspectives, views, and other momentos. I do not however want to restore the editor area multiple tab groups at all. I choose not to implement the IPersistableEditor interface, and therefore my editor sessions are not restored, but when my application restarts, it still has split windows (swt sashes for multiple tab groups), etc, and i wish it was just 1 editor area tab group like default.
2) I would like to programaticaly split/duplicate an editor into another tab group, for example I would like a button that says "Split Horizontal" and that opens a new editor in a new tab group beside the current one.
Any help is much appreciated! Happy Coding!
/P
1) Funny, seems like a bug in the platform.
You can explicitly close all editors upon workbench window close. One option to do this would be to override the preWindowShellClose method in your WorkbenchWindowAdvisor:
public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor {
#Override
public boolean preWindowShellClose() {
getWindowConfigurer().getWindow().getActivePage().closeAllEditors(true);
return super.preWindowShellClose();
}
}
If you don't have access to the ApplicationWorkbenchWindowAdvisor, you can try to do the same with the IPerspectiveListenerX
2) I think there is no public API for this. The editor area behavior is defined in the presentation factory (see org.eclipse.ui.presentationFactories extension-point). You could clone the RCP standard presentation and implement the desired split-editor-area-on-demand functionality.

Activate the activator class

I am using eclipse 3.6. I created one sample plugin application. It is neither a eclipse rcp nor workbench. Now when I run the eclipse I want that plugin also to be loaded. But I dont want to use IStartUp. Because what I have found out is
IStartup will be called after the workbench is loaded. I want to refresh some menu. So Is there any way to activate my plugin while the eclipse loaded?
I tried to use Bundle Activation policy. But that is also not activating my Activator class. I just put one System.out. println("Inside start()"). So that is not called. Now can I make it activate my activator?
EDIT:
what my exact requirement is, I have created one workbench application.It is not eclipse rcp application. Now I want to remove the following menu and menu items from the eclipse before the eclipe is loaded.
1. File Menu
2.) Search Menu
3.)Run Menu
4.)Help->search,Dynamic Help,Key assist,Tips and trick,Report Bug,Cheat Sheet.
These menus are inbuilt menu of eclipse. So that is the reason I have to do in this way.
So I already implemented by using startup extension point. But the early startup is called after the eclipse is started.So I need to do some refreshment on the workbench.Then only the menu item will get removed.So I thought I need startup extension point will not satisfy my requirement as it doesnot refresh the workbench.I need to activate the my plugin and refresh the workbench before it is loaded.
Thanks
Bhanu
You can set the needed start level for your plugin using touch point instruction.
You are just a plugin that expects to run in the Eclipse IDE?
Then the answer is, you cannot do what you want.
If you start before the workbench has finished initializing, most of the services that could be used won't work: The workbench itself, menu service, command service, etc.
For most plugins in eclipse, the plugin.xml should be used to add menus, views, editors, etc to eclipse. When necessary, the framework will instantiate them.
org.eclipse.ui.IStartup is available and as you mentioned it will be called after the workbench has been initialized, but before any windows have been shown. It's not to be used lightly, and not by plugins contributing to the UI as it allows all extension from that plugin to be loaded.
EDIT:
If you are an RCP app, you control the main menu. As an RCP app, you have access to the ActionBarAdvisor, WorkbenchAdvisor, WorkbenchWindowAdvisor, which all have lifecycle methods.
If you are an an eclipse plugin, you can add to the main menu ... you cannot easily remove from the main menu. This is by design. Start levels and org.eclipse.ui.startup are 2 mechanisms that won't do what you want.
You still need to answer these questions:
There might still be a way. The crux of your problem is: "I want to refresh some menu"
What kind of menu (popup, main menu,
compound list of menu items in a
menu, etc)?
Where is the menu contribution coming from?
Which specific menu item is it?
Please edit your question (do not comment) and include the information from the above 3 questions, please.