Introduce Documents UI.
[gpl/argeo-suite.git] / org.argeo.suite.ui / src / org / argeo / suite / ui / RecentItems.java
index 09480ba5a226096d1e145665a1f21755cba8b9a6..0104a687ea5fda0d9d27044212cbc89daf4560cf 100644 (file)
@@ -2,6 +2,7 @@ package org.argeo.suite.ui;
 
 import static org.argeo.eclipse.ui.EclipseUiUtils.notEmpty;
 
+import java.util.List;
 import java.util.Map;
 
 import javax.jcr.Node;
@@ -14,19 +15,17 @@ import javax.jcr.observation.EventListener;
 import javax.jcr.query.Query;
 import javax.jcr.query.QueryResult;
 
-import org.argeo.api.NodeConstants;
 import org.argeo.cms.ui.CmsTheme;
 import org.argeo.cms.ui.CmsUiProvider;
 import org.argeo.cms.ui.CmsView;
 import org.argeo.cms.ui.util.CmsUiUtils;
-import org.argeo.connect.ui.ConnectUiConstants;
-import org.argeo.connect.ui.util.BasicNodeListContentProvider;
-import org.argeo.connect.ui.widgets.DelayedText;
-import org.argeo.connect.util.XPathUtils;
 import org.argeo.eclipse.ui.EclipseUiUtils;
+import org.argeo.entity.EntityConstants;
 import org.argeo.entity.EntityTypes;
 import org.argeo.jcr.Jcr;
 import org.argeo.jcr.JcrUtils;
+import org.argeo.suite.ui.widgets.DelayedText;
+import org.argeo.suite.util.XPathUtils;
 import org.eclipse.jface.layout.TableColumnLayout;
 import org.eclipse.jface.viewers.ColumnLabelProvider;
 import org.eclipse.jface.viewers.ColumnWeightData;
@@ -34,8 +33,10 @@ import org.eclipse.jface.viewers.DoubleClickEvent;
 import org.eclipse.jface.viewers.IDoubleClickListener;
 import org.eclipse.jface.viewers.ILabelProvider;
 import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
 import org.eclipse.jface.viewers.SelectionChangedEvent;
 import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.Viewer;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.events.KeyEvent;
 import org.eclipse.swt.events.KeyListener;
@@ -45,7 +46,6 @@ import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.layout.GridLayout;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Label;
 import org.eclipse.swt.widgets.Table;
 import org.eclipse.swt.widgets.TableColumn;
 import org.eclipse.swt.widgets.Text;
