import org.argeo.cms.CmsException;
import org.argeo.cms.CmsImageManager;
import org.argeo.cms.CmsNames;
-import org.argeo.cms.CmsSession;
import org.argeo.cms.CmsTypes;
-import org.argeo.cms.text.IdentityTextInterpreter;
import org.argeo.cms.text.Img;
import org.argeo.cms.text.Paragraph;
import org.argeo.cms.text.TextInterpreter;
import org.argeo.cms.widgets.EditableText;
import org.argeo.cms.widgets.StyledControl;
import org.argeo.jcr.JcrUtils;
-import org.eclipse.rap.addons.fileupload.FileDetails;
-import org.eclipse.rap.addons.fileupload.FileUploadEvent;
-import org.eclipse.rap.addons.fileupload.FileUploadHandler;
-import org.eclipse.rap.addons.fileupload.FileUploadListener;
+import org.eclipse.rap.fileupload.FileDetails;
+import org.eclipse.rap.fileupload.FileUploadEvent;
+import org.eclipse.rap.fileupload.FileUploadHandler;
+import org.eclipse.rap.fileupload.FileUploadListener;
import org.eclipse.rap.rwt.RWT;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyEvent;
private final Section mainSection;
- private TextInterpreter textInterpreter = new IdentityTextInterpreter();
- private CmsImageManager imageManager = CmsSession.current.get()
+ private TextInterpreter textInterpreter = new TextInterpreterImpl();
+ private CmsImageManager imageManager = CmsUtils.getCmsView()
.getImageManager();
private FileUploadListener fileUploadListener;
currentParagraph = newParagraph;
currentParagraphN = newNode;
}
+ persistChanges(sectionNode);
}
// TODO or rather return the created paragarphs?
layout(toLayout.toArray(new Control[toLayout.size()]));
"TAB", "SHIFT+TAB", "ALT+ARROW_LEFT", "ALT+ARROW_RIGHT",
"ALT+ARROW_UP", "ALT+ARROW_DOWN", "RETURN", "CTRL+RETURN",
"ENTER", "DELETE" });
- text.setData(RWT.CANCEL_KEYS, new String[] { "ALT+ARROW_LEFT",
- "ALT+ARROW_RIGHT" });
+ text.setData(RWT.CANCEL_KEYS, new String[] { "RETURN",
+ "ALT+ARROW_LEFT", "ALT+ARROW_RIGHT" });
text.addKeyListener(this);
} else if (part instanceof Img) {
((Img) part).setFileUploadListener(fileUploadListener);
try {
Node paragraphNode = paragraph.getNode();
paragraphNode.setProperty(CMS_STYLE, style);
- paragraphNode.getSession().save();
+ persistChanges(paragraphNode);
updateContent(paragraph);
layout(paragraph);
} catch (RepositoryException e1) {
// if we die in between, at least we still have the whole text
// in the first node
- textInterpreter.write(secondNode, second);
- textInterpreter.write(firstNode, first);
+ try {
+ textInterpreter.write(secondNode, second);
+ textInterpreter.write(firstNode, first);
+ } catch (Exception e) {
+ // so that no additional nodes are created:
+ JcrUtils.discardUnderlyingSessionQuietly(firstNode);
+ throw e;
+ }
+
+ persistChanges(firstNode);
Paragraph secondParagraph = paragraphSplitted(paragraph,
secondNode);
sectionNode.getProperty(Property.JCR_TITLE),
txt.substring(0, caretPosition));
sectionNode.orderBefore(p(paragraphNode.getIndex()), p(1));
- sectionNode.getSession().save();
+ persistChanges(sectionNode);
Paragraph paragraph = sectionTitleSplitted(sectionTitle,
paragraphNode);
String previousTxt = textInterpreter.read(previousNode);
textInterpreter.write(previousNode, previousTxt + txt);
paragraphNode.remove();
- sectionNode.getSession().save();
+ persistChanges(sectionNode);
Paragraph previousParagraph = paragraphMergedWithPrevious(
paragraph, previousNode);
.getIdentifier());
nextNode.remove();
- sectionNode.getSession().save();
+ persistChanges(sectionNode);
paragraphMergedWithNext(paragraph, removed);
edit(paragraph, txt.length());
}
// sectionNode.orderBefore(p(partNode.getIndex()),
// p(newNode.getIndex()));
- sectionNode.getSession().save();
+ persistChanges(sectionNode);
Img img = newImg((TextSection) section, newNode);
edit(img, null);
layout(img.getControl());
refresh(newSection);
newSection.getParent().layout();
layout(newSection);
- newSectionNode.getSession().save();
+ persistChanges(sectionNode);
} else if (getEdited() instanceof SectionTitle) {
SectionTitle sectionTitle = (SectionTitle) getEdited();
Section section = sectionTitle.getSection();
TextSection newSection = new TextSection(section,
section.getStyle(), sectionN);
refresh(newSection);
- previousSectionN.getSession().save();
+ persistChanges(previousSectionN);
}
} catch (RepositoryException e) {
throw new CmsException("Cannot deepen " + getEdited(), e);
refresh(mergedSection);
mergedSection.getParent().layout();
layout(mergedSection);
- mergedNode.getSession().save();
+ persistChanges(mergedNode);
}
} catch (RepositoryException e) {
throw new CmsException("Cannot undeepen " + getEdited(), e);
// KEY LISTENER
@Override
- public void keyPressed(KeyEvent e) {
+ public void keyPressed(KeyEvent ke) {
if (log.isTraceEnabled())
- log.trace(e);
+ log.trace(ke);
if (getEdited() == null)
return;
- boolean altPressed = (e.stateMask & SWT.ALT) != 0;
- boolean shiftPressed = (e.stateMask & SWT.SHIFT) != 0;
- boolean ctrlPressed = (e.stateMask & SWT.CTRL) != 0;
-
- // Common
- if (e.keyCode == SWT.ESC) {
- cancelEdit();
- } else if (e.character == '\r') {
- splitEdit();
- } else if (e.character == 'S') {
- if (ctrlPressed)
- saveEdit();
- } else if (e.character == '\t') {
- if (!shiftPressed) {
- deepen();
- } else if (shiftPressed) {
- undeepen();
- }
- } else {
- if (getEdited() instanceof Paragraph) {
- Paragraph paragraph = (Paragraph) getEdited();
- Section section = paragraph.getSection();
- if (altPressed && e.keyCode == SWT.ARROW_RIGHT) {
- edit(section.nextSectionPart(paragraph), 0);
- } else if (altPressed && e.keyCode == SWT.ARROW_LEFT) {
- edit(section.previousSectionPart(paragraph), 0);
- } else if (e.character == SWT.BS) {
- Text text = (Text) paragraph.getControl();
- int caretPosition = text.getCaretPosition();
- if (caretPosition == 0) {
- mergeWithPrevious();
- }
- } else if (e.character == SWT.DEL) {
- Text text = (Text) paragraph.getControl();
- int caretPosition = text.getCaretPosition();
- int charcount = text.getCharCount();
- if (caretPosition == charcount) {
- mergeWithNext();
+ boolean altPressed = (ke.stateMask & SWT.ALT) != 0;
+ boolean shiftPressed = (ke.stateMask & SWT.SHIFT) != 0;
+ boolean ctrlPressed = (ke.stateMask & SWT.CTRL) != 0;
+
+ try {
+ // Common
+ if (ke.keyCode == SWT.ESC) {
+ cancelEdit();
+ } else if (ke.character == '\r') {
+ splitEdit();
+ } else if (ke.character == 'S') {
+ if (ctrlPressed)
+ saveEdit();
+ } else if (ke.character == '\t') {
+ if (!shiftPressed) {
+ deepen();
+ } else if (shiftPressed) {
+ undeepen();
+ }
+ } else {
+ if (getEdited() instanceof Paragraph) {
+ Paragraph paragraph = (Paragraph) getEdited();
+ Section section = paragraph.getSection();
+ if (altPressed && ke.keyCode == SWT.ARROW_RIGHT) {
+ edit(section.nextSectionPart(paragraph), 0);
+ } else if (altPressed && ke.keyCode == SWT.ARROW_LEFT) {
+ edit(section.previousSectionPart(paragraph), 0);
+ } else if (ke.character == SWT.BS) {
+ Text text = (Text) paragraph.getControl();
+ int caretPosition = text.getCaretPosition();
+ if (caretPosition == 0) {
+ mergeWithPrevious();
+ }
+ } else if (ke.character == SWT.DEL) {
+ Text text = (Text) paragraph.getControl();
+ int caretPosition = text.getCaretPosition();
+ int charcount = text.getCharCount();
+ if (caretPosition == charcount) {
+ mergeWithNext();
+ }
}
}
}
+ } catch (Exception e) {
+ ke.doit = false;
+ notifyEditionException(e);
}
}
}
}
- private EditablePart findDataParent(Control parent) {
- if (parent instanceof EditablePart) {
- return (EditablePart) parent;
- }
- if (parent.getParent() != null)
- return findDataParent(parent.getParent());
- else
- throw new CmsException("No data parent found");
- }
-
@Override
public void mouseUp(MouseEvent e) {
}