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,
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.
Thanks Phil.
I will try to follow the JArchi behaviour in my plugin.
Hi Phil,
It runs like a charm!!
Thanks again :-)
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)