X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=org.argeo.cms%2Fsrc%2Forg%2Fargeo%2Fcms%2Fviewers%2FAbstractPageViewer.java;h=21f259c8882d22be81695533091c93be57e4fee5;hb=85ced0e58ded00f296948b6dff51f84994855080;hp=837cf99292368b9617eeb8cecdfc39d296a57574;hpb=f515b2024832307daeb5c772830d00d45f88b6fe;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.cms/src/org/argeo/cms/viewers/AbstractPageViewer.java b/org.argeo.cms/src/org/argeo/cms/viewers/AbstractPageViewer.java index 837cf9929..21f259c88 100644 --- a/org.argeo.cms/src/org/argeo/cms/viewers/AbstractPageViewer.java +++ b/org.argeo.cms/src/org/argeo/cms/viewers/AbstractPageViewer.java @@ -5,6 +5,7 @@ import java.util.Observer; import javax.jcr.Node; import javax.jcr.RepositoryException; +import javax.jcr.Session; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -20,6 +21,7 @@ import org.eclipse.swt.events.MouseListener; 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 @@ -38,25 +40,6 @@ 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 @@ -165,8 +148,16 @@ public abstract class AbstractPageViewer extends ContentViewer implements 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); @@ -247,6 +238,30 @@ public abstract class AbstractPageViewer extends ContentViewer implements "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; @@ -268,5 +283,4 @@ public abstract class AbstractPageViewer extends ContentViewer implements public ISelection getSelection() { return selection; } - -} +} \ No newline at end of file