1 package org
.argeo
.app
.ui
.library
;
3 import java
.util
.SortedMap
;
4 import java
.util
.TreeMap
;
7 import javax
.jcr
.NodeIterator
;
8 import javax
.jcr
.RepositoryException
;
9 import javax
.jcr
.Session
;
10 import javax
.jcr
.nodetype
.NodeType
;
11 import javax
.jcr
.query
.Query
;
13 import org
.argeo
.api
.acr
.Content
;
14 import org
.argeo
.api
.cms
.CmsConstants
;
15 import org
.argeo
.app
.api
.EntityType
;
16 import org
.argeo
.app
.ui
.SuiteEvent
;
17 import org
.argeo
.app
.ui
.SuiteIcon
;
18 import org
.argeo
.app
.ui
.widgets
.TreeOrSearchArea
;
19 import org
.argeo
.cms
.jcr
.acr
.JcrContentProvider
;
20 import org
.argeo
.cms
.swt
.CmsSwtTheme
;
21 import org
.argeo
.cms
.swt
.CmsSwtUtils
;
22 import org
.argeo
.cms
.ui
.CmsUiProvider
;
23 import org
.argeo
.jcr
.Jcr
;
24 import org
.argeo
.jcr
.JcrException
;
25 import org
.eclipse
.jface
.viewers
.ColumnLabelProvider
;
26 import org
.eclipse
.jface
.viewers
.DoubleClickEvent
;
27 import org
.eclipse
.jface
.viewers
.IDoubleClickListener
;
28 import org
.eclipse
.jface
.viewers
.ISelectionChangedListener
;
29 import org
.eclipse
.jface
.viewers
.ITreeContentProvider
;
30 import org
.eclipse
.jface
.viewers
.SelectionChangedEvent
;
31 import org
.eclipse
.jface
.viewers
.TreeViewerColumn
;
32 import org
.eclipse
.jface
.viewers
.Viewer
;
33 import org
.eclipse
.swt
.SWT
;
34 import org
.eclipse
.swt
.graphics
.Image
;
35 import org
.eclipse
.swt
.layout
.GridLayout
;
36 import org
.eclipse
.swt
.widgets
.Composite
;
37 import org
.eclipse
.swt
.widgets
.Control
;
39 public class JcrContentEntryArea
implements CmsUiProvider
{
40 private JcrContentProvider jcrContentProvider
;
43 public Control
createUiPart(Composite parent
, Content context
) {
44 CmsSwtTheme theme
= CmsSwtUtils
.getCmsTheme(parent
);
46 parent
.setLayout(new GridLayout());
47 Ui ui
= new Ui(parent
, SWT
.NONE
);
48 ui
.setLayoutData(CmsSwtUtils
.fillAll());
50 TreeViewerColumn nameCol
= new TreeViewerColumn(ui
.getTreeViewer(), SWT
.NONE
);
51 nameCol
.getColumn().setWidth(400);
52 nameCol
.setLabelProvider(new ColumnLabelProvider() {
55 public String
getText(Object element
) {
56 Node node
= (Node
) element
;
57 return Jcr
.getTitle(node
);
61 public Image
getImage(Object element
) {
62 Node node
= (Node
) element
;
64 if (Jcr
.isNodeType(node
, NodeType
.NT_FOLDER
)) {
65 icon
= theme
.getSmallIcon(SuiteIcon
.folder
);
66 } else if (Jcr
.isNodeType(node
, NodeType
.NT_FILE
)) {
67 // TODO check recognized document types
68 icon
= theme
.getSmallIcon(SuiteIcon
.document
);
69 } else if (Jcr
.isNodeType(node
, EntityType
.document
.get())) {
70 icon
= theme
.getSmallIcon(SuiteIcon
.document
);
73 icon
= theme
.getSmallIcon(SuiteIcon
.folder
);
82 ui
.getTreeViewer().addDoubleClickListener(new IDoubleClickListener() {
85 public void doubleClick(DoubleClickEvent event
) {
86 Node user
= (Node
) ui
.getTreeViewer().getStructuredSelection().getFirstElement();
88 CmsSwtUtils
.getCmsView(parent
).sendEvent(SuiteEvent
.openNewPart
.topic(),
89 SuiteEvent
.eventProperties(user
));
94 ui
.getTreeViewer().addSelectionChangedListener(new ISelectionChangedListener() {
95 public void selectionChanged(SelectionChangedEvent event
) {
96 Node user
= (Node
) ui
.getTreeViewer().getStructuredSelection().getFirstElement();
98 CmsSwtUtils
.getCmsView(parent
).sendEvent(SuiteEvent
.refreshPart
.topic(),
99 SuiteEvent
.eventProperties(user
));
104 ui
.getTreeViewer().setContentProvider(new SpacesContentProvider());
105 Session session
= jcrContentProvider
.getJcrSession(context
, CmsConstants
.SYS_WORKSPACE
);
106 ui
.getTreeViewer().setInput(session
);
110 protected boolean isLeaf(Node node
) {
111 return Jcr
.isNodeType(node
, EntityType
.entity
.get()) || Jcr
.isNodeType(node
, EntityType
.document
.get())
112 || Jcr
.isNodeType(node
, NodeType
.NT_FILE
);
115 public void setJcrContentProvider(JcrContentProvider jcrContentProvider
) {
116 this.jcrContentProvider
= jcrContentProvider
;
119 class Ui
extends TreeOrSearchArea
{
121 public Ui(Composite parent
, int style
) {
122 super(parent
, style
);
127 class SpacesContentProvider
implements ITreeContentProvider
{
130 public Object
[] getElements(Object inputElement
) {
131 Session session
= (Session
) inputElement
;
133 Query query
= session
.getWorkspace().getQueryManager()
134 .createQuery("SELECT * FROM [" + EntityType
.space
.get() + "]", Query
.JCR_SQL2
);
135 NodeIterator spacesIt
= query
.execute().getNodes();
136 SortedMap
<String
, Node
> map
= new TreeMap
<>();
137 while (spacesIt
.hasNext()) {
138 Node space
= spacesIt
.nextNode();
139 String path
= space
.getPath();
140 map
.put(path
, space
);
142 return map
.values().toArray();
143 } catch (RepositoryException e
) {
144 throw new JcrException(e
);
149 public Object
[] getChildren(Object parentElement
) {
150 Node parent
= (Node
) parentElement
;
153 return Jcr
.getNodes(parent
).toArray();
157 public Object
getParent(Object element
) {
158 Node node
= (Node
) element
;
159 return Jcr
.getParent(node
);
163 public boolean hasChildren(Object element
) {
164 Node node
= (Node
) element
;
165 return !isLeaf(node
);
169 public void dispose() {
173 public void inputChanged(Viewer viewer
, Object oldInput
, Object newInput
) {