]> git.argeo.org Git - lgpl/argeo-commons.git/blob - SimpleCmsHeader.java
e8bf66297e26a9d551f37cd32296e40dfeecded9
[lgpl/argeo-commons.git] / SimpleCmsHeader.java
1 package org.argeo.cms.ui.util;
2
3 import java.util.ArrayList;
4 import java.util.List;
5
6 import javax.jcr.Node;
7 import javax.jcr.RepositoryException;
8
9 import org.argeo.cms.CmsException;
10 import org.argeo.cms.swt.CmsStyles;
11 import org.argeo.cms.swt.CmsSwtUtils;
12 import org.argeo.cms.ui.CmsUiProvider;
13 import org.eclipse.rap.rwt.RWT;
14 import org.eclipse.swt.SWT;
15 import org.eclipse.swt.layout.GridData;
16 import org.eclipse.swt.layout.GridLayout;
17 import org.eclipse.swt.widgets.Composite;
18 import org.eclipse.swt.widgets.Control;
19
20 /** A header in three parts */
21 public class SimpleCmsHeader implements CmsUiProvider {
22 private List<CmsUiProvider> lead = new ArrayList<CmsUiProvider>();
23 private List<CmsUiProvider> center = new ArrayList<CmsUiProvider>();
24 private List<CmsUiProvider> end = new ArrayList<CmsUiProvider>();
25
26 private Boolean subPartsSameWidth = false;
27
28 @Override
29 public Control createUi(Composite parent, Node context) throws RepositoryException {
30 Composite header = new Composite(parent, SWT.NONE);
31 header.setData(RWT.CUSTOM_VARIANT, CmsStyles.CMS_HEADER);
32 header.setBackgroundMode(SWT.INHERIT_DEFAULT);
33 header.setLayout(CmsSwtUtils.noSpaceGridLayout(new GridLayout(3, false)));
34
35 configurePart(context, header, lead);
36 configurePart(context, header, center);
37 configurePart(context, header, end);
38 return header;
39 }
40
41 protected void configurePart(Node context, Composite parent, List<CmsUiProvider> partProviders)
42 throws RepositoryException {
43 final int style;
44 final String custom;
45 if (lead == partProviders) {
46 style = SWT.LEAD;
47 custom = CmsStyles.CMS_HEADER_LEAD;
48 } else if (center == partProviders) {
49 style = SWT.CENTER;
50 custom = CmsStyles.CMS_HEADER_CENTER;
51 } else if (end == partProviders) {
52 style = SWT.END;
53 custom = CmsStyles.CMS_HEADER_END;
54 } else {
55 throw new CmsException("Unsupported part providers " + partProviders);
56 }
57
58 Composite part = new Composite(parent, SWT.NONE);
59 part.setData(RWT.CUSTOM_VARIANT, custom);
60 GridData gridData = new GridData(style, SWT.FILL, true, true);
61 part.setLayoutData(gridData);
62 part.setLayout(CmsSwtUtils.noSpaceGridLayout(new GridLayout(partProviders.size(), subPartsSameWidth)));
63 for (CmsUiProvider uiProvider : partProviders) {
64 Control subPart = uiProvider.createUi(part, context);
65 subPart.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
66 }
67 }
68
69 public void setLead(List<CmsUiProvider> lead) {
70 this.lead = lead;
71 }
72
73 public void setCenter(List<CmsUiProvider> center) {
74 this.center = center;
75 }
76
77 public void setEnd(List<CmsUiProvider> end) {
78 this.end = end;
79 }
80
81 public void setSubPartsSameWidth(Boolean subPartsSameWidth) {
82 this.subPartsSameWidth = subPartsSameWidth;
83 }
84
85 public List<CmsUiProvider> getLead() {
86 return lead;
87 }
88
89 public List<CmsUiProvider> getCenter() {
90 return center;
91 }
92
93 public List<CmsUiProvider> getEnd() {
94 return end;
95 }
96
97 }