1 package org
.argeo
.cms
.swt
.acr
;
3 import java
.util
.Collections
;
4 import java
.util
.LinkedHashMap
;
7 import org
.argeo
.api
.acr
.Content
;
8 import org
.argeo
.cms
.swt
.CmsSwtUtils
;
9 import org
.argeo
.cms
.ux
.widgets
.EditablePart
;
10 import org
.eclipse
.swt
.SWT
;
11 import org
.eclipse
.swt
.widgets
.Composite
;
12 import org
.eclipse
.swt
.widgets
.Control
;
14 /** A structured UI related to a JCR context. */
15 public class SwtSection
extends ContentComposite
{
16 private static final long serialVersionUID
= -5933796173755739207L;
18 private final SwtSection parentSection
;
19 private Composite sectionHeader
;
20 private final Integer relativeDepth
;
22 public SwtSection(Composite parent
, int style
, Content node
) {
23 this(parent
, findSection(parent
), style
, node
);
26 public SwtSection(SwtSection section
, int style
, Content node
) {
27 this(section
, section
, style
, node
);
30 protected SwtSection(Composite parent
, SwtSection parentSection
, int style
, Content node
) {
31 super(parent
, style
, node
);
32 this.parentSection
= parentSection
;
33 if (parentSection
!= null) {
34 relativeDepth
= getProvidedContent().getDepth() - parentSection
.getProvidedContent().getDepth();
38 setLayout(CmsSwtUtils
.noSpaceGridLayout());
41 public Map
<String
, SwtSection
> getSubSections() {
42 LinkedHashMap
<String
, SwtSection
> result
= new LinkedHashMap
<String
, SwtSection
>();
43 for (Control child
: getChildren()) {
44 if (child
instanceof Composite
) {
45 collectDirectSubSections((Composite
) child
, result
);
48 return Collections
.unmodifiableMap(result
);
51 private void collectDirectSubSections(Composite composite
, LinkedHashMap
<String
, SwtSection
> subSections
) {
52 if (composite
== sectionHeader
|| composite
instanceof EditablePart
)
54 if (composite
instanceof SwtSection
) {
55 SwtSection section
= (SwtSection
) composite
;
56 subSections
.put(section
.getProvidedContent().getSessionLocalId(), section
);
60 for (Control child
: composite
.getChildren())
61 if (child
instanceof Composite
)
62 collectDirectSubSections((Composite
) child
, subSections
);
65 public Composite
createHeader() {
66 return createHeader(this);
69 public Composite
createHeader(Composite parent
) {
70 if (sectionHeader
!= null)
71 sectionHeader
.dispose();
73 sectionHeader
= new Composite(parent
, SWT
.NONE
);
74 sectionHeader
.setLayoutData(CmsSwtUtils
.fillWidth());
75 sectionHeader
.setLayout(CmsSwtUtils
.noSpaceGridLayout());
76 // sectionHeader.moveAbove(null);
81 public Composite
getHeader() {
82 if (sectionHeader
!= null && sectionHeader
.isDisposed())
88 public SwtSectionPart
getSectionPart(String partId
) {
89 for (Control child
: getChildren()) {
90 if (child
instanceof SwtSectionPart
) {
91 SwtSectionPart sectionPart
= (SwtSectionPart
) child
;
92 if (sectionPart
.getPartId().equals(partId
))
99 public SwtSectionPart
nextSectionPart(SwtSectionPart sectionPart
) {
100 Control
[] children
= getChildren();
101 for (int i
= 0; i
< children
.length
; i
++) {
102 if (sectionPart
== children
[i
]) {
103 for (int j
= i
+ 1; j
< children
.length
; j
++) {
104 if (children
[i
+ 1] instanceof SwtSectionPart
) {
105 return (SwtSectionPart
) children
[i
+ 1];
109 // if (i + 1 < children.length) {
110 // Composite next = (Composite) children[i + 1];
111 // return (SectionPart) next;
120 public SwtSectionPart
previousSectionPart(SwtSectionPart sectionPart
) {
121 Control
[] children
= getChildren();
122 for (int i
= 0; i
< children
.length
; i
++) {
123 if (sectionPart
== children
[i
])
125 Composite previous
= (Composite
) children
[i
- 1];
126 return (SwtSectionPart
) previous
;
135 public String
toString() {
136 if (parentSection
== null)
137 return "Main section " + getContent();
138 return "Section " + getContent();
141 public SwtSection
getParentSection() {
142 return parentSection
;
145 public Integer
getRelativeDepth() {
146 return relativeDepth
;
149 /** Recursively finds the related section in the parents (can be itself) */
150 public static SwtSection
findSection(Control control
) {
153 if (control
instanceof SwtSection
)
154 return (SwtSection
) control
;
156 return findSection(control
.getParent());