Order of a $(selection)

Started by blayde64, March 16, 2024, 11:26:35 AM

Previous topic - Next topic

blayde64

As i understand it $(selection) is ordered. I wanted to select two views in the model browser, and apply several properties from the first selected object to the second selected one.  I had thought this would work:

var targetObj = $(selection).get(0);
var sourceObj = $(selection).get(1);

If i have two views "A" and "B", it doesn't matter if i select A or B first, i always have "A" returned in target object. Is there any way i can programmatically identify the first selected item? ie, not have the selection sorted?

Many thanks.

Phil Beauvoir

#1
The jArchi "selection" variable is taken from the underlying Eclipse global selection and there is no guarantee of the order of elements (and this might be different on Mac and Windows). When you select objects in a View the selection order reflects the order in which you click on them, but in the Models Tree this is not the case, because (as you found) they are sorted alphabetically.

BTW, because the "selection" variable is a collection you don't need to wrap it as in "$(selection)" just use it like "selection.get(0);"
If you value and use Archi, please consider making a donation!
Ask your ArchiMate related questions to the ArchiMate Community's Discussion Board.