Make abstract page viewer more robust.
[lgpl/argeo-commons.git] / org.argeo.cms.ui / src / org / argeo / cms / ui / viewers / AbstractPageViewer.java
index a60c4f62e3824cc498d2c13cf54aaecdc8a07a15..e5ae67a794c51a50842937c5ab42a53989a20e14 100644 (file)
@@ -164,7 +164,8 @@ public abstract class AbstractPageViewer extends ContentViewer implements Observ
                                        mouseListener = null;
                                refresh(getControl());
                                // layout(getControl());
-                               layoutPage();
+                               if (!getControl().isDisposed())
+                                       layoutPage();
                        } catch (RepositoryException e) {
                                throw new JcrException("Cannot refresh", e);
                        }
@@ -198,9 +199,9 @@ public abstract class AbstractPageViewer extends ContentViewer implements Observ
                        }
 
                        part.startEditing();
+                       edited = part;
                        updateContent(part);
                        prepare(part, caretPosition);
-                       edited = part;
                        edited.getControl().addFocusListener(new FocusListener() {
                                private static final long serialVersionUID = 6883521812717097017L;
 
@@ -239,8 +240,12 @@ public abstract class AbstractPageViewer extends ContentViewer implements Observ
                                save(edited);
 
                        edited.stopEditing();
-                       updateContent(edited);
-                       layout(((EditablePart) edited).getControl());
+                       EditablePart editablePart = edited;
+                       Control control = ((EditablePart) edited).getControl();
+                       edited = null;
+                       // TODO make edited state management more robust
+                       updateContent(editablePart);
+                       layout(control);
                } catch (RepositoryException e) {
                        throw new JcrException("Cannot stop editing", e);
                } finally {