Improve DocBook ACR support
authorMathieu Baudier <mbaudier@argeo.org>
Sun, 18 Jun 2023 06:20:22 +0000 (08:20 +0200)
committerMathieu Baudier <mbaudier@argeo.org>
Sun, 18 Jun 2023 06:20:22 +0000 (08:20 +0200)
org.argeo.app.core/src/org/argeo/app/docbook/DbkAcrUtils.java
swt/org.argeo.app.swt/src/org/argeo/app/swt/docbook/DbkVideo.java
swt/org.argeo.app.swt/src/org/argeo/app/swt/docbook/DocBookViewer.java

index 8dda2b49dfb6e4d689c5fcf1abb2bd169ebfde30..8a92db379ec76ee4fb77b6bce3fe6809f7f2d983 100644 (file)
@@ -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() {
        }
index 8055634ded7af6829d771fc5dec7fd660a3a8929..6c42146bb8f7bd45bab03cd6fb67d238c3fc9bc3 100644 (file)
@@ -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();
index 9956adeed1f873edcc329b0675bda22690bc0c9e..141a900be2a96543b410c944ab12875ee4497e28 100644 (file)
@@ -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<String> getAvailableStyles(SwtEditablePart editablePart) {
+               return new ArrayList<>();
+       }
+
        public TextSection getMainSection() {
                return mainSection;
        }