Author Topic: Getting clicked model  (Read 9314 times)

conio123

  • EA Novice
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
Getting clicked model
« on: January 22, 2014, 06:58:45 pm »
Hello,
I have a question about interaction with currently clicked model. If I click an item in Project Browser, is it possible to get information which item was clicked? What I want to do is
1) select an item and change specific parameters in whole package (for example I want to change Status of all elements in package from Proposed to Approved).
2) I want my script/C# tool to be able to expand the package list for all subelements inside it. So I click an element, choose my addin, click Expand and I get fully expanded list (all subelements of a list are also expanded).
My question is:
What "tool" I need to use for this task - can I use C# addin or I need to use some sparx script (I googled something about it). If it is a script, could you please provide me a name of it, or some resources, so I can read more about it, learn how to use it.
Thank you guys in advance,
Regards,
Konrad

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Getting clicked model
« Reply #1 on: January 22, 2014, 09:00:11 pm »
Try Repository.GetTreeSelectedElements or GetTreeSelectedObject and then you can alter the returned element(s).

q.

conio123

  • EA Novice
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
Re: Getting clicked model
« Reply #2 on: January 23, 2014, 08:07:14 pm »
Thanks, I will try that. And how about visuals - is it possible to make my addin expand a list inside Sparx tool?

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Getting clicked model
« Reply #3 on: January 23, 2014, 09:39:29 pm »
Not sure what you mean, so I guess. You can extend EA by add-ins. It's a bit different to simple scripts as you have to provide a compiled DLL which conforms call conditions. There's a tutorial from Geert Bellekens which you can use.

q.
« Last Edit: January 23, 2014, 09:41:43 pm by qwerty »

Uffe

  • EA Practitioner
  • ***
  • Posts: 1859
  • Karma: +133/-14
  • Flutes: 1; Clarinets: 1; Saxes: 5 and counting
    • View Profile
Re: Getting clicked model
« Reply #4 on: January 23, 2014, 10:16:29 pm »
In an Add-In (not in a script), you get events from EA when certain things happen.

There are events to do what you're after, which in the API are referred to as "context item events." They are ContextItemChanged (user selects something), ContextItemDoubleClicked (user double-clicks or presses return with an item selected) and NotifyContextItemModified (user makes a change to an item).

Double-Click is probably your best bet - otherwise things will start happening in the model when the user just highlights something, which tends to ruin models and anger users. :)

You can also add menu items to your Add-In. These are shown in the top-level menu and the context menus (under Extensions in both cases). This is even better in most cases, since it reduces the risk of accidental function triggering even further.

Finally, you can write scripts and place them in a "project browser" or "diagram" script group. These are then available in the corresponding context menus (under Scripts).

Cheers,

/Uffe
My theories are always correct, just apply them to the right reality.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13378
  • Karma: +563/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Getting clicked model
« Reply #5 on: January 23, 2014, 10:46:15 pm »
Quote
Thanks, I will try that. And how about visuals - is it possible to make my addin expand a list inside Sparx tool?
That's exactly what the EA Navigator does.
Since it's open source you can copy/paste/adapt for your own needs.

Geert

conio123

  • EA Novice
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
Re: Getting clicked model
« Reply #6 on: January 23, 2014, 10:55:10 pm »
Thank you for the answers. I didn't know about Context items, might be I overlooked them in documentation.
Anyway, I might have been not clear enough in what I wrote.
What I want to do, except for what you wrote, which was very good help, is to make my addin expand a whole list with just one click.
I have such structure (took from example):

All items here are expanded - I had to manually click at first Domain Specific Modeling, than GML, than ApplicationSchema and then DataType to expand sublists. So i made 4 clicks. If wanted to expand all elements in this tree, I would have to expand FeatureType, CodeList.. Than in higher level, I'd have to click WSDL item and repeat procedure. For big projects it's a bit annoying - we have a really big model in company, so making 1000 clicks is no fun. What I want do do is to make an addin, which will do what I wrote with just one click, so MyAddin -> Expand whole tree and tadaa, 1000 clicks done with one.
Is it possible to write such addin?
Thank you in advance,
Konrad

Uffe

  • EA Practitioner
  • ***
  • Posts: 1859
  • Karma: +133/-14
  • Flutes: 1; Clarinets: 1; Saxes: 5 and counting
    • View Profile
