import javax.jcr.Node;
import javax.jcr.RepositoryException;
-import org.argeo.cms.CmsException;
import org.argeo.cms.ui.util.CmsUiUtils;
import org.argeo.cms.ui.widgets.JcrComposite;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
+/** A structured UI related to a JCR context. */
public class Section extends JcrComposite {
private static final long serialVersionUID = -5933796173755739207L;
private Composite sectionHeader;
private final Integer relativeDepth;
- public Section(Composite parent, int style, Node node) throws RepositoryException {
+ public Section(Composite parent, int style, Node node) {
this(parent, findSection(parent), style, node);
}
- public Section(Section section, int style, Node node) throws RepositoryException {
+ public Section(Section section, int style, Node node) {
this(section, section, style, node);
}
- protected Section(Composite parent, Section parentSection, int style, Node node) throws RepositoryException {
+ protected Section(Composite parent, Section parentSection, int style, Node node) {
super(parent, style, node);
- this.parentSection = parentSection;
- if (parentSection != null) {
- relativeDepth = getNode().getDepth() - parentSection.getNode().getDepth();
- } else {
- relativeDepth = 0;
+ try {
+ this.parentSection = parentSection;
+ if (parentSection != null) {
+ relativeDepth = getNode().getDepth() - parentSection.getNode().getDepth();
+ } else {
+ relativeDepth = 0;
+ }
+ setLayout(CmsUiUtils.noSpaceGridLayout());
+ } catch (RepositoryException e) {
+ throw new IllegalStateException("Cannot create section from " + node, e);
}
- setLayout(CmsUiUtils.noSpaceGridLayout());
}
public Map<String, Section> getSubSections() throws RepositoryException {
collectDirectSubSections((Composite) child, subSections);
}
- public void createHeader() {
+ public Composite createHeader() {
+ return createHeader(this);
+ }
+
+ public Composite createHeader(Composite parent) {
if (sectionHeader != null)
- throw new CmsException("Section header was already created");
+ sectionHeader.dispose();
- sectionHeader = new Composite(this, SWT.NONE);
+ sectionHeader = new Composite(parent, SWT.NONE);
sectionHeader.setLayoutData(CmsUiUtils.fillWidth());
sectionHeader.setLayout(CmsUiUtils.noSpaceGridLayout());
// sectionHeader.moveAbove(null);
// layout();
+ return sectionHeader;
}
public Composite getHeader() {
public SectionPart getSectionPart(String partId) {
for (Control child : getChildren()) {
if (child instanceof SectionPart) {
- SectionPart paragraph = (SectionPart) child;
- if (paragraph.getPartId().equals(partId))
- return paragraph;
+ SectionPart sectionPart = (SectionPart) child;
+ if (sectionPart.getPartId().equals(partId))
+ return sectionPart;
}
}
return null;