Rename home repository into ego repository.
[lgpl/argeo-commons.git] / org.argeo.cms.e4 / src / org / argeo / cms / e4 / jcr / JcrBrowserView.java
index 3eff807330d6012564f0ebb7e840a1ef06a16f62..3e328daa3ee874045cf50015c8d1307565ec0f8f 100644 (file)
@@ -33,19 +33,27 @@ import javax.jcr.observation.ObservationManager;
 
 import org.argeo.cms.CmsException;
 import org.argeo.cms.ui.jcr.JcrBrowserUtils;
-import org.argeo.cms.ui.jcr.JcrDClickListener;
 import org.argeo.cms.ui.jcr.NodeContentProvider;
 import org.argeo.cms.ui.jcr.NodeLabelProvider;
 import org.argeo.cms.ui.jcr.OsgiRepositoryRegister;
 import org.argeo.cms.ui.jcr.PropertiesContentProvider;
 import org.argeo.cms.ui.jcr.model.SingleJcrNodeElem;
+import org.argeo.cms.util.CmsUtils;
 import org.argeo.eclipse.ui.EclipseUiException;
 import org.argeo.eclipse.ui.TreeParent;
 import org.argeo.eclipse.ui.jcr.AsyncUiEventListener;
 import org.argeo.eclipse.ui.jcr.utils.NodeViewerComparer;
+import org.argeo.jcr.JcrUtils;
+import org.argeo.node.NodeConstants;
 import org.argeo.node.security.CryptoKeyring;
-import org.eclipse.jface.action.MenuManager;
+import org.argeo.node.security.Keyring;
+import org.eclipse.e4.core.contexts.IEclipseContext;
+import org.eclipse.e4.core.di.annotations.Optional;
+import org.eclipse.e4.ui.services.EMenuService;
+import org.eclipse.e4.ui.workbench.modeling.EPartService;
+import org.eclipse.e4.ui.workbench.modeling.ESelectionService;
 import org.eclipse.jface.viewers.ColumnLabelProvider;
+import org.eclipse.jface.viewers.IBaseLabelProvider;
 import org.eclipse.jface.viewers.ISelectionChangedListener;
 import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.jface.viewers.ITreeContentProvider;
