Hyperlink Event

From Documentation
Revision as of 07:18, 24 November 2010 by Ashishd (talk | contribs)


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 onHyperlink event there is org.zkoss.zss.ui.event.Events.ON_HYPERLINK 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 HyperlinkEvent.getKeys().

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

Last Update : 2010/11/24


Version Date Content
     


All source code listed in this book is at Github.


Last Update : 2010/11/24

Copyright © Potix Corporation. This article is licensed under GNU Free Documentation License.