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;
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) {
}
protected void refreshTextSection(TextSection section) {
+ Content sectionContent = section.getContent();
+ // Style
+ Optional<String> roleAttr = sectionContent.get(DbkAttr.role.qName(), String.class);
+ String style = roleAttr.orElse(section.getDefaultTextStyle());
+ if (style != null)
+ CmsSwtUtils.style(section, style);
+
+ // Title
+ Optional<Content> 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);
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(),
// 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