Improve CMS UI
authorMathieu Baudier <mbaudier@argeo.org>
Mon, 10 Dec 2018 14:18:44 +0000 (15:18 +0100)
committerMathieu Baudier <mbaudier@argeo.org>
Mon, 10 Dec 2018 14:18:44 +0000 (15:18 +0100)
org.argeo.cms.ui/src/org/argeo/cms/ui/dialogs/CmsMessageDialog.java
org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/jcr/NodeColumnLabelProvider.java [new file with mode: 0644]
org.argeo.jcr/src/org/argeo/jcr/JcrUtils.java

index 521c4b010f92ba91ced8095a871becef21e4babe..fa85dff462c3dcac791c2f947faa4cf3a9431cee 100644 (file)
@@ -1,10 +1,13 @@
 package org.argeo.cms.ui.dialogs;
 
 import org.argeo.cms.CmsMsg;
+import org.argeo.cms.util.CmsUtils;
 import org.argeo.eclipse.ui.EclipseUiUtils;
 import org.argeo.eclipse.ui.Selected;
 import org.argeo.eclipse.ui.dialogs.LightweightDialog;
 import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.TraverseEvent;
+import org.eclipse.swt.events.TraverseListener;
 import org.eclipse.swt.graphics.Point;
 import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.layout.GridLayout;
