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 Localized title
= null;
33 public Control
createUi(Composite parent
, Node context
) throws RepositoryException
{
34 if (entryArea
!= null) {
35 SashFormEditionArea sashFormEditionArea
= new SashFormEditionArea(parent
, parent
.getStyle());
36 entryArea
.createUi(sashFormEditionArea
.getEntryArea(), context
);
37 if (this.workArea
!= null) {
38 this.workArea
.createUi(sashFormEditionArea
.getEditorArea(), context
);
40 return sashFormEditionArea
;
42 if (this.workArea
!= null) {
43 Composite area
= new Composite(parent
, SWT
.NONE
);
44 this.workArea
.createUi(area
, context
);
47 CmsTheme theme
= CmsTheme
.getCmsTheme(parent
);
48 TabbedArea tabbedArea
= createTabbedArea(parent
, theme
);
54 public void view(CmsUiProvider uiProvider
, Composite workArea
, Node context
) {
55 TabbedArea tabbedArea
;
56 if (workArea
instanceof SashFormEditionArea
) {
57 tabbedArea
= ((SashFormEditionArea
) workArea
).getTabbedArea();
58 } else if (workArea
instanceof TabbedArea
) {
59 tabbedArea
= (TabbedArea
) workArea
;
61 throw new IllegalArgumentException("Unsupported work area " + workArea
.getClass().getName());
62 tabbedArea
.view(uiProvider
, context
);
66 public void open(CmsUiProvider uiProvider
, Composite workArea
, Node context
) {
67 TabbedArea tabbedArea
= ((SashFormEditionArea
) workArea
).getTabbedArea();
68 tabbedArea
.open(uiProvider
, context
);
72 public Localized
getTitle() {
76 public void init(BundleContext bundleContext
, Map
<String
, Object
> properties
) {
77 weights
= LangUtils
.toStringList(properties
.get(Property
.weights
.name()));
78 startMaximized
= properties
.containsKey(Property
.startMaximized
.name())
79 && "true".equals(properties
.get(Property
.startMaximized
.name()));
81 String titleStr
= (String
) properties
.get(SuiteLayer
.Property
.title
.name());
82 if (titleStr
!= null) {
83 if (titleStr
.startsWith("%")) {
84 title
= new Localized() {
87 public String
name() {
92 public ClassLoader
getL10nClassLoader() {
93 return bundleContext
!= null
94 ? bundleContext
.getBundle().adapt(BundleWiring
.class).getClassLoader()
95 : getClass().getClassLoader();
99 title
= new Localized
.Untranslated(titleStr
);
104 public void destroy(BundleContext bundleContext
, Map
<String
, String
> properties
) {
108 public void setEntryArea(CmsUiProvider entryArea
) {
109 this.entryArea
= entryArea
;
112 public void setWorkArea(CmsUiProvider workArea
) {
113 this.workArea
= workArea
;
116 TabbedArea
createTabbedArea(Composite parent
, CmsTheme theme
) {
117 TabbedArea tabbedArea
= new TabbedArea(parent
, SWT
.NONE
);
118 tabbedArea
.setBodyStyle(SuiteStyle
.mainTabBody
.style());
119 tabbedArea
.setTabStyle(SuiteStyle
.mainTab
.style());
120 tabbedArea
.setTabSelectedStyle(SuiteStyle
.mainTabSelected
.style());
121 tabbedArea
.setCloseIcon(SuiteIcon
.close
.getSmallIcon(theme
));
122 tabbedArea
.setLayoutData(CmsUiUtils
.fillAll());
126 /** A work area based on an entry area and and a tabbed area. */
127 class SashFormEditionArea
extends SashForm
{
128 private static final long serialVersionUID
= 2219125778722702618L;
129 private CmsTheme theme
;
130 private Composite entryArea
;
131 private Composite editorArea
;
132 private TabbedArea tabbedArea
;
134 SashFormEditionArea(Composite parent
, int style
) {
135 super(parent
, SWT
.HORIZONTAL
);
136 theme
= CmsTheme
.getCmsTheme(parent
);
138 if (SWT
.RIGHT_TO_LEFT
== (style
& SWT
.RIGHT_TO_LEFT
)) {// arabic, hebrew, etc.
139 editorArea
= new Composite(this, SWT
.BORDER
);
140 entryArea
= new Composite(this, SWT
.BORDER
);
142 entryArea
= new Composite(this, SWT
.NONE
);
143 editorArea
= new Composite(this, SWT
.NONE
);
146 if (weights
.size() != 0) {
147 int[] actualWeight
= new int[weights
.size()];
148 for (int i
= 0; i
< weights
.size(); i
++) {
149 actualWeight
[i
] = Integer
.parseInt(weights
.get(i
));
151 setWeights(actualWeight
);
153 int[] actualWeights
= new int[] { 3000, 7000 };
154 setWeights(actualWeights
);
157 setMaximizedControl(editorArea
);
158 editorArea
.setLayout(new GridLayout());
160 if (DefaultEditionLayer
.this.workArea
== null) {
161 tabbedArea
= createTabbedArea(editorArea
, theme
);
166 Composite
getEntryArea() {
170 TabbedArea
getTabbedArea() {
174 Composite
getEditorArea() {