]>
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
.util
.CmsUtils
;
12 import org
.argeo
.cms
.widgets
.JcrComposite
;
13 import org
.eclipse
.swt
.SWT
;
14 import org
.eclipse
.swt
.widgets
.Composite
;
15 import org
.eclipse
.swt
.widgets
.Control
;
17 public class Section
extends JcrComposite
{
18 private static final long serialVersionUID
= -5933796173755739207L;
20 private final Section parentSection
;
21 private Composite sectionHeader
;
22 private final Integer relativeDepth
;
24 public Section(Composite parent
, int style
, Node node
) throws RepositoryException
{
25 this(parent
, findSection(parent
), style
, node
);
28 public Section(Section section
, int style
, Node node
) throws RepositoryException
{
29 this(section
, section
, style
, node
);
32 protected Section(Composite parent
, Section parentSection
, int style
, Node node
) throws RepositoryException
{
33 super(parent
, style
, node
);
34 this.parentSection
= parentSection
;
35 if (parentSection
!= null) {
36 relativeDepth
= getNode().getDepth() - parentSection
.getNode().getDepth();
40 setLayout(CmsUtils
.noSpaceGridLayout());
43 public Map
<String
, Section
> getSubSections() throws RepositoryException
{
44 LinkedHashMap
<String
, Section
> result
= new LinkedHashMap
<String
, Section
>();
45 for (Control child
: getChildren()) {
46 if (child
instanceof Composite
) {
47 collectDirectSubSections((Composite
) child
, result
);
50 return Collections
.unmodifiableMap(result
);
53 private void collectDirectSubSections(Composite composite
, LinkedHashMap
<String
, Section
> subSections
)
54 throws RepositoryException
{
55 if (composite
== sectionHeader
|| composite
instanceof EditablePart
)
57 if (composite
instanceof Section
) {
58 Section section
= (Section
) composite
;
59 subSections
.put(section
.getNodeId(), section
);
63 for (Control child
: composite
.getChildren())
64 if (child
instanceof Composite
)
65 collectDirectSubSections((Composite
) child
, subSections
);
68 public void createHeader() {
69 if (sectionHeader
!= null)
70 throw new CmsException("Section header was already created");
72 sectionHeader
= new Composite(this, SWT
.NONE
);
73 sectionHeader
.setLayoutData(CmsUtils
.fillWidth());
74 sectionHeader
.setLayout(CmsUtils
.noSpaceGridLayout());
75 // sectionHeader.moveAbove(null);
79 public Composite
getHeader() {
80 if (sectionHeader
!= null && sectionHeader
.isDisposed())
86 public SectionPart
getSectionPart(String partId
) {
87 for (Control child
: getChildren()) {
88 if (child
instanceof SectionPart
) {
89 SectionPart paragraph
= (SectionPart
) child
;
90 if (paragraph
.getPartId().equals(partId
))
97 public SectionPart
nextSectionPart(SectionPart sectionPart
) {
98 Control
[] children
= getChildren();
99 for (int i
= 0; i
< children
.length
; i
++) {
100 if (sectionPart
== children
[i
])
101 if (i
+ 1 < children
.length
) {
102 Composite next
= (Composite
) children
[i
+ 1];
103 return (SectionPart
) next
;
111 public SectionPart
previousSectionPart(SectionPart sectionPart
) {
112 Control
[] children
= getChildren();
113 for (int i
= 0; i
< children
.length
; i
++) {
114 if (sectionPart
== children
[i
])
116 Composite previous
= (Composite
) children
[i
- 1];
117 return (SectionPart
) previous
;
126 public String
toString() {
127 if (parentSection
== null)
128 return "Main section " + getNode();
129 return "Section " + getNode();
132 public Section
getParentSection() {
133 return parentSection
;
136 public Integer
getRelativeDepth() {
137 return relativeDepth
;
140 /** Recursively finds the related section in the parents (can be itself) */
141 public static Section
findSection(Control control
) {
144 if (control
instanceof Section
)
145 return (Section
) control
;
147 return findSection(control
.getParent());