Hyperlink Event"
(Created page with '{{ZKSpreadsheetEssentialsPageHeader}} __TOC__ Users can write hyperlink event listener for events such as hyperlink click. ===Purpose=== Implement hyperlink event listener for …') |
|||
Line 48: | Line 48: | ||
===Composer=== | ===Composer=== | ||
− | |||
In composer below we define onHyperlink event handler. You can retrieve href using <javadoc method="getHref()">org.zkoss.zss.ui.event.HyperlinkEvent</javadoc> and also keys pressed using <javadoc method="getKeys()">org.zkoss.zss.ui.event.HyperlinkEvent<javadoc>. | In composer below we define onHyperlink event handler. You can retrieve href using <javadoc method="getHref()">org.zkoss.zss.ui.event.HyperlinkEvent</javadoc> and also keys pressed using <javadoc method="getKeys()">org.zkoss.zss.ui.event.HyperlinkEvent<javadoc>. | ||
<source lang="java" high="7,8"> | <source lang="java" high="7,8"> | ||
Line 80: | Line 79: | ||
} | } | ||
</source> | </source> | ||
+ | =Version History= | ||
+ | {{LastUpdated}} | ||
+ | {| border='1px' | width="100%" | ||
+ | ! Version !! Date !! Content | ||
+ | |- | ||
+ | | | ||
+ | | | ||
+ | | | ||
+ | |} | ||
+ | |||
+ | {{ZKSpreadsheetEssentialsPageFooter}} |
Revision as of 07:09, 24 November 2010
Users can write hyperlink event listener for events such as hyperlink click.
Purpose
Implement hyperlink event listener for hyperlink event such as hyperlink click.
Hyperlink event
- onHyperlink - This event is fired when user clicks on ZK Spreadsheet cell associated with a hyperlink. Event listeners are provided with HyperlinkEvent in the event listener.
Registering Hyperlink Event
Hyperlink event can be registered to ZK Spreadsheet either by calling AbstractComponent.addEventListener(String, EventListener) or by using ZK MVC way i.e. using naming convention of <hyperlink-event-name>$<component-id>. Here is an example shown using first way
...
ss.addEventListener(org.zkoss.zss.ui.event.Events.ON_HYPERLINK,
new EventListener() {
public void onEvent(Event event) throws Exception {
doHyperlinkEvent((HyperlinkEvent) event);
}
});
...
Note: All ZK Spreadsheet supported mouse events have a corresponding static constants declared in org.zkoss.zss.ui.event.Events
class. For example for onCellClick event there is org.zkoss.zss.ui.event.Events.ON_CELL_CLICK
and so on.
Here is an example shown using second way
...
public void onHyperlink$ss(HyperlinkEvent event) {
// do hyperlink event processing
}
...
ZUML
<?page title="ZSS" contentType="text/html;charset=UTF-8"?>
<zk>
<window title="ZSS Hyperlink Events" border="normal" width="100%"
height="100%" apply="org.zkoss.zssessentials.events.HyperlinkEventComposer">
<label value="Keys:"></label><label id="keysLbl"></label>
<spreadsheet id="ss" width="800px" height="800px" maxrows="35"
maxcolumns="10" src="/WEB-INF/excel/events/events.xlsx">
</spreadsheet>
</window>
</zk>
Example above loads an excel file with a cell value having a hyperlink.
Composer
In composer below we define onHyperlink event handler. You can retrieve href using HyperlinkEvent.getHref() and also keys pressed using <javadoc method="getKeys()">org.zkoss.zss.ui.event.HyperlinkEvent<javadoc>.
public class HyperlinkEventComposer extends GenericForwardComposer {
Spreadsheet ss;
Label keysLbl;
public void onHyperlink$ss(HyperlinkEvent event) {
String href = event.getHref();
int key = event.getKeys();
switch (key) {
case HyperlinkEvent.ALT_KEY | HyperlinkEvent.LEFT_CLICK:
keysLbl.setValue("ALT+LEFT CLICK");
break;
case HyperlinkEvent.CTRL_KEY | HyperlinkEvent.LEFT_CLICK:
keysLbl.setValue("CTRL+LEFT CLICK");
break;
case HyperlinkEvent.SHIFT_KEY | HyperlinkEvent.LEFT_CLICK:
keysLbl.setValue("SHIFT_KEY+LEFT CLICK");
break;
case HyperlinkEvent.LEFT_CLICK:
keysLbl.setValue("LEFT CLICK");
break;
default:
keysLbl.setValue("NONE");
break;
}
}
}
Version History
Version | Date | Content |
---|---|---|
All source code listed in this book is at Github.