com.vaadin.flow.component.spreadsheet.
Class DefaultHyperlinkCellClickHandler
- java.lang.Object
-
- com.vaadin.flow.component.spreadsheet.DefaultHyperlinkCellClickHandler
-
All Implemented Interfaces:
public class DefaultHyperlinkCellClickHandler extends Object implements Spreadsheet.HyperlinkCellClickHandler
Default implementation of the
Spreadsheet.HyperlinkCellClickHandler
interface. Handles links to cells in either the same or some other sheet, as well as external URLs.Since:
1.0
Author:
Vaadin Ltd.
See Also:
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
DefaultHyperlinkCellClickHandler.HyperlinkOpenStyle
Choose how external links should open
-
Constructor Summary
Constructors Constructor Description DefaultHyperlinkCellClickHandler(Spreadsheet spreadsheet)
DefaultHyperlinkCellClickHandler(Spreadsheet spreadsheet, DefaultHyperlinkCellClickHandler.HyperlinkOpenStyle openStyle)
-
Method Summary
All Methods Modifier and Type Method Description protected String
getFirstArgumentFromFormula(org.apache.poi.ss.usermodel.Cell cell)
we parse the formula with a formula/POI trick so we don't have to use tricky regular expressions that hit terminal runaway evaluation cases see: https://www.regular-expressions.info/catastrophic.html Instead, translate
String
getHyperlinkFunctionTarget(org.apache.poi.ss.usermodel.Cell cell)
Should only be called for cells
isHyperlinkFormulaCell(Cell)
returns true.protected DefaultHyperlinkCellClickHandler.HyperlinkOpenStyle
getOpenStyle()
expose for subclasses
protected Spreadsheet
getSpreadsheet()
expose for subclasses
static boolean
isHyperlinkFormulaCell(org.apache.poi.ss.usermodel.Cell cell)
Returns true if the cell contains a hyperlink function.
void
onHyperLinkCellClick(org.apache.poi.ss.usermodel.Cell cell, org.apache.poi.ss.usermodel.Hyperlink hyperlink)
Called when a hyperlink cell has been clicked.
protected void
openExternalLink(String address)
Uses the
DefaultHyperlinkCellClickHandler.HyperlinkOpenStyle
to open link addresses.void
setOpenStyle(DefaultHyperlinkCellClickHandler.HyperlinkOpenStyle openStyle)
-
-
-
Constructor Detail
-
DefaultHyperlinkCellClickHandler
public DefaultHyperlinkCellClickHandler(Spreadsheet spreadsheet)
Parameters:
spreadsheet
-
-
DefaultHyperlinkCellClickHandler
public DefaultHyperlinkCellClickHandler(Spreadsheet spreadsheet, DefaultHyperlinkCellClickHandler.HyperlinkOpenStyle openStyle)
Parameters:
spreadsheet
-openStyle
- defaults toDefaultHyperlinkCellClickHandler.HyperlinkOpenStyle.NewTab
if null
-
-
Method Detail
-
getSpreadsheet
protected Spreadsheet getSpreadsheet()
expose for subclasses
Returns:
Spreadsheet for this handler
-
getOpenStyle
protected DefaultHyperlinkCellClickHandler.HyperlinkOpenStyle getOpenStyle()
expose for subclasses
Returns:
the openStyle
-
setOpenStyle
public void setOpenStyle(DefaultHyperlinkCellClickHandler.HyperlinkOpenStyle openStyle)
Parameters:
openStyle
- the openStyle to set (uses NewTab if null)
-
onHyperLinkCellClick
public void onHyperLinkCellClick(org.apache.poi.ss.usermodel.Cell cell, org.apache.poi.ss.usermodel.Hyperlink hyperlink)
Called when a hyperlink cell has been clicked.
Specified by:
onHyperLinkCellClick
in interfaceSpreadsheet.HyperlinkCellClickHandler
Parameters:
cell
-hyperlink
- may be null, only for Excel link relations, not formula
-
getHyperlinkFunctionTarget
public String getHyperlinkFunctionTarget(org.apache.poi.ss.usermodel.Cell cell)
Should only be called for cells
isHyperlinkFormulaCell(Cell)
returns true. Returns the target for tooltip use by default.The address is inside the first argument:
HYPERLINK("address","friendly name")
orHYPERLINK("#!viewName[/arguments]","friendly name")
orHYPERLINK(D5,"friendly name")
orHYPERLINK([arbitrary formula],"friendly name")
Specified by:
getHyperlinkFunctionTarget
in interfaceSpreadsheet.HyperlinkCellClickHandler
Parameters:
cell
- Target cell containing a hyperlink functionReturns:
the address that the hyperlink function points to
-
getFirstArgumentFromFormula
protected String getFirstArgumentFromFormula(org.apache.poi.ss.usermodel.Cell cell)
we parse the formula with a formula/POI trick so we don't have to use tricky regular expressions that hit terminal runaway evaluation cases see: https://www.regular-expressions.info/catastrophic.html Instead, translate
HYPERLINK(arg1[, arg2]) to IF(true, arg1[, arg2])
-
isHyperlinkFormulaCell
public static final boolean isHyperlinkFormulaCell(org.apache.poi.ss.usermodel.Cell cell)
Returns true if the cell contains a hyperlink function.
Parameters:
cell
- Cell to investigateReturns:
True if hyperlink is found
-
openExternalLink
protected void openExternalLink(String address)
Uses the
DefaultHyperlinkCellClickHandler.HyperlinkOpenStyle
to open link addresses. Subclass and override to use something else with the address.Parameters:
address
- to navigate to
-
-