2016-08-29 2 views
0

Enterprise ArchitectのC#アドインを使用して、特定の親要素に特定の子要素のみを追加できるように制限しています。子要素Aをドラッグ及び親素子Cにドロップされた場合、例えばC#アドインを使用してEnterprise Architectの子要素を制限する

要素素子Bにドロップする必要がある場合は、それが削除されます。私はEA_OnPostNewElementメソッドとそのための削除メソッドを使用して、それは正常に動作します。

ユーザーが特定の親に子要素をドロップした後、しばらくしてから、親要素の外に子要素をドラッグして、ダイアグラムの他の要素に子要素として追加できます。

ここでは、エンタープライズアーキテクトのGUIの変更を観察し、その子要素を元の親の場所に戻すことで、制限を追加する方法はありますか。親切に助けてください。

+0

まだ解決策がありません..? – Arshad

+0

@ dahsra ..コードをありがとう。間違った親に子要素をドロップすると、その子の親の名前は実際の親の名前で更新されますが、それは同じ間違った親の場所に残ります。正しい親の下に子要素を実際に戻すことは可能ですか? – rashmi

+0

回答を更新しました。 – Arshad

答えて

1

あなたは、両方のをEA_OnContextItemChangedとはそうあなたがそれを達成することができをEA_OnNotifyContextItemModified使用する必要があります。

public Dictionary<int, int> lstChildElements = new Dictionary<int, int>(); 

dictonryを宣言し、ここでのサンプルコード

public void EA_OnContextItemChanged(EA.Repository Repository, string GUID, EA.ObjectType ot) 
    { 

     EA.Element addedElement = Repository.GetElementByGuid(GUID); 
     if (addedElement == null) 
      return; 
     int identifiedParentID = 0; 
     bool isAvailable = lstChildElements.TryGetValue(addedElement.ElementID, out identifiedParentID); 
     if (!isAvailable) 
     { 
      if (addedElement.Stereotype == "Child" && addedElement.ParentID != 0) 
      { 
       EA.Element parentElemnt = Session.Repository.GetElementByID(addedElement.ParentID); 
       if (parentElemnt != null) 
        if (parentElemnt.Stereotype == "anyCustomDefined") 
         lstChildElements.Add(addedElement.ElementID, addedElement.ParentID); 
      } 
     } 


    } 

    public void EA_OnNotifyContextItemModified(EA.Repository Repository, string GUID, EA.ObjectType ot) 
    { 

     EA.Element addedElement = Repository.GetElementByGuid(GUID); 
     if (addedElement == null) 
      return; 
     int identifiedParentID = 0; 
     bool isAvailable = lstChildElements.TryGetValue(addedElement.ElementID, out identifiedParentID); 
     if (isAvailable) 
     { 
      if (addedElement.Stereotype == "Child" && addedElement.ParentID != 0) 
      { 
       EA.Element parentElemnt = Repository.GetElementByID(addedElement.ParentID); 
       if (parentElemnt != null) 
        if (parentElemnt.Stereotype != "anyCustomDefined") 
        { 
         addedElement.ParentID = identifiedParentID != 0 ? identifiedParentID : addedElement.ParentID; 
         addedElement.Update(); 
         lstChildElements[addedElement.ElementID] = addedElement.ParentID; 
        } 
      } 
      else if (addedElement.Stereotype == "Child" && addedElement.ParentID == 0) 
      { 
       addedElement.ParentID = identifiedParentID; 
       addedElement.Update(); 
      } 
     } 



    } 

ではそれが役に立てば幸い...!

であり、ダイアグラムを更新するにはリロードする必要があります。

EA.Diagram activeDiagram = Session.Repository.GetCurrentDiagram(); 
     if (activeDiagram != null) 
      Session.Repository.ReloadDiagram(activeDiagram.DiagramID); 

又は

Repository.RefreshOpenDiagrams(); 

コードは、図を再ロードするために使用することができるの両方。

+0

@ dahsra ..ありがとう。私は今それを試しています。すぐに更新されます。 – rashmi

0

context eventsを使用すると、選択した要素とその所有者を追跡できます。

要素の所有者を変更したときにイベントEA_OnNotifyContextItemModifiedが発生しているかどうかはわかりません。 しかし、新しい要素が選択された後も同じ所有者を持っているかどうかを確認することはできません。

関連する問題