Hyperlink Event"

From Documentation
(Created page with '{{ZKSpreadsheetEssentialsPageHeader}} __TOC__ Users can write hyperlink event listener for events such as hyperlink click. ===Purpose=== Implement hyperlink event listener for …')
 
m (correct highlight (via JWB))
 
(8 intermediate revisions by 4 users not shown)
Line 1: Line 1:
 
{{ZKSpreadsheetEssentialsPageHeader}}
 
{{ZKSpreadsheetEssentialsPageHeader}}
 +
 +
{{Deprecated|url=http://books.zkoss.org/wiki/ZK_Spreadsheet_Essentials}}
  
 
__TOC__
 
__TOC__
Line 7: Line 9:
 
Implement hyperlink event listener for hyperlink event such as hyperlink click.
 
Implement hyperlink event listener for hyperlink event such as hyperlink click.
 
===Hyperlink event===
 
===Hyperlink event===
* '''onHyperlink''' - This event is fired when user clicks on ZK Spreadsheet cell associated with a hyperlink. Event listeners are provided with <javadoc>org.zkoss.zss.ui.event.HyperlinkEvent</javadoc> in the event listener.
+
* '''onHyperlink''' - This event is fired when user clicks on ZK Spreadsheet cell associated with a hyperlink. Event listeners are provided with <javadoc directory="zss">org.zkoss.zss.ui.event.HyperlinkEvent</javadoc> in the event listener.
  
  
 
===Registering Hyperlink Event===
 
===Registering Hyperlink Event===
Hyperlink event can be registered to ZK Spreadsheet either by calling <javadoc method="addEventListener(java.lang.String, org.zkoss.zk.ui.event.EventListener)">org.zkoss.zk.ui.AbstractComponent</javadoc> 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
+
Hyperlink event can be registered to ZK Spreadsheet either by calling <javadoc directory="zss" method="addEventListener(java.lang.String, org.zkoss.zk.ui.event.EventListener)">org.zkoss.zk.ui.AbstractComponent</javadoc> or by using [[ZK_Developer's_Reference/MVC| ZK MVC]] way i.e. using naming convention of <hyperlink-event-name>$<component-id>. Here is an example shown using first way
  
 
<source lang="java">
 
<source lang="java">
Line 23: Line 25:
 
...
 
...
 
</source>
 
</source>
'''Note''': All ZK Spreadsheet supported mouse events have a corresponding static constants declared in <code>org.zkoss.zss.ui.event.Events</code> class. For example for onCellClick event there is <code>org.zkoss.zss.ui.event.Events.ON_CELL_CLICK</code> and so on.
+
'''Note''': All ZK Spreadsheet supported mouse events have a corresponding static constants declared in <code>org.zkoss.zss.ui.event.Events</code> class. For example for onHyperlink event there is <code>org.zkoss.zss.ui.event.Events.ON_HYPERLINK</code> and so on.
  
 
Here is an example shown using second way
 
Here is an example shown using second way
Line 33: Line 35:
 
...
 
...
 
</source>
 
</source>
 +
 
===ZUML===
 
===ZUML===
 
<source lang="xml">
 
<source lang="xml">
Line 48: Line 51:
  
 
===Composer===
 
===Composer===
<source lang="java">
+
In composer below we define onHyperlink event handler. You can retrieve href using <javadoc directory="zss" method="getHref()">org.zkoss.zss.ui.event.HyperlinkEvent</javadoc> and also keys pressed using <javadoc directory="zss" 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" highlight="7,8">
<source lang="java" high="7,8">
 
 
public class HyperlinkEventComposer extends GenericForwardComposer {
 
public class HyperlinkEventComposer extends GenericForwardComposer {
  
Line 80: Line 82:
 
}
 
}
 
</source>
 
</source>
 +
 +
View the complete source of composer [https://code.google.com/p/zkbooks/source/browse/trunk/zssessentials/examples/src/org/zkoss/zssessentials/events/HyperlinkEventComposer.java here]
 +
 +
=Version History=
 +
{{LastUpdated}}
 +
{| border='1px' | width="100%"
 +
! Version !! Date !! Content
 +
|-
 +
| &nbsp;
 +
| &nbsp;
 +
| &nbsp;
 +
|}
 +
 +
{{ZKSpreadsheetEssentialsPageFooter}}

Latest revision as of 12:57, 19 January 2022


Stop.png This article is out of date, please refer to http://books.zkoss.org/wiki/ZK_Spreadsheet_Essentials for more up to date information.

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;
		}
	}
}

View the complete source of composer here

Version History

Last Update : 2022/01/19


Version Date Content
     


All source code listed in this book is at Github.


Last Update : 2022/01/19

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