X-Git-Url: https://git.argeo.org/?p=gpl%2Fargeo-suite.git;a=blobdiff_plain;f=publishing%2Forg.argeo.publishing.ui%2Fsrc%2Forg%2Fargeo%2Fdocbook%2Fui%2FAbstractDbkViewer.java;fp=publishing%2Forg.argeo.publishing.ui%2Fsrc%2Forg%2Fargeo%2Fdocbook%2Fui%2FAbstractDbkViewer.java;h=44e6f547a4088f6ff59f642c30a7cf58df1e7102;hp=02509f25732bec1b037f840a9b81526e94e3c68b;hb=f4c6893c66cd619e699cb9392ff8c45367796154;hpb=d583547f3046d1e0d9a1dc689abe71dcd1decfb7 diff --git a/publishing/org.argeo.publishing.ui/src/org/argeo/docbook/ui/AbstractDbkViewer.java b/publishing/org.argeo.publishing.ui/src/org/argeo/docbook/ui/AbstractDbkViewer.java index 02509f2..44e6f54 100644 --- a/publishing/org.argeo.publishing.ui/src/org/argeo/docbook/ui/AbstractDbkViewer.java +++ b/publishing/org.argeo.publishing.ui/src/org/argeo/docbook/ui/AbstractDbkViewer.java @@ -114,10 +114,11 @@ public abstract class AbstractDbkViewer extends AbstractPageViewer implements Ke 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 { @@ -356,22 +357,47 @@ public abstract class AbstractDbkViewer extends AbstractPageViewer implements Ke } } - 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."); } @@ -862,8 +888,8 @@ public abstract class AbstractDbkViewer extends AbstractPageViewer implements Ke 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