Javafx, SceneSwaping - javafx-8

I have a application managing 4 FXML files that work like this: you press next button on layout, and another scene with another FXML file loads. You press another button and so on. Thats a Scene swaping training application.
Everything works well until I try to load last(forth) FXML file that has diffrent top Layout(StackPane) than others(AnchorPane).
I get exception: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
This is the code that works for swaping FXML files with AnchorPane top Layout, but throws and exception when I try to load FXML file with StackPane top layout.
private void buttGoToWindow3Action(ActionEvent event) throws IOException{
Parent window3;
window3 = (StackPane)FXMLLoader.load(getClass().getResource("/ScenePackage/FXMLWindow3.fxml"));
Stage mainWindow;
mainWindow = (Stage) ((Node)event.getSource()).getScene().getWindow();
mainWindow.getScene().setRoot(newScene);
}
It seems like mainWindow dont want to accept diffrent Layout. How can I fix it?

In a long long exception list Ive found this line:
Caused by: javafx.fxml.LoadException: No controller specified.
So I went to the SceneBuilder and set proper controller class for the FXML file.
And it worked, so it was not a casting problem.
Im not sure why its required at this stage of program. Probably because there are methods set inside SceneBuilder(so also inside FXML file)to events and no controller class with methods to execute.

Related

Unable to load FXML when placed in a package

I got this type of file hierarchy in JavaFXApplication5 project.
Ive made another package for all the fxml files, so when project gets big it will be easier to find certain files.
Now in JavaFXApplication5 main class I have a line which Im sure causes an exception(java.lang.reflect.InvocationTargetException) when application is trying to run.
AnchorPane root = (AnchorPane) FXMLLoader.load(getClass().getResource("FXMLNew.fxml"));
Im sure its because the "FXMLNew.fxml" root is wrong. But I dont know how to set it when is in another package...?
Or maybe these type of files should be put in normal folder?
To load a fxml which is inside a package, use /package-name/fxml-file-name.fxml
For your case:
AnchorPane root = (AnchorPane)FXMLLoader.load(getClass().getResource("/windows/FXMLNew.fxml"));

Apache Wicket does not load (or display) static image

