Book a Demo

Author Topic: Open dialog with EA as parent or default dialog  (Read 9268 times)

clicht

  • EA Novice
  • *
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Open dialog with EA as parent or default dialog
« on: September 08, 2011, 12:36:27 am »
The following code help you do open an Dialog where the EA is the parent/owner of the Form. It is designed as method extension to Windows.Forms.Form:
Code: [Select]
   static public DialogResult ShowDialogAtMainWindow(this Form form)
    {
      IWin32Window win32Window = InternalHelpers.GetMainWindow();
      if (win32Window != null)  // null means that the main window handle could not be evaluated
        return form.ShowDialog(win32Window);
      else
        return form.ShowDialog();  //fallback: use it without owner
    }

Further following code helps you to open standard EA-Property dialogs. Also designed as method extension to the EA.Repository:
Code: [Select]
 public enum EaType
  {
    Package,
    Element,
    Attribute,
    Operation,
    Diagram
  }

  public static class EaRepositoryExtensions
  {
    public static void OpenEaPropertyDlg(this EA.Repository rep, int id, EaType type)
    {
      string dlg;
      switch (type)
      {
        case EaType.Package: dlg = "PKG"; break;
        case EaType.Element: dlg = "ELM"; break;
        case EaType.Attribute: dlg = "ATT"; break;
        case EaType.Operation: dlg = "OP"; break;
        case EaType.Diagram: dlg = "DGM"; break;
        default: dlg = String.Empty; break;
      }
      string ret = rep.CustomCommand("CFormCommandHelper", "ProcessCommand", "Dlg=" + dlg + ";id=" + id + ";hwnd=" + InternalHelpers.GetMainWindow().Handle);
    }

    public static void OpenPackagePropertyDlg(this EA.Repository rep, int packageId)
    {
      rep.OpenEaPropertyDlg(packageId, EaType.Package);
    }

    public static void OpenElementPropertyDlg(this EA.Repository rep, int elementId)
    {
      rep.OpenEaPropertyDlg(elementId, EaType.Element);
    }

    public static void OpenAttributePropertyDlg(this EA.Repository rep, int attributeId)
    {
      rep.OpenEaPropertyDlg(attributeId, EaType.Attribute);
    }

    public static void OpenOperationPropertyDlg(this EA.Repository rep, int opertaionId)
    {
      rep.OpenEaPropertyDlg(opertaionId, EaType.Operation);
    }

    public static void OpenDiagramPropertyDlg(this EA.Repository rep, int diagramId)
    {
      rep.OpenEaPropertyDlg(diagramId, EaType.Diagram);
    }
}

Therefore following helpers are required:
Code: [Select]
public calss InternalHelpers
{
    static public IWin32Window GetMainWindow()
    {
      System.Diagnostics.Process proc = System.Diagnostics.Process.GetCurrentProcess();
      if (proc.MainWindowTitle == "")  //somtimes a wrong handle is returned, in this case also the title is emty
        return null;                   //return null in this case
      else                             //otherwise return the right handle
        return new WindowWrapper(proc.MainWindowHandle);
    }


    internal class WindowWrapper : System.Windows.Forms.IWin32Window
    {
      public WindowWrapper(IntPtr handle)
      {
        _hwnd = handle;
      }

      public IntPtr Handle
      {
        get { return _hwnd; }
      }

      private IntPtr _hwnd;
    }
}
« Last Edit: September 08, 2011, 12:37:39 am by clicht »

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Open dialog with EA as parent or default dialo
« Reply #1 on: September 12, 2011, 05:39:29 pm »
Hmm, seems nice.
Have you though about publishing it on the community site? http://community.sparxsystems.com
Here on the forum it will probably be forgotten and never be found again in just a few weeks.

Geert

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Open dialog with EA as parent or default dialo
« Reply #2 on: July 24, 2012, 04:17:10 pm »
I've started to use this CustomCommand thing to open the properties dialog from my Navigator, but I would like to use it for messages in a sequence diagram as well.

Any idea if that is possible?

And how do we find out what parameters to use?

Geert

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Open dialog with EA as parent or default dialo
« Reply #3 on: July 25, 2012, 03:20:08 pm »
I've implemented the feature in the current version 2.2 (build 2.2.4.0) of the EA Navigator, unfortunately without support for the properties dialog of messages.

If anyone knows how to open that one that would be great.

Geert

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Open dialog with EA as parent or default dialo
« Reply #4 on: July 25, 2012, 10:18:34 pm »
With a brute force I discovered that using 'RTF' as DLG parameter will start the document generation dialogue. But it needs a package id and I haven't figured out how to supply that...

I also tried to get the connector dialogue to be invoked by supplying the connector id, but to no avail.

q.

mlk

  • EA Novice
  • *
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Re: Open dialog with EA as parent or default dialo
« Reply #5 on: November 17, 2012, 01:18:43 am »
Great job, but... have you already found the DLG parameter for connector dialog?  

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Open dialog with EA as parent or default dialo
« Reply #6 on: November 17, 2012, 01:28:59 am »
No. Discovering above was just courtesy/fun. Nothing I needed for myself. Volunteers are welcome.

q.

mlk

  • EA Novice
  • *
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Re: Open dialog with EA as parent or default dialo
« Reply #7 on: November 18, 2012, 10:45:11 pm »
I need it (connector dialog), so I would like to try, but I will be appreciated if any of you give me a tip how to start (tools, methods, etc). Groping for the right abbreviation (i.e. "CNN", "CND", "CN") gives nothing.

stao

  • EA User
  • **
  • Posts: 137
  • Karma: +0/-0
    • View Profile
Re: Open dialog with EA as parent or default dialo
« Reply #8 on: November 19, 2012, 08:17:55 am »
a "trick" can be to select the connector on a diagram and send a "press enter" to EA. Never tried it myself but perhaps worth a try.

mlk

  • EA Novice
  • *
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Re: Open dialog with EA as parent or default dialo
« Reply #9 on: November 20, 2012, 08:54:18 pm »
@stao, I handle the native window's message loop (Sparx Enterprise Architect). Unfortunately messages tell me nothing.

The code below writes every native's message (handle parameter in the contructor comes from clicht's code):
Quote

public class MyNativeWindow : NativeWindow {                  

                  public MyNativeWindow(IntPtr handle) {
                        this.AssignHandle(handle);
                  }

                  [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")]
                  protected override void WndProc(ref Message m) {
                        Debug.WriteLine("Native::" + m.ToString());
                        base.WndProc(ref m);
                  }
            }