From 0bc3237979494a2564d80b4255a1efbbf9ff454e Mon Sep 17 00:00:00 2001 From: Mathieu Baudier Date: Sun, 18 Jun 2023 08:20:22 +0200 Subject: [PATCH] Improve DocBook ACR support --- .../org/argeo/app/docbook/DbkAcrUtils.java | 11 +++++++++ .../org/argeo/app/swt/docbook/DbkVideo.java | 9 +++++-- .../argeo/app/swt/docbook/DocBookViewer.java | 24 +++++++++++++++---- 3 files changed, 37 insertions(+), 7 deletions(-) diff --git a/org.argeo.app.core/src/org/argeo/app/docbook/DbkAcrUtils.java b/org.argeo.app.core/src/org/argeo/app/docbook/DbkAcrUtils.java index 8dda2b4..8a92db3 100644 --- a/org.argeo.app.core/src/org/argeo/app/docbook/DbkAcrUtils.java +++ b/org.argeo.app.core/src/org/argeo/app/docbook/DbkAcrUtils.java @@ -1,7 +1,9 @@ package org.argeo.app.docbook; import org.argeo.api.acr.Content; +import org.argeo.app.api.EntityType; +/** Utilities when using ACR to access DocBook. */ public class DbkAcrUtils { /** Whether this DocBook element is of this type. */ public static boolean isDbk(Content content, DbkType type) { @@ -23,6 +25,15 @@ public class DbkAcrUtils { } } + public static Content getMetadata(Content infoContainer) { + if (!infoContainer.hasChild(DbkType.info)) + return null; + Content info = infoContainer.child(DbkType.info); + if (!info.hasChild(EntityType.local)) + return null; + return info.child(EntityType.local); + } + /** singleton */ private DbkAcrUtils() { } diff --git a/swt/org.argeo.app.swt/src/org/argeo/app/swt/docbook/DbkVideo.java b/swt/org.argeo.app.swt/src/org/argeo/app/swt/docbook/DbkVideo.java index 8055634..6c42146 100644 --- a/swt/org.argeo.app.swt/src/org/argeo/app/swt/docbook/DbkVideo.java +++ b/swt/org.argeo.app.swt/src/org/argeo/app/swt/docbook/DbkVideo.java @@ -44,13 +44,14 @@ public class DbkVideo extends StyledControl implements SwtSectionPart, ContentPa super(parent, style); editable = !(SWT.READ_ONLY == (style & SWT.READ_ONLY)); this.section = section; - setStyle(DbkType.videoobject.name()); + // set data before setting style since it creates the control setData(node); + setStyle(DbkType.videoobject.name()); } @Override protected Control createControl(Composite box, String style) { - Content mediaobject = getNode(); + Content mediaobject = getContent(); Composite wrapper = new Composite(box, SWT.NONE); wrapper.setLayout(CmsSwtUtils.noSpaceGridLayout()); @@ -78,6 +79,8 @@ public class DbkVideo extends StyledControl implements SwtSectionPart, ContentPa updateB.setText("Update"); updateB.addSelectionListener(new Selected() { + private static final long serialVersionUID = -8234047511858456222L; + @Override public void widgetSelected(SelectionEvent e) { Content videodata = mediaobject.child(DbkType.videoobject).child(DbkType.videodata); @@ -139,6 +142,8 @@ public class DbkVideo extends StyledControl implements SwtSectionPart, ContentPa deleteB.setText("Delete"); deleteB.addSelectionListener(new Selected() { + private static final long serialVersionUID = -7552456185687361642L; + @Override public void widgetSelected(SelectionEvent e) { mediaobject.remove(); diff --git a/swt/org.argeo.app.swt/src/org/argeo/app/swt/docbook/DocBookViewer.java b/swt/org.argeo.app.swt/src/org/argeo/app/swt/docbook/DocBookViewer.java index 9956ade..141a900 100644 --- a/swt/org.argeo.app.swt/src/org/argeo/app/swt/docbook/DocBookViewer.java +++ b/swt/org.argeo.app.swt/src/org/argeo/app/swt/docbook/DocBookViewer.java @@ -3,6 +3,8 @@ package org.argeo.app.swt.docbook; import static org.argeo.app.docbook.DbkAcrUtils.isDbk; import static org.argeo.app.docbook.DbkType.para; +import java.util.ArrayList; +import java.util.List; import java.util.Optional; import org.argeo.api.acr.Content; @@ -22,6 +24,7 @@ import org.eclipse.swt.layout.GridData; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; +/** Displays DocBook content. */ public class DocBookViewer extends AbstractPageViewer { private TextInterpreter textInterpreter = new DbkTextInterpreter(); @@ -52,14 +55,14 @@ public class DocBookViewer extends AbstractPageViewer { protected void refresh(Control control) { if (!(control instanceof SwtSection)) return; - long begin = System.currentTimeMillis(); +// long begin = System.currentTimeMillis(); SwtSection section = (SwtSection) control; if (section instanceof TextSection) { CmsSwtUtils.clear(mainSection); refreshTextSection(mainSection); } - long duration = System.currentTimeMillis() - begin; +// long duration = System.currentTimeMillis() - begin; // System.out.println(duration + " ms - " + DbkUtils.getTitle(section.getNode())); } @@ -90,7 +93,7 @@ public class DocBookViewer extends AbstractPageViewer { for (Content child : section.getContent()) { if (child.hasContentClass(DbkType.section)) { processingSubSections = true; - TextSection childSection = new TextSection(section, 0, child); + TextSection childSection = newTextSection(section, child); // new TextSection(section, 0, child); childSection.setLayoutData(CmsSwtUtils.fillWidth()); refreshTextSection(childSection); } else { @@ -107,6 +110,8 @@ public class DocBookViewer extends AbstractPageViewer { } else { throw new IllegalArgumentException("Unsupported media object " + child); } + } else if (isDbk(child, DbkType.info)) { + // TODO enrich UI based on info } else if (isDbk(child, DbkType.title)) { // already managed // TODO check that it is first? @@ -145,7 +150,7 @@ public class DocBookViewer extends AbstractPageViewer { } else if (part instanceof DbkImg) { DbkImg editableImage = (DbkImg) part; -// imageManager.load(partContent, part.getControl(), editableImage.getPreferredImageSize()); + imageManager.load(partContent, part.getControl(), editableImage.getPreferredImageSize()); } else if (part instanceof DbkVideo) { DbkVideo video = (DbkVideo) part; video.load(part.getControl()); @@ -161,6 +166,11 @@ public class DocBookViewer extends AbstractPageViewer { } } + /** To be overridden in order to provide additional SectionPart types */ + protected TextSection newTextSection(SwtSection section, Content node) { + return new TextSection(section, SWT.NONE, node); + } + protected Paragraph newParagraph(TextSection parent, Content node) { Paragraph paragraph = new Paragraph(parent, parent.getStyle(), node); updateContent(paragraph); @@ -222,12 +232,16 @@ public class DocBookViewer extends AbstractPageViewer { * level. * * @return the parent to use for the {@link DbkSectionTitle}, by default - * {@link Section#getHeader()} + * {@link SwtSection#getHeader()} */ protected Composite newSectionHeader(TextSection section) { return section.getHeader(); } + protected List getAvailableStyles(SwtEditablePart editablePart) { + return new ArrayList<>(); + } + public TextSection getMainSection() { return mainSection; } -- 2.30.2