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;
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;
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);
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;
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;
}
--- /dev/null
+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);
+ }
+ }
+
+}
* 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;
/**
* 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);
}
}
+ /** 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 {
/**
* 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);
/**
* 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);
}
/**
- * @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);
/**
* 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 {
* 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) {