Collaboration Edit

From Documentation


Available in ZK Spreadsheet EE only

ZK Spreadsheet supports Collaboration Edit automatically as long as two or more Spreadsheet UI components share a common book with proper scope.

Purpose

Share a common book and allow collaboration editing on the book.

The Common Shared Book

Following, we show you a very typical Excel file. Let us construct an Excel workbook and share it for everyone that visit the page.

simple.xlsx

Simple.png

Create the Book And Set the Sharing Scope to Application

Import the book and set the book's share scope to APPLICATION. And you are done! ZK Spreadsheet will synchronize information and show the friend focuses for you.

ZUML

coedit.zul

<window id="mainwin" apply="org.zkoss.zssessentials.coedit.CoeditComposer" width="100%" vflex="1">
    <spreadsheet id="ss"
        maxrows="200"
        maxcolumns="40"
        vflex="1"
        width="100%">
    </spreadsheet>
</window>

Composer

This composer prepares the singleton book, set its shareScope to APPLICATION and associates the book with the spreadsheet UI component.

CoeditComposer.java

package org.zkoss.zssessentials.coedit;
public class CoeditComposer extends GenericForwardComposer {
	private static Book book = null;
	private Spreadsheet ss;
	
	public void doAfterCompose(Component comp) throws Exception {
		super.doAfterCompose(comp);
		synchronized (CoeditComposer.class) {
			if (book == null) { //initialize the shared Book
				final Importer importer = Importers.getImporter("excel");
				final InputStream is = Sessions.getCurrent().getWebApp().getResourceAsStream("/WEB-INF/excel/coedit/simple.xlsx");
				book = importer.imports(is, "simple.xlsx");
				book.setShareScope(EventQueues.APPLICATION); //share the work book in Application Scope
			}
		}
		ss.setBook(book);
	}
}

Result

Open a browser to visit the coedit.zul page and then open another browser to visit the same coedit.zul page. Because two browsers share the same simple.xlsx book in APPLICATION scope, any change made from one browser will reflect on another one. Note that the orange box that show the current friend focus of the other browser.

Coedit-result.png

View complete source of ZUML coedit.zul

View complete source of composer CoeditComposer.java

Version History

Last Update : 2012/01/10


Version Date Content
Since 2.2.0 January, 2012 Support coediting
     


All source code listed in this book is at Github.


Last Update : 2012/01/10

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