1 package org
.argeo
.eclipse
.ui
.jcr
.views
;
3 import java
.util
.Arrays
;
6 import javax
.jcr
.Property
;
7 import javax
.jcr
.PropertyType
;
8 import javax
.jcr
.Repository
;
9 import javax
.jcr
.RepositoryException
;
10 import javax
.jcr
.Session
;
11 import javax
.jcr
.nodetype
.NodeType
;
13 import org
.apache
.commons
.logging
.Log
;
14 import org
.apache
.commons
.logging
.LogFactory
;
15 import org
.argeo
.ArgeoException
;
16 import org
.argeo
.eclipse
.ui
.jcr
.browser
.NodeContentProvider
;
17 import org
.argeo
.eclipse
.ui
.jcr
.browser
.NodeLabelProvider
;
18 import org
.argeo
.eclipse
.ui
.jcr
.browser
.PropertiesContentProvider
;
19 import org
.argeo
.eclipse
.ui
.jcr
.browser
.RepositoryNode
;
20 import org
.argeo
.eclipse
.ui
.jcr
.browser
.WorkspaceNode
;
21 import org
.argeo
.eclipse
.ui
.jcr
.utils
.JcrFileProvider
;
22 import org
.argeo
.eclipse
.ui
.jcr
.utils
.NodeViewerComparer
;
23 import org
.argeo
.eclipse
.ui
.specific
.FileHandler
;
24 import org
.argeo
.jcr
.ArgeoJcrConstants
;
25 import org
.argeo
.jcr
.JcrUtils
;
26 import org
.argeo
.jcr
.RepositoryRegister
;
27 import org
.eclipse
.jface
.action
.MenuManager
;
28 import org
.eclipse
.jface
.viewers
.ColumnLabelProvider
;
29 import org
.eclipse
.jface
.viewers
.DoubleClickEvent
;
30 import org
.eclipse
.jface
.viewers
.IDoubleClickListener
;
31 import org
.eclipse
.jface
.viewers
.ISelectionChangedListener
;
32 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
33 import org
.eclipse
.jface
.viewers
.ITreeContentProvider
;
34 import org
.eclipse
.jface
.viewers
.SelectionChangedEvent
;
35 import org
.eclipse
.jface
.viewers
.TableViewer
;
36 import org
.eclipse
.jface
.viewers
.TableViewerColumn
;
37 import org
.eclipse
.jface
.viewers
.TreeViewer
;
38 import org
.eclipse
.swt
.SWT
;
39 import org
.eclipse
.swt
.custom
.SashForm
;
40 import org
.eclipse
.swt
.layout
.FillLayout
;
41 import org
.eclipse
.swt
.layout
.GridData
;
42 import org
.eclipse
.swt
.layout
.GridLayout
;
43 import org
.eclipse
.swt
.widgets
.Composite
;
44 import org
.eclipse
.swt
.widgets
.Menu
;
46 public class GenericJcrBrowser
extends AbstractJcrBrowser
{
47 private final static Log log
= LogFactory
.getLog(GenericJcrBrowser
.class);
49 /** DEPENDENCY INJECTION **/
50 private Session session
;
51 private RepositoryRegister repositoryRegister
;
53 private TreeViewer nodesViewer
;
54 private NodeContentProvider nodeContentProvider
;
55 private TableViewer propertiesViewer
;
57 private JcrFileProvider jcrFileProvider
;
58 private FileHandler fileHandler
;
61 public void createPartControl(Composite parent
) {
64 Session nodeSession
= session
;
65 if (nodeSession
== null) {
66 Repository nodeRepository
= JcrUtils
.getRepositoryByAlias(
67 repositoryRegister
, ArgeoJcrConstants
.ALIAS_NODE
);
68 if (nodeRepository
!= null)
70 nodeSession
= nodeRepository
.login();
71 } catch (RepositoryException e1
) {
72 throw new ArgeoException("Cannot login to node repository");
76 // Instantiate the generic object that fits for
78 // Note that in RAP, it registers a service handler that provide the
79 // access to the files.
80 jcrFileProvider
= new JcrFileProvider();
81 fileHandler
= new FileHandler(jcrFileProvider
);
83 parent
.setLayout(new FillLayout());
84 SashForm sashForm
= new SashForm(parent
, SWT
.VERTICAL
);
85 sashForm
.setSashWidth(4);
86 sashForm
.setLayout(new FillLayout());
88 // Create the tree on top of the view
89 Composite top
= new Composite(sashForm
, SWT
.NONE
);
90 GridLayout gl
= new GridLayout(1, false);
93 nodeContentProvider
= new NodeContentProvider(nodeSession
,
97 nodesViewer
= createNodeViewer(top
, nodeContentProvider
);
100 MenuManager menuManager
= new MenuManager();
101 Menu menu
= menuManager
.createContextMenu(nodesViewer
.getTree());
102 nodesViewer
.getTree().setMenu(menu
);
103 getSite().registerContextMenu(menuManager
, nodesViewer
);
104 getSite().setSelectionProvider(nodesViewer
);
105 nodesViewer
.setInput(getViewSite());
107 // Create the property viewer on the bottom
108 Composite bottom
= new Composite(sashForm
, SWT
.NONE
);
109 bottom
.setLayout(new GridLayout(1, false));
110 propertiesViewer
= new TableViewer(bottom
);
111 propertiesViewer
.getTable().setLayoutData(
112 new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
113 propertiesViewer
.getTable().setHeaderVisible(true);
114 propertiesViewer
.setContentProvider(new PropertiesContentProvider());
115 TableViewerColumn col
= new TableViewerColumn(propertiesViewer
,
117 col
.getColumn().setText("Name");
118 col
.getColumn().setWidth(200);
119 col
.setLabelProvider(new ColumnLabelProvider() {
120 public String
getText(Object element
) {
122 return ((Property
) element
).getName();
123 } catch (RepositoryException e
) {
124 throw new ArgeoException(
125 "Unexpected exception in label provider", e
);
129 col
= new TableViewerColumn(propertiesViewer
, SWT
.NONE
);
130 col
.getColumn().setText("Value");
131 col
.getColumn().setWidth(400);
132 col
.setLabelProvider(new ColumnLabelProvider() {
133 public String
getText(Object element
) {
135 Property property
= (Property
) element
;
136 if (property
.getType() == PropertyType
.BINARY
)
138 else if (property
.isMultiple())
139 return Arrays
.asList(property
.getValues()).toString();
141 return property
.getValue().getString();
142 } catch (RepositoryException e
) {
143 throw new ArgeoException(
144 "Unexpected exception in label provider", e
);
148 col
= new TableViewerColumn(propertiesViewer
, SWT
.NONE
);
149 col
.getColumn().setText("Type");
150 col
.getColumn().setWidth(200);
151 col
.setLabelProvider(new ColumnLabelProvider() {
152 public String
getText(Object element
) {
154 return PropertyType
.nameFromValue(((Property
) element
)
156 } catch (RepositoryException e
) {
157 throw new ArgeoException(
158 "Unexpected exception in label provider", e
);
162 propertiesViewer
.setInput(getViewSite());
164 sashForm
.setWeights(getWeights());
165 nodesViewer
.setComparer(new NodeViewerComparer());
169 * To be overridden to adapt size of form and result frames.
171 protected int[] getWeights() {
172 return new int[] { 70, 30 };
176 // public void setFocus() {
177 // nodesViewer.getTree().setFocus();
183 // public void refresh(Object obj) {
184 // nodesViewer.refresh(obj);
187 // public void nodeAdded(Node parentNode, Node newNode) {
188 // nodesViewer.refresh(parentNode);
189 // nodesViewer.expandToLevel(newNode, 0);
192 // public void nodeRemoved(Node parentNode) {
194 // IStructuredSelection newSel = new StructuredSelection(parentNode);
195 // nodesViewer.setSelection(newSel, true);
197 // IStructuredSelection tmpSel = (IStructuredSelection) nodesViewer
199 // nodesViewer.refresh(tmpSel.getFirstElement());
202 private JcrFileProvider
getJcrFileProvider() {
203 return jcrFileProvider
;
206 private FileHandler
getFileHandler() {
210 protected TreeViewer
createNodeViewer(Composite parent
,
211 final ITreeContentProvider nodeContentProvider
) {
213 final TreeViewer tmpNodeViewer
= new TreeViewer(parent
, SWT
.MULTI
);
215 tmpNodeViewer
.getTree().setLayoutData(
216 new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
218 tmpNodeViewer
.setContentProvider(nodeContentProvider
);
219 tmpNodeViewer
.setLabelProvider(new NodeLabelProvider());
221 .addSelectionChangedListener(new ISelectionChangedListener() {
222 public void selectionChanged(SelectionChangedEvent event
) {
223 if (!event
.getSelection().isEmpty()) {
224 IStructuredSelection sel
= (IStructuredSelection
) event
226 propertiesViewer
.setInput(sel
.getFirstElement());
228 propertiesViewer
.setInput(getViewSite());
233 tmpNodeViewer
.addDoubleClickListener(new IDoubleClickListener() {
234 public void doubleClick(DoubleClickEvent event
) {
235 if (event
.getSelection() == null
236 || event
.getSelection().isEmpty())
238 Object obj
= ((IStructuredSelection
) event
.getSelection())
240 if (obj
instanceof RepositoryNode
) {
241 RepositoryNode rpNode
= (RepositoryNode
) obj
;
243 tmpNodeViewer
.refresh(obj
);
244 } else if (obj
instanceof WorkspaceNode
) {
245 ((WorkspaceNode
) obj
).login();
246 tmpNodeViewer
.refresh(obj
);
247 } else if (obj
instanceof Node
) {
248 Node node
= (Node
) obj
;
250 // double clic on a file node triggers its opening
252 if (node
.isNodeType(NodeType
.NT_FILE
)) {
253 String name
= node
.getName();
254 String id
= node
.getIdentifier();
255 // For the file provider to be able to browse the
258 // TODO : enhanced that.
259 getJcrFileProvider().setRootNodes(
260 (Object
[]) nodeContentProvider
263 getFileHandler().openFile(name
, id
);
265 } catch (RepositoryException re
) {
266 throw new ArgeoException(
267 "Repository error while getting Node file info",
273 return tmpNodeViewer
;
277 protected TreeViewer
getNodeViewer() {
281 /** DEPENDENCY INJECTION **/
282 public void setRepositoryRegister(RepositoryRegister repositoryRegister
) {
283 this.repositoryRegister
= repositoryRegister
;
286 public void setSession(Session session
) {
287 this.session
= session
;