1 package org
.argeo
.cms
.swt
.widgets
;
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
.swt
.acr
.ContentComposite
;
10 import org
.argeo
.cms
.ux
.widgets
.EditablePart
;
11 import org
.eclipse
.swt
.SWT
;
12 import org
.eclipse
.swt
.widgets
.Composite
;
13 import org
.eclipse
.swt
.widgets
.Control
;
15 /** A structured UI related to a JCR context. */
16 public class SwtSection
extends ContentComposite
{
17 private static final long serialVersionUID
= -5933796173755739207L;
19 private final SwtSection parentSection
;
20 private Composite sectionHeader
;
21 private final Integer relativeDepth
;
23 public SwtSection(Composite parent
, int style
, Content node
) {
24 this(parent
, findSection(parent
), style
, node
);
27 public SwtSection(SwtSection section
, int style
, Content node
) {
28 this(section
, section
, style
, node
);
31 protected SwtSection(Composite parent
, SwtSection parentSection
, int style
, Content node
) {
32 super(parent
, style
, node
);
33 this.parentSection
= parentSection
;
34 if (parentSection
!= null) {
35 relativeDepth
= getProvidedContent().getDepth() - parentSection
.getProvidedContent().getDepth();
39 setLayout(CmsSwtUtils
.noSpaceGridLayout());
42 public Map
<String
, SwtSection
> getSubSections() {
43 LinkedHashMap
<String
, SwtSection
> result
= new LinkedHashMap
<String
, SwtSection
>();
44 for (Control child
: getChildren()) {
45 if (child
instanceof Composite
) {
46 collectDirectSubSections((Composite
) child
, result
);
49 return Collections
.unmodifiableMap(result
);
52 private void collectDirectSubSections(Composite composite
, LinkedHashMap
<String
, SwtSection
> subSections
) {
53 if (composite
== sectionHeader
|| composite
instanceof EditablePart
)
55 if (composite
instanceof SwtSection
) {
56 SwtSection section
= (SwtSection
) composite
;
57 subSections
.put(section
.getProvidedContent().getSessionLocalId(), section
);
61 for (Control child
: composite
.getChildren())
62 if (child
instanceof Composite
)
63 collectDirectSubSections((Composite
) child
, subSections
);
66 public Composite
createHeader() {
67 return createHeader(this);
70 public Composite
createHeader(Composite parent
) {
71 if (sectionHeader
!= null)
72 sectionHeader
.dispose();
74 sectionHeader
= new Composite(parent
, SWT
.NONE
);
75 sectionHeader
.setLayoutData(CmsSwtUtils
.fillWidth());
76 sectionHeader
.setLayout(CmsSwtUtils
.noSpaceGridLayout());
77 // sectionHeader.moveAbove(null);
82 public Composite
getHeader() {
83 if (sectionHeader
!= null && sectionHeader
.isDisposed())
89 public SwtSectionPart
getSectionPart(String partId
) {
90 for (Control child
: getChildren()) {
91 if (child
instanceof SwtSectionPart
) {
92 SwtSectionPart sectionPart
= (SwtSectionPart
) child
;
93 if (sectionPart
.getPartId().equals(partId
))
100 public SwtSectionPart
nextSectionPart(SwtSectionPart sectionPart
) {
101 Control
[] children
= getChildren();
102 for (int i
= 0; i
< children
.length
; i
++) {
103 if (sectionPart
== children
[i
]) {
104 for (int j
= i
+ 1; j
< children
.length
; j
++) {
105 if (children
[i
+ 1] instanceof SwtSectionPart
) {
106 return (SwtSectionPart
) children
[i
+ 1];
110 // if (i + 1 < children.length) {
111 // Composite next = (Composite) children[i + 1];
112 // return (SectionPart) next;
121 public SwtSectionPart
previousSectionPart(SwtSectionPart sectionPart
) {
122 Control
[] children
= getChildren();
123 for (int i
= 0; i
< children
.length
; i
++) {
124 if (sectionPart
== children
[i
])
126 Composite previous
= (Composite
) children
[i
- 1];
127 return (SwtSectionPart
) previous
;
136 public String
toString() {
137 if (parentSection
== null)
138 return "Main section " + getContent();
139 return "Section " + getContent();
142 public SwtSection
getParentSection() {
143 return parentSection
;
146 public Integer
getRelativeDepth() {
147 return relativeDepth
;
150 /** Recursively finds the related section in the parents (can be itself) */
151 public static SwtSection
findSection(Control control
) {
154 if (control
instanceof SwtSection
)
155 return (SwtSection
) control
;
157 return findSection(control
.getParent());