]> git.argeo.org Git - gpl/argeo-suite.git/blob - swt/org.argeo.app.ui/src/org/argeo/app/ui/docbook/TextSection.java
Prepare refactoring suite UX
[gpl/argeo-suite.git] / swt / org.argeo.app.ui / src / org / argeo / app / ui / docbook / TextSection.java
1 package org.argeo.app.ui.docbook;
2
3 import javax.jcr.Node;
4
5 import org.argeo.app.docbook.DbkType;
6 import org.argeo.cms.swt.CmsSwtUtils;
7 import org.argeo.cms.swt.SwtEditablePart;
8 import org.argeo.cms.ui.viewers.Section;
9 import org.argeo.cms.ui.widgets.TextStyles;
10 import org.eclipse.swt.SWT;
11 import org.eclipse.swt.widgets.Composite;
12 import org.eclipse.swt.widgets.Control;
13
14 /** An editable section. */
15 public class TextSection extends Section {
16 private static final long serialVersionUID = -8625209546243220689L;
17 private String defaultTextStyle = DbkType.para.name();
18 private String titleStyle;
19
20 private final boolean flat;
21
22 private boolean titleReadOnly = false;
23
24 private final int level;
25
26 public TextSection(Composite parent, int style, Node node) {
27 this(parent, findSection(parent), style, node);
28 }
29
30 public TextSection(TextSection section, int style, Node node) {
31 this(section, section.getParentSection(), style, node);
32 }
33
34 private TextSection(Composite parent, Section parentSection, int style, Node node) {
35 super(parent, parentSection, style, node);
36 flat = SWT.FLAT == (style & SWT.FLAT);
37 if (parentSection instanceof TextSection) {
38 level = ((TextSection) parentSection).getLevel() + 1;
39 } else {
40 level = 0;
41 }
42 CmsSwtUtils.style(this, DbkType.section.name());
43 }
44
45 public String getDefaultTextStyle() {
46 return defaultTextStyle;
47 }
48
49 public boolean isFlat() {
50 return flat;
51 }
52
53 /** The level of this section, similar to h1, h2, etc. in HTML. */
54 public int getLevel() {
55 return level;
56 }
57
58 public String getTitleStyle() {
59 if (titleStyle != null)
60 return titleStyle;
61 // TODO make base H styles configurable
62 // Integer relativeDepth = getRelativeDepth();
63 // System.out.println("Level: " + getLevel());
64 return "h" + (getLevel() + 1);
65 }
66
67 public void setDefaultTextStyle(String defaultTextStyle) {
68 this.defaultTextStyle = defaultTextStyle;
69 }
70
71 public void setTitleStyle(String titleStyle) {
72 this.titleStyle = titleStyle;
73 }
74
75 public boolean isTitleReadOnly() {
76 return titleReadOnly;
77 }
78
79 public void setTitleReadOnly(boolean titleReadOnly) {
80 this.titleReadOnly = titleReadOnly;
81 }
82 }