Context Menu

From Documentation
Revision as of 06:38, 22 August 2013 by Hawk (talk | contribs)



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.


Purpose

ZK Spreadsheet supports various context menus to support row/column/cell actions for individual or selected number of cells.

Show Context Menu

Use Spreadsheet.setShowContextMenu to show context menu.

Row

ZKSsEss Spreadsheet Toolbar rowContextMenu.png

For row context menu use ActionHandler for each menuitem. By default, ActionHandler does nothing when users clicks on Paste Special, Format Cell and Row Height, to use customized ActionHandler <refer to here.

Paste Special

Refer to here

Format Cell

By default, ActionHandler does nothing when users clicks the button, developer are able to override ActionHandler.doFormatCell

	@Override
	public void doFormatCell(Rect selection) {
		Spreadsheet spreadsheet = getSpreadsheet();
		if (spreadsheet.getBook() != null && isValidSelection(selection)) {
			FormatDialog dialog = new FormatDialog(selection);
			//omit	
		}
	}

Refer to sample code formatDialog.zul and CustomizedActionHandler.java

Row Height

By default, ActionHandler does nothing when users clicks the button, developers are able to override ActionHandler.doRowHeight

	@Override
	public void doRowHeight(Rect selection) {
		Spreadsheet spreadsheet = getSpreadsheet();
		if (spreadsheet.getBook() != null && isValidSelection(selection)) {
			HeaderSizeDialog dialog = new HeaderSizeDialog("row", selection);
			//omit	
		}
	}

Refer to sample code headerSizeDialog.zul and CustomizedActionHandler.java

Column

ZKSsEss Spreadsheet Toolbar columnContextMenu.png

For column context menu use ActionHandler for each button/menuitem. By default, ActionHandler does nothing when users clicks Paste Special, Format Cell and Column Width, to use customized ActionHandler refer to here .

Paste Special

Refer to here

Format Cell

Refer to here

Column Width

By default, ActionHandler does nothing when user click the button, developers are able to override ActionHandler.doColumnWidth

	@Override
	public void doColumnWidth(Rect selection) {
		Spreadsheet spreadsheet = getSpreadsheet();
		if (spreadsheet.getBook() != null && isValidSelection(selection)) {
			HeaderSizeDialog dialog = new HeaderSizeDialog("column", selection);
			//omit
		}
	}

Refer to sample code headerSizeDialog.zul and CustomizedActionHandler.java

Cell

ZKSsEss Spreadsheet Toolbar cellContextMenu.png

For cell context menu, use ActionHandler for each button/menuitem. By default, ActionHandler does nothing when users click Paste Special, Format Cell and Hyperlink, to use customized ActionHandler refer to here.

Paste Special

Refer to here

Format Cell

Refer to here

Hyperlink

Refer to here

I18N

Each menuitem maps to a key, developers can browse all I18 keys by Action.getLabelKeys

Here are the partial keys for context menu

Action I18 Key
Cut zss.cut
Copy zss.copy
Paste Special zss.pasteSpecial
Insert zss.insert
Insert Rows zss.insertSheetRow
Insert Columns zss.insertSheetColumn
Shift Cell Right zss.shiftCellRight
Shift Cell Down zss.shiftCellDown
Delete zss.del
Delete Rows zss.deleteSheetRow
Delete Columns zss.deleteSheetColumn
Shift Cell Left zss.shiftCellLeft
Shift Cell Up zss.shiftCellUp
Clear Context zss.clearContent
Format Cell zss.formatCell
Row Height zss.rowHeight
Column Width zss.columnWidth
Hide Row zss.hideRow
Unhide Row zss.unhideRow
Hide Column zss.hideColumn
Unhide Column zss.unhideColumn
Filter zss.filter
Reapply Filter zss.reapplyFilter
Sort zss.sort
Sort Ascending zss.sortAscending
Sort Descending zss.sortDescending
Custom Sort zss.customSort
Hyperlink zss.hyperlink

Refer to sample i3-label.properties

ZUML

Here is an example of a ZUL file

<zk>
	<window vflex="1" width="100%" apply="org.zkoss.zssessentials.config.ContextMenuComposer">
		<button id="toggleContextMenu" label="Toggle Context Menu"/>
		<spreadsheet showContextMenu="true"
			id="ss" vflex="true" width="100%"
			src="/WEB-INF/excel/config/ZSS-demo_sample.xlsx" maxcolumns="40" maxrows="200"
			></spreadsheet>
	</window>
</zk>

View complete source of ZUML contextMenu.zul

Composer

The composer uses Spreadsheet.setShowContextMenu to show or hide context menu.

	public void onClick$toggleContextMenu() {
		boolean toggle = !spreadsheet.isShowContextMenu();
		spreadsheet.setShowContextMenu(toggle);
	}

See the full source code for Composer here

Version History

Last Update : 2013/08/22


Version Date Content
2.3.0 April, 2012 Context Menu
     


All source code listed in this book is at Github.

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