]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.cms.ui/src/org/argeo/cms/ui/viewers/Section.java
1 package org
.argeo
.cms
.ui
.viewers
;
3 import java
.util
.Collections
;
4 import java
.util
.LinkedHashMap
;
8 import javax
.jcr
.RepositoryException
;
10 import org
.argeo
.cms
.ui
.util
.CmsUiUtils
;
11 import org
.argeo
.cms
.ui
.widgets
.JcrComposite
;
12 import org
.eclipse
.swt
.SWT
;
13 import org
.eclipse
.swt
.widgets
.Composite
;
14 import org
.eclipse
.swt
.widgets
.Control
;
16 /** A structured UI related to a JCR context. */
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
) {
25 this(parent
, findSection(parent
), style
, node
);
28 public Section(Section section
, int style
, Node node
) {
29 this(section
, section
, style
, node
);
32 protected Section(Composite parent
, Section parentSection
, int style
, Node node
) {
33 super(parent
, style
, node
);
35 this.parentSection
= parentSection
;
36 if (parentSection
!= null) {
37 relativeDepth
= getNode().getDepth() - parentSection
.getNode().getDepth();
41 setLayout(CmsUiUtils
.noSpaceGridLayout());
42 } catch (RepositoryException e
) {
43 throw new IllegalStateException("Cannot create section from " + node
, e
);
47 public Map
<String
, Section
> getSubSections() throws RepositoryException
{
48 LinkedHashMap
<String
, Section
> result
= new LinkedHashMap
<String
, Section
>();
49 for (Control child
: getChildren()) {
50 if (child
instanceof Composite
) {
51 collectDirectSubSections((Composite
) child
, result
);
54 return Collections
.unmodifiableMap(result
);
57 private void collectDirectSubSections(Composite composite
, LinkedHashMap
<String
, Section
> subSections
)
58 throws RepositoryException
{
59 if (composite
== sectionHeader
|| composite
instanceof EditablePart
)
61 if (composite
instanceof Section
) {
62 Section section
= (Section
) composite
;
63 subSections
.put(section
.getNodeId(), section
);
67 for (Control child
: composite
.getChildren())
68 if (child
instanceof Composite
)
69 collectDirectSubSections((Composite
) child
, subSections
);
72 public Composite
createHeader() {
73 return createHeader(this);
76 public Composite
createHeader(Composite parent
) {
77 if (sectionHeader
!= null)
78 sectionHeader
.dispose();
80 sectionHeader
= new Composite(parent
, SWT
.NONE
);
81 sectionHeader
.setLayoutData(CmsUiUtils
.fillWidth());
82 sectionHeader
.setLayout(CmsUiUtils
.noSpaceGridLayout());
83 // sectionHeader.moveAbove(null);
88 public Composite
getHeader() {
89 if (sectionHeader
!= null && sectionHeader
.isDisposed())
95 public SectionPart
getSectionPart(String partId
) {
96 for (Control child
: getChildren()) {
97 if (child
instanceof SectionPart
) {
98 SectionPart sectionPart
= (SectionPart
) child
;
99 if (sectionPart
.getPartId().equals(partId
))
106 public SectionPart
nextSectionPart(SectionPart sectionPart
) {
107 Control
[] children
= getChildren();
108 for (int i
= 0; i
< children
.length
; i
++) {
109 if (sectionPart
== children
[i
]) {
110 for (int j
= i
+ 1; j
< children
.length
; j
++) {
111 if (children
[i
+ 1] instanceof SectionPart
) {
112 return (SectionPart
) children
[i
+ 1];
116 // if (i + 1 < children.length) {
117 // Composite next = (Composite) children[i + 1];
118 // return (SectionPart) next;
127 public SectionPart
previousSectionPart(SectionPart sectionPart
) {
128 Control
[] children
= getChildren();
129 for (int i
= 0; i
< children
.length
; i
++) {
130 if (sectionPart
== children
[i
])
132 Composite previous
= (Composite
) children
[i
- 1];
133 return (SectionPart
) previous
;
142 public String
toString() {
143 if (parentSection
== null)
144 return "Main section " + getNode();
145 return "Section " + getNode();
148 public Section
getParentSection() {
149 return parentSection
;
152 public Integer
getRelativeDepth() {
153 return relativeDepth
;
156 /** Recursively finds the related section in the parents (can be itself) */
157 public static Section
findSection(Control control
) {
160 if (control
instanceof Section
)
161 return (Section
) control
;
163 return findSection(control
.getParent());