1 package org
.argeo
.suite
.ui
;
3 import java
.util
.ArrayList
;
8 import javax
.jcr
.RepositoryException
;
10 import org
.argeo
.cms
.ui
.CmsTheme
;
11 import org
.argeo
.cms
.ui
.CmsUiProvider
;
12 import org
.argeo
.cms
.ui
.util
.CmsUiUtils
;
13 import org
.argeo
.cms
.ui
.widgets
.TabbedArea
;
14 import org
.argeo
.util
.LangUtils
;
15 import org
.eclipse
.swt
.SWT
;
16 import org
.eclipse
.swt
.custom
.SashForm
;
17 import org
.eclipse
.swt
.layout
.GridLayout
;
18 import org
.eclipse
.swt
.widgets
.Composite
;
19 import org
.eclipse
.swt
.widgets
.Control
;
21 /** An app layer based on an entry area and an editor area. */
22 public class DefaultEditionLayer
implements SuiteLayer
{
23 private CmsUiProvider entryArea
;
24 private CmsUiProvider workArea
;
25 private List
<String
> weights
= new ArrayList
<>();
26 private boolean startMaximized
= false;
29 public Control
createUi(Composite parent
, Node context
) throws RepositoryException
{
30 if (entryArea
!= null) {
31 SashFormEditionArea sashFormEditionArea
= new SashFormEditionArea(parent
, parent
.getStyle());
32 entryArea
.createUi(sashFormEditionArea
.getEntryArea(), context
);
33 if (this.workArea
!= null) {
34 this.workArea
.createUi(sashFormEditionArea
.getEditorArea(), context
);
36 return sashFormEditionArea
;
38 if (this.workArea
!= null) {
39 Composite area
= new Composite(parent
, SWT
.NONE
);
40 this.workArea
.createUi(area
, context
);
43 CmsTheme theme
= CmsTheme
.getCmsTheme(parent
);
44 TabbedArea tabbedArea
= createTabbedArea(parent
, theme
);
50 public void view(CmsUiProvider uiProvider
, Composite workArea
, Node context
) {
51 TabbedArea tabbedArea
;
52 if (workArea
instanceof SashFormEditionArea
) {
53 tabbedArea
= ((SashFormEditionArea
) workArea
).getTabbedArea();
54 } else if (workArea
instanceof TabbedArea
) {
55 tabbedArea
= (TabbedArea
) workArea
;
57 throw new IllegalArgumentException("Unsupported work area " + workArea
.getClass().getName());
58 tabbedArea
.view(uiProvider
, context
);
62 public void open(CmsUiProvider uiProvider
, Composite workArea
, Node context
) {
63 TabbedArea tabbedArea
= ((SashFormEditionArea
) workArea
).getTabbedArea();
64 tabbedArea
.open(uiProvider
, context
);
67 public void init(Map
<String
, Object
> properties
) {
68 weights
= LangUtils
.toStringList(properties
.get(Property
.weights
.name()));
69 startMaximized
= properties
.containsKey(Property
.startMaximized
.name())
70 && "true".equals(properties
.get(Property
.startMaximized
.name()));
73 public void setEntryArea(CmsUiProvider entryArea
) {
74 this.entryArea
= entryArea
;
77 public void setWorkArea(CmsUiProvider workArea
) {
78 this.workArea
= workArea
;
81 TabbedArea
createTabbedArea(Composite parent
, CmsTheme theme
) {
82 TabbedArea tabbedArea
= new TabbedArea(parent
, SWT
.NONE
);
83 tabbedArea
.setBodyStyle(SuiteStyle
.mainTabBody
.style());
84 tabbedArea
.setTabStyle(SuiteStyle
.mainTab
.style());
85 tabbedArea
.setTabSelectedStyle(SuiteStyle
.mainTabSelected
.style());
86 tabbedArea
.setCloseIcon(SuiteIcon
.close
.getSmallIcon(theme
));
87 tabbedArea
.setLayoutData(CmsUiUtils
.fillAll());
91 /** A work area based on an entry area and and a tabbed area. */
92 class SashFormEditionArea
extends SashForm
{
93 private static final long serialVersionUID
= 2219125778722702618L;
94 private CmsTheme theme
;
95 private Composite entryArea
;
96 private Composite editorArea
;
97 private TabbedArea tabbedArea
;
99 SashFormEditionArea(Composite parent
, int style
) {
100 super(parent
, SWT
.HORIZONTAL
);
101 theme
= CmsTheme
.getCmsTheme(parent
);
103 if (SWT
.RIGHT_TO_LEFT
== (style
& SWT
.RIGHT_TO_LEFT
)) {// arabic, hebrew, etc.
104 editorArea
= new Composite(this, SWT
.BORDER
);
105 entryArea
= new Composite(this, SWT
.BORDER
);
107 entryArea
= new Composite(this, SWT
.NONE
);
108 editorArea
= new Composite(this, SWT
.NONE
);
111 if (weights
.size() != 0) {
112 int[] actualWeight
= new int[weights
.size()];
113 for (int i
= 0; i
< weights
.size(); i
++) {
114 actualWeight
[i
] = Integer
.parseInt(weights
.get(i
));
116 setWeights(actualWeight
);
118 int[] actualWeights
= new int[] { 3000, 7000 };
119 setWeights(actualWeights
);
122 setMaximizedControl(editorArea
);
123 editorArea
.setLayout(new GridLayout());
125 if (DefaultEditionLayer
.this.workArea
== null) {
126 tabbedArea
= createTabbedArea(editorArea
, theme
);
131 Composite
getEntryArea() {
135 TabbedArea
getTabbedArea() {
139 Composite
getEditorArea() {