Collaboration Edit"
m (correct highlight (via JWB)) |
|||
Line 17: | Line 17: | ||
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. | 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. | ||
− | < | + | <code>''simple.xlsx''</code> |
[[Image:simple.png]] | [[Image:simple.png]] | ||
Line 25: | Line 25: | ||
===ZUML=== | ===ZUML=== | ||
− | < | + | <code>''coedit.zul''</code> |
<source lang="xml"> | <source lang="xml"> | ||
<window id="mainwin" apply="org.zkoss.zssessentials.coedit.CoeditComposer" width="100%" vflex="1"> | <window id="mainwin" apply="org.zkoss.zssessentials.coedit.CoeditComposer" width="100%" vflex="1"> | ||
Line 38: | Line 38: | ||
===Composer=== | ===Composer=== | ||
− | This composer prepares the singleton book, set its shareScope to < | + | This composer prepares the singleton book, set its shareScope to <code>APPLICATION</code> and associate the book with the spreadsheet UI component. |
− | < | + | <code>''CoeditComposer.java''</code> |
− | <source lang="java" | + | <source lang="java" highlight="13, 16"> |
package org.zkoss.zssessentials.coedit; | package org.zkoss.zssessentials.coedit; | ||
public class CoeditComposer extends GenericForwardComposer { | public class CoeditComposer extends GenericForwardComposer { |
Latest revision as of 12:54, 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.
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.
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
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.
View complete source of ZUML coedit.zul
View complete source of composer CoeditComposer.java
Version History
Version | Date | Content |
---|---|---|
Since 2.2.0 | January, 2012 | Support coediting |
All source code listed in this book is at Github.