@@ -54,7 +54,9 @@ import org.eclipse.swt.widgets.ToolItem;
 
 /** List recent items. */
 public class RecentItems implements CmsUiProvider {
-//     private final static int SEARCH_TEXT_DELAY = 800;
+       private final static int SEARCH_TEXT_DELAY = 800;
+       private final static int SEARCH_DEFAULT_LIMIT = 100;
+
        private CmsTheme theme;
 
        private String entityType;
@@ -63,20 +65,22 @@ public class RecentItems implements CmsUiProvider {
        public Control createUi(Composite parent, Node context) throws RepositoryException {
                theme = CmsTheme.getCmsTheme(parent);
                parent.setLayout(new GridLayout());
+//             parent.setLayout(CmsUiUtils.noSpaceGridLayout());
+               parent.setLayout(new GridLayout());
 
-               Composite top = new Composite(parent, SWT.NONE);
-               CmsUiUtils.style(top, SuiteStyle.recentItems);
-               top.setLayoutData(CmsUiUtils.fillWidth());
-               top.setLayout(CmsUiUtils.noSpaceGridLayout(2));
-               Label lbl = new Label(top, SWT.NONE);
-               lbl.setLayoutData(CmsUiUtils.fillAll());
-               lbl.setText(SuiteMsg.recentItems.lead());
-               CmsUiUtils.style(lbl, SuiteStyle.recentItems);
-
-               ToolBar topToolBar = new ToolBar(top, SWT.NONE);
-               ToolItem addItem = new ToolItem(topToolBar, SWT.FLAT);
-//             CmsUiUtils.style(addItem, SuiteStyle.recentItems);
-               addItem.setImage(SuiteIcon.add.getSmallIcon(theme));
+//             Composite top = new Composite(parent, SWT.BORDER);
+//             CmsUiUtils.style(top, SuiteStyle.recentItems);
+//             top.setLayoutData(CmsUiUtils.fillWidth());
+//             top.setLayout(CmsUiUtils.noSpaceGridLayout(2));
+//             Label lbl = new Label(top, SWT.FLAT);
+//             lbl.setLayoutData(CmsUiUtils.fillWidth());
+//             lbl.setText(SuiteMsg.recentItems.lead());
+//             CmsUiUtils.style(lbl, SuiteStyle.recentItems);
+//
+//             ToolBar topToolBar = new ToolBar(top, SWT.NONE);
+//             ToolItem addItem = new ToolItem(topToolBar, SWT.FLAT);
+////           CmsUiUtils.style(addItem, SuiteStyle.recentItems);
+//             addItem.setImage(SuiteIcon.add.getSmallIcon(theme));
 
                if (context == null)
                        return null;
@@ -93,7 +97,8 @@ public class RecentItems implements CmsUiProvider {
                deleteItem.setEnabled(false);
 //             CmsUiUtils.style(deleteItem, SuiteStyle.recentItems);
                deleteItem.setImage(SuiteIcon.delete.getSmallIcon(theme));
-
+               ToolItem addItem = new ToolItem(bottomToolBar, SWT.FLAT);
+               addItem.setImage(SuiteIcon.add.getSmallIcon(theme));
                entityViewer.getViewer().addDoubleClickListener(new IDoubleClickListener() {
 
                        @Override
@@ -123,7 +128,7 @@ public class RecentItems implements CmsUiProvider {
        }
 
        public void init(Map<String, String> properties) {
-               entityType = properties.get(NodeConstants.DATA_TYPE);
+               entityType = properties.get(EntityConstants.TYPE);
        }
 
        class SingleEntityViewer {
@@ -164,7 +169,7 @@ public class RecentItems implements CmsUiProvider {
                        // Use a delayed text: the query won't be done until the user stop
                        // typing for 800ms
                        int style = SWT.BORDER | SWT.SEARCH | SWT.ICON_CANCEL;
-                       DelayedText delayedText = new DelayedText(parent, style, ConnectUiConstants.SEARCH_TEXT_DELAY);
+                       DelayedText delayedText = new DelayedText(parent, style, SEARCH_TEXT_DELAY);
                        filterTxt = delayedText.getText();
                        filterTxt.setLayoutData(EclipseUiUtils.fillWidth());
 
@@ -212,7 +217,8 @@ public class RecentItems implements CmsUiProvider {
                }
 
                protected TableViewer createListPart(Composite parent, ILabelProvider labelProvider) {
-                       parent.setLayout(new GridLayout());
+//                     parent.setLayout(new GridLayout());
+//                     parent.setLayout(CmsUiUtils.noSpaceGridLayout());
 
                        Composite tableComposite = new Composite(parent, SWT.NONE);
                        GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_VERTICAL
@@ -298,7 +304,7 @@ public class RecentItems implements CmsUiProvider {
                                // session.refresh(false);
                                Query xpathQuery = XPathUtils.createQuery(session, xpathQueryStr);
 
-                               xpathQuery.setLimit(ConnectUiConstants.SEARCH_DEFAULT_LIMIT);
+                               xpathQuery.setLimit(SEARCH_DEFAULT_LIMIT);
                                QueryResult result = xpathQuery.execute();
 
                                NodeIterator nit = result.getNodes();
@@ -326,5 +332,25 @@ public class RecentItems implements CmsUiProvider {
                        }
 
                }
+
+               class BasicNodeListContentProvider implements IStructuredContentProvider {
+                       private static final long serialVersionUID = 1L;
+                       // keep a cache of the Nodes in the content provider to be able to
+                       // manage long request
+                       private List<Node> nodes;
+
+                       public void dispose() {
+                       }
+
+                       /** Expects a list of nodes as a new input */
+                       @SuppressWarnings("unchecked")
+                       public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+                               nodes = (List<Node>) newInput;
+                       }
+
+                       public Object[] getElements(Object arg0) {
+                               return nodes.toArray();
+                       }
+               }
        }
 }