@@ -58,26 +66,29 @@ import org.eclipse.swt.SWT;
 import org.eclipse.swt.custom.SashForm;
 import org.eclipse.swt.layout.FillLayout;
 import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Menu;
 
 /**
  * Basic View to display a sash form to browse a JCR compliant multiple
  * repository environment
  */
 public class JcrBrowserView {
+       final static String ID = "org.argeo.cms.e4.jcrbrowser";
+       final static String NODE_VIEWER_POPUP_MENU_ID = "org.argeo.cms.e4.popupmenu.nodeViewer";
+
        private boolean sortChildNodes = true;
 
        /* DEPENDENCY INJECTION */
-       private CryptoKeyring keyring;
+       @Inject
+       @Optional
+       private Keyring keyring;
        @Inject
        private RepositoryFactory repositoryFactory;
        @Inject
        private Repository nodeRepository;
 
-       // Current user session on the "Argeo node" default workspace
+       // Current user session on the home repository default workspace
        private Session userSession;
 
        private OsgiRepositoryRegister repositoryRegister = new OsgiRepositoryRegister();
@@ -89,21 +100,22 @@ public class JcrBrowserView {
        private EventListener resultsObserver;
 
        @PostConstruct
-       public void createPartControl(Composite parent) {
+       public void createPartControl(Composite parent, IEclipseContext context, EPartService partService,
+                       ESelectionService selectionService, EMenuService menuService) {
                repositoryRegister.init();
 
                parent.setLayout(new FillLayout());
                SashForm sashForm = new SashForm(parent, SWT.VERTICAL);
-               sashForm.setSashWidth(4);
-               sashForm.setLayout(new FillLayout());
+               // sashForm.setSashWidth(4);
+               // sashForm.setLayout(new FillLayout());
 
                // Create the tree on top of the view
                Composite top = new Composite(sashForm, SWT.NONE);
-               GridLayout gl = new GridLayout(1, false);
-               top.setLayout(gl);
+               // GridLayout gl = new GridLayout(1, false);
+               top.setLayout(CmsUtils.noSpaceGridLayout());
 
                try {
-                       this.userSession = this.nodeRepository.login();
+                       this.userSession = this.nodeRepository.login(NodeConstants.HOME);
                } catch (RepositoryException e) {
                        throw new CmsException("Cannot open user session", e);
                }
@@ -115,27 +127,35 @@ public class JcrBrowserView {
                nodesViewer = createNodeViewer(top, nodeContentProvider);
 
                // context menu : it is completely defined in the plugin.xml file.
-               MenuManager menuManager = new MenuManager();
-               Menu menu = menuManager.createContextMenu(nodesViewer.getTree());
+               // MenuManager menuManager = new MenuManager();
+               // Menu menu = menuManager.createContextMenu(nodesViewer.getTree());
 
-               nodesViewer.getTree().setMenu(menu);
+               // nodesViewer.getTree().setMenu(menu);
 
                nodesViewer.setInput("");
 
                // Create the property viewer on the bottom
                Composite bottom = new Composite(sashForm, SWT.NONE);
-               bottom.setLayout(new GridLayout(1, false));
+               bottom.setLayout(CmsUtils.noSpaceGridLayout());
                propertiesViewer = createPropertiesViewer(bottom);
 
                sashForm.setWeights(getWeights());
                nodesViewer.setComparer(new NodeViewerComparer());
-
+               nodesViewer.addSelectionChangedListener(new ISelectionChangedListener() {
+                       public void selectionChanged(SelectionChangedEvent event) {
+                               IStructuredSelection selection = (IStructuredSelection) event.getSelection();
+                               selectionService.setSelection(selection.toList());
+                       }
+               });
+               nodesViewer.addDoubleClickListener(new JcrE4DClickListener(nodesViewer, partService));
+               menuService.registerContextMenu(nodesViewer.getControl(), NODE_VIEWER_POPUP_MENU_ID);
                // getSite().registerContextMenu(menuManager, nodesViewer);
                // getSite().setSelectionProvider(nodesViewer);
        }
 
        @PreDestroy
        public void dispose() {
+               JcrUtils.logoutQuietly(userSession);
                repositoryRegister.destroy();
        }
 
@@ -167,7 +187,7 @@ public class JcrBrowserView {
                tmpNodeViewer.getTree().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
 
                tmpNodeViewer.setContentProvider(nodeContentProvider);
-               tmpNodeViewer.setLabelProvider(new NodeLabelProvider());
+               tmpNodeViewer.setLabelProvider((IBaseLabelProvider) new NodeLabelProvider());
                tmpNodeViewer.addSelectionChangedListener(new ISelectionChangedListener() {
                        public void selectionChanged(SelectionChangedEvent event) {
                                if (!event.getSelection().isEmpty()) {
@@ -191,12 +211,12 @@ public class JcrBrowserView {
                                throw new EclipseUiException("Cannot register listeners", e);
                        }
 
-               tmpNodeViewer.addDoubleClickListener(new JcrDClickListener(tmpNodeViewer));
+               // tmpNodeViewer.addDoubleClickListener(new JcrDClickListener(tmpNodeViewer));
                return tmpNodeViewer;
        }
 
        protected TableViewer createPropertiesViewer(Composite parent) {
-               propertiesViewer = new TableViewer(parent);
+               propertiesViewer = new TableViewer(parent, SWT.NONE);
                propertiesViewer.getTable().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
                propertiesViewer.getTable().setHeaderVisible(true);
                propertiesViewer.setContentProvider(new PropertiesContentProvider());
@@ -263,9 +283,8 @@ public class JcrBrowserView {
        /**
         * Resets the tree content provider
         * 
-        * @param sortChildNodes
-        *            if true the content provider will use a comparer to sort nodes
-        *            that might slow down the display
+        * @param sortChildNodes if true the content provider will use a comparer to
+        *                       sort nodes that might slow down the display
         */
        public void setSortChildNodes(boolean sortChildNodes) {
                this.sortChildNodes = sortChildNodes;