import javax.jcr.Node;
import javax.jcr.RepositoryException;
+import javax.jcr.Session;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Widget;
+import org.xml.sax.SAXParseException;
/** Base class for viewers related to a page */
public abstract class AbstractPageViewer extends ContentViewer implements
private EditablePart edited;
private ISelection selection = StructuredSelection.EMPTY;
- // FIXME Added by BSinou to manage non-section Composite.
- // Is it the correct method?
- @Deprecated
- protected AbstractPageViewer(Composite parent, int style,
- CmsEditable cmsEditable) {
- // read only at UI level
- readOnly = SWT.READ_ONLY == (style & SWT.READ_ONLY);
-
- this.cmsEditable = cmsEditable == null ? CmsEditable.NON_EDITABLE
- : cmsEditable;
- if (this.cmsEditable instanceof Observable)
- ((Observable) this.cmsEditable).addObserver(this);
-
- if (cmsEditable.canEdit()) {
- mouseListener = createMouseListener();
- }
- page = findPage(parent);
- }
-
protected AbstractPageViewer(Section parent, int style,
CmsEditable cmsEditable) {
// read only at UI level
if (edited == part)
return;
- if (edited != null && edited != part)
- stopEditing(true);
+ if (edited != null && edited != part) {
+ EditablePart previouslyEdited = edited;
+ try {
+ stopEditing(true);
+ } catch (Exception e) {
+ notifyEditionException(e);
+ edit(previouslyEdited, caretPosition);
+ return;
+ }
+ }
part.startEditing();
updateContent(part);
"Edited should not be null or disposed at this stage");
}
+ /** Persist all changes. */
+ protected void persistChanges(Session session) throws RepositoryException {
+ session.save();
+ session.refresh(false);
+ // TODO notify that changes have been persisted
+ }
+
+ /** Convenience method using a Node in order to save the underlying session. */
+ protected void persistChanges(Node anyNode) throws RepositoryException {
+ persistChanges(anyNode.getSession());
+ }
+
+ /** Notify edition exception */
+ protected void notifyEditionException(Throwable e) {
+ Throwable eToLog = e;
+ if (e instanceof IllegalArgumentException)
+ if (e.getCause() instanceof SAXParseException)
+ eToLog = e.getCause();
+ log.error(eToLog.getMessage());
+ if (log.isTraceEnabled())
+ log.trace("Full stack of " + eToLog.getMessage(), e);
+ // TODO Light error notification popup
+ }
+
// GETTERS / SETTERS
public boolean isReadOnly() {
return readOnly;
public ISelection getSelection() {
return selection;
}
-
-}
+}
\ No newline at end of file