9dc7e1002dea7e68d91f6f4eb1a28532b5a05f75
[gpl/argeo-suite.git] / publishing / org.argeo.publishing.ui / src / org / argeo / docbook / ui / DocumentTextEditor.java
1 package org.argeo.docbook.ui;
2
3 import javax.jcr.Node;
4 import javax.jcr.Property;
5 import javax.jcr.RepositoryException;
6
7 import org.argeo.cms.text.TextSection;
8 import org.argeo.cms.ui.CmsEditable;
9 import org.argeo.cms.ui.util.CmsUiUtils;
10 import org.eclipse.swt.widgets.Composite;
11
12 /** Text editor where sections and subsections can be managed by the user. */
13 public class DocumentTextEditor extends AbstractDbkViewer {
14         private static final long serialVersionUID = 6049661610883342325L;
15
16         public DocumentTextEditor(Composite parent, int style, Node textNode, CmsEditable cmsEditable)
17                         throws RepositoryException {
18                 super(new TextSection(parent, style, textNode), style, cmsEditable);
19                 refresh();
20                 getMainSection().setLayoutData(CmsUiUtils.fillWidth());
21         }
22
23         @Override
24         protected void initModel(Node textNode) throws RepositoryException {
25                 if (isFlat()) {
26                         textNode.addNode(DocBookNames.DBK_PARA, DocBookTypes.PARA)
27                                         .addNode(DocBookNames.JCR_XMLTEXT, DocBookTypes.XMLTEXT)
28                                         .setProperty(DocBookNames.JCR_XMLCHARACTERS, "Hello World!");
29                 }
30 //              else
31 //                      textNode.setProperty(DocBookNames.DBK_TITLE, textNode.getName());
32         }
33
34         @Override
35         protected Boolean isModelInitialized(Node textNode) throws RepositoryException {
36                 return textNode.hasProperty(Property.JCR_TITLE) || textNode.hasNode(DocBookNames.DBK_PARA)
37                                 || (!isFlat() && textNode.hasNode(DocBookNames.DBK_SECTION));
38         }
39
40 }