I am currently working my way into wicket and developed a small demo application. Now I want to display a static image in that application (to be more specific, this image should be added to a panel which is then added to the home page).
This is what I have so far:
1) The HTML code for the panel that should hold the image. There is no specific wicket code present, it should only hold an image present in the project structure.
<html><body>
<wicket:panel>
Just some static text inside the image panel...<br/>
<img src="test.jpg"></img>
</wicket:panel>
</body></html>
The panel is called ImagePanel and all three files (ImagePanel.java, ImagePanel.html, test.jpg) are located in the same package.
2) The Java code for the ImagePanel - rather short, as there is nothing really to do:
public class ImagePanel extends Panel {
public ImagePanel(String id) {
super(id);
}
}
3) The HTML code for the homepage:
<html><body>
<div wicket:id="dynamicComponent"></div>
</body></html>
4) And the Java code for the homepage:
public HomePage() {
add(new ImagePanel("dynamicComponent"));
}
Please note the following: In practice, HomePage.java and ImagePanel.java are located in different OSGi-projects. The code for the HomePage is simplified here, in practice the ImagePanel is located via a service and dynamically added. This works so far, I see the static text. But the image is not loaded, I just get this broken-image-thumbnail.
Like I said, all three ImagePanel-related files (.java, .html, the picture) are located in the very same package. I can access the Panel itself from the homepage-project as I can see the static text. But I can't get the image to display.
The Application Server I use is Jetty, started from inside the project that holds the homepage.
Update:
I've narrowed the problem to the following:
Everything works fine as long as I only display static text inside of ImagePanel.html. As soon as I want to add the image (even if inside of a wicket:link-tag as suggested below) I end up with the following exception:
[qtp401543768-20] WARN org.apache.wicket.core.util.lang.WicketObjects - Could not resolve class [plugin.ImagePanel]
java.lang.ClassNotFoundException: plugin.ImagePanel
So without the image the server bundle is able to load the class from the gui bundle and display the static text. With the image I end up with a ClassNotFoundException for the same class.
Find the whole stack trace here: stack trace
In your template, put a around
<wicket:link>
<img src="test.jpg"></img>
</wicket:link>
Wicket will rewrite the url so that the image works.
If you have a dynamic Image that you want to load a Package Resource, you use PackageResourceReference.
e.g.
add(new Image("myImage", new PackageResourceReference(MyClass.class, "test.jpg"));
Thanks for the help, though meanwhile I managed to solve the problem myself. It was not a sole wicket problem but also some difficulties with the OSGi-bundle-setup.
As I mentioned before, the ImagePanel is located in a different OSGi bundle than the HomePage. The problem arised as all Wicket-libraries are located in the HomePage-bundle (I get Linker errors if both bundles use their own libraries). Therefore loading an image in the ImagePanel used classes located in the HomePage-bundle who now couldn't access the image.
I solved the problem by introducing an OSGi-Service in the ImagePanel-bundle that passes all used images as byte arrays to the HomePage-bundle. The HomePage-bundle has now access to all resources and registers them as SharedResource with an id given again by the ImagePanel-bundle.
After registration, it is no problem to access the images in the ImagePanel-bundle via SharedResourceReference.

JavaFX Scenebuilder does not see ids when FXML is in a different package than controller

i installed netbeans with java se7, and javafx samples are running fine. In scenebuilder, i can select an ID for each control defined and annotated with #FXML in my controller. however, i like my project organised. when i create a new package, and move my FXML file there, (myapp/views) and the controller stays in the root where it was -> myapp, then in scenebuilder does not seem to find the id.
I know about the 'controller class' in the FXML, but since i didn't move my controller, that should not be changed.
More specific, when both my controller and fxml are in the package 'holidayapp', it works. moving the fxml to a subpackage holidayapp/views', doesn't work. The controller class remains
<AnchorPane id="AnchorPane" prefHeight="200" prefWidth="320" xmlns:fx="http://javafx.com/fxml" fx:controller="holidayapp.HolidayViewController">
as the HolidayViewController remains in the root package. I do nothing else but moving the fxml file from the main package into a subpackage.
I would like to see the id's from the holidayViewController in my scenebuilder. Compoling and running with the fxml in a subpackage, was never any problem.
Thanks
I think you might be suffering from the following issue:
https://bugs.openjdk.java.net/browse/JDK-8091793
If you think you do, please consider to vote for and/or comment on this issue.
The way I worked with this was placing my Main class into the view (the one that extends Application). This gave me access to my Controller classes, their variables, and methods. This works for SceneBuilder 1.1.
I can only speak for when using Eclipse and not NetBeans so doing this may still result in nothing.

GWT MVP Presenter Unable to Update View Listbox Component

I am writing a GWT MVP application using the gwt-platform library (very nice once you get used to it). My issue occurs when my presenter attempts to update the contents of a Listbox. The problem occurs on line 66 of the below file:
https://github.com/dartmanx/mapmaker2/blob/master/src/main/java/org/jason/mapmaker/client/presenter/MapmakerStackPanelPresenter2.java
I am sure that the application is calling the onSuccess() method (a breakpoint in the debugger works), and that the result is populated.
One thing I've noticed is that the associated view, MapmakerStackPanelViewImpl2.java, seems to be initialized twice. I find myself wondering if I'm trying to update a control on that view that is not attached to the actual user interface. That file is here:
https://github.com/dartmanx/mapmaker2/blob/master/src/main/java/org/jason/mapmaker/client/view/MapmakerStackPanelView2.java
Any help would be appreciated.
The problem was that there were two copies of the view floating around. I used Gin to inject the view into the constructor of the presenter, and problem went away.

Programmatically showing a View from an Eclipse Plug-in

I have a plug-in to an Eclipse RCP application that has a view. After an event occurs in the RCP application, the plug-in is instantiated, its methods are called to populate the plug-in's model, but I cannot find how to make the view appear without going to the "Show View..." menu.
I would think that there would be something in the workbench singleton that could handle this, but I have not found out how anywhere.
You are probably looking for this:
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView("viewId");
If called from handler of a command
HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().showView(viewId);
would be better, as I know.
I found the need to bring the view to the front after it had been opened and pushed to the background. The activate method does the trick.
PlatformUI.getWorkbench()
.getActiveWorkbenchWindow()
.getActivePage()
.activate(workbenchPartToActivate);
NOTE: The workbenchPartToActivate is an instance of IWorkbenchPart.
In e4, the EPartService is responsible for opening Parts. This can also be used to open e3 ViewParts. Instantiate the following class through your IEclipseContext, call the openPart-Method, and you should see the Eclipse internal browser view.
public class Opener {
#Inject
EPartService partService;
public void openPart() {
MPart part = partService.createPart("org.eclipse.ui.browser.view");
part.setLabel("Browser");
partService.showPart(part, PartState.ACTIVATE);
}
}
Here you can find an example of how this works together with your Application.e4xmi.