X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=org.argeo.app.swt%2Fsrc%2Forg%2Fargeo%2Fapp%2Fswt%2Fdocbook%2FDocBookViewer.java;h=5e94e48f1695a687840ca6597d5c70b30fb0780b;hb=83e74449e8af94776a41e26cc2b94e752239e6ba;hp=6cd5172aceda5bcbe68a0b5ef9cea61d97552ba3;hpb=3304f8934e1dc5846fc6214997bc54faaa93bb39;p=gpl%2Fargeo-suite.git diff --git a/org.argeo.app.swt/src/org/argeo/app/swt/docbook/DocBookViewer.java b/org.argeo.app.swt/src/org/argeo/app/swt/docbook/DocBookViewer.java index 6cd5172..5e94e48 100644 --- a/org.argeo.app.swt/src/org/argeo/app/swt/docbook/DocBookViewer.java +++ b/org.argeo.app.swt/src/org/argeo/app/swt/docbook/DocBookViewer.java @@ -16,6 +16,7 @@ import org.argeo.cms.swt.acr.SwtSection; import org.argeo.cms.swt.acr.SwtSectionPart; import org.argeo.cms.swt.widgets.EditableText; import org.argeo.cms.swt.widgets.StyledControl; +import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; @@ -25,6 +26,10 @@ public class DocBookViewer extends AbstractPageViewer { private TextSection mainSection; + private boolean showMainTitle = true; + + private String defaultSectionStyle; + public DocBookViewer(Composite parent, int style, Content item, CmsEditable cmsEditable) { super(parent, style, cmsEditable); for (Content child : item) { @@ -54,6 +59,27 @@ public class DocBookViewer extends AbstractPageViewer { } protected void refreshTextSection(TextSection section) { + Content sectionContent = section.getContent(); + // Style + Optional roleAttr = sectionContent.get(DbkAttr.role.qName(), String.class); + String style = roleAttr.orElse(section.getDefaultTextStyle()); + if (style != null) + CmsSwtUtils.style(section, style); + + // Title + Optional titleContent = sectionContent.soleChild(DbkType.title.qName()); + + if (titleContent.isPresent()) { + boolean showTitle = getMainSection() == section ? showMainTitle : true; + if (showTitle) { + if (section.getHeader() == null) + section.createHeader(); + DbkSectionTitle title = newSectionTitle(section, titleContent.get()); + title.setLayoutData(CmsSwtUtils.fillWidth()); + updateContent(title); + } + } + for (Content child : section.getContent()) { if (child.hasContentClass(DbkType.section.qName())) { TextSection childSection = new TextSection(section, 0, child); @@ -89,9 +115,9 @@ public class DocBookViewer extends AbstractPageViewer { if (paragraph == getEdited()) paragraph.setText(textInterpreter.raw(partContent)); else - paragraph.setText(textInterpreter.raw(partContent)); - //paragraph.setText(textInterpreter.readSimpleHtml(partContent)); - + paragraph.setText(textInterpreter.readSimpleHtml(partContent)); + // paragraph.setText(textInterpreter.readSimpleHtml(partContent)); + // } else if (part instanceof DbkImg) { // DbkImg editableImage = (DbkImg) part; // // imageManager.load(partNode, part.getControl(), @@ -101,16 +127,54 @@ public class DocBookViewer extends AbstractPageViewer { // video.load(part.getControl()); // } } + } else if (part instanceof DbkSectionTitle) { + DbkSectionTitle title = (DbkSectionTitle) part; + title.setStyle(title.getSection().getTitleStyle()); + // use control AFTER setting style + if (title == getEdited()) + title.setText(textInterpreter.read(title.getContent())); + else + title.setText(textInterpreter.readSimpleHtml(title.getContent())); } -// else if (part instanceof DbkSectionTitle) { -// DbkSectionTitle title = (DbkSectionTitle) part; -// title.setStyle(title.getSection().getTitleStyle()); -// // use control AFTER setting style -// if (title == getEdited()) -// title.setText(textInterpreter.read(title.getNode())); -// else -// title.setText(textInterpreter.readSimpleHtml(title.getNode())); -// } + } + + protected DbkSectionTitle newSectionTitle(TextSection parent, Content titleNode) { + int style = parent.getStyle(); + Composite titleParent = newSectionHeader(parent); + if (parent.isTitleReadOnly()) + style = style | SWT.READ_ONLY; + DbkSectionTitle title = new DbkSectionTitle(titleParent, style, titleNode); + updateContent(title); + title.setMouseListener(getMouseListener()); + title.setFocusListener(getFocusListener()); + return title; + } + + /** + * To be overridden in order to provide additional processing at the section + * level. + * + * @return the parent to use for the {@link DbkSectionTitle}, by default + * {@link Section#getHeader()} + */ + protected Composite newSectionHeader(TextSection section) { + return section.getHeader(); + } + + public TextSection getMainSection() { + return mainSection; + } + + public void setShowMainTitle(boolean showMainTitle) { + this.showMainTitle = showMainTitle; + } + + public String getDefaultSectionStyle() { + return defaultSectionStyle; + } + + public void setDefaultSectionStyle(String defaultSectionStyle) { + this.defaultSectionStyle = defaultSectionStyle; } @Override