Author Topic: Controls hidden when creating a screen  (Read 4823 times)

Eric Johannsen

  • EA User
  • **
  • Posts: 43
  • Karma: +0/-0
  • Model Driven Business[ch0174]
    • View Profile
Controls hidden when creating a screen
« on: July 19, 2007, 03:58:32 pm »
Hi,

I'm trying to create a UI screen along with its associated UI controls through automation and place them on a new diagram.  The controls are created just fine, but when I build the diagram, they seem to be "behind" the screen.  If I select them in the Project Browser and do "Locate in current diagram" I can see the arrow-shaped grab bar for the UI control in question, but he UI control itself remains hidden.

I can see no way in the API to change the Z-Order of the controls on the diagram, though I add them to the diagram in a way that seems logical... first I create the screen, then add the screen to the diagram, then create the first UI control, then add it to the diagram, then create the second UI control, ...

I'm using EA 6.5.805.

This is reproducable with a small sample app:

Code: [Select]

namespace Canonic.EAPlugin.DocumentParser
{
   class Testbed
   {

       public void MakeScreen(EA.Repository rep)
       {
           EA.Package pack = rep.GetTreeSelectedPackage();
           EA.Diagram diag = (EA.Diagram)pack.Diagrams.AddNew("Test UI Diagram", "Logical");
           diag.Update();

           EA.Element screen = (EA.Element)pack.Elements.AddNew("My Test Screen", "Screen");
           pack.Update();
           screen.Notes = "My Notes";
           screen.Update();

           string screenPosition = "l=100;t=100;r=600;b=700";

           EA.DiagramObject diagObjScreen =
               (EA.DiagramObject)diag.DiagramObjects.AddNew(screenPosition, "");
           diagObjScreen.ElementID = screen.ElementID;
           diagObjScreen.Update();

           CreateControl(screen, diag, "Label One", "label", 110, 200, 110, 120);
           CreateControl(screen, diag, "Textbox One", "textbox", 210, 300, 110, 120);
           CreateControl(screen, diag, "Label One", "label", 110, 200, 210, 220);
           CreateControl(screen, diag, "Textbox One", "textbox", 210, 300, 210, 220);

           CreateControl(screen, diag, "Button One", "button", 150, 180, 300, 320);

       }

       private void CreateControl(EA.Element screen, EA.Diagram diag, string name, string stereotype,
           int l, int r, int t, int b)
       {
           EA.Element ctl = null;

           ctl = (EA.Element)screen.Elements.AddNew(name, "UI Control");
           screen.Update();
           ctl.Stereotype = stereotype;
           ctl.Update();

           StringBuilder sb = new StringBuilder();
           sb.AppendFormat("l={0};r={1};", l, r).AppendFormat("t={0};b={1};", t, b);
           string controlPosition = sb.ToString();

           EA.DiagramObject diagObjCtl =
               (EA.DiagramObject)diag.DiagramObjects.AddNew(controlPosition, "");
           diagObjCtl.ElementID = ctl.ElementID;
           diagObjCtl.Update();

           diag.Update();
       }
   }
}


Thanks!

Eric

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8085
  • Karma: +118/-20
    • View Profile
Re: Controls hidden when creating a screen
« Reply #1 on: July 19, 2007, 04:03:58 pm »
If you look at the help page for DiagramObject you'll see that Sequence controls Z-order.

Eric Johannsen

  • EA User
  • **
  • Posts: 43
  • Karma: +0/-0
  • Model Driven Business[ch0174]
    • View Profile
Re: Controls hidden when creating a screen
« Reply #2 on: July 19, 2007, 04:06:14 pm »
Does a Sequence of "0" or "1" have any special meaning, or do you just compare the relative numbers?

Eric Johannsen

  • EA User
  • **
  • Posts: 43
  • Karma: +0/-0
  • Model Driven Business[ch0174]
    • View Profile
Re: Controls hidden when creating a screen
« Reply #3 on: July 19, 2007, 04:10:06 pm »
I modified my test code to set the sequence and still get the same result.  Any thoughts on what I'm doing wrong still?

Eric

Code: [Select]

   class Testbed
   {
       private int zorder = 1;

       public void MakeScreen(EA.Repository rep)
       {
           zorder = 1;

           EA.Package pack = rep.GetTreeSelectedPackage();
           EA.Diagram diag = (EA.Diagram)pack.Diagrams.AddNew("Test UI Diagram", "Logical");
           diag.Update();

           EA.Element screen = (EA.Element)pack.Elements.AddNew("My Test Screen", "Screen");
           pack.Update();
           screen.Notes = "My Notes";
           screen.Update();

           string screenPosition = "l=100;t=100;r=600;b=700";

           EA.DiagramObject diagObjScreen =
               (EA.DiagramObject)diag.DiagramObjects.AddNew(screenPosition, "");
           diagObjScreen.ElementID = screen.ElementID;
           diagObjScreen.Sequence = zorder++;
           diagObjScreen.Update();

           CreateControl(screen, diag, "Label One", "label", 110, 200, 110, 120);
           CreateControl(screen, diag, "Textbox One", "textbox", 210, 300, 110, 120);
           CreateControl(screen, diag, "Label One", "label", 110, 200, 210, 220);
           CreateControl(screen, diag, "Textbox One", "textbox", 210, 300, 210, 220);

           CreateControl(screen, diag, "Button One", "button", 150, 180, 300, 320);

       }

       private void CreateControl(EA.Element screen, EA.Diagram diag, string name, string stereotype,
           int l, int r, int t, int b)
       {
           EA.Element ctl = null;

           ctl = (EA.Element)screen.Elements.AddNew(name, "UI Control");
           screen.Update();
           ctl.Stereotype = stereotype;
           ctl.Update();

           StringBuilder sb = new StringBuilder();
           sb.AppendFormat("l={0};r={1};", l, r).AppendFormat("t={0};b={1};", t, b);
           string controlPosition = sb.ToString();

           EA.DiagramObject diagObjCtl =
               (EA.DiagramObject)diag.DiagramObjects.AddNew(controlPosition, "");
           diagObjCtl.ElementID = ctl.ElementID;
           diagObjCtl.Sequence = zorder++;
           diagObjCtl.Update();

           diag.Update();
       }
   }

Aaron B

  • EA Administrator
  • EA User
  • *****
  • Posts: 941
  • Karma: +18/-0
    • View Profile
Re: Controls hidden when creating a screen
« Reply #4 on: July 19, 2007, 04:44:10 pm »
Quote
The sequence position when loading into diagram (affects Z order). The Z-order is one-based and the lowest value is in the foreground.

According to the documentation, the lowest value is in the foreground, so it looks like you need to do your sequence numbering in the opposite direction.  I.e. Start with a higher zorder value and do '--' instead of '++'.

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: Controls hidden when creating a screen
« Reply #5 on: July 19, 2007, 04:45:25 pm »
Eric,

I've not studied your code in depth, nor have I tried it out, but here's a possibility.

Try calling screen.Elements.Refresh(); right after ctl.Update();

This might cause EA to update it's internal (memory) list of Elements. I cannot say for sure it this will work, but give it a shot.

David
No, you can't have it!

Eric Johannsen

  • EA User
  • **
  • Posts: 43
  • Karma: +0/-0
  • Model Driven Business[ch0174]
    • View Profile
Re: Controls hidden when creating a screen
« Reply #6 on: July 20, 2007, 01:09:35 pm »
SOLUTION:

I just had to set the zorder correctly.  There was no need to call screen.Elements.Refresh();

Thanks for everyone's help!