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 an ACR 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 public SwtSection(SwtSection section
, int style
) {
31 this(section
, style
, null);
34 protected SwtSection(Composite parent
, SwtSection parentSection
, int style
, Content node
) {
35 super(parent
, style
, node
);
36 this.parentSection
= parentSection
;
37 if (parentSection
!= null && hasContent() && parentSection
.hasContent()) {
38 relativeDepth
= getProvidedContent().getDepth() - parentSection
.getProvidedContent().getDepth();
42 setLayout(CmsSwtUtils
.noSpaceGridLayout());
45 public Map
<String
, SwtSection
> getSubSections() {
46 LinkedHashMap
<String
, SwtSection
> result
= new LinkedHashMap
<String
, SwtSection
>();
47 for (Control child
: getChildren()) {
48 if (child
instanceof Composite
) {
49 collectDirectSubSections((Composite
) child
, result
);
52 return Collections
.unmodifiableMap(result
);
55 private void collectDirectSubSections(Composite composite
, LinkedHashMap
<String
, SwtSection
> subSections
) {
56 if (composite
== sectionHeader
|| composite
instanceof EditablePart
)
58 if (composite
instanceof SwtSection
) {
59 SwtSection section
= (SwtSection
) composite
;
60 subSections
.put(section
.getProvidedContent().getSessionLocalId(), section
);
64 for (Control child
: composite
.getChildren())
65 if (child
instanceof Composite
)
66 collectDirectSubSections((Composite
) child
, subSections
);
69 public Composite
createHeader() {
70 return createHeader(this);
73 public Composite
createHeader(Composite parent
) {
74 if (sectionHeader
!= null)
75 sectionHeader
.dispose();
77 sectionHeader
= new Composite(parent
, SWT
.NONE
);
78 sectionHeader
.setLayoutData(CmsSwtUtils
.fillWidth());
79 sectionHeader
.setLayout(CmsSwtUtils
.noSpaceGridLayout());
80 // sectionHeader.moveAbove(null);
85 public Composite
getHeader() {
86 if (sectionHeader
!= null && sectionHeader
.isDisposed())
92 public SwtSectionPart
getSectionPart(String partId
) {
93 for (Control child
: getChildren()) {
94 if (child
instanceof SwtSectionPart
) {
95 SwtSectionPart sectionPart
= (SwtSectionPart
) child
;
96 if (sectionPart
.getPartId().equals(partId
))
103 public SwtSectionPart
nextSectionPart(SwtSectionPart sectionPart
) {
104 Control
[] children
= getChildren();
105 for (int i
= 0; i
< children
.length
; i
++) {
106 if (sectionPart
== children
[i
]) {
107 for (int j
= i
+ 1; j
< children
.length
; j
++) {
108 if (children
[i
+ 1] instanceof SwtSectionPart
) {
109 return (SwtSectionPart
) children
[i
+ 1];
113 // if (i + 1 < children.length) {
114 // Composite next = (Composite) children[i + 1];
115 // return (SectionPart) next;
124 public SwtSectionPart
previousSectionPart(SwtSectionPart sectionPart
) {
125 Control
[] children
= getChildren();
126 for (int i
= 0; i
< children
.length
; i
++) {
127 if (sectionPart
== children
[i
])
129 Composite previous
= (Composite
) children
[i
- 1];
130 return (SwtSectionPart
) previous
;
139 public String
toString() {
140 if (parentSection
== null)
141 return "Main section " + getContent();
142 return "Section " + getContent();
145 public SwtSection
getParentSection() {
146 return parentSection
;
149 public Integer
getRelativeDepth() {
150 return relativeDepth
;
153 /** Recursively finds the related section in the parents (can be itself) */
154 public static SwtSection
findSection(Control control
) {
157 if (control
instanceof SwtSection
)
158 return (SwtSection
) control
;
160 return findSection(control
.getParent());