Author Topic: Saving Changes on OnEAContextItemChanged  (Read 31 times)

alexIsmaier

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Saving Changes on OnEAContextItemChanged
« on: January 12, 2017, 03:00:52 am »
Hello,

I am developing an EA Add-in where it is possible to change attributes of diagram elements.
The idea is to save the data entered in the Add-in (separate Window) if the item is deselected.
This means the saving process takes place in case of the OnEAContextItemChanged event.

The problem is that this leads to the message that another user possibly modified the diagram.
This can be resolved by calling the repository.RefreshOpenDiagrams(true) method.
However then the selection in EA is lost and i have no idea how to restore it (if it is possible through the API).

The main questions are the following:
1. Is it possible to avoid calling RefreshOpenDiagrams(true) while not having a synchronisation issue?
2. Is it possible to get an Event such as ContextItem deselected? (Called before ContextItemChanged)
3. Can i select a Context Item in the diagram (Main View) from the Add-in?

Thanks in Advance,
Alex

Uffe

  • EA User
  • **
  • Posts: 868
  • Karma: +65/-5
  • Flutes: 1; Clarinets: 1; Saxes: 5 and counting
    • View Profile
Re: Saving Changes on OnEAContextItemChanged
« Reply #1 on: January 12, 2017, 04:02:58 am »
Hi Alex,

1. Possibly by setting Repository.EnableUIUpdates to False, then setting it to True after you've made your changes.
2. No, but if you remember the item type and ID from OnContextItemChanged you can reselect it after calling RefreshOpenDiagrams().
3. Yes, by adding the element ID to the Diagram.SelectedObjects collection. (In the case of a connector, only one can be selected at a time so it is stored in Diagram.SelectedConnector which is not a collection.)


HTH,


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

alexIsmaier

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Re: Saving Changes on OnEAContextItemChanged
« Reply #2 on: January 12, 2017, 09:23:53 pm »
Thanks for your fast answer, the first option unfortunately does not work.
Reselecting an Edge (Connector) works like a charm, however i have some questions about the SelectedObjects collection.
This is my code right now:
Object obj;
EA.ObjectType oType = repository.GetContextItem(out obj);

repository.RefreshOpenDiagrams(true);

if (oType == EA.ObjectType.otConnector)
{
       repository.GetCurrentDiagram().SelectedConnector = (EA.Connector)obj;
}
else if (oType == EA.ObjectType.otElement)
{
      Collection newSelection = repository.GetCurrentDiagram().SelectedObjects;
      EA.Element dObj = (EA.Element)obj;
      IDualElement el = repository.GetCurrentDiagram().SelectedObjects.AddNew(dObj.ElementID.ToString(),
                                                                                                                               dObj.ObjectType.ToString());
      newSelection = repository.GetCurrentDiagram().SelectedObjects;
}


This code works for reselecting the object (obj), however when looking at the documentation it states that i should:
-call AddNew()
-modify the returned object
-call Update() on the returned object
-call Refresh() on the collection

However, the object returned by AddNew() (el) for me is always null, making it difficult to call Update() on it...
Also if i were to call Refresh() on the SelectedObjects collection, it would remove my item I added with AddNew().
How do I implement this the correct way?
Are there any problems i will run into if i leave my code this way?