Archi Forum

Archi Plug-ins => jArchi => Topic started by: rchevallier on June 09, 2023, 13:43:17 PM

Title: open (or switch to) a view with jArchi
Post by: rchevallier on June 09, 2023, 13:43:17 PM
Hi all,

My context: I have a script which go thru all the views of a model for some verification. When the view doesn't validate, the idea is the script stops and the view is opened and selected in the Archi UI to show to the user.

I don't find the verb to open/select a view in UI in the jArchi doc. Seems only opening a model in UI model tree is supported (model.openInUI(), model.setAsCurrent())

Any solution ?

Thanks
Title: Re: open (or switch to) a view with jArchi
Post by: Phil Beauvoir on June 09, 2023, 13:50:34 PM
Hi, opening a View in the UI is not implemented in jArchi. You could open a feature request if you wish.

Phil
Title: Re: open (or switch to) a view with jArchi
Post by: rchevallier on June 09, 2023, 13:51:40 PM
Thanks for the quick confirmation. I'll do it
Title: Re: open (or switch to) a view with jArchi
Post by: Thomas Rohde on June 13, 2023, 14:04:24 PM
I found this buried in one of my older scripts. Give it a try (replace view):

try {
    var method = Packages.com.archimatetool.script.dom.model.ArchimateDiagramModelProxy.class.getDeclaredMethod("getEObject");
    method.setAccessible(true);
    var v = method.invoke(view);
    Packages.com.archimatetool.editor.ui.services.EditorManager.openDiagramEditor(v);
} catch (e) {
    console.log("> Attempted to open view. ");
}
Title: Re: open (or switch to) a view with jArchi
Post by: Phil Beauvoir on June 13, 2023, 14:06:52 PM
Quote from: Thomas Rohde on June 13, 2023, 14:04:24 PMI found this buried in one of my older scripts. Give it a try:

try {
    var method = Packages.com.archimatetool.script.dom.model.ArchimateDiagramModelProxy.class.getDeclaredMethod("getEObject");
    method.setAccessible(true);
    var v = method.invoke(view);
    Packages.com.archimatetool.editor.ui.services.EditorManager.openDiagramEditor(v);
} catch (e) {
    console.log("> Attempted to open view. ");
}

Should work but mark it as "dangerous" since it accesses the underlying EObject. Note that it'll only work if the model that owns the view is open in Archi.
Title: Re: open (or switch to) a view with jArchi
Post by: rchevallier on June 14, 2023, 17:36:15 PM
Quote from: Thomas Rohde on June 13, 2023, 14:04:24 PMI found this buried in one of my older scripts. Give it a try (replace view):

try {
    var method = Packages.com.archimatetool.script.dom.model.ArchimateDiagramModelProxy.class.getDeclaredMethod("getEObject");
    method.setAccessible(true);
    var v = method.invoke(view);
    Packages.com.archimatetool.editor.ui.services.EditorManager.openDiagramEditor(v);
} catch (e) {
    console.log("> Attempted to open view. ");
}

Thanks, works great, using it until the api evolves.
I understand it's unsupported and not recommended.