Book a Demo

Author Topic: Adding a hyperlink element to a diagram  (Read 7213 times)

Pedro

  • EA Novice
  • *
  • Posts: 15
  • Karma: +0/-0
    • View Profile
Adding a hyperlink element to a diagram
« on: July 16, 2013, 11:42:34 pm »
As in this similar question (http://www.sparxsystems.com/cgi-bin/yabb/YaBB.cgi?num=1373547380), this also seems pretty easy, but I cannot do it...

Suppose I have a Diagram wlog with one element. I would like to create a Hyperlink and connect this Hyperlink with the element with a NoteLink. The Hyperlink would of Type == 'Web Site', and also have the Hide Icon option checked.

When I try this:

Code: [Select]
try
            {
                elemHyperlink = (Element)package.Elements.AddNew("test", "Hyperlink");
                elemHyperlink.Update();
                package.Update();
            }
            catch { }

I receive a exception saying that the type Hyperlink does not exist. I believe the logic for adding it is pretty similar to the linked question.

What I also tried was to add a Hyperlink in a eap project with a diagram and navigate through the DiagramObjects. This did not help very much.   I figured out this property Style = "DUID=6CDA3456;HideIcon=1;", but that all.

Thank you

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Adding a hyperlink element to a diagram
« Reply #1 on: July 17, 2013, 01:20:52 am »
You need to create a Text element where PDATA1 is diagram.diagramId. That will render as hyperlink to the diagram.

From my Inside book:
Quote
For UMLDiagrams: Diagram_ID of the underlying diagram;
here NType == 0 means Frame and 1 Reference
if you want diagram frames. I have to add the above info for hyperlinks.

q.
« Last Edit: July 17, 2013, 01:24:08 am by qwerty »

Pedro

  • EA Novice
  • *
  • Posts: 15
  • Karma: +0/-0
    • View Profile
Re: Adding a hyperlink element to a diagram
« Reply #2 on: July 17, 2013, 02:12:45 am »
God, I really did not understand you answer. Maybe I wasn't clear:



This is what I want to achieve. Currently, I am trying by using this code:

Code: [Select]
private static void AddTextElementToDiagram(Package package, Element element, int fatherIdInTheDiagram,string usNotelinkAddress, Diagram rootDiagram)
        {
            Element elemHyperlink = null;
            try
            {
                
                elemHyperlink = (Element)package.Elements.AddNew("$inet://" + usNotelinkAddress, "Text");
                elemHyperlink.StyleEx = "DUID=6CDA3456;HideIcon=1;";
                elemHyperlink.Notes = "To US in Rally";
                elemHyperlink.Update();
                package.Update();
            }
            catch { }
            // get the position of the Element
            DiagramObject diaObj = null;
            foreach (DiagramObject dObj in rootDiagram.DiagramObjects)
            {
                if (dObj.ElementID == fatherIdInTheDiagram)
                {
                    diaObj = dObj;
                    break;
                }
            }
            int left = diaObj.left + 2 * (diaObj.right - diaObj.left);
            int right = diaObj.right + 2 * (diaObj.right - diaObj.left);

            string position = String.Format("l={0};r={1};t={2};b={3};", left, right, diaObj.top, diaObj.bottom);
            DiagramObject diaObject = (DiagramObject)rootDiagram.DiagramObjects.AddNew(position, "");
            rootDiagram.Update();
            diaObject.ElementID = elemHyperlink.ElementID;
            diaObject.Update();
            package.Elements.Refresh();
            // make a connector
            Connector con = (Connector)element.Connectors.AddNew("test", "NoteLink");
            con.SupplierID = elemHyperlink.ElementID;
            con.Update();
            element.Connectors.Refresh();

Which results in a single Text, without the link.

Please, can you be a little more clear?

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Adding a hyperlink element to a diagram
« Reply #3 on: July 17, 2013, 06:48:49 am »
A bit my fault. I was referring to diagram hyperlinks. if you want to create a simple hyperlink it's similar. Create a Text element, set PDATA1 to 0 and add "LinkOpen=open;" to Style. Name/Alias contain the link itself. Then place this element in diagramObjects as usual.

It might be necessary to set PDATA3 to 0 as well.

The DUID above is superfluous. And HideIcon seems contra-productive. Try to omit it.

Don't blame me, I'm too lazy to learn/read Cxx languages. So I did not check your code.

There's an unresolved link in your post, but I guess the images shows the hyperlink.

q.

P.S. PDATA1 corresponds to MiscData[0]
« Last Edit: July 17, 2013, 09:11:35 am by qwerty »

Pedro

  • EA Novice
  • *
  • Posts: 15
  • Karma: +0/-0
    • View Profile
Re: Adding a hyperlink element to a diagram
« Reply #4 on: July 17, 2013, 08:03:42 pm »
Quote
It might be necessary to set PDATA3 to 0 as well.

I understood the relation between the MiscData and PDATA; MiscData is how you access the PDATA properties. But I'm struggling in this part. The MiscData property is readonly. If I am creating a new text element, how to set them?

Sorry for the broken link, but was just a print from a element connected to a hyperlink, precisely.

Best,

Pedro

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Adding a hyperlink element to a diagram
« Reply #5 on: July 17, 2013, 08:34:02 pm »
The only way is to write a SQL:
Code: [Select]
Repository.Execute ("UPDATE t_object SET ... WHERE Object_ID = <...>")Use that after you have created the element and called Update.

q.

Pedro

  • EA Novice
  • *
  • Posts: 15
  • Karma: +0/-0
    • View Profile
Re: Adding a hyperlink element to a diagram
« Reply #6 on: July 17, 2013, 10:38:57 pm »
Thanks for all the feedback! It is working as I wish now, but I'm not using the Repository.Execute. For the record, I'm doing the following:

Create the element which will be the hyperlink:
Code: [Select]
hyperlink = (Element)package.Elements.AddNew("$inet://" + usNotelinkAddress, "Text");
 hyperlink.Subtype = 19;
 hyperlink.Alias = "To US in Rally";
 hyperlink.Name = "$inet://" + usNotelinkAddress;
 hyperlink.Update();
 package.Update();

I call attention for the subtype 19. It is what the difference in the end. Unfortunately, it is not documented in the Sparx (terrible) documentation. Also, the  "$inet://" string makes the hyperlink to open inside EA owns "web browser", which is what I want. If you do not add it, the hyperlink will open in your default browser.

Create the Diagram Object in the diagram and link the hyperlink element created before to it:
Code: [Select]
DiagramObject diaObject = (DiagramObject)rootDiagram.DiagramObjects.AddNew(position, "");
 rootDiagram.Update();
 diaObject.ElementID = hyperlink.ElementID;
 diaObject.Style = "DUID=6CDA3456;HideIcon=1;";
 diaObject.Update();
 package.Elements.Refresh();

Set the Style was necessary for me, since I do not want the hyperlink icon appearing. But I have no idea what the DUID is about :P

Last step, we need to make a connector.
Code: [Select]
Connector con = (Connector)element.Connectors.AddNew("", "NoteLink");
con.SupplierID = hyperlink.ElementID;
con.Update();
element.Connectors.Refresh();

My connector has my element as origin and my hyperlink as destination; you can switch that by creating the connector in the hyperlink element and setting the SupplierID property with your element ID. I believe makes no difference, but all I know is that I know nothing...

Thanks again for the help!

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Adding a hyperlink element to a diagram
« Reply #7 on: July 18, 2013, 01:03:27 am »
I have also no idea about the DUID. But I know that you can safely omit it. EA however will eventually create a new DUID entry in some cases.

q.

Pedro

  • EA Novice
  • *
  • Posts: 15
  • Karma: +0/-0
    • View Profile
Re: Adding a hyperlink element to a diagram
« Reply #8 on: August 16, 2013, 10:12:12 pm »
Just to keep in the same thread: it is possible to change the size of the hyperlink from the code? They are too wide, like:

"[This is may hyperlink                                               ]"

And then, in the end, they seem not well positioned since the arrows point to the middle.

I just see position properties when creating the diagram object...

Best,

Dusso

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Adding a hyperlink element to a diagram
« Reply #9 on: August 17, 2013, 01:08:07 am »
They are diagramObjects as other elements. So you can change their RectXX values to change size and position.

q.
« Last Edit: August 17, 2013, 01:08:47 am by qwerty »