Multiple Hyperlinks in Generic Table

MagicDraw OpenAPI, scripting related questions and discussions

Moderator: Moderators

Multiple Hyperlinks in Generic Table

Postby talberi » Thu Sep 13, 2018 5:42 am

I'm creating a custom column in a generic table that uses the HyperlinkUtils class in the MagicDraw API to return all of the hyperlinks of a row element (using HyperlinkUtils.getAllHyperlinks). In the evaluation window I can see the hyperlink elements that I'm retrieving, so I know the script works. However, the table will not display them as hyperlinks in the cell. I think this has something to with setting the Type for the column expression, but I cannot select a type that actually shows hyperlinks in the table. The best I can do is show their URL string, but I want actual clickable hyperlinks in the table.

The thing is, if I show the Active Hyperlink column for the element, the table does provide a clickable hyperlink. But I want to show all of the element hyperlinks, not just the active one. It's strange that the generic table is able to display the active hyperlink as an actual clickable hyperlink, but does not allow a custom column to return a hyperlink element. Is there any way to get this to work?
talberi
Forum Beginner
Forum Beginner
 
Posts: 32
Posts Rating:0
Joined: Fri Nov 03, 2017 4:51 am

Re: Multiple Hyperlinks in Generic Table

Postby taylor@mitre.org » Mon Jan 23, 2023 8:49 am

I would also like to add a clickable Hyperlink in a Generic Table custom column. Below is a code snip of my Groovy script which does display the short text of the hyperlink in the table column, but the text is not active and not displayed as a hyperlink. Is there a way to create and display a hyperlink in a custom column?

def project = Application.getInstance().getProject()
def String diagramName = diagramNameArg.getAt(0)
def String qualifiedName = qualifiedNameArg.getAt(0)
def output = []
def Element element = Finder.byQualifiedName().find(project, qualifiedName)

if (element != null) {

def Hyperlink clickable = HyperlinkUtils.createHyperlink(diagramName, element)
HyperlinkUtils.addHyperlink(element, clickable)

if (HyperlinkUtils.hasHyperlink(element)) {

HyperlinkUtils.makeActive(element, clickable)

def String shortText = HyperlinkUtils.getDisplayableHyperlinkText(clickable).getShortText()
def String url = clickable.getUrl()
def String linkString = "<a href='${url}'>${shortText}</a>"
Comment comment = ModelHelper.getCommentElement(element)
def String plainString = HtmlTextUtils.removeHtmlBodyPTags(comment.getBody())
def String newComment = plainString + " " + linkString
def String htmlString = HtmlTextUtils.wrapInHtmlBodyPTags(newComment)

output.add(htmlString)
}
}
taylor@mitre.org
Forum Newbie
Forum Newbie
 
Posts: 1
Posts Rating:0
Joined: Fri Feb 19, 2021 1:38 pm


Return to Programmatic Extendibility

Who is online

Users browsing this forum: No registered users and 0 guests

cron