1 package org
.argeo
.app
.ui
;
3 import java
.util
.ArrayList
;
7 import org
.argeo
.api
.acr
.Content
;
8 import org
.argeo
.api
.cms
.CmsTheme
;
9 import org
.argeo
.cms
.Localized
;
10 import org
.argeo
.cms
.swt
.CmsSwtUtils
;
11 import org
.argeo
.cms
.swt
.acr
.SwtUiProvider
;
12 import org
.argeo
.cms
.swt
.widgets
.SwtTabbedArea
;
13 import org
.argeo
.cms
.ui
.CmsUiProvider
;
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
;
20 import org
.osgi
.framework
.BundleContext
;
21 import org
.osgi
.framework
.wiring
.BundleWiring
;
23 /** An app layer based on an entry area and an editor area. */
24 public class DefaultEditionLayer
implements SuiteLayer
{
25 private CmsUiProvider entryArea
;
26 private CmsUiProvider defaultView
;
27 private CmsUiProvider workArea
;
28 private List
<String
> weights
= new ArrayList
<>();
29 private boolean startMaximized
= false;
30 private boolean fixedEntryArea
= false;
31 private boolean singleTab
= false;
32 private Localized title
= null;
35 public Control
createUiPart(Composite parent
, Content context
) {
36 // TODO Factorize more, or split into more specialised classes?
37 if (entryArea
!= null) {
39 FixedEditionArea editionArea
= new FixedEditionArea(parent
, parent
.getStyle());
40 Control entryAreaC
= entryArea
.createUiPart(editionArea
.getEntryArea(), context
);
41 CmsSwtUtils
.style(entryAreaC
, SuiteStyle
.entryArea
);
42 if (this.defaultView
!= null) {
43 editionArea
.getTabbedArea().view(defaultView
, context
);
47 SashFormEditionArea editionArea
= new SashFormEditionArea(parent
, parent
.getStyle());
48 entryArea
.createUiPart(editionArea
.getEntryArea(), context
);
49 if (this.defaultView
!= null) {
50 editionArea
.getTabbedArea().view(defaultView
, context
);
55 if (this.workArea
!= null) {
56 Composite area
= new Composite(parent
, SWT
.NONE
);
57 this.workArea
.createUiPart(area
, context
);
60 CmsTheme theme
= CmsSwtUtils
.getCmsTheme(parent
);
61 SwtTabbedArea tabbedArea
= createTabbedArea(parent
, theme
);
67 public void view(SwtUiProvider uiProvider
, Composite workAreaC
, Content context
) {
68 if (workArea
!= null) {
69 CmsSwtUtils
.clear(workAreaC
);
70 workArea
.createUiPart(workAreaC
, context
);
71 workAreaC
.layout(true, true);
76 SwtTabbedArea tabbedArea
= findTabbedArea(workAreaC
);
77 if (tabbedArea
== null)
78 throw new IllegalArgumentException("Unsupported work area " + workAreaC
.getClass().getName());
79 if (uiProvider
== null) {
81 tabbedArea
.closeAllTabs();
82 if (this.defaultView
!= null) {
83 tabbedArea
.view(defaultView
, context
);
86 tabbedArea
.view(uiProvider
, context
);
91 public Content
getCurrentContext(Composite workArea
) {
92 SwtTabbedArea tabbedArea
= findTabbedArea(workArea
);
93 if (tabbedArea
== null)
95 return tabbedArea
.getCurrentContext();
98 private SwtTabbedArea
findTabbedArea(Composite workArea
) {
99 SwtTabbedArea tabbedArea
= null;
100 if (workArea
instanceof SashFormEditionArea
) {
101 tabbedArea
= ((SashFormEditionArea
) workArea
).getTabbedArea();
102 } else if (workArea
instanceof FixedEditionArea
) {
103 tabbedArea
= ((FixedEditionArea
) workArea
).getTabbedArea();
104 } else if (workArea
instanceof SwtTabbedArea
) {
105 tabbedArea
= (SwtTabbedArea
) workArea
;
111 public void open(SwtUiProvider uiProvider
, Composite workArea
, Content context
) {
112 SwtTabbedArea tabbedArea
= ((SashFormEditionArea
) workArea
).getTabbedArea();
113 tabbedArea
.open(uiProvider
, context
);
117 public Localized
getTitle() {
121 public void init(BundleContext bundleContext
, Map
<String
, Object
> properties
) {
122 weights
= LangUtils
.toStringList(properties
.get(Property
.weights
.name()));
123 startMaximized
= properties
.containsKey(Property
.startMaximized
.name())
124 && "true".equals(properties
.get(Property
.startMaximized
.name()));
125 fixedEntryArea
= properties
.containsKey(Property
.fixedEntryArea
.name())
126 && "true".equals(properties
.get(Property
.fixedEntryArea
.name()));
127 if (fixedEntryArea
&& weights
.size() != 0) {
128 throw new IllegalArgumentException("Property " + Property
.weights
.name() + " should not be set if property "
129 + Property
.fixedEntryArea
.name() + " is set.");
131 singleTab
= properties
.containsKey(Property
.singleTab
.name())
132 && "true".equals(properties
.get(Property
.singleTab
.name()));
134 String titleStr
= (String
) properties
.get(SuiteLayer
.Property
.title
.name());
135 if (titleStr
!= null) {
136 if (titleStr
.startsWith("%")) {
137 title
= new Localized() {
140 public String
name() {
145 public ClassLoader
getL10nClassLoader() {
146 return bundleContext
!= null
147 ? bundleContext
.getBundle().adapt(BundleWiring
.class).getClassLoader()
148 : getClass().getClassLoader();
152 title
= new Localized
.Untranslated(titleStr
);
157 public void destroy(BundleContext bundleContext
, Map
<String
, String
> properties
) {
161 public void setEntryArea(CmsUiProvider entryArea
) {
162 this.entryArea
= entryArea
;
165 public void setWorkArea(CmsUiProvider workArea
) {
166 this.workArea
= workArea
;
169 public void setDefaultView(CmsUiProvider defaultView
) {
170 this.defaultView
= defaultView
;
173 SwtTabbedArea
createTabbedArea(Composite parent
, CmsTheme theme
) {
174 SwtTabbedArea tabbedArea
= new SwtTabbedArea(parent
, SWT
.NONE
);
175 tabbedArea
.setSingleTab(singleTab
);
176 tabbedArea
.setBodyStyle(SuiteStyle
.mainTabBody
.style());
177 tabbedArea
.setTabStyle(SuiteStyle
.mainTab
.style());
178 tabbedArea
.setTabSelectedStyle(SuiteStyle
.mainTabSelected
.style());
179 tabbedArea
.setCloseIcon(SuiteIcon
.close
.getSmallIcon(theme
));
180 tabbedArea
.setLayoutData(CmsSwtUtils
.fillAll());
184 // /** A work area based on an entry area and and a tabbed area. */
185 class SashFormEditionArea
extends SashForm
{
186 private static final long serialVersionUID
= 2219125778722702618L;
187 private SwtTabbedArea tabbedArea
;
188 private Composite entryC
;
190 SashFormEditionArea(Composite parent
, int style
) {
191 super(parent
, SWT
.HORIZONTAL
);
192 CmsTheme theme
= CmsSwtUtils
.getCmsTheme(parent
);
195 if (SWT
.RIGHT_TO_LEFT
== (style
& SWT
.RIGHT_TO_LEFT
)) {// arabic, hebrew, etc.
196 editorC
= new Composite(this, SWT
.BORDER
);
197 entryC
= new Composite(this, SWT
.BORDER
);
199 entryC
= new Composite(this, SWT
.NONE
);
200 editorC
= new Composite(this, SWT
.NONE
);
203 // sash form specific
204 if (weights
.size() != 0) {
205 int[] actualWeight
= new int[weights
.size()];
206 for (int i
= 0; i
< weights
.size(); i
++) {
207 actualWeight
[i
] = Integer
.parseInt(weights
.get(i
));
209 setWeights(actualWeight
);
211 int[] actualWeights
= new int[] { 3000, 7000 };
212 setWeights(actualWeights
);
215 setMaximizedControl(editorC
);
217 GridLayout editorAreaLayout
= CmsSwtUtils
.noSpaceGridLayout();
218 // editorAreaLayout.verticalSpacing = 0;
219 // editorAreaLayout.marginBottom = 0;
220 // editorAreaLayout.marginHeight = 0;
221 // editorAreaLayout.marginLeft = 0;
222 // editorAreaLayout.marginRight = 0;
223 editorC
.setLayout(editorAreaLayout
);
225 tabbedArea
= createTabbedArea(editorC
, theme
);
228 SwtTabbedArea
getTabbedArea() {
232 Composite
getEntryArea() {
238 class FixedEditionArea
extends Composite
{
239 private static final long serialVersionUID
= -5525672639277322465L;
240 private SwtTabbedArea tabbedArea
;
241 private Composite entryC
;
243 public FixedEditionArea(Composite parent
, int style
) {
244 super(parent
, style
);
245 CmsTheme theme
= CmsSwtUtils
.getCmsTheme(parent
);
247 setLayout(CmsSwtUtils
.noSpaceGridLayout(2));
250 if (SWT
.RIGHT_TO_LEFT
== (style
& SWT
.RIGHT_TO_LEFT
)) {// arabic, hebrew, etc.
251 editorC
= new Composite(this, SWT
.NONE
);
252 entryC
= new Composite(this, SWT
.NONE
);
254 entryC
= new Composite(this, SWT
.NONE
);
255 editorC
= new Composite(this, SWT
.NONE
);
257 entryC
.setLayoutData(CmsSwtUtils
.fillHeight());
259 GridLayout editorAreaLayout
= CmsSwtUtils
.noSpaceGridLayout();
260 // editorAreaLayout.verticalSpacing = 0;
261 // editorAreaLayout.marginBottom = 0;
262 // editorAreaLayout.marginHeight = 0;
263 // editorAreaLayout.marginLeft = 0;
264 // editorAreaLayout.marginRight = 0;
265 editorC
.setLayout(editorAreaLayout
);
266 editorC
.setLayoutData(CmsSwtUtils
.fillAll());
268 tabbedArea
= createTabbedArea(editorC
, theme
);
271 SwtTabbedArea
getTabbedArea() {
275 Composite
getEntryArea() {