@@ -33,8 +36,20 @@ public class CmsMessageDialog extends LightweightDialog {
        protected Control createDialogArea(Composite parent) {
                parent.setLayout(new GridLayout());
 
+               TraverseListener traverseListener = new TraverseListener() {
+                       private static final long serialVersionUID = -1158892811534971856L;
+
+                       public void keyTraversed(TraverseEvent e) {
+                               if (e.detail == SWT.TRAVERSE_RETURN)
+                                       okPressed();
+                               else if (e.detail == SWT.TRAVERSE_ESCAPE)
+                                       cancelPressed();
+                       }
+               };
+
                // message
                Composite body = new Composite(parent, SWT.NONE);
+               body.addTraverseListener(traverseListener);
                GridLayout bodyGridLayout = new GridLayout();
                bodyGridLayout.marginHeight = 20;
                bodyGridLayout.marginWidth = 20;
@@ -42,13 +57,15 @@ public class CmsMessageDialog extends LightweightDialog {
                body.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
 
                Label messageLbl = new Label(body, SWT.WRAP);
+               CmsUtils.markup(messageLbl);
+               messageLbl.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
                messageLbl.setFont(EclipseUiUtils.getBoldFont(parent));
                if (message != null)
                        messageLbl.setText(message);
-               createInputArea(body);
 
                // buttons
                Composite buttons = new Composite(parent, SWT.NONE);
+               buttons.addTraverseListener(traverseListener);
                buttons.setLayoutData(new GridData(SWT.END, SWT.FILL, true, false));
                if (kind == INFORMATION || kind == WARNING) {
                        GridLayout layout = new GridLayout(1, true);
@@ -60,7 +77,16 @@ public class CmsMessageDialog extends LightweightDialog {
                        close.setText(CmsMsg.close.lead());
                        close.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
                        close.addSelectionListener((Selected) (e) -> closeShell(OK));
+                       close.setFocus();
+                       close.addTraverseListener(traverseListener);
+
+                       buttons.setTabList(new Control[] { close });
                } else if (kind == CONFIRM || kind == QUESTION) {
+                       Control input = createInputArea(body);
+                       if (input != null) {
+                               input.addTraverseListener(traverseListener);
+                               body.setTabList(new Control[] { input });
+                       }
                        GridLayout layout = new GridLayout(2, true);
                        layout.marginWidth = 0;
                        layout.marginHeight = 0;
@@ -70,13 +96,22 @@ public class CmsMessageDialog extends LightweightDialog {
                        cancel.setText(CmsMsg.cancel.lead());
                        cancel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
                        cancel.addSelectionListener((Selected) (e) -> cancelPressed());
+                       cancel.addTraverseListener(traverseListener);
 
                        Button ok = new Button(buttons, SWT.FLAT);
                        ok.setText(CmsMsg.ok.lead());
                        ok.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
                        ok.addSelectionListener((Selected) (e) -> okPressed());
+                       ok.addTraverseListener(traverseListener);
+                       if (input == null)
+                               ok.setFocus();
+                       else
+                               input.setFocus();
+
+                       buttons.setTabList(new Control[] { ok, cancel });
                }
                // pack();
+               parent.setTabList(new Control[] { body, buttons });
                return body;
        }
 
diff --git a/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/jcr/NodeColumnLabelProvider.java b/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/jcr/NodeColumnLabelProvider.java
new file mode 100644 (file)
index 0000000..c464478
--- /dev/null
@@ -0,0 +1,52 @@
+package org.argeo.eclipse.ui.jcr;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+
+import org.eclipse.jface.viewers.ColumnLabelProvider;
+import org.eclipse.swt.graphics.Image;
+
+/** Simplifies writing JCR-based column label provider. */
+public class NodeColumnLabelProvider extends ColumnLabelProvider {
+       private static final long serialVersionUID = -6586692836928505358L;
+
+       protected String getNodeText(Node node) throws RepositoryException {
+               return super.getText(node);
+       }
+
+       protected String getNodeToolTipText(Node node) throws RepositoryException {
+               return super.getToolTipText(node);
+       }
+
+       protected Image getNodeImage(Node node) throws RepositoryException {
+               return super.getImage(node);
+       }
+
+       @Override
+       public String getText(Object element) {
+               try {
+                       return getNodeText((Node) element);
+               } catch (RepositoryException e) {
+                       throw new RuntimeException("Runtime repository exception when accessing " + element, e);
+               }
+       }
+
+       @Override
+       public Image getImage(Object element) {
+               try {
+                       return getNodeImage((Node) element);
+               } catch (RepositoryException e) {
+                       throw new RuntimeException("Runtime repository exception when accessing " + element, e);
+               }
+       }
+
+       @Override
+       public String getToolTipText(Object element) {
+               try {
+                       return getNodeToolTipText((Node) element);
+               } catch (RepositoryException e) {
+                       throw new RuntimeException("Runtime repository exception when accessing " + element, e);
+               }
+       }
+
+}
index 158b52a8f270ace93b58e8e1a4083a686d94cdbf..5bbc207ea3e918eec41aa5536b5c009b1ca89142 100644 (file)
@@ -86,8 +86,7 @@ public class JcrUtils {
         * Queries one single node.
         * 
         * @return one single node or null if none was found
-        * @throws ArgeoJcrException
-        *             if more than one node was found
+        * @throws ArgeoJcrException if more than one node was found
         */
        public static Node querySingleNode(Query query) {
                NodeIterator nodeIterator;
@@ -236,10 +235,8 @@ public class JcrUtils {
        /**
         * The provided data as a path ('/' at the end, not the beginning)
         * 
-        * @param cal
-        *            the date
-        * @param addHour
-        *            whether to add hour as well
+        * @param cal     the date
+        * @param addHour whether to add hour as well
         */
        public static String dateAsPath(Calendar cal, Boolean addHour) {
                StringBuffer buf = new StringBuffer(14);
@@ -363,6 +360,15 @@ public class JcrUtils {
                }
        }
 
+       /** Concisely get the path of the given node. */
+       public static String getPath(Node node) {
+               try {
+                       return node.getPath();
+               } catch (RepositoryException e) {
+                       throw new ArgeoJcrException("Cannot get path of " + node, e);
+               }
+       }
+
        /** Concisely get the boolean value of a property */
        public static Boolean check(Node node, String propertyName) {
                try {
@@ -395,8 +401,7 @@ public class JcrUtils {
        /**
         * Create sub nodes relative to a parent node
         * 
-        * @param nodeType
-        *            the type of the leaf node
+        * @param nodeType the type of the leaf node
         */
        public static Node mkdirs(Node parentNode, String relativePath, String nodeType) {
                return mkdirs(parentNode, relativePath, nodeType, null);
@@ -405,8 +410,7 @@ public class JcrUtils {
        /**
         * Create sub nodes relative to a parent node
         * 
-        * @param nodeType
-        *            the type of the leaf node
+        * @param nodeType the type of the leaf node
         */
        public static Node mkdirs(Node parentNode, String relativePath, String nodeType, String intermediaryNodeType) {
                List<String> tokens = tokenize(relativePath);
@@ -457,8 +461,7 @@ public class JcrUtils {
        }
 
        /**
-        * @param type
-        *            the type of the leaf node
+        * @param type the type of the leaf node
         */
        public static Node mkdirs(Session session, String path, String type) {
                return mkdirs(session, path, type, null, false);
@@ -1157,10 +1160,8 @@ public class JcrUtils {
        /**
         * Update lastModified recursively until this parent.
         * 
-        * @param node
-        *            the node
-        * @param untilPath
-        *            the base path, null is equivalent to "/"
+        * @param node      the node
+        * @param untilPath the base path, null is equivalent to "/"
         */
        public static void updateLastModifiedAndParents(Node node, String untilPath) {
                try {
@@ -1347,8 +1348,8 @@ public class JcrUtils {
         * Copy only nt:folder and nt:file, without their additional types and
         * properties.
         * 
-        * @param recursive
-        *            if true copies folders as well, otherwise only first level files
+        * @param recursive if true copies folders as well, otherwise only first level
+        *                  files
         * @return how many files were copied
         */
        public static Long copyFiles(Node fromNode, Node toNode, Boolean recursive, JcrMonitor monitor, boolean onlyAdd) {