Change package of non-JCR SWT components.
[lgpl/argeo-commons.git] / jcr / org.argeo.cms.ui / src / org / argeo / cms / ui / viewers / JcrVersionCmsEditable.java
index 07724f4b11c51a1f00e05c6a068929d9d5c8dfe8..298fbdea9b6d3dd2b58fc6e01d50a5cb954c58b8 100644 (file)
@@ -1,16 +1,14 @@
 package org.argeo.cms.ui.viewers;
 
-import java.util.Observable;
-
 import javax.jcr.Node;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 import javax.jcr.nodetype.NodeType;
 import javax.jcr.version.VersionManager;
 
-import org.argeo.api.cms.ux.CmsEditable;
-import org.argeo.cms.CmsException;
-import org.argeo.cms.ui.CmsEditionEvent;
+import org.argeo.api.cms.ux.CmsEditionEvent;
+import org.argeo.cms.ux.AbstractCmsEditable;
+import org.argeo.jcr.JcrException;
 import org.eclipse.rap.rwt.RWT;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.widgets.Display;
@@ -18,23 +16,21 @@ import org.eclipse.swt.widgets.Event;
 import org.eclipse.swt.widgets.Listener;
 
 /** Provides the CmsEditable semantic based on JCR versioning. */
-public class JcrVersionCmsEditable extends Observable implements CmsEditable {
+public class JcrVersionCmsEditable extends AbstractCmsEditable {
        private final String nodePath;// cache
        private final VersionManager versionManager;
        private final Boolean canEdit;
 
        public JcrVersionCmsEditable(Node node) throws RepositoryException {
                this.nodePath = node.getPath();
-               if (node.getSession().hasPermission(node.getPath(),
-                               Session.ACTION_SET_PROPERTY)) {
+               if (node.getSession().hasPermission(node.getPath(), Session.ACTION_SET_PROPERTY)) {
                        // was Session.ACTION_ADD_NODE
                        canEdit = true;
                        if (!node.isNodeType(NodeType.MIX_VERSIONABLE)) {
                                node.addMixin(NodeType.MIX_VERSIONABLE);
                                node.getSession().save();
                        }
-                       versionManager = node.getSession().getWorkspace()
-                                       .getVersionManager();
+                       versionManager = node.getSession().getWorkspace().getVersionManager();
                } else {
                        canEdit = false;
                        versionManager = null;
@@ -43,8 +39,7 @@ public class JcrVersionCmsEditable extends Observable implements CmsEditable {
                // bind keys
                if (canEdit) {
                        Display display = Display.getCurrent();
-                       display.setData(RWT.ACTIVE_KEYS, new String[] { "CTRL+RETURN",
-                                       "CTRL+E" });
+                       display.setData(RWT.ACTIVE_KEYS, new String[] { "CTRL+RETURN", "CTRL+E" });
                        display.addFilter(SWT.KeyDown, new Listener() {
                                private static final long serialVersionUID = -4378653870463187318L;
 
@@ -70,8 +65,7 @@ public class JcrVersionCmsEditable extends Observable implements CmsEditable {
                                return false;
                        return versionManager.isCheckedOut(nodePath);
                } catch (RepositoryException e) {
-                       throw new CmsException("Cannot check whether " + nodePath
-                                       + " is editing", e);
+                       throw new JcrException("Cannot check whether " + nodePath + " is editing", e);
                }
        }
 
@@ -79,23 +73,22 @@ public class JcrVersionCmsEditable extends Observable implements CmsEditable {
        public void startEditing() {
                try {
                        versionManager.checkout(nodePath);
-                       setChanged();
+//                     setChanged();
                } catch (RepositoryException e1) {
-                       throw new CmsException("Cannot publish " + nodePath);
+                       throw new JcrException("Cannot publish " + nodePath, e1);
                }
-               notifyObservers(new CmsEditionEvent(nodePath,
-                               CmsEditionEvent.START_EDITING));
+               notifyListeners(new CmsEditionEvent(nodePath, CmsEditionEvent.START_EDITING, this));
        }
 
        @Override
        public void stopEditing() {
                try {
                        versionManager.checkin(nodePath);
-                       setChanged();
+//                     setChanged();
                } catch (RepositoryException e1) {
-                       throw new CmsException("Cannot publish " + nodePath, e1);
+                       throw new JcrException("Cannot publish " + nodePath, e1);
                }
-               notifyObservers(new CmsEditionEvent(nodePath,
-                               CmsEditionEvent.STOP_EDITING));
+               notifyListeners(new CmsEditionEvent(nodePath, CmsEditionEvent.STOP_EDITING, this));
        }
+
 }