lock [Solved] Plugin Usage

7 years 11 months ago #733 by mersa
maybe one more question ;)

is the project import/export functionality accessible by the api?
thanks in advance.
The topic has been locked.
7 years 11 months ago #734 by mersa
what i'm trying to do, is to export an (open) project, just like the already available functionality in modelio (don't ask why) For that purpose, i only zip the entire project folder. No problem up to that point.

But some points come up when i import it again. How can i get access to my workspaceview and update it?
Ideally, i'm also able to open the newly imported project and close the current one.
Am i right, that this move away from the model related scope of a module and is better done with a plugin?
The topic has been locked.
7 years 11 months ago - 7 years 11 months ago #737 by fpo
I haven't check precisely but i don't think project import/export functions are indeed accessible through the API, but as you guessed it basically consist of zipping/unzipping the whole project directory in the workspace and then forcing the workspace to refresh.

Anyway, the procedure you describe implies some work being done while no project is opened (importing the project and, more critically, opening it) which is indeed out of the scope of a module (which is meant to work "inside" a project, i.e. when a project is opened).

As to how you can force the workspace view to refresh, you'll have to use undocumented internal classes (which means that this is not official API and it might change or altogether disappear in futur versions for all I know). You can have a look at the ImportProjectHandler class from app.impexp plugin. Basically, what you want to do is get the IWorkspace handle from the App singleton in app.internal plugin and call IWorkspace#refreshProjects on it.

Hope this helps, but remember: not official API!

Edit: forgot to mention that you should definitely close the project before exporting it, or you'll get a "project is locked" warning when trying to open the exported/imported version for the first time.
The topic has been locked.
7 years 11 months ago #738 by mersa
Hey,

i wasn't able to find the relevant classes, but this is definitly a good starting point for me, even if i do not fully understand what you wrote. But i will check that first.

Thank you.
The topic has been locked.
7 years 11 months ago - 7 years 11 months ago #739 by fpo
Ok, I'll try to make things clearer then.

First of all, what you want to do (if i understood correctly) is very (if not completely) similar to what is being done in the com.modeliosoft.modelio.app.impexp.project.ImportProjectHandler and com.modeliosoft.modelio.app.impexp.project.ExportProjectHandler classes that can be found in the org.modelio.app.impexp plugin of Modelio (sorry about the namespacing not matching the plugin name, legacy and all that...).
These classes are the ones called by the RCP when user clicks on the "import project" command of the File menu and the "export project" contextual menu command in the workspace view. So the code of these classes should be a good starting point for you.

But then, the problem is that these classes use other classes (most importantly for your case: com.modeliosoft.modelio.internal.app.services.App from plugin org.modelio.app.internal used to get a handle on com.modeliosoft.modelio.internal.app.IWorkspace from plugin org.modelio.app.api) that are NOT part of the "official" stable API (as is hinted by the "internal" in their namespacing). It is usually discouraged to access and use internal classes, for the simple reason that there is no guarantee whatsoever on their evolution in future versions, meaning code relying on them may or may not continue to work as expected (or even to compile) in the future versions.
On the other hand, there is no way to do what you ask through api... unless.

Unless what you want to do is EXACTLY what these classes do (including the file chooser for the import project, etc). In which case, you could use the RCP platform services to call them directly.
The steps for the export (for example) would be:
A) show/create the workspace view and give it focus (using IWorkbenchPage#showView("com.modeliosoft.modelio.app.WorkspaceNavigatorViewID"))
B) force selection of the project you want to export
C) Get a handle on the IHandlerService (ask the workbench for it) and ask it to execute the "com.modeliosoft.modelio.app.impexp.ExportProjectCommandID" command.
Import is even easier, as it doesn't require view and selection manipulation: just get the IHandlerService and ask it to execute the "com.modeliosoft.modelio.app.impexp.ImportProjectCommandID" command.
The topic has been locked.
7 years 11 months ago - 7 years 11 months ago #752 by mersa
Hey,

thank you for this very detailed explanation. Obviously it would have been smarter just to use the ImportProjectHandler/ExportProjectHandler classes. Anyway, to keep it simpel, i keep my code as it is and just want to do the refresh thing.

But i think i'm acting a little bit dumb..

I tried

org.modelio.app.internal used to get a handle on com.modeliosoft.modelio.internal.app.IWorkspace from plugin org.modelio.app.api


by App.getInstance().getWorkspace(); to get the workspace and do a refresh on it but it doesn´t work.
So how do i get a handle on my workspace?

Edit: Oh, and thanks for the warnings regarding the usage of internal classes. I'm aware of that problem but i don't see any alternatives at the moment.
The topic has been locked.
Moderators: tmachmaab
Time to create page: 0.051 seconds
^ Back to Top