Collaboration Edit

From Documentation



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.


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 will show you a very typical Excel file. Let us construct an Excel workbook and share it for everyone that visits 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 display other users' focus to show what they are working on at the moment

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 associate 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. As two browsers share the same simple.xlsx book in APPLICATION scope, any change made from one browser will reflect on the other. Note that the orange box shows the other user's focus and his/her current status at another browser.

Coedit-result.png

View complete source of ZUML coedit.zul

View complete source of composer CoeditComposer.java

Version History

Last Update : 2022/01/19


Version Date Content
Since 2.2.0 January, 2012 Support coediting
     


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.