Toolbar"

From Documentation
m
Line 17: Line 17:
  
  
Each toolbar's button represent a action, the ActionHandler process action when user click it.  
+
Each toolbar's button represents an action, the ActionHandler process action when user click it.  
 
<br/>For example, the paste toolbarbutton and menuitem represent <javadoc directory="zss"  method="PASTE">org.zkoss.zss.ui.Action</javadoc>, deveoper could override  
 
<br/>For example, the paste toolbarbutton and menuitem represent <javadoc directory="zss"  method="PASTE">org.zkoss.zss.ui.Action</javadoc>, deveoper could override  
 
default behavior by override <javadoc directory="zss"  method="doPaste">org.zkoss.zss.ui.sys.ActionHandler</javadoc>
 
default behavior by override <javadoc directory="zss"  method="doPaste">org.zkoss.zss.ui.sys.ActionHandler</javadoc>
Line 242: Line 242:
  
 
Refer to sample [http://code.google.com/p/zkbooks/source/browse/trunk/zssessentials/examples/WebContent/WEB-INF/i3-label.properties i3-label.properties]
 
Refer to sample [http://code.google.com/p/zkbooks/source/browse/trunk/zssessentials/examples/WebContent/WEB-INF/i3-label.properties i3-label.properties]
 +
 
===ZUML===
 
===ZUML===
 
Here is a sample example ZUL file
 
Here is a sample example ZUL file

Revision as of 07:04, 9 April 2012

WarningTriangle-32x32.png This page is under construction, so we cannot guarantee the accuracy of the content!



Purpose

ZK Spreadsheet supports various toolbar buttons to perform actions.

Show toolbar

Use Spreadsheet.setShowToolbar to show toolbar.

Action Handler

The Spreadsheet use a default ActionHandler to perform toolbar button's action. Developer could set customized ActionHandler by API Spreadsheet.setActionHandler or by library property org.zkoss.zss.ui.ActionHandler.class, refer to sample zk.xml

Each spreadsheet instance use it own ActionHandler. ActionHandler can't share across different spreadsheet instance.


Each toolbar's button represents an action, the ActionHandler process action when user click it.
For example, the paste toolbarbutton and menuitem represent Action.PASTE, deveoper could override default behavior by override ActionHandler.doPaste
ZKSsEss Spreadsheet Toolbar paste.png

New Book

ZKSsEss Spreadsheet Toolbar newBook.png
The default ActionHandler does nothing when user click the button, developer could override ActionHandler.doNewBook

	@Override
	public void doNewBook() {
		getSpreadsheet().setSrc("/WEB-INF/excel/config/blank.xlsx");
	}

Refer to sample code CustomizedActionHandler.java

Save Book

ZKSsEss Spreadsheet Toolbar saveBook.png
The default ActionHandler does nothing when user click the button, developer could override ActionHandler.doSaveBook

	@Override
	public void doSaveBook() {
		Spreadsheet spreadsheet = getSpreadsheet();
		if (spreadsheet.getBook() != null) {
			final String filePath = Executions.getCurrent().getDesktop().getWebApp().getRealPath(spreadsheet.getSrc());
			
			Exporter exporter = Exporters.getExporter("excel");
			FileOutputStream outputStream = null;
			try {
				outputStream = new FileOutputStream(new File(filePath));
				exporter.export(spreadsheet.getBook(), outputStream);
				try {
					Messagebox.show("Saved");
				} catch (InterruptedException e) {
				}
			} catch (FileNotFoundException e) {
				try {
					Messagebox.show("Save excel failed");
				} catch (InterruptedException e1) {
				}
			} finally {
				if (outputStream != null) {
					try {
						outputStream.close();
					} catch (IOException e) {
					}
				}
			}
		}			
	}

Refer to Export to Excel sample code CustomizedActionHandler.java

Export PDF

ZKSsEss Spreadsheet Toolbar exportPDF.png
The default ActionHandler does nothing when user click the button, developer could override ActionHandler.doExportPDF

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

Refer to Export to PDF and sample code exportPDFDialog.zulCustomizedActionHandler.java

Paste Special

ZKSsEss Spreadsheet Toolbar pasteSpecial.png
The default ActionHandler does nothing when user click the button, developer could override ActionHandler.doPasteSpecial

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

Refer to sample code pasteSpecialDialog.zul and CustomizedActionHandler.java

Custom Sort

ZKSsEss Spreadsheet Toolbar customSort.png
The default ActionHandler does nothing when user click the button, developer could override ActionHandler.doCustomSort

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

Refer to sample code customSortDialog.zul and CustomizedActionHandler.java

Hyperlink

ZKSsEss Spreadsheet Toolbar hyperlink.png
The default ActionHandler does nothing when user click the button, developer could override ActionHandler.doHyperlink

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

Close Book

ZKSsEss Spreadsheet Toolbar closeBookButton.png
The default ActionHandler.doCloseBook will invoke ActionHandler.toggleActionOnBookClosed, developer could override it to disable or enable action by Spreadsheet.setActionDisabled.

ZKSsEss Spreadsheet Toolbar bookClosed.png

Disabled action on book close will enable on ActionHandler.doSheetSelect, it will invoke ActionHandler.toggleActionOnSheetSelected

I18N

Each button/menuitem map to a key, developer could browser all I18 keys by Action.getLabelKeys

Here is partial keys for toolbar

Action I18 Key
Paste zss.paste
Paste Formula zss.pasteFormula
Paste Value zss.pasteValue
Paste All Except Border zss.pasteAllExceptBorder
Paste Transpose zss.pasteTranspose
Paste Special zss.pasteSpecial
Merge And Center zss.mergeAndCenter
Merge Across zss.mergeAcross
Merge Cell zss.mergeCell
Unmerge Cell zss.unmergeCell
Insert Cell zss.insertCell
Shift Cell Right zss.shiftCellRight
Shift Cell Down zss.shiftCellDown
Insert Sheet Row zss.insertSheetRow
Insert Sheet Column zss.insertSheetColumn
Delete Cell zss.deleteCell
Shift Cell Left zss.shiftCellLeft
Shift Cell Up zss.shiftCellUp
Clear zss.clear
Clear Context zss.clearContent
Clear Style zss.clearStyle
Clear All zss.clearAll
sort zss.sort
Sort And Filter zss.sortAndFilter
Sort Ascending zss.sortAscending
Sort Descending zss.sortDescending
Custom Sort zss.customSort
Filter zss.filter
Clear Filter zss.clearFilter
Reapply Filter zss.reapplyFilter
Column Chart zss.columnChart
Column Chart 3D zss.columnChart3D
Line Chart zss.lineChart
Line Chart 3D zss.lineChart3D
Pie Chart zss.pieChart
Bar Chart zss.barChart
Bar Chart 3D zss.barChart3D
Scatter Chart zss.scatterChart
Doughnut Chart zss.doughnutChart
Hyperlink zss.hyperlink

Refer to sample i3-label.properties

ZUML

Here is a sample example ZUL file

<zk>
	<window vflex="1" width="100%" apply="org.zkoss.zssessentials.config.ToolbarComposer">
		<button id="toggleToolbar" label="Toggle toolbar"/>
		<spreadsheet showToolbar="true"
			id="spreadsheet" vflex="true" width="100%"
			src="/WEB-INF/excel/config/ZSS-demo_sample.xlsx" maxcolumns="40" maxrows="200"
			></spreadsheet>
	</window>
</zk>

Composer

The composer use Spreadsheet.setShowToolbar to show or hide toolbar.

	public void onClick$toggleToolbar() {
		boolean isShowToolbar = spreadsheet.isShowToolbar();
		spreadsheet.setShowToolbar(!isShowToolbar);
	}

See the full source code for Composer here

Version History

Last Update : 2012/04/09


Version Date Content
2.3.0 April, 2012 Toolbar
     


All source code listed in this book is at Github.

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