Skip to content

Commit

Permalink
Fixed #503 Support adding ScreenTip text when creating links.
Browse files Browse the repository at this point in the history
  • Loading branch information
ylussaud committed Dec 1, 2023
1 parent 99030b8 commit 5dd5c14
Show file tree
Hide file tree
Showing 44 changed files with 170 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,11 @@ private enum Dir {
*/
private URI linkTargetURI;

/**
* The current link title if any, <code>null</code> otherwise.
*/
private String linkTitle;

/**
* The numbering ID.
*/
Expand Down Expand Up @@ -333,6 +338,7 @@ private Context copy() {
Context res = new Context(baseURI, mStyle);

res.linkTargetURI = linkTargetURI;
res.linkTitle = linkTitle;
res.numbering = numbering;
res.numberingID = numberingID;
res.numberingLevel = numberingLevel;
Expand Down Expand Up @@ -1215,7 +1221,7 @@ private void insertText(MParagraph parent, final Context context, TextNode node,
} else {
context.style.setForegroundColor(LINK_COLOR);
final MHyperLink mLink = new MHyperLinkImpl(textToInsert, context.style,
context.linkTargetURI.toString());
context.linkTargetURI.toString(), context.linkTitle);
parentContents.add(mLink);
}
}
Expand Down Expand Up @@ -1369,6 +1375,9 @@ private MParagraph startElement(MParagraph parent, Context context, Element elem
res = parent;
} else if ("a".equals(nodeName)) {
context.linkTargetURI = toURI(context.baseURI, element.attr(HREF));
if (element.hasAttr("title")) {
context.linkTitle = element.attr("title");
}
res = parent;
} else if ("br".equals(nodeName)) {
final MList parentContents = (MList) parent.getContents();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2017 Obeo.
* Copyright (c) 2017, 2023 Obeo.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -33,4 +33,19 @@ public interface MHyperLink extends MText {
*/
void setUrl(String url);

/**
* Gets the tool tip.
*
* @return the tool tip
*/
String getToolTip();

/**
* Sets the tool tip.
*
* @param toolTip
* the new tool tip
*/
void setToolTip(String toolTip);

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2017 Obeo.
* Copyright (c) 2017, 2023 Obeo.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
Expand All @@ -26,6 +26,11 @@ public class MHyperLinkImpl extends MTextImpl implements MHyperLink {
*/
private String url;

/**
* The tool tip.
*/
private String toolTip;

/**
* Constructor.
*
Expand All @@ -37,8 +42,25 @@ public class MHyperLinkImpl extends MTextImpl implements MHyperLink {
* the url
*/
public MHyperLinkImpl(String text, MStyle style, String url) {
this(text, style, url, null);
}

/**
* Constructor.
*
* @param text
* the text
* @param style
* the {@link MStyle}
* @param url
* the url
* @param toolTip
* the tool tip
*/
public MHyperLinkImpl(String text, MStyle style, String url, String toolTip) {
super(text, style);
this.url = url;
this.toolTip = toolTip;
}

@Override
Expand All @@ -50,4 +72,15 @@ public String getUrl() {
public void setUrl(String url) {
this.url = url;
}

@Override
public String getToolTip() {
return toolTip;
}

@Override
public void setToolTip(String toolTip) {
this.toolTip = toolTip;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,10 @@ private XWPFParagraph insertMHyperLink(XWPFParagraph paragraph, XWPFRun run, MHy
.addExternalRelationship(hyperLink.getUrl(), XWPFRelation.HYPERLINK.getRelation()).getId();
final CTHyperlink cLink = res.getCTP().addNewHyperlink();
cLink.setId(id);
final String toolTip = hyperLink.getToolTip();
if (toolTip != null) {
cLink.setTooltip(toolTip);
}

if (hyperLink.getStyle() != null) {
applyMStyle(linkRun, hyperLink.getStyle());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2016 Obeo.
* Copyright (c) 2016, 2023 Obeo.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -42,6 +42,24 @@ public class LinkServices {
)
// @formatter:on
public MHyperLink asLink(String text, String url) {
return asLink(text, url, null);
}

// @formatter:off
@Documentation(
value = "Converts a String to an hyperlink",
params = {
@Param(name = "text", value = "The label of the link"),
@Param(name = "url", value = "The destination of the link"),
@Param(name = "toolTip", value = "The tool tip of the link"),
},
result = "A link with the given label that point to the given url.",
examples = {
@Example(expression = "'My website'.asLink('https://www.example.org', 'My tool tip')", result = "a link to https://www.example.org with the label My website with a tool tip"),
}
)
// @formatter:on
public MHyperLink asLink(String text, String url, String toolTip) {
final String localText;
if (text != null) {
localText = text;
Expand All @@ -55,7 +73,7 @@ public MHyperLink asLink(String text, String url) {
localURL = "";
}

return new MHyperLinkImpl(localText, null, localURL);
return new MHyperLinkImpl(localText, null, localURL, toolTip);
}

// @formatter:off
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

=== HEADER ===

=== BODY ===

A simple demonstration of a query :
[query: .fromHTMLURI('doc.html')]
End of demonstration.
=== FOOTER ===

=== TEMPLATES ===
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<genconf:Generation xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:genconf="http://www.obeonetwork.org/m2doc/genconf/1.0" name="a" templateFileName="a-template.docx" resultFileName="a-actual-generation.docx" validationFileName="a-actual-validation.docx"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<html>
<head>
</head>
<body>
<a href="https://www.obeo.fr" title="This is a title/tooltip">Obeo's website</a>
</body>
</html>


Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

=== HEADER ===

=== BODY ===

A simple demonstration of an http hyperlink:
[query: .asLink('Mona Lisa', 'Mona_Lisa.jpg', 'The Mona Lisa painting')]
End of demonstration.
=== FOOTER ===

=== TEMPLATES ===
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="ASCII"?>
<genconf:Generation xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:genconf="http://www.obeonetwork.org/m2doc/genconf/1.0" name="asLinkFile" templateFileName="asLinkFile-template.docx" resultFileName="asLinkFile-actual-generation.docx" validationFileName="asLinkFile-actual-validation.docx"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

=== HEADER ===

=== BODY ===

A simple demonstration of an http hyperlink:
[query: .asLink('Obeo's website', 'http://www.obeo.fr', 'A link to Obeo's website.')]
End of demonstration.
=== FOOTER ===

=== TEMPLATES ===
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="ASCII"?>
<genconf:Generation xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:genconf="http://www.obeonetwork.org/m2doc/genconf/1.0" name="asLinkHttpWithStyle" templateFileName="asLinkHttpWithStyle-template.docx" resultFileName="asLinkHttpWithStyle-actual-generation.docx" validationFileName="asLinkHttpWithStyle-actual-validation.docx"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

=== HEADER ===

=== BODY ===

A simple demonstration of an http hyperlink:
[query: .asLink('Obeo's website', 'http://www.obeo.fr', 'This will open the Obeo website.')]
End of demonstration.
=== FOOTER ===

=== TEMPLATES ===
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="ASCII"?>
<genconf:Generation xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:genconf="http://www.obeonetwork.org/m2doc/genconf/1.0" name="asLinkHttp" templateFileName="asLinkHttp-template.docx" resultFileName="asLinkHttp-actual-generation.docx" validationFileName="asLinkHttp-actual-validation.docx"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

=== HEADER ===

=== BODY ===

[query: .asLink('some link', 'http://www.obeo.fr', 'Some tool tip.')]

=== FOOTER ===

=== TEMPLATES ===
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="ASCII"?>
<genconf:Generation xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:genconf="http://www.obeonetwork.org/m2doc/genconf/1.0" name="asLinkHttpWithoutRPr" templateFileName="asLinkHttpWithoutRPr-template.docx" resultFileName="asLinkHttpWithoutRPr-actual-generation.docx" validationFileName="asLinkHttpWithoutRPr-actual-validation.docx"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

=== HEADER ===

=== BODY ===

A simple demonstration of an http hyperlink:
[query: .asLink('Yvan Lussaud', 'mailto:[email protected]', 'Send me an email !')]
End of demonstration.
=== FOOTER ===

=== TEMPLATES ===
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="ASCII"?>
<genconf:Generation xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:genconf="http://www.obeonetwork.org/m2doc/genconf/1.0" name="asLinkMailto" templateFileName="asLinkMailto-template.docx" resultFileName="asLinkMailto-actual-generation.docx" validationFileName="asLinkMailto-actual-validation.docx"/>

0 comments on commit 5dd5c14

Please sign in to comment.