How to get the selected model from an Archi plugin

Started by abel, November 19, 2023, 20:49:19 PM

Previous topic - Next topic

abel

Hi all,
I'm trying to automatise actions with an Archi plugin over the current model, but I cannot find which one is it.

If you try to do the same using a JArchi is very easy, but I haven't found any method like "getTheCurrentModel()" or something similar. Could you give me a clue on how to do it?

Thanks in advance,

Phil Beauvoir

#1
Hi, in the context of running Archi on the desktop, the "current" model is the one (if any) that has the focus, i.e. is selected, in the UI (Model Tree or diagram). Typically a plug-in will register itself as a selection listener in a View or menu. You can also get the current selection from the Workbench and drill into that to find what model object is selected, and the model from that.

jArchi does it as follows:

https://github.com/archimatetool/archi-scripting-plugin/blob/master/com.archimatetool.script/src/com/archimatetool/script/WorkbenchPartTracker.java

Depending on your needs you should take a look at how the Archi plug-ins manage the workbecnh selection to get the current model.
If you value and use Archi, please consider making a donation!
Ask your ArchiMate related questions to the ArchiMate Community's Discussion Board.

abel

Thanks Phil.

I will try to follow the JArchi behaviour in my plugin.

abel


Phil Beauvoir

If you want to access the current selected model statically you can do it this way:

IWorkbenchPart part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getPartService().getActivePart();
if(part != null) {
    IArchimateModel model = part.getAdapter(IArchimateModel.class);
}

(check for possible null values in that first line)
If you value and use Archi, please consider making a donation!
Ask your ArchiMate related questions to the ArchiMate Community's Discussion Board.