loadProject needs restart to work ?

Post here questions and problems related to oXygen frameworks/document types.
Lilipi
Posts: 5
Joined: Wed Dec 01, 2021 1:32 pm

loadProject needs restart to work ?

Post by Lilipi »

Hi,

I'm using the method

Code: Select all

ro.sync.exml.workspace.api.standalone.project.ProjectController#loadProject
in order to update some profiling attributes automatically.
In order to do that, I update the existing project file programmatically. When calling

Code: Select all

loadProject
, nothing appends on UI (no confirm dialog or something) which is OK.

But if I go after that in my preferences, profiling attributes aren't updated :
profiling-attr-1.png
profiling-attr-1.png (36.22 KiB) Viewed 317 times
If I restart my Oxygen editor, and then go back to my preferences without doing something, profiling attributes seems to be OK :
profiling-attr-2.png
profiling-attr-2.png (48.28 KiB) Viewed 317 times
Is there any way to do that without restarting Oxygen ?

Regards
adrian_sorop
Posts: 41
Joined: Wed Jun 22, 2016 2:48 pm

Re: loadProject needs restart to work ?

Post by adrian_sorop »

Hi!
No, this API does not need Oxygen restart to work.
I've tested on my side (with Oxygen 24.0) and the

Code: Select all

ro.sync.exml.workspace.api.standalone.project.ProjectController.loadProject(File)
work as expected.
All settings were loaded without restarting Oxygen.

A "blind" advice would be to try loading the project on AWT: use

Code: Select all

javax.swing.SwingUtilities.invokeLater(Runnable)
Give it a try and let me know if this was usefull.
If this doesn't work, please give us more infomation: Oxygen version, how the API is used (a small code snippet), where is the new project located (on a local drive, on a web drive) and other information that you might consider important.

Best regards,
Adrian S.
Adrian Sorop
<oXygen/> XML Editor
http://www.oxygenxml.com
Lilipi
Posts: 5
Joined: Wed Dec 01, 2021 1:32 pm

Re: loadProject needs restart to work ?

Post by Lilipi »

Hi,

Thanks for your answer.
I've updated a little bit my code and still doesn't have the expected result.

I think I'm not using correctly the loadProject function.
Here is a piece of code, perhaps you could help me ?

Code: Select all

 
 PluginWorkspaceProvider.getPluginWorkspace().open(existingProjectFile.toURI().toURL()); //open updated file with profiling attributes
 final StandalonePluginWorkspace standalonePluginWorkspace = (StandalonePluginWorkspace) PluginWorkspaceProvider.getPluginWorkspace();
 standalonePluginWorkspace.getProjectManager().loadProject(existingProjectFile); //trying to load project file
 
Some additional explanations :
- Before doing this, I copy the file with my new profiling attributes in current project file (.xpr)
- 'existingProjectFile' is the current .xpr file.
Now I've got this result :
- Nothing is updated in my preferences but when I go to project view, it detects that the project file was updated (if I click on 'reload' then it's ok)

In my first atempt, I was not calling 'open' function. I don't know if this is required or not.

Any help would be appreciated
adrian_sorop
Posts: 41
Joined: Wed Jun 22, 2016 2:48 pm

Re: loadProject needs restart to work ?

Post by adrian_sorop »

All right,
Now I fully undestand what and how you want to do.
I've tested and reproduced the problem.
The options are not recognized becaused Oxygen doesn't "undestand" that you use the loadProject() API like a refresh.
The Project Controller uses the a File Change Watcher and the file change watcher decides when the data should be read from disk and when is read from memeory. Because you bypass the file change watcher, the options used are the one cached (from memory).
I'll log an issue to treat this use-case.
Meanwhile, the first workaround I can think of is to load a dummy project.
After the dummy project is loaded, load again the original project.
This way, Oxygen will be forced to read the "real" options from disk, not the cached ones.
The downside for this issue is that you might see a flicker when the project switching occurs

Code: Select all

StandalonePluginWorkspace pluginWorkspace = (StandalonePluginWorkspace) PluginWorkspaceProvider.getPluginWorkspace();
            ProjectController projectController = pluginWorkspace.getProjectManager();
            File theRealProjectFile = new File(projectController.getCurrentProjectURL().toURI());
            
            // do here the changes you need
                        
            // load a dummy project 
            projectController.loadProject(new File("file/path/to/a/dummy/project.xpr"));
            // load the real project, this time the values will be read from disk, not from memory
            projectController.loadProject(theRealProjectFile);    
Let me know if this works out for you,
Adrian S
Adrian Sorop
<oXygen/> XML Editor
http://www.oxygenxml.com
Post Reply