]>
git.argeo.org Git - gpl/argeo-jcr.git/blob - swt/org.argeo.cms.jcr.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
.swt
.CmsSwtUtils
;
11 import org
.argeo
.cms
.swt
.SwtEditablePart
;
12 import org
.argeo
.cms
.ui
.widgets
.JcrComposite
;
13 import org
.eclipse
.swt
.SWT
;
14 import org
.eclipse
.swt
.widgets
.Composite
;
15 import org
.eclipse
.swt
.widgets
.Control
;
17 /** A structured UI related to a JCR context. */
18 public class Section
extends JcrComposite
{
19 private static final long serialVersionUID
= -5933796173755739207L;
21 private final Section parentSection
;
22 private Composite sectionHeader
;
23 private final Integer relativeDepth
;
25 public Section(Composite parent
, int style
, Node node
) {
26 this(parent
, findSection(parent
), style
, node
);
29 public Section(Section section
, int style
, Node node
) {
30 this(section
, section
, style
, node
);
33 protected Section(Composite parent
, Section parentSection
, int style
, Node node
) {
34 super(parent
, style
, node
);
36 this.parentSection
= parentSection
;
37 if (parentSection
!= null) {
38 relativeDepth
= getNode().getDepth() - parentSection
.getNode().getDepth();
42 setLayout(CmsSwtUtils
.noSpaceGridLayout());
43 } catch (RepositoryException e
) {
44 throw new IllegalStateException("Cannot create section from " + node
, e
);
48 public Map
<String
, Section
> getSubSections() throws RepositoryException
{
49 LinkedHashMap
<String
, Section
> result
= new LinkedHashMap
<String
, Section
>();
50 for (Control child
: getChildren()) {
51 if (child
instanceof Composite
) {
52 collectDirectSubSections((Composite
) child
, result
);
55 return Collections
.unmodifiableMap(result
);
58 private void collectDirectSubSections(Composite composite
, LinkedHashMap
<String
, Section
> subSections
)
59 throws RepositoryException
{
60 if (composite
== sectionHeader
|| composite
instanceof SwtEditablePart
)
62 if (composite
instanceof Section
) {
63 Section section
= (Section
) composite
;
64 subSections
.put(section
.getNodeId(), section
);
68 for (Control child
: composite
.getChildren())
69 if (child
instanceof Composite
)
70 collectDirectSubSections((Composite
) child
, subSections
);
73 public Composite
createHeader() {
74 return createHeader(this);
77 public Composite
createHeader(Composite parent
) {
78 if (sectionHeader
!= null)
79 sectionHeader
.dispose();
81 sectionHeader
= new Composite(parent
, SWT
.NONE
);
82 sectionHeader
.setLayoutData(CmsSwtUtils
.fillWidth());
83 sectionHeader
.setLayout(CmsSwtUtils
.noSpaceGridLayout());
84 // sectionHeader.moveAbove(null);
89 public Composite
getHeader() {
90 if (sectionHeader
!= null && sectionHeader
.isDisposed())
96 public SectionPart
getSectionPart(String partId
) {
97 for (Control child
: getChildren()) {
98 if (child
instanceof SectionPart
) {
99 SectionPart sectionPart
= (SectionPart
) child
;
100 if (sectionPart
.getPartId().equals(partId
))
107 public SectionPart
nextSectionPart(SectionPart sectionPart
) {
108 Control
[] children
= getChildren();
109 for (int i
= 0; i
< children
.length
; i
++) {
110 if (sectionPart
== children
[i
]) {
111 for (int j
= i
+ 1; j
< children
.length
; j
++) {
112 if (children
[i
+ 1] instanceof SectionPart
) {
113 return (SectionPart
) children
[i
+ 1];
117 // if (i + 1 < children.length) {
118 // Composite next = (Composite) children[i + 1];
119 // return (SectionPart) next;
128 public SectionPart
previousSectionPart(SectionPart sectionPart
) {
129 Control
[] children
= getChildren();
130 for (int i
= 0; i
< children
.length
; i
++) {
131 if (sectionPart
== children
[i
])
133 Composite previous
= (Composite
) children
[i
- 1];
134 return (SectionPart
) previous
;
143 public String
toString() {
144 if (parentSection
== null)
145 return "Main section " + getNode();
146 return "Section " + getNode();
149 public Section
getParentSection() {
150 return parentSection
;
153 public Integer
getRelativeDepth() {
154 return relativeDepth
;
157 /** Recursively finds the related section in the parents (can be itself) */
158 public static Section
findSection(Control control
) {
161 if (control
instanceof Section
)
162 return (Section
) control
;
164 return findSection(control
.getParent());