1 package org.argeo.suite.ui;
3 import java.util.ArrayList;
8 import javax.jcr.RepositoryException;
10 import org.argeo.cms.Localized;
11 import org.argeo.cms.ui.CmsTheme;
12 import org.argeo.cms.ui.CmsUiProvider;
13 import org.argeo.cms.ui.util.CmsUiUtils;
14 import org.argeo.suite.ui.widgets.TabbedArea;
15 import org.argeo.util.LangUtils;
16 import org.eclipse.swt.SWT;
17 import org.eclipse.swt.custom.SashForm;
18 import org.eclipse.swt.layout.GridLayout;
19 import org.eclipse.swt.widgets.Composite;
20 import org.eclipse.swt.widgets.Control;
21 import org.osgi.framework.BundleContext;
22 import org.osgi.framework.wiring.BundleWiring;
24 /** An app layer based on an entry area and an editor area. */
25 public class DefaultEditionLayer implements SuiteLayer {
26 private CmsUiProvider entryArea;
27 private CmsUiProvider workArea;
28 private List<String> weights = new ArrayList<>();
29 private boolean startMaximized = false;
30 private boolean singleTab = false;
31 private Localized title = null;
34 public Control createUi(Composite parent, Node context) throws RepositoryException {
35 if (entryArea != null) {
36 SashFormEditionArea sashFormEditionArea = new SashFormEditionArea(parent, parent.getStyle());
37 entryArea.createUi(sashFormEditionArea.getEntryArea(), context);
38 if (this.workArea != null) {
39 this.workArea.createUi(sashFormEditionArea.getEditorArea(), context);
41 return sashFormEditionArea;
43 if (this.workArea != null) {
44 Composite area = new Composite(parent, SWT.NONE);
45 this.workArea.createUi(area, context);
48 CmsTheme theme = CmsTheme.getCmsTheme(parent);
49 TabbedArea tabbedArea = createTabbedArea(parent, theme);
55 public void view(CmsUiProvider uiProvider, Composite workArea, Node context) {
56 TabbedArea tabbedArea;
57 if (workArea instanceof SashFormEditionArea) {
58 tabbedArea = ((SashFormEditionArea) workArea).getTabbedArea();
59 } else if (workArea instanceof TabbedArea) {
60 tabbedArea = (TabbedArea) workArea;
62 throw new IllegalArgumentException("Unsupported work area " + workArea.getClass().getName());
63 tabbedArea.view(uiProvider, context);
67 public void open(CmsUiProvider uiProvider, Composite workArea, Node context) {
68 TabbedArea tabbedArea = ((SashFormEditionArea) workArea).getTabbedArea();
69 tabbedArea.open(uiProvider, context);
73 public Localized getTitle() {
77 public void init(BundleContext bundleContext, Map<String, Object> properties) {
78 weights = LangUtils.toStringList(properties.get(Property.weights.name()));
79 startMaximized = properties.containsKey(Property.startMaximized.name())
80 && "true".equals(properties.get(Property.startMaximized.name()));
81 singleTab = properties.containsKey(Property.singleTab.name())
82 && "true".equals(properties.get(Property.singleTab.name()));
84 String titleStr = (String) properties.get(SuiteLayer.Property.title.name());
85 if (titleStr != null) {
86 if (titleStr.startsWith("%")) {
87 title = new Localized() {
90 public String name() {
95 public ClassLoader getL10nClassLoader() {
96 return bundleContext != null
97 ? bundleContext.getBundle().adapt(BundleWiring.class).getClassLoader()
98 : getClass().getClassLoader();
102 title = new Localized.Untranslated(titleStr);
107 public void destroy(BundleContext bundleContext, Map<String, String> properties) {
111 public void setEntryArea(CmsUiProvider entryArea) {
112 this.entryArea = entryArea;
115 public void setWorkArea(CmsUiProvider workArea) {
116 this.workArea = workArea;
119 TabbedArea createTabbedArea(Composite parent, CmsTheme theme) {
120 TabbedArea tabbedArea = new TabbedArea(parent, SWT.NONE);
121 tabbedArea.setSingleTab(singleTab);
122 tabbedArea.setBodyStyle(SuiteStyle.mainTabBody.style());
123 tabbedArea.setTabStyle(SuiteStyle.mainTab.style());
124 tabbedArea.setTabSelectedStyle(SuiteStyle.mainTabSelected.style());
125 tabbedArea.setCloseIcon(SuiteIcon.close.getSmallIcon(theme));
126 tabbedArea.setLayoutData(CmsUiUtils.fillAll());
130 /** A work area based on an entry area and and a tabbed area. */
131 class SashFormEditionArea extends SashForm {
132 private static final long serialVersionUID = 2219125778722702618L;
133 private CmsTheme theme;
134 private Composite entryArea;
135 private Composite editorArea;
136 private TabbedArea tabbedArea;
138 SashFormEditionArea(Composite parent, int style) {
139 super(parent, SWT.HORIZONTAL);
140 theme = CmsTheme.getCmsTheme(parent);
142 if (SWT.RIGHT_TO_LEFT == (style & SWT.RIGHT_TO_LEFT)) {// arabic, hebrew, etc.
143 editorArea = new Composite(this, SWT.BORDER);
144 entryArea = new Composite(this, SWT.BORDER);
146 entryArea = new Composite(this, SWT.NONE);
147 editorArea = new Composite(this, SWT.NONE);
150 if (weights.size() != 0) {
151 int[] actualWeight = new int[weights.size()];
152 for (int i = 0; i < weights.size(); i++) {
153 actualWeight[i] = Integer.parseInt(weights.get(i));
155 setWeights(actualWeight);
157 int[] actualWeights = new int[] { 3000, 7000 };
158 setWeights(actualWeights);
161 setMaximizedControl(editorArea);
162 editorArea.setLayout(new GridLayout());
164 if (DefaultEditionLayer.this.workArea == null) {
165 tabbedArea = createTabbedArea(editorArea, theme);
170 Composite getEntryArea() {
174 TabbedArea getTabbedArea() {
178 Composite getEditorArea() {