scenebuilder icon indicating copy to clipboard operation
scenebuilder copied to clipboard

ADD Refresh library menu item

Open luca-domenichini opened this issue 3 years ago • 8 comments

When developing a collection of custom controls, after adding them from jar/fxml manager as a folder of classes, it would be useful to have a way to refresh the library from scratch without restarting SceneBuilder. This is especially useful when developing new controls, since it would be possible to append those new controls to the library on the fly without restarting SB.

Expected Behavior

Provide a new item in the library context menù to refresh the library on the fly

Current Behavior

No way to refresh the library. A workaround consists of dropping an entry in the library add it again (very time consuming, especially when library is big)

I am opening this feature as of point 2 of #236

luca-domenichini avatar Aug 11 '21 15:08 luca-domenichini

I was of the opinion that the WatcherService does that for us i.e. any change in the library is automatically loaded into SB. Since you created a PR, it definitely doesn't do this.

I am not accustomed to this part of SB and since you have already worked with it in the past, can you give me a quick overview of what exactly is LibraryFolderWatcher doing and why do we need an external button to load any new change ?

abhinayagarwal avatar Aug 29 '21 09:08 abhinayagarwal

The button is needed because the service that keeps monitored the library folder - LibraryFolderWatcher - just tracks changes on that folder, e.g. jars and fxmls. If we add a folder to the library the .class files are on a different folder and the watcher service does not automatically reloads when they change. I think this is ok, because when we link a folder with classes we are probably developing on that and .class files are probably changing very often. Reloading the library every time a single .class file changes would be very time consuming. The KISS principle here suggested me to simply have a manual refresh button..

luca-domenichini avatar Aug 29 '21 18:08 luca-domenichini

Thank you for the explanation. I have another question: Do you think keeping a service which monitors the Library folder holds water? Can we query and update the changes whenever the user opens the LibraryManager? Moreover, with the current PR we also have a "Refresh" button to load any changes if required.

I personally do not like a thread which queries a directory every second for the entire lifecycle of SB when the chances of a add/remove/update of a JAR/FXML in it is very rare.

abhinayagarwal avatar Aug 30 '21 05:08 abhinayagarwal

I see your point @abhinayagarwal and agree with you. The manual refresh button is simpler and straightforward, and we can avoid polling the filesystem. I will need to rework the refresh action though, because now it simply triggers the underlying thread..

luca-domenichini avatar Aug 30 '21 12:08 luca-domenichini

Do you want me to proceed that way? Dropping the thread and have just the refresh button? Offcourse, manipulating the library through the library manager dialog will have to refresh the library too..

luca-domenichini avatar Aug 30 '21 12:08 luca-domenichini

Today when the user touches anything on the library manager dialog, either by adding or removing something, a refresh of the custom library starts. Maybe it would be simpler and more efficient to do the refresh just once when user clicks OK, so if the user clicks Cancel all the operations should be discarded -- today there is just a Close button since all modifications in that dialog are performed instantly.

@abhinayagarwal can you confirm this todo list?

  • have the library manager to refresh the library just once on a new OK button and discard modifications on Cancel button
  • remove the polling thread on filesystem (and have just the refresh button to manually trigger the refresh)

luca-domenichini avatar Sep 06 '21 09:09 luca-domenichini

If the thread is just polling file system for changes, I think it would be better to remove the polling system and replace it with your suggestion. Since @jperedadnr has done some work in this area in the past, maybe he can chime in his thoughts.

abhinayagarwal avatar Sep 06 '21 09:09 abhinayagarwal

@abhinayagarwal @jperedadnr I updated the PR removing the polling thread. The library is now refreshed when the user closes the library manager dialog AND make some modifications on it (adding, removing, etc..). If the user just opens the dialog and do nothing, it is not refreshed. Offcourse, there is the new Refresh button too...

If you give me an OK, I can rename the class LibraryFolderWatcher into a more appropriate LibraryFolderExplorer since now it does just an explore without watching anymore..

luca-domenichini avatar Sep 08 '21 11:09 luca-domenichini