Scene Builder - Custom Control Reuse - javafx

I've been at this problem trying to find workarounds for weeks now and I am starting to give up. I must be doing something fundamentally wrong. Anyway, this is my situation. I have previously made a neat little program using JavaFX but have now discovered Scene Builder and want to build it all again using this tool. The project includes several components that are frequently reused such as the one below. This is made up of a label, a slider, a text field and another custom component, an InfoIcon.
I have understood that the done thing is to import the custom component (the InfoIcon) as a .jar file into Scene Builder when building my SliderVariable as I call it. This works great and I can run a small demo of my SliderVariable from within Eclipse by creating a main method, a scene and making a SliderVariable in this scene. As mentioned this works great. Importing or Including the InfoIcon does not do what I want (I don't think) because then I cannot easily make changes to the InfoIcon (or its controller) and update my SliderVariable and then see the effects in the final product.
The problems arise when I want to take it one step further and in turn use my SliderVariable in Scene Builder. I do as with the InfoIcon. I export my slider variable to a non-executable jar and then import it into Scene Builder. Here Scene Builder complains that it cannot find any UI components and thus fails to import it. I have discovered that this is because when I export the SliderVariable as a jar it does not also package its dependencies meaning the InfoIcon doesn't get bundled with it and that the compiler cannot find this component as I try to use it.
I have tried to solve this with FatJar which I cannot get working (and it seems like it is not in use any more). I have tried Maven where I couldn't import the Maven project dependency of the InfoIcon in the FXML of the SliderVariable. Finally I have also tried simply not importing a jar but instead including the source code of InfoIcon in a separate package of SliderVariable but then I couldn't import it into my FXML. I am desperate. What do people normally do if they want to reuse custom components with their own controllers in Scene Builder? Is this even done? Should I just give up :'(?
This unwieldly post must be highly confusing but I do not know how to make it clearer. Any sort of response would be greatly appreciated and if you do not believe this forum is the right place to post something like this (which it probably isn't) please point me to someplace else where I am more welcome.
Many thanks.
EDIT 1: I have now added a folder in my project called Dependencies. In here I put a copy (not a reference to) my InfoIcon.jar.
I then add this .jar file to my Build Path and remove the old one. I then enter SceneBuilder and reimport the InfoIcon jar but this time from the Dependencies folder I just created. At this point the small project test I've made still runs fine. I then export as JAR file with the following settings and hit finish.
I then try to import it into Scene Builder and Scene Builder tells me it cannot find any UI components.
EDIT 2: Should I select these items?
Note that the jar file is in Dependencies but also in Referenced Libraries (which is not visible here). This type of selection makes it so that Scene Builder can find and Import the InfoIcon but not the SliderVariable.

When you export InfoIcon, you can simply select the packages and classes related to it in the Eclipse's package explorer (or other similar explorer views), and choose export.
Similarly, when you try to export SliderVariable control, you need to choose everything you have selected in InfoIcon, on top of other files that are needed by SliderVariable control itself.
If InfoIcon is imported into SliderVariable project as a JAR file, then you would need to manually select that JAR file during the export of SliderVariable.

Related

Use custom made widget in another project

I have come across this custom widget,
https://github.com/akontsevich/WidgetBox
however I am unable to work out how to use it in my current project.
I have tried including the files in my project, as well as including a .pri file in my project.pro but it won't.
How do you use custom widgets, (this one for example) in a project?
You've got two ways to work with that.
First look at the project file for the widget: WidgetBox pro.
Notice the lines:
TEMPLATE = lib
...
creator_target.output = WidgetBoxPlugin.dll
This means you can build a library from the project and use it inside yours (after including proper headers)
Another way would be to include all the sources from the WidgetBox project into yours and build them along with your source.
Which approach to use depends on your needs. If you don't plan to modify the widget building it once from the authors project should be enough for you.

Custom Components in Scenebuilder 2.0

In Scenebuilder 1.1, you could import an entire custom component as a whole.
In 2.0, however, it is importing the component as separate pieces (Container and nodes). Since my custom component relies on being unified to work with its controller and IDs, this breaks it.
Is there anything I can do as of yet? I'd really like to be able to use Java 8 and Scenebuilder 2.0 for its DatePicker. If a full stable release is right around the corner, perhaps I can wait. I'd preferably want to avoid hacky solutions.
Any ideas?
I have only found one way to deal with this kind of back-compatibility: building my own scenebuilder.
It is officially open source so you can check it out with mercurial on bitbucket for instance.
Then you build it and modify it to put all your custom components and dependencies in the same classpath for one unique classloader.
Check the class named FXOMLLoader, it is where the classloader is used, my fix was to explicitly only use one classloader for all components and adding a few repertories with my deps inside to the classpath for it to work.
I have used Jar Class Loader library to do so, and it works pretty well. This is pretty hacky though.

Flex Builder: Not picking up new files

I have a working AS3 project and it compiles fine to a SWF. I added a new file (via various means: import, drag-drop, new), but it doesn't compile this new file. I'm using Flex Builder 3. I've tried a clean an rebuild. I've tried renaming. It picks up the existing files fine, but not the new one. The project is set to use a HTML wrapper. I see some build files (I think). The new file is in an existing folder and package.
Any idea what could be wrong?
First, the SWF Compiler will optimize your end code. If you never use a class or create an instance of it anywhere in your application; that code will never be compiled in your application. this is a common occurrence if you're using Flex Remoting with some backend; and a VAlue Object is never instantiated directly, instead you're always returning arrays of it. You'll find you get a lot of "Generic Objects" without the backend object-to- AS3 object translation of the Flex Remoting Gateway.
You didn't specify what type of file you are adding. If it is an ActionScript file it won't automatically be compiled in the swf. You'll have to 'include' it in another class somehow. IF it is an ActionScript class or MXML Component, make sure you are using that class somehow in your code. If it is another file type, such as an image or other asset you'll have to embed that file into your code somehow.
We might be able to offer more help if you were to tell us what type of file is not being added to the final SWC. Also tell us how you can tell.

FLEX components: updating import statements to move the component into another folder

I've just imported a Flex component into my project.
I have a theory question about importing.
all the imports statements in the component source files started with "com.subFolder.etc", but I have preferred to move the component folders into "componentName" and to replace all import statements as "componentName.com.subFolder.etc"
Is this ok ? Everything works perfectly, but I was wondering if the method is correct.
thanks
You can put the components anywhere you like, however you want to organize them. People will site best practices and theory but if you know where everything is and you tell the compiler where they are:
import componentName.com.subFolder.componentToBeUsed;
Everything will compile and run just fine.
Usually you will see code and components broken up in a domain model.
So you'll have:
com.yoursite.views
com.yoursite.events
com.someothersite.renderers
Which correspond to:
/com/yoursite/views
/com/yoursite/events
Basically all of your code living in folders within /com/yoursite/
and:
/com/someothersite/renderers
being a custom renderer you imported from someothersite.com to use in your application.
In the end, for the compiler and the flash player I don't think it matters where you put things as long as your happy and understand it all...and of course 6 months from now when you come back to look at this code!
It's totally correct, yes.
Note that Flex Builder (if you're using it) can automatically replace your import statements/class name when you rename a directory or a .mxml/.as file.
I never tried moving a complete structure, though, but I would't be surprised if it worked too.

FlashDevelop - Why does code-completion not work with mx.controls

Today's my first day with Flex and FlashDevelop. In my ActionScript file, I have this line.
import flash.display.SimpleButton;
FlashDevelop is aware about this and Code-completion works fine.
But, when I have this line.
import mx.controls.Button;
Then code-completion doesn't work.
Works perfectly well for me w/o doing anything special. But maybe your project's properties got borked. Do this:
Open Project Properties
Go to Compiler Options tab
In Advanced -> Intrinsic Libraries add the following
Library\AS3\frameworks\Flex3
I had the same problem. Your AS3 class path is pointing at a directory to low in the flashdevelop library folder structure to pick the mx class prototypes.
1.) Within Flashdevelop press F10 to open the 'Settings' window.
2.) In the list on the left click on the 'AS3Context' option.
3.) Imediately Under the group title of 'Language' on the right hand side of the window, find the 'AS3 Classpath' option. Its value is typically set to 'Library\AS3\Intrinsic'. Change the the 'AS3 Classpath' value to read 'Library\AS3'.
4.) FIXED. Flashdevelop should now be aware of the mx libraries, thus autocomplete should now also work.
To include any swc to code complete, add it's parent folder to the swc libraries option. Some people claim that using intrinsic libraries works, but it didn't for me. Here's the paths to both settings:
ProjectSettings->CompilerOptions->SWCLibraries = {path to FOLDER containing swc's}
ProjectSettings->CompilerOptions->IntrinsicLibraries = {path to same FOLDER containing swc's}
It seems like you are missing the Flex framework in your build path. Have you looked at the libraries being included?

Resources