Menu bar not displaying in eclipse e4 on restore state - java

I am creating an RCP application using Eclipse 4.4.1 with the Compatibility Layer (migration from 3.x to 4.x). I have defined menus in the application model. Menus are displaying properly when the application is launched for the first time, but restarting the application is hiding the menu bar completely and only showing the toolbar.
Why might no menus be displaying when the RCP Application is restored?

This sounds like this bug here that I just recently myself encountered:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=388808
Personally, the workaround in the bug report did not exactly work for me (it may for you however). What did work for me was based off of the final post here by Karl Puperze, (slightly modified):
https://www.eclipse.org/forums/index.php/t/446433/
public class ForceMainMenuProcessor
{
#Execute
public void execute(#Optional MApplication application, #Optional EModelService modelService)
{
MTrimmedWindow window = (MTrimmedWindow)
modelService.find("<id of your main trimmed window>", application);
if (window == null || window.getMainMenu() != null)
{ return; }
final MMenu mainMenu = modelService.createModelElement(MMenu.class);
mainMenu.setElementId("org.eclipse.ui.main.menu");
window.setMainMenu(mainMenu);
}
}
From that, the last steps were to make sure I defined (with no content) a menu in the main e4xmi file that had the org.eclipse.ui.main.menu id, then defined a fragment that contained the menu contents.
To the plugin.xml, added to the org.eclipse.e4.workbench.model extension point a fragment that pointed to the .e4xmi model fragment that was just created and set the 'apply' to always.
Finally, to the same extension point, added a processor and pointed it to the class above. beforefragment was true and apply was always.
The e4xmi files were still used to define the menu, but in code, because of the defined processor above, the menu is forced to appear regardless of whatever persistent state was saved in the workspace. I ended up with this solution after already splitting the menu into a separate model fragment, so I am not sure if that part of the solution is definitely required, but most certainly defining the processor is.

Related

no load the information whe i open a window, vaadin and java

Well, I will try to explain the problem as well as possible.
I'm using vaadin 8 and I'm using java. I'm doing an app like Youtube.
First Of All I have two important class for the problem. 1º user_header. 2º main_user_page.
On the first class (1º). I have some code integrated with components vaadin that creates a header for youtube with An image and nickname.
public class Zona_de_busqueda_UR extends Zona_de_busqueda_UR_ventana {
public Zona_de_busqueda_UR() {
imagenCabeceraURZ.setSource(new ExternalResource(parametros.getMiniaturaUsuarioNavega()));
apodoCabeceraURZ.setCaption(parametros.getApodoUsuarioNavega());
}
The two atributtes are components vaadin, and I'm setting the text to show on the app.
On the second class (2º). is one page, where (after I initiate session) I can see a normal page with videos and the header of the class (1º). THIS CLASS IS WHAT I RUN AND THIS CLASS CALL THE OTHER WHERE THE ATRIBUTTES ARE EJECUTED.
public class Pagina_inicio_UR extends Pagina_inicio_UR_ventana implements View {
Zona_de_busqueda_UR cabeceraZUR = new Zona_de_busqueda_UR();
public Pagina_inicio_UR() {
horizontalLayout.addComponent(cabeceraZUR);
}
In this class, only call the other class what you can see.
The problem is that the value of the components is showing where I refresh the app, but this would be after I initiate session. I show an example with photos.
First Of all, I initiate session.
![a busy cat(https://raw.githubusercontent.com/jmr779/images/master/primero.PNG)
And then, The header is without information...
![a busy cat(https://raw.githubusercontent.com/jmr779/images/master/segundo.PNG)
Now, I click F5 on my browser or refresh the page and I can see the information but I want see the information without having to click F5 or refresh.
![a busy cat(https://raw.githubusercontent.com/jmr779/images/master/tercero.PNG)
Thanks for the help.

support multiple instances of views in eclipse e4

In eclipse 3.x, we can able to open multiple instances of view part by providing different secondary id. How can i achieve the same behaviour in eclipse 4, I am not able to find any property of part which support this behaviour.
Other question is I am migrating 3.x application to 4.x using compat layer, i have imported 3.x views in application model and added them in perspectives using placeholders. My problem is if i open first instance of same view, it opens at appropriate partsashcontainer as defined in application model but after that if i open another instance of view, it opens in any area of the perspective instead of defined layout?
So how can i force eclipse 4 to open a view in one layout area if i am opening multiple instances of the view simultaneously?
The solution is as suggested by #greg-449, I have to create part using EpartService and then attach the part to partstack. As i am using comapt layer so it is not straight forward and have to write some dirty code to achieve that:
IEclipseContext serviceContext = E4Workbench
.getServiceContext();
final IEclipseContext appContext = (IEclipseContext) serviceContext
.getActiveChild();
EModelService modelService = appContext
.get(EModelService.class);
MApplication app = serviceContext.get(MApplication.class);
EPartService partService = serviceContext
.get(EPartService.class);
MPartStack stack = (MPartStack) modelService.find(
"partstack.2", app);
MPart part = modelService.createModelElement(MPart.class);
part.setElementId("viewID");
part.setContributionURI("bundleclass://org.eclipse.ui.workbench/org.eclipse.ui.internal.e4.compatibility.CompatibilityView");
part.setCloseable(true);
part.getTags().add(EPartService.REMOVE_ON_HIDE_TAG);
stack.getChildren().add(part); // Add part to stack
MPart viewPart = partService.showPart(part,
PartState.ACTIVATE); // Show part
ViewReference ref = ((WorkbenchPage) PlatformUI
.getWorkbench().getActiveWorkbenchWindow()
.getActivePage()).getViewReference(part);
IViewPart viewRef = ref.getView(true);
Using this we can open the view using E4 and get the instance of IViewpart to perform other operations of 3.X

Eclipse RCP - Strange behaviour using a Wizard

I've got an Eclipse RCP application and a strange behaviour while using a wizard page. Following situation:
I've got a wizard page which is part of a multi-page-wizard. At this page I override the createContent(...) method to create my widgets, etc. After creating my widgets 2 private methods addListeners() and init() are called which initializes my widgets out of the model and add some listeners (e.g. a ModifyListener). The obscure behaviour is the following: When I first call init() and after that call addListeners() everything works fine. But if I do it the vice versa I got a NullPointerException in the WizardDialog.updateButtons() method which is part of RCP framework: There is a variable called currentPage as the following code excerpt shows. This variable causes the NPE mentioned above. If I do it the right way, the variable is correctly set.
...
if (backButton != null) {
backButton.setEnabled(currentPage.getPreviousPage() != null);
}
...
I don't get this behaviour. Can someony explain it to me? Within the 2 private methods mentioned above no framework-calls are done. Maybe it's some timing issue?
Best regards,
AnarchoEnte

PropertySheetView in netbeans application development

I am creating a application using Netbeans Appication development.
i have created a API and a lookup that checks for all the implementation and displays them to a Jlist placed inside a TopComponent.
public interface DemoAPI {
public String getType();
public String getName();
}
used
Lookup.Result<DemoAPI> DemoResult;
DemoResult=Lookup.getDefault().lookupResult(DemoAPI.class);
public void resultChanged(LookupEvent ev) {
for (DemoAPI demo : DemoResult.allInstances()) {
//Added the demo to Jlist using demo.getName() as display Name
}
}
for getting all the implementation of DemoAPI and Displaying in ListBox.
How can i Display the properties (Type and Name) in the propertySheetView for the corresponding selected Jlist Value.
To achieve this you most certainly need to use Nodes combined with an ExplorerManager and a corresponding view, replacing your JList.
This tutorial explains the basics of nodes and using them with an ExplorerManager and all kind of different views. In your created nodes you would override the getSheed()-Method and create your PropertySheet there.
The Netbeans Developer FAQ is a nice place which descripes a lot of the usual tasks when developing an application. Nodes and Explorer should tell you a lot about Nodes, ExplorerManagers and the several Views. Properties and PropertySheets has some nice extra info regarding PropertySheets.

How to change theme in SWT application

I'm new to developing SWT applications and am looking for an easy way to change the theme of a small application which I have already developed.
After doing some googling I'm able to tell that there seems to be something called presentations which seems like a way I can download a ready made theme and just apply it to my application. Is that right?
Alternatively can anyone point me to a good tutorial on the right way to go about it?
thanks
If you are just talking about SWT without Ecipse RCP, then there is no way to theme the application.
One of the main advantage of SWT is that it uses OS resources to resemble system applications. Using themes would contradict this approach.
If you are however using Eclipse RCP 4, look at #Ran's answer.
The org.eclipse.e4.ui.css.swt.theme extension point supports the creation of extensions for themes. This extension defines an ID for the style and a pointer to the CSS file.
You can also define the default theme via the cssTheme property in your org.eclipse.core.runtime.products extension. This can also be used to define a fixed styling.
To switch the styling you use the IThemeEngine.
package com.example.e4.rcp.todo.handlers;
import org.eclipse.e4.core.di.annotations.Execute;
import org.eclipse.e4.ui.css.swt.theme.IThemeEngine;
public class ThemeSwitchHandler {
// Remember the state
static boolean defaulttheme= true;
#Execute
public void switchTheme(IThemeEngine engine) {
System.out.println("ThemeSwitchHandler called");
// The last argument controls
// whether the change should be persisted and
// restored on restart
if (!defaulttheme) {
engine.setTheme("com.vogella.e4.todo.defaulttheme", true);
} else {
engine.setTheme("com.vogella.e4.todo.redtheme", true);
}
defaulttheme= !defaulttheme;
}
}

Categories

Resources