Archi Forum

Archi Plug-ins => jArchi => Topic started by: rchevallier on February 03, 2023, 19:42:08 PM

Title: How to known the kind of object
Post by: rchevallier on February 03, 2023, 19:42:08 PM
how to recognize in jArchi if a selected object is an element? a relationship?
Thx
Title: Re: How to known the kind of object
Post by: Jean-Baptiste Sarrodie on February 03, 2023, 20:34:02 PM
Hi,

The straightforward answer is, check its type and see if it contains the string "relationship".

But another option is to filter the selection (which is a collection of only one object in this case) with either 'element' or 'relationship' and see if its lenght is zero or not:

if(selection.filter('element').size()) {
   console.log('Selection contains at least one element')
}
if(selection.filter('relationship').size()) {
   console.log('Selection contains at least one relationship')
}

Regards,

JB
Title: Re: How to known the kind of object
Post by: rchevallier on February 04, 2023, 16:18:42 PM
Thanks, so no magic  :'(
Then how to distinguish a visual Object (selection in a view) from a Concept (selection in the model tree) ?
Title: Re: How to known the kind of object
Post by: Jean-Baptiste Sarrodie on February 04, 2023, 16:56:07 PM
Hi,

Quote from: rchevallier on February 04, 2023, 16:18:42 PMThen how to distinguish a visual Object (selection in a view) from a Concept (selection in the model tree) ?

if (selection.first().concept == selection.first()) {
  console.log('This is a concept')
} else {
  console.log('This is a visual object')
}

Regards,

JB
Title: Re: How to known the kind of object
Post by: rchevallier on February 04, 2023, 18:06:50 PM
Thanks
Title: Re: How to known the kind of object
Post by: Phil Beauvoir on February 05, 2023, 09:23:17 AM
Also this will tell you the class of the object:

selection.first().class