Re: Getting clicked model
« Reply #7 on: January 24, 2014, 12:35:32 am »
Well, it's kind of possible.

Note first off that the ContextItem events are triggered regardless of where in the GUI something happened - in other words, if you write an Add-In which responds to OnContextItemChanged by expanding the project browser, it will do so when the user selects the package in a diagram as well as in the browser.

If instead you write the Add-In to expand the project browser when the user selects a menu item, you can see where the menu item was selected (the MenuLocation parameter of the MenuClick event) and only respond when it is clicked in the browser. Means the user will have to click twice to trigger the function, but might still be preferable.

As for expanding the project browser, there's no "expand-everything-from-this-node" function. What you can do is call Repository.ShowInProjectView(). This selects the specified item in the project browser, expanding items above it as necessary. If you traverse the package ("Domain Specific Modeling") and call ShowInProjectView() once for each item you'll achieve the desired effect (you only need to call it once for a given collection of diagrams, attributes or methods, but you need to traverse the packages and elements). So it might take some time.

Another approach would be to write your own project browser and launch that as an Add-In custom view or just as its own window. Geert's EA Navigator would be a good starting point for that.

Cheers,


/Uffe
My theories are always correct, just apply them to the right reality.

conio123

  • EA Novice
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
Re: Getting clicked model
« Reply #8 on: January 24, 2014, 02:11:19 am »
Thank you, I think I understand the idea. Just one small question. If I click such item:

I get no EA_ContextItemChanged event. If I click any child of it, event is fired properly. Is there any way to get selected item of that type? The reason I am asking is beacause in our projects we have like ~100 items of that type in one EAP file, so I'd like to know which one was selected.
If I select a child of it, I user GetPackageByGUID, which is perfectly fine, but getting selected top level container - is it possible?
Thank you for your help, I appreciate it really much:)

Uffe

  • EA Practitioner
  • ***
  • Posts: 1859
  • Karma: +133/-14
  • Flutes: 1; Clarinets: 1; Saxes: 5 and counting
    • View Profile
Re: Getting clicked model
« Reply #9 on: January 25, 2014, 03:17:00 am »
I'm not sure but my gut says 'no.'

Root nodes are the subject of a bit of special handling in EA, and while they are packages in some respects they aren't in others.

You can select them in the browser, but you can't drag them into diagrams (or anywhere else, they don't follow the mouse pointer when you move it) and you can't see their properties: double-clicking or pressing return does nothing.

This suggests to me that the ContextItem events aren't fired for these guys at all.

You might be able to do something creative with calls to Repository.GetContextItemType() and Repository.GetContextObject() a couple of times a second, I think (but I don't know) they'll return meaningful results even if the selected item is a root node.


/Uffe
My theories are always correct, just apply them to the right reality.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13378
  • Karma: +563/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Getting clicked model
« Reply #10 on: January 27, 2014, 06:31:43 pm »
I can confirm. The ContextItems events aren't fired for root nodes.

Geert

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8074
  • Karma: +118/-20
    • View Profile
Re: Getting clicked model
« Reply #11 on: January 28, 2014, 08:03:55 am »
Quote
All items here are expanded - I had to manually click at first Domain Specific Modeling, than GML, than ApplicationSchema and then DataType to expand sublists. So i made 4 clicks. If wanted to expand all elements in this tree, I would have to expand FeatureType, CodeList.
Are you aware that there is a common windows shortcut for expanding trees?

Select the node you want to expand and press '*'. There is also an item in the context menu of packages. (Contents | Expand Branch)

motivatedgorilla

  • EA User
  • **
  • Posts: 44
  • Karma: +0/-0
    • View Profile
Re: Getting clicked model
« Reply #12 on: January 31, 2014, 05:04:44 am »
I tried pressing "*" on a given package but it does not expand

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Getting clicked model
« Reply #13 on: January 31, 2014, 05:11:02 am »
Neither does it work for me (/my XP). Maybe it's a question of the Windoze version. Windoze is as consistent as EA.

q.

EXploringEA

  • EA User
  • **
  • Posts: 172
  • Karma: +8/-0
    • View Profile
Re: Getting clicked model
« Reply #14 on: January 31, 2014, 05:21:48 am »
It works in XP and win7 when you use the * on the numeric keypad but not the shift key version (shift + 8 in the UK). Not all *'s are the same :D

EXploringEA - information, utilities and addins