X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=org.argeo.cms.ui%2Fsrc%2Forg%2Fargeo%2Fcms%2Fui%2Fviewers%2FSection.java;h=88585e18506844551527d98f29b96db63459337a;hb=11c9710b1d2456c8304a5841d775af008a794431;hp=83ea5607614f1d727d5d76aec7276c0b37f9359f;hpb=5b3108fe285bca50565b58b63fa4feddc96c0765;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.cms.ui/src/org/argeo/cms/ui/viewers/Section.java b/org.argeo.cms.ui/src/org/argeo/cms/ui/viewers/Section.java index 83ea56076..88585e185 100644 --- a/org.argeo.cms.ui/src/org/argeo/cms/ui/viewers/Section.java +++ b/org.argeo.cms.ui/src/org/argeo/cms/ui/viewers/Section.java @@ -7,13 +7,13 @@ import java.util.Map; 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; @@ -21,23 +21,27 @@ public class Section extends JcrComposite { 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 getSubSections() throws RepositoryException { @@ -65,15 +69,20 @@ public class Section extends JcrComposite { 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() { @@ -86,9 +95,9 @@ public class Section extends JcrComposite { 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; @@ -97,13 +106,20 @@ public class Section extends JcrComposite { public SectionPart nextSectionPart(SectionPart sectionPart) { Control[] children = getChildren(); for (int i = 0; i < children.length; i++) { - if (sectionPart == children[i]) - if (i + 1 < children.length) { - Composite next = (Composite) children[i + 1]; - return (SectionPart) next; - } else { - // next section + if (sectionPart == children[i]) { + for (int j = i + 1; j < children.length; j++) { + if (children[i + 1] instanceof SectionPart) { + return (SectionPart) children[i + 1]; + } } + +// if (i + 1 < children.length) { +// Composite next = (Composite) children[i + 1]; +// return (SectionPart) next; +// } else { +// // next section +// } + } } return null; }