Improve default app.
[gpl/argeo-suite.git] / library / org.argeo.documents.ui / src / org / argeo / documents / ui / DocumentsFolderUiProvider.java
1 package org.argeo.documents.ui;
2
3 import java.nio.file.Path;
4 import java.nio.file.spi.FileSystemProvider;
5
6 import javax.jcr.Node;
7 import javax.jcr.RepositoryException;
8
9 import org.argeo.cms.fs.CmsFsUtils;
10 import org.argeo.cms.ui.CmsUiProvider;
11 import org.argeo.cms.ui.CmsView;
12 import org.argeo.cms.ui.util.CmsUiUtils;
13 import org.argeo.jcr.Jcr;
14 import org.argeo.suite.ui.SuiteEvent;
15 import org.eclipse.swt.SWT;
16 import org.eclipse.swt.widgets.Composite;
17 import org.eclipse.swt.widgets.Control;
18
19 /** UI provider of a document folder. */
20 public class DocumentsFolderUiProvider implements CmsUiProvider {
21         private FileSystemProvider nodeFileSystemProvider;
22
23         @Override
24         public Control createUi(Composite parent, Node context) throws RepositoryException {
25                 CmsView cmsView = CmsView.getCmsView(parent);
26                 DocumentsFolderComposite dfc = new DocumentsFolderComposite(parent, SWT.NONE, context) {
27
28                         @Override
29                         protected void externalNavigateTo(Path path) {
30                                 Node folderNode = cmsView.doAs(() -> CmsFsUtils.getNode(Jcr.getSession(context).getRepository(), path));
31                                 parent.addDisposeListener((e1) -> Jcr.logout(folderNode));
32                                 cmsView.sendEvent(SuiteEvent.openNewPart.topic(), SuiteEvent.eventProperties(folderNode));
33                         }
34                 };
35                 dfc.setLayoutData(CmsUiUtils.fillAll());
36                 dfc.populate(cmsView.doAs(() -> CmsFsUtils.getPath(nodeFileSystemProvider, context)));
37                 return dfc;
38         }
39
40         public void setNodeFileSystemProvider(FileSystemProvider nodeFileSystemProvider) {
41                 this.nodeFileSystemProvider = nodeFileSystemProvider;
42         }
43
44 }