media=media
style=style
+insertParagraph=insert paragraph
deleteParagraph=delete paragraph
deleteSection=delete section
//
section, deleteSection,
//
- media, deleteMedia, insertMedia,
+ media, deleteMedia, insertMedia, insertParagraph,
//
;
}
public static Node insertImageAfter(Node sibling) {
try {
- // FIXME make it more robust
- if (DbkType.imagedata.get().equals(sibling.getName())) {
- sibling = sibling.getParent().getParent();
- }
-
Node parent = sibling.getParent();
Node mediaNode = addDbk(parent, DbkType.mediaobject);
// TODO optimise?
// // TODO make it more robust and generic
// String fileRef = mediaNode.getName();
// imageDataNode.setProperty(DocBookNames.DBK_FILEREF, fileRef);
- return imageDataNode;
+ return mediaNode;
} catch (RepositoryException e) {
throw new JcrException("Cannot insert empty image after " + sibling, e);
}
Node child = ni.nextNode();
SectionPart sectionPart = null;
if (isDbk(child, DbkType.mediaobject)) {
- if (child.hasNode(DbkType.imageobject.get())) {
- Node imageDataNode = child.getNode(DbkType.imageobject.get()).getNode(DbkType.imagedata.get());
- sectionPart = newImg(textSection, imageDataNode);
- }
+ sectionPart = newImg(textSection, child);
+// if (child.hasNode(DbkType.imageobject.get())) {
+// Node imageDataNode = child.getNode(DbkType.imageobject.get()).getNode(DbkType.imagedata.get());
+// sectionPart = newImg(textSection, imageDataNode);
+// }
} else if (isDbk(child, para)) {
sectionPart = newParagraph(textSection, child);
} else {
}
}
- void insertPart(Section section, Node node) {
+ SectionPart insertPart(Section section, Node node) {
try {
refresh(section);
layoutPage();
+ for (Control control : section.getChildren()) {
+ if (control instanceof SectionPart) {
+ SectionPart sectionPart = (SectionPart) control;
+ Node partNode = sectionPart.getNode();
+ if (partNode.getPath().equals(node.getPath()))
+ return sectionPart;
+ }
+ }
+ throw new IllegalStateException("New section part " + node + "not found");
} catch (RepositoryException e) {
throw new JcrException("Cannot insert part " + node + " in section " + section.getNode(), e);
}
}
+ void addParagraph(SectionPart partBefore, String txt) {
+ Section section = partBefore.getSection();
+ SectionPart nextSectionPart = section.nextSectionPart(partBefore);
+ Node newNode = addDbk(section.getNode(), para);
+ textInterpreter.write(newNode, txt != null ? txt : "");
+ if (nextSectionPart != null) {
+ try {
+ Node nextNode = nextSectionPart.getNode();
+ section.getNode().orderBefore(Jcr.getIndexedName(newNode), Jcr.getIndexedName(nextNode));
+ } catch (RepositoryException e) {
+ throw new JcrException("Cannot order " + newNode + " before " + nextSectionPart.getNode(), e);
+ }
+ }
+ Jcr.save(newNode);
+ Paragraph paragraph = (Paragraph) insertPart(partBefore.getSection(), newNode);
+ edit(paragraph, 0);
+ }
+
void deletePart(SectionPart sectionPart) {
try {
Node node = sectionPart.getNode();
Session session = node.getSession();
if (sectionPart instanceof DbkImg) {
- // FIXME make it more robust
- node = node.getParent().getParent();
if (!isDbk(node, DbkType.mediaobject))
throw new IllegalArgumentException("Node " + node + " is not a media object.");
}
float height = bounds.height;
float textLength = lbl.getText().length();
float area = width * height;
- float charArea = area/textLength;
- float lines = textLength/width;
+ float charArea = area / textLength;
+ float lines = textLength / width;
float proportion = point.y * width + point.x;
int pos = (int) (textLength * (proportion / area));
// TODO refine it
Img img = (Img) editablePart;
deletePartB(parent, DbkMsg.deleteMedia.lead(), img);
insertMediaB(parent, DbkMsg.insertMedia.lead(), img);
+ insertParagraphB(parent, DbkMsg.insertParagraph.lead(), img);
} else if (editablePart instanceof DocBookSectionTitle) {
DocBookSectionTitle sectionTitle = (DocBookSectionTitle) editablePart;
}
+ protected void insertParagraphB(Composite parent, String msg, SectionPart sectionPart) {
+ Label insertMediaB = new Label(parent, SWT.NONE);
+ insertMediaB.setText(msg);
+ insertMediaB.addMouseListener((MouseDown) (e) -> {
+ textViewer.addParagraph(sectionPart, null);
+ hide();
+ });
+ }
+
protected void deletePartB(Composite parent, String msg, SectionPart sectionPart) {
Label deleteB = new Label(shell, SWT.NONE);
deleteB.setText(msg);
this.baseFolder = baseFolder;
}
+ Node getImageDataNode(Node mediaObjectNode) throws RepositoryException {
+ if (mediaObjectNode.hasNode(DbkType.imageobject.get())) {
+ Node imageDataNode = mediaObjectNode.getNode(DbkType.imageobject.get()).getNode(DbkType.imagedata.get());
+ return imageDataNode;
+ } else {
+ throw new IllegalStateException("No image data found for " + mediaObjectNode);
+ }
+ }
+
@Override
public Binary getImageBinary(Node node) throws RepositoryException {
Node fileNode = null;
- if (DbkUtils.isDbk(node, DbkType.imagedata)) {
- fileNode = getFileNode(node);
+ if (DbkUtils.isDbk(node, DbkType.mediaobject)) {
+ Node imageDataNode = getImageDataNode(node);
+ fileNode = getFileNode(imageDataNode);
}
if (node.isNodeType(NT_FILE)) {
fileNode = node;
}
}
- public Point getImageSize(Node imageDataNode) throws RepositoryException {
+ public Point getImageSize(Node mediaObjectNode) throws RepositoryException {
+ Node imageDataNode = getImageDataNode(mediaObjectNode);
Node fileNode = getFileNode(imageDataNode);
if (fileNode == null)
return new Point(0, 0);
}
@Override
- protected void processNewImageFile(Node context, Node fileNode, ImageData id)
+ protected void processNewImageFile(Node mediaObjectNode, Node fileNode, ImageData id)
throws RepositoryException, IOException {
+ Node imageDataNode = getImageDataNode(mediaObjectNode);
updateSize(fileNode, id);
String filePath = fileNode.getPath();
String relPath = filePath.substring(baseFolder.getPath().length() + 1);
- context.setProperty(DbkAttr.fileref.name(), relPath);
+ imageDataNode.setProperty(DbkAttr.fileref.name(), relPath);
}
@Override
- public String getImageUrl(Node imageDataNode) throws RepositoryException {
+ public String getImageUrl(Node mediaObjectNode) throws RepositoryException {
+ Node imageDataNode = getImageDataNode(mediaObjectNode);
// TODO factorise
String fileref = null;
if (imageDataNode.hasProperty(DbkAttr.fileref.name()))