Author Topic: Drag & Drop from Project Browser into Add-In Form  (Read 2743 times)

L.Krobot

  • EA Novice
  • *
  • Posts: 15
  • Karma: +0/-0
    • View Profile
Drag & Drop from Project Browser into Add-In Form
« on: March 07, 2015, 04:34:43 am »
I'm developing various Add-Ins, and I would like to know how to enable the "Drag & Drop" of elements (or packages) from the Project Browser window into ListBox in my Add-In C# Windows Form.
thx.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13404
  • Karma: +567/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Drag & Drop from Project Browser into Add-In F
« Reply #1 on: March 09, 2015, 06:30:29 pm »
I don't think you can. The only "drag-n-drop" feature currently implemented in the API is the EA_OnPreDropFromTree event, but I think that will only work if an element is dropped on an actual diagram, not if it is dropped on a add-in window.

But you never know...

If it doesn't work you can always send in a feature request

Geert

L.Krobot

  • EA Novice
  • *
  • Posts: 15
  • Karma: +0/-0
    • View Profile
Re: Drag & Drop from Project Browser into Add-In F
« Reply #2 on: March 13, 2015, 01:18:13 am »
Thanks,

as Geert said, there is no way to drop it directly on the form, but you must have open a diagram where you will try to drop your objects. It is not exactly what i wanted, but it works ...

You drag your object from the project browser to the diagram, and when you drop it, it will not drop on the diagram, but the name will appear in your ListBox (obviously, your add-in form must be activated and visible)...

here is how I did it:

1. first, I create the method:
Code: [Select]
       public Boolean EA_OnPreDropFromTree( EA.Repository Repository, EA.EventProperties Info ) {2. then, get the properties from Info:
Code: [Select]
           // first property is: objectID
            EA.EventProperty property = Info.Get( 0 );
            string objectIdX = property.Value.Trim();
            int objectId = Convert.ToInt32( objectIdX );

            // second property is: objectType
            property = Info.Get( 1 );
            string objectTypeX = property.Value.Trim();
3. after this, get the objects, and add their names into ListBox:
Code: [Select]
           switch ( objectTypeX )
            {
                case "4": // object type 4 = Element
                    EA.Element selectedElement = Repository.GetElementByID( objectId );
                    listBox1.Items.Add( selectedElement.Name );
                    break;
                case "5": // object type 5 = Package
                    EA.Package selectedPackage = Repository.GetPackageByID( objectId );
                    listBox1.Items.Add( selectedPackage.Name );
                    break;
                default:
                    break;
            }
4. and on the end, return "false" in order to prevent dropping objects onto diagram:
Code: [Select]
           return false;
full snippet:
Code: [Select]
       public Boolean EA_OnPreDropFromTree( EA.Repository Repository, EA.EventProperties Info ) {
            // first property is: objectID
            EA.EventProperty property = Info.Get( 0 );
            string objectIdX = property.Value.Trim();
            int objectId = Convert.ToInt32( objectIdX );

            // second property is: objectType
            property = Info.Get( 1 );
            string objectTypeX = property.Value.Trim();

            switch ( objectTypeX )
            {
                case "4": // object type 4 = Element
                    EA.Element selectedElement = Repository.GetElementByID( objectId );
                    listBox1.Items.Add( selectedElement.Name );
                    break;
                case "5": // object type 5 = Package
                    EA.Package selectedPackage = Repository.GetPackageByID( objectId );
                    listBox1.Items.Add( selectedPackage.Name );
                    break;
                default:
                    break;
            }

            return false;

        }

ljk