1 package org
.argeo
.app
.swt
.docbook
;
3 import static org
.argeo
.app
.docbook
.DbkAcrUtils
.isDbk
;
4 import static org
.argeo
.app
.docbook
.DbkType
.para
;
6 import java
.util
.Optional
;
8 import org
.argeo
.api
.acr
.Content
;
9 import org
.argeo
.api
.cms
.ux
.CmsEditable
;
10 import org
.argeo
.app
.docbook
.DbkAttr
;
11 import org
.argeo
.app
.docbook
.DbkType
;
12 import org
.argeo
.cms
.swt
.CmsSwtUtils
;
13 import org
.argeo
.cms
.swt
.SwtEditablePart
;
14 import org
.argeo
.cms
.swt
.acr
.AbstractPageViewer
;
15 import org
.argeo
.cms
.swt
.acr
.SwtSection
;
16 import org
.argeo
.cms
.swt
.acr
.SwtSectionPart
;
17 import org
.argeo
.cms
.swt
.widgets
.EditableText
;
18 import org
.argeo
.cms
.swt
.widgets
.StyledControl
;
19 import org
.eclipse
.swt
.widgets
.Composite
;
20 import org
.eclipse
.swt
.widgets
.Control
;
22 public class DocBookViewer
extends AbstractPageViewer
{
24 private TextInterpreter textInterpreter
= new DbkTextInterpreter();
26 private TextSection mainSection
;
28 public DocBookViewer(Composite parent
, int style
, Content item
, CmsEditable cmsEditable
) {
29 super(parent
, style
, cmsEditable
);
30 for (Content child
: item
) {
31 if (child
.hasContentClass(DbkType
.article
.qName())) {
32 if (mainSection
!= null)
33 throw new IllegalStateException("Main section already created");
34 mainSection
= new TextSection(parent
, 0, child
);
35 mainSection
.setLayoutData(CmsSwtUtils
.fillAll());
41 protected void refresh(Control control
) {
42 if (!(control
instanceof SwtSection
))
44 long begin
= System
.currentTimeMillis();
45 SwtSection section
= (SwtSection
) control
;
46 if (section
instanceof TextSection
) {
47 CmsSwtUtils
.clear(mainSection
);
48 refreshTextSection(mainSection
);
51 long duration
= System
.currentTimeMillis() - begin
;
52 // System.out.println(duration + " ms - " + DbkUtils.getTitle(section.getNode()));
56 protected void refreshTextSection(TextSection section
) {
57 for (Content child
: section
.getContent()) {
58 if (child
.hasContentClass(DbkType
.section
.qName())) {
59 TextSection childSection
= new TextSection(section
, 0, child
);
60 childSection
.setLayoutData(CmsSwtUtils
.fillAll());
61 refreshTextSection(childSection
);
62 } else if (child
.hasContentClass(DbkType
.para
.qName())) {
63 Paragraph para
= new Paragraph(section
, 0, child
);
64 para
.setLayoutData(CmsSwtUtils
.fillWidth());
71 protected void updateContent(SwtEditablePart part
) {
72 if (part
instanceof SwtSectionPart
) {
73 SwtSectionPart sectionPart
= (SwtSectionPart
) part
;
74 Content partContent
= sectionPart
.getContent();
76 if (part
instanceof StyledControl
&& (sectionPart
.getSection() instanceof TextSection
)) {
77 TextSection section
= (TextSection
) sectionPart
.getSection();
78 StyledControl styledControl
= (StyledControl
) part
;
79 if (isDbk(partContent
, para
)) {
80 Optional
<String
> roleAttr
= partContent
.get(DbkAttr
.role
.qName(), String
.class);
81 String style
= roleAttr
.orElse(section
.getDefaultTextStyle());
82 styledControl
.setStyle(style
);
85 // use control AFTER setting style, since it may have been reset
87 if (part
instanceof EditableText
) {
88 EditableText paragraph
= (EditableText
) part
;
89 if (paragraph
== getEdited())
90 paragraph
.setText(textInterpreter
.raw(partContent
));
92 paragraph
.setText(textInterpreter
.raw(partContent
));
93 //paragraph.setText(textInterpreter.readSimpleHtml(partContent));
95 // } else if (part instanceof DbkImg) {
96 // DbkImg editableImage = (DbkImg) part;
97 // // imageManager.load(partNode, part.getControl(),
98 // // editableImage.getPreferredImageSize());
99 // } else if (part instanceof DbkVideo) {
100 // DbkVideo video = (DbkVideo) part;
101 // video.load(part.getControl());
105 // else if (part instanceof DbkSectionTitle) {
106 // DbkSectionTitle title = (DbkSectionTitle) part;
107 // title.setStyle(title.getSection().getTitleStyle());
108 // // use control AFTER setting style
109 // if (title == getEdited())
110 // title.setText(textInterpreter.read(title.getNode()));
112 // title.setText(textInterpreter.readSimpleHtml(title.getNode()));
117 public Control
getControl() {