In our Eclipse E4 (pure e4) application I have to open a new window and show some views in a new window (which is completely different from the main window). In the new window I am trying to add menu (File->Import) pro-grammatically. I have written the below code but the new window is not showing the menus. Anything I am missing?
`
MTrimmedWindow window = MBasicFactory.INSTANCE.createTrimmedWindow();
....
MMenu menuBar = MenuFactoryImpl.eINSTANCE.createMenu();
menuBar.setLabel("Test");
window.setMainMenu(menuBar);
MMenu fileMenu = MenuFactoryImpl.eINSTANCE.createMenu();
fileMenu.setElementId("file");
fileMenu.setLabel("File");
menuBar.getChildren().add(fileMenu);
MMenuItem item1 = MenuFactoryImpl.eINSTANCE.createDirectMenuItem();
item1.setElementId("item1");
item1.setLabel("item1");
fileMenu.getChildren().add(item1);`
Don't add the window to the application children until after you have created and setup the main menu (and anything else you want to have in the window).
When you add the window to the application child list it is rendered immediately. So if you have not set the main menu at that point it will not be shown.
If your window design is fixed you can avoid all this code by designing the window in the Application.e4xmi. Just turn off the 'to be rendered' flag so it is not show initially and then do:
MTrimmedWindow window = (MTrimmedWindow)modelService.find("window id", app);
window.setToBeRendered(true);
to show the window.
Related
when i right click on button open a context menu. how i will do it. i try this code also
MenuManager menuManager = new MenuManager();
Menu menu = menuManager.createContextMenu(btn.getText());
btn.getText().setMenu(menu);
getSite().registerContextMenu(menuManager, btn);
getSite().setSelectionProvider(btn);
I got problem in createContextMenu. Please Help me
createContextMenu requires a Control as its argument, you are passing the button text String. The setMenu method also belongs to Control. So:
MenuManager menuManager = new MenuManager();
Menu menu = menuManager.createContextMenu(btn);
btn.setMenu(menu);
getSite().registerContextMenu(menuManager, btn);
Button does not implement ISelectionProvider so you will have to write one if you want to use the button as the selection provider.
Note that a part can only register one context menu like this and there can only be one selection provider for a part.
If you want context menu contributions from other parts of Eclipe to be added to the menu you must add the line:
menuManager.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
I am running into a focus issue for the jxBrowser. I integrated the jxBrowser into eclipse as a view and editor, using JavaFX FXCanvas as a container of the jxBrowser. When switching between views within Eclipse, the browser no longer receive focus. It is not possible to use the keyboard, and it is not possible to scroll around the view. Any one know any workaround?
Here is an example of the code:
container = new javafx.embed.swt.FXCanvas(parent, SWT.NONE);
container.setLayout(gridLayout);
container.setLayoutData(gridData);
browser = new Browser();
browserView = new BrowserView(browser);
container.setScene(new javafx.scene.Scene(browserView));
Thanks!
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);
HI,
I am facing some problem.. I want to hide the menu when eclipse workbench starts.
But the problem is menu is not hiding when the eclipse workbench starts. It is hiding only
when some refresh is happened. for example: when I change the default perspective to some other perspective, I am getting the desired out put. That means menu is hiding.
But when the eclipse workbench is loaded it is not hiding the menu. Below is my code.
PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
public void run() {
try {
IWorkbenchWindow window = Workbench.getInstance().getActiveWorkbenchWindow()
if(window instanceof WorkbenchWindow) {
MenuManager menuManager = ((WorkbenchWindow)window).getMenuManager();
IContributionItem[] items = menuManager.getItems();
for(IContributionItem item:items){
System.out.println("item.getId()::: "+item.getId());
menuManager.remove("org.eclipse.ui.run");
menuManager.remove("help");
menuManager.remove("project");
}
}
}`
}
};
Given that you are looking to hide some features, I don't think that this is the best approach. (Not I am using the term feature here in the colloquial way, not as an Eclipse feature.
I would recommend one of two avenues:
Perspectives: See the extension point org.eclipse.ui.perspectives. This allows you to create a new perspective like the debug perspective or the Java perspective. Using a perspective, you can select exactly what menu items and views are shown and which ones are hidden.
Capabilities (aka activites): See the extension point org.eclipse.ui.activities. This allows you to have some fairly fine-grained control over what features are available in the workspace. See more info here: http://wiki.eclipse.org/Galileo_Capabilities
Put Your code in org.eclipse.ui.startup extention point. Make a Startup class after implementing the interface IStartup. For Details follow this link:-
Eclipse plugin : disable/enable dynamically an action from main menubar
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/