Context Menu"
m (correct highlight (via JWB)) |
|||
Line 24: | Line 24: | ||
By default, <b>ActionHandler</b> does nothing when users clicks the button, developer are able to override <javadoc directory="zss" method="doFormatCell">org.zkoss.zss.ui.sys.ActionHandler</javadoc> | By default, <b>ActionHandler</b> does nothing when users clicks the button, developer are able to override <javadoc directory="zss" method="doFormatCell">org.zkoss.zss.ui.sys.ActionHandler</javadoc> | ||
− | <source lang="java" | + | <source lang="java" highlight="2"> |
@Override | @Override | ||
public void doFormatCell(Rect selection) { | public void doFormatCell(Rect selection) { | ||
Line 40: | Line 40: | ||
By default, <b>ActionHandler</b> does nothing when users clicks the button, developers are able to override <javadoc directory="zss" method="doRowHeight">org.zkoss.zss.ui.sys.ActionHandler</javadoc> | By default, <b>ActionHandler</b> does nothing when users clicks the button, developers are able to override <javadoc directory="zss" method="doRowHeight">org.zkoss.zss.ui.sys.ActionHandler</javadoc> | ||
− | <source lang="java" | + | <source lang="java" highlight="2"> |
@Override | @Override | ||
public void doRowHeight(Rect selection) { | public void doRowHeight(Rect selection) { | ||
Line 66: | Line 66: | ||
By default, <b>ActionHandler</b> does nothing when user click the button, developers are able to override <javadoc directory="zss" method="doColumnWidth">org.zkoss.zss.ui.sys.ActionHandler</javadoc> | By default, <b>ActionHandler</b> does nothing when user click the button, developers are able to override <javadoc directory="zss" method="doColumnWidth">org.zkoss.zss.ui.sys.ActionHandler</javadoc> | ||
− | <source lang="java" | + | <source lang="java" highlight="2"> |
@Override | @Override | ||
public void doColumnWidth(Rect selection) { | public void doColumnWidth(Rect selection) { | ||
Line 162: | Line 162: | ||
Here is an example of a ZUL file | Here is an example of a ZUL file | ||
− | <source lang="xml" | + | <source lang="xml" highlight="4"> |
<zk> | <zk> | ||
<window vflex="1" width="100%" apply="org.zkoss.zssessentials.config.ContextMenuComposer"> | <window vflex="1" width="100%" apply="org.zkoss.zssessentials.config.ContextMenuComposer"> | ||
Line 178: | Line 178: | ||
===Composer=== | ===Composer=== | ||
The composer uses <javadoc directory="zss" method="setShowContextMenu">org.zkoss.zss.ui.Spreadsheet</javadoc> to show or hide context menu. | The composer uses <javadoc directory="zss" method="setShowContextMenu">org.zkoss.zss.ui.Spreadsheet</javadoc> to show or hide context menu. | ||
− | <source lang="java" | + | <source lang="java" highlight="3"> |
public void onClick$toggleContextMenu() { | public void onClick$toggleContextMenu() { | ||
boolean toggle = !spreadsheet.isShowContextMenu(); | boolean toggle = !spreadsheet.isShowContextMenu(); |
Latest revision as of 12:55, 19 January 2022
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
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
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
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
Version | Date | Content |
---|---|---|
2.3.0 | April, 2012 | Context Menu |
All source code listed in this book is at Github.