1 package org
.argeo
.cms
.viewers
;
3 import java
.util
.Observable
;
6 import javax
.jcr
.RepositoryException
;
7 import javax
.jcr
.Session
;
8 import javax
.jcr
.nodetype
.NodeType
;
9 import javax
.jcr
.version
.VersionManager
;
11 import org
.argeo
.cms
.CmsEditable
;
12 import org
.argeo
.cms
.CmsEditionEvent
;
13 import org
.argeo
.cms
.CmsException
;
14 import org
.eclipse
.rap
.rwt
.RWT
;
15 import org
.eclipse
.swt
.SWT
;
16 import org
.eclipse
.swt
.widgets
.Display
;
17 import org
.eclipse
.swt
.widgets
.Event
;
18 import org
.eclipse
.swt
.widgets
.Listener
;
20 /** Provides the CmsEditable semantic based on JCR versioning. */
21 public class JcrVersionCmsEditable
extends Observable
implements CmsEditable
{
22 private final String nodePath
;// cache
23 private final VersionManager versionManager
;
24 private final Boolean canEdit
;
26 public JcrVersionCmsEditable(Node node
) throws RepositoryException
{
27 this.nodePath
= node
.getPath();
28 if (node
.getSession().hasPermission(node
.getPath(),
29 Session
.ACTION_ADD_NODE
)) {
31 if (!node
.isNodeType(NodeType
.MIX_VERSIONABLE
)) {
32 node
.addMixin(NodeType
.MIX_VERSIONABLE
);
33 node
.getSession().save();
35 versionManager
= node
.getSession().getWorkspace()
39 versionManager
= null;
44 Display display
= Display
.getCurrent();
45 display
.setData(RWT
.ACTIVE_KEYS
, new String
[] { "CTRL+RETURN",
47 display
.addFilter(SWT
.KeyDown
, new Listener() {
48 private static final long serialVersionUID
= -4378653870463187318L;
50 public void handleEvent(Event e
) {
51 boolean ctrlPressed
= (e
.stateMask
& SWT
.CTRL
) != 0;
52 if (ctrlPressed
&& e
.keyCode
== '\r')
54 else if (ctrlPressed
&& e
.keyCode
== 'E')
62 public Boolean
canEdit() {
66 public Boolean
isEditing() {
70 return versionManager
.isCheckedOut(nodePath
);
71 } catch (RepositoryException e
) {
72 throw new CmsException("Cannot check whether " + nodePath
78 public void startEditing() {
80 versionManager
.checkout(nodePath
);
82 } catch (RepositoryException e1
) {
83 throw new CmsException("Cannot publish " + nodePath
);
85 notifyObservers(new CmsEditionEvent(nodePath
,
86 CmsEditionEvent
.START_EDITING
));
90 public void stopEditing() {
92 versionManager
.checkin(nodePath
);
94 } catch (RepositoryException e1
) {
95 throw new CmsException("Cannot publish " + nodePath
, e1
);
97 notifyObservers(new CmsEditionEvent(nodePath
,
98 CmsEditionEvent
.STOP_EDITING
));