open (or switch to) a view with jArchi

Started by rchevallier, June 09, 2023, 13:43:17 PM

Previous topic - Next topic

rchevallier

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

Phil Beauvoir

Hi, opening a View in the UI is not implemented in jArchi. You could open a feature request if you wish.

Phil
If you value and use Archi, please consider making a donation!
Ask your ArchiMate related questions to the ArchiMate Community's Discussion Board.

rchevallier

Thanks for the quick confirmation. I'll do it

Thomas Rohde

#3
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. ");
}

Phil Beauvoir

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.
If you value and use Archi, please consider making a donation!
Ask your ArchiMate related questions to the ArchiMate Community's Discussion Board.

rchevallier

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.