]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.cms.ui/src/org/argeo/cms/viewers/Section.java
1 package org
.argeo
.cms
.viewers
;
3 import java
.util
.Collections
;
4 import java
.util
.LinkedHashMap
;
8 import javax
.jcr
.RepositoryException
;
10 import org
.argeo
.cms
.CmsException
;
11 import org
.argeo
.cms
.CmsNames
;
12 import org
.argeo
.cms
.util
.CmsUtils
;
13 import org
.argeo
.cms
.widgets
.JcrComposite
;
14 import org
.eclipse
.swt
.SWT
;
15 import org
.eclipse
.swt
.widgets
.Composite
;
16 import org
.eclipse
.swt
.widgets
.Control
;
18 public class Section
extends JcrComposite
implements CmsNames
{
19 private static final long serialVersionUID
= -5933796173755739207L;
21 private final Section parentSection
;
22 private Composite sectionHeader
;
23 private final Integer relativeDepth
;
25 public Section(Composite parent
, int style
, Node node
)
26 throws RepositoryException
{
27 this(parent
, findSection(parent
), style
, node
);
30 public Section(Section section
, int style
, Node node
)
31 throws RepositoryException
{
32 this(section
, section
, style
, node
);
35 protected Section(Composite parent
, Section parentSection
, int style
,
36 Node node
) throws RepositoryException
{
37 super(parent
, style
, node
);
38 this.parentSection
= parentSection
;
39 if (parentSection
!= null) {
40 relativeDepth
= getNode().getDepth()
41 - parentSection
.getNode().getDepth();
45 setLayout(CmsUtils
.noSpaceGridLayout());
48 public Map
<String
, Section
> getSubSections() throws RepositoryException
{
49 LinkedHashMap
<String
, Section
> result
= new LinkedHashMap
<String
, Section
>();
50 for (Control child
: getChildren()) {
51 if (child
instanceof Composite
) {
52 collectDirectSubSections((Composite
) child
, result
);
55 return Collections
.unmodifiableMap(result
);
58 private void collectDirectSubSections(Composite composite
,
59 LinkedHashMap
<String
, Section
> subSections
)
60 throws RepositoryException
{
61 if (composite
== sectionHeader
|| composite
instanceof EditablePart
)
63 if (composite
instanceof Section
) {
64 Section section
= (Section
) composite
;
65 subSections
.put(section
.getNodeId(), section
);
69 for (Control child
: composite
.getChildren())
70 if (child
instanceof Composite
)
71 collectDirectSubSections((Composite
) child
, subSections
);
74 public void createHeader() {
75 if (sectionHeader
!= null)
76 throw new CmsException("Section header was already created");
78 sectionHeader
= new Composite(this, SWT
.NONE
);
79 sectionHeader
.setLayoutData(CmsUtils
.fillWidth());
80 sectionHeader
.setLayout(CmsUtils
.noSpaceGridLayout());
81 // sectionHeader.moveAbove(null);
85 public Composite
getHeader() {
86 if (sectionHeader
!= null && sectionHeader
.isDisposed())
92 public SectionPart
getSectionPart(String partId
) {
93 for (Control child
: getChildren()) {
94 if (child
instanceof SectionPart
) {
95 SectionPart paragraph
= (SectionPart
) child
;
96 if (paragraph
.getPartId().equals(partId
))
103 public SectionPart
nextSectionPart(SectionPart sectionPart
) {
104 Control
[] children
= getChildren();
105 for (int i
= 0; i
< children
.length
; i
++) {
106 if (sectionPart
== children
[i
])
107 if (i
+ 1 < children
.length
) {
108 Composite next
= (Composite
) children
[i
+ 1];
109 return (SectionPart
) next
;
117 public SectionPart
previousSectionPart(SectionPart sectionPart
) {
118 Control
[] children
= getChildren();
119 for (int i
= 0; i
< children
.length
; i
++) {
120 if (sectionPart
== children
[i
])
122 Composite previous
= (Composite
) children
[i
- 1];
123 return (SectionPart
) previous
;
132 public String
toString() {
133 if (parentSection
== null)
134 return "Main section " + getNode();
135 return "Section " + getNode();
138 public Section
getParentSection() {
139 return parentSection
;
142 public Integer
getRelativeDepth() {
143 return relativeDepth
;
146 /** Recursively finds the related section in the parents (can be itself) */
147 public static Section
findSection(Control control
) {
150 if (control
instanceof Section
)
151 return (Section
) control
;
153 return findSection(control
.getParent());