1 package org
.argeo
.cms
.ui
.viewers
;
4 import javax
.jcr
.RepositoryException
;
5 import javax
.jcr
.Session
;
6 import javax
.jcr
.nodetype
.NodeType
;
7 import javax
.jcr
.version
.VersionManager
;
9 import org
.argeo
.api
.cms
.ux
.CmsEditionEvent
;
10 import org
.argeo
.cms
.ux
.AbstractCmsEditable
;
11 import org
.argeo
.jcr
.JcrException
;
12 import org
.eclipse
.rap
.rwt
.RWT
;
13 import org
.eclipse
.swt
.SWT
;
14 import org
.eclipse
.swt
.widgets
.Display
;
15 import org
.eclipse
.swt
.widgets
.Event
;
16 import org
.eclipse
.swt
.widgets
.Listener
;
18 /** Provides the CmsEditable semantic based on JCR versioning. */
19 public class JcrVersionCmsEditable
extends AbstractCmsEditable
{
20 private final String nodePath
;// cache
21 private final VersionManager versionManager
;
22 private final Boolean canEdit
;
24 public JcrVersionCmsEditable(Node node
) throws RepositoryException
{
25 this.nodePath
= node
.getPath();
26 if (node
.getSession().hasPermission(node
.getPath(), Session
.ACTION_SET_PROPERTY
)) {
27 // was Session.ACTION_ADD_NODE
29 if (!node
.isNodeType(NodeType
.MIX_VERSIONABLE
)) {
30 node
.addMixin(NodeType
.MIX_VERSIONABLE
);
31 node
.getSession().save();
33 versionManager
= node
.getSession().getWorkspace().getVersionManager();
36 versionManager
= null;
41 Display display
= Display
.getCurrent();
42 display
.setData(RWT
.ACTIVE_KEYS
, new String
[] { "CTRL+RETURN", "CTRL+E" });
43 display
.addFilter(SWT
.KeyDown
, new Listener() {
44 private static final long serialVersionUID
= -4378653870463187318L;
46 public void handleEvent(Event e
) {
47 boolean ctrlPressed
= (e
.stateMask
& SWT
.CTRL
) != 0;
48 if (ctrlPressed
&& e
.keyCode
== '\r')
50 else if (ctrlPressed
&& e
.keyCode
== 'E')
58 public Boolean
canEdit() {
62 public Boolean
isEditing() {
66 return versionManager
.isCheckedOut(nodePath
);
67 } catch (RepositoryException e
) {
68 throw new JcrException("Cannot check whether " + nodePath
+ " is editing", e
);
73 public void startEditing() {
75 versionManager
.checkout(nodePath
);
77 } catch (RepositoryException e1
) {
78 throw new JcrException("Cannot publish " + nodePath
, e1
);
80 notifyListeners(new CmsEditionEvent(nodePath
, CmsEditionEvent
.START_EDITING
, this));
84 public void stopEditing() {
86 versionManager
.checkin(nodePath
);
88 } catch (RepositoryException e1
) {
89 throw new JcrException("Cannot publish " + nodePath
, e1
);
91 notifyListeners(new CmsEditionEvent(nodePath
, CmsEditionEvent
.STOP_EDITING
, this));