1 package org
.argeo
.app
.ui
;
3 import java
.util
.ArrayList
;
7 import org
.argeo
.api
.acr
.Content
;
8 import org
.argeo
.cms
.Localized
;
9 import org
.argeo
.cms
.swt
.CmsSwtTheme
;
10 import org
.argeo
.cms
.swt
.CmsSwtUtils
;
11 import org
.argeo
.cms
.swt
.acr
.SwtTabbedArea
;
12 import org
.argeo
.cms
.swt
.acr
.SwtUiProvider
;
13 import org
.argeo
.util
.LangUtils
;
14 import org
.eclipse
.swt
.SWT
;
15 import org
.eclipse
.swt
.custom
.SashForm
;
16 import org
.eclipse
.swt
.layout
.GridLayout
;
17 import org
.eclipse
.swt
.widgets
.Composite
;
18 import org
.eclipse
.swt
.widgets
.Control
;
19 import org
.osgi
.framework
.BundleContext
;
20 import org
.osgi
.framework
.wiring
.BundleWiring
;
22 /** An app layer based on an entry area and an editor area. */
23 public class DefaultEditionLayer
implements SuiteLayer
{
24 private SwtUiProvider entryArea
;
25 private SwtUiProvider defaultView
;
26 private SwtUiProvider workArea
;
27 private List
<String
> weights
= new ArrayList
<>();
28 private boolean startMaximized
= false;
29 private boolean fixedEntryArea
= false;
30 private boolean singleTab
= false;
31 private Localized title
= null;
34 public Control
createUiPart(Composite parent
, Content context
) {
35 // TODO Factorize more, or split into more specialised classes?
36 if (entryArea
!= null) {
38 FixedEditionArea editionArea
= new FixedEditionArea(parent
, parent
.getStyle());
39 Control entryAreaC
= entryArea
.createUiPart(editionArea
.getEntryArea(), context
);
40 CmsSwtUtils
.style(entryAreaC
, SuiteStyle
.entryArea
);
41 if (this.defaultView
!= null) {
42 editionArea
.getTabbedArea().view(defaultView
, context
);
46 SashFormEditionArea editionArea
= new SashFormEditionArea(parent
, parent
.getStyle());
47 entryArea
.createUiPart(editionArea
.getEntryArea(), context
);
48 if (this.defaultView
!= null) {
49 editionArea
.getTabbedArea().view(defaultView
, context
);
54 if (this.workArea
!= null) {
55 Composite area
= new Composite(parent
, SWT
.NONE
);
56 this.workArea
.createUiPart(area
, context
);
59 CmsSwtTheme theme
= CmsSwtUtils
.getCmsTheme(parent
);
60 SwtTabbedArea tabbedArea
= createTabbedArea(parent
, theme
);
66 public void view(SwtUiProvider uiProvider
, Composite workAreaC
, Content context
) {
67 if (workArea
!= null) {
68 CmsSwtUtils
.clear(workAreaC
);
69 workArea
.createUiPart(workAreaC
, context
);
70 workAreaC
.layout(true, true);
75 SwtTabbedArea tabbedArea
= findTabbedArea(workAreaC
);
76 if (tabbedArea
== null)
77 throw new IllegalArgumentException("Unsupported work area " + workAreaC
.getClass().getName());
78 if (uiProvider
== null) {
80 tabbedArea
.closeAllTabs();
81 if (this.defaultView
!= null) {
82 tabbedArea
.view(defaultView
, context
);
85 tabbedArea
.view(uiProvider
, context
);
90 public Content
getCurrentContext(Composite workArea
) {
91 SwtTabbedArea tabbedArea
= findTabbedArea(workArea
);
92 if (tabbedArea
== null)
94 return tabbedArea
.getCurrentContext();
97 private SwtTabbedArea
findTabbedArea(Composite workArea
) {
98 SwtTabbedArea tabbedArea
= null;
99 if (workArea
instanceof SashFormEditionArea
) {
100 tabbedArea
= ((SashFormEditionArea
) workArea
).getTabbedArea();
101 } else if (workArea
instanceof FixedEditionArea
) {
102 tabbedArea
= ((FixedEditionArea
) workArea
).getTabbedArea();
103 } else if (workArea
instanceof SwtTabbedArea
) {
104 tabbedArea
= (SwtTabbedArea
) workArea
;
110 public void open(SwtUiProvider uiProvider
, Composite workArea
, Content context
) {
111 SwtTabbedArea tabbedArea
= ((SashFormEditionArea
) workArea
).getTabbedArea();
112 tabbedArea
.open(uiProvider
, context
);
116 public Localized
getTitle() {
120 public void init(BundleContext bundleContext
, Map
<String
, Object
> properties
) {
121 weights
= LangUtils
.toStringList(properties
.get(Property
.weights
.name()));
122 startMaximized
= properties
.containsKey(Property
.startMaximized
.name())
123 && "true".equals(properties
.get(Property
.startMaximized
.name()));
124 fixedEntryArea
= properties
.containsKey(Property
.fixedEntryArea
.name())
125 && "true".equals(properties
.get(Property
.fixedEntryArea
.name()));
126 if (fixedEntryArea
&& weights
.size() != 0) {
127 throw new IllegalArgumentException("Property " + Property
.weights
.name() + " should not be set if property "
128 + Property
.fixedEntryArea
.name() + " is set.");
130 singleTab
= properties
.containsKey(Property
.singleTab
.name())
131 && "true".equals(properties
.get(Property
.singleTab
.name()));
133 String titleStr
= (String
) properties
.get(SuiteLayer
.Property
.title
.name());
134 if (titleStr
!= null) {
135 if (titleStr
.startsWith("%")) {
136 title
= new Localized() {
139 public String
name() {
144 public ClassLoader
getL10nClassLoader() {
145 return bundleContext
!= null
146 ? bundleContext
.getBundle().adapt(BundleWiring
.class).getClassLoader()
147 : getClass().getClassLoader();
151 title
= new Localized
.Untranslated(titleStr
);
156 public void destroy(BundleContext bundleContext
, Map
<String
, String
> properties
) {
160 public void setEntryArea(SwtUiProvider entryArea
) {
161 this.entryArea
= entryArea
;
164 public void setWorkArea(SwtUiProvider workArea
) {
165 this.workArea
= workArea
;
168 public void setDefaultView(SwtUiProvider defaultView
) {
169 this.defaultView
= defaultView
;
172 SwtTabbedArea
createTabbedArea(Composite parent
, CmsSwtTheme theme
) {
173 SwtTabbedArea tabbedArea
= new SwtTabbedArea(parent
, SWT
.NONE
);
174 tabbedArea
.setSingleTab(singleTab
);
175 tabbedArea
.setBodyStyle(SuiteStyle
.mainTabBody
.style());
176 tabbedArea
.setTabStyle(SuiteStyle
.mainTab
.style());
177 tabbedArea
.setTabSelectedStyle(SuiteStyle
.mainTabSelected
.style());
178 tabbedArea
.setCloseIcon(theme
.getSmallIcon(SuiteIcon
.close
));
179 tabbedArea
.setLayoutData(CmsSwtUtils
.fillAll());
183 // /** A work area based on an entry area and and a tabbed area. */
184 class SashFormEditionArea
extends SashForm
{
185 private static final long serialVersionUID
= 2219125778722702618L;
186 private SwtTabbedArea tabbedArea
;
187 private Composite entryC
;
189 SashFormEditionArea(Composite parent
, int style
) {
190 super(parent
, SWT
.HORIZONTAL
);
191 CmsSwtTheme theme
= CmsSwtUtils
.getCmsTheme(parent
);
194 if (SWT
.RIGHT_TO_LEFT
== (style
& SWT
.RIGHT_TO_LEFT
)) {// arabic, hebrew, etc.
195 editorC
= new Composite(this, SWT
.BORDER
);
196 entryC
= new Composite(this, SWT
.BORDER
);
198 entryC
= new Composite(this, SWT
.NONE
);
199 editorC
= new Composite(this, SWT
.NONE
);
202 // sash form specific
203 if (weights
.size() != 0) {
204 int[] actualWeight
= new int[weights
.size()];
205 for (int i
= 0; i
< weights
.size(); i
++) {
206 actualWeight
[i
] = Integer
.parseInt(weights
.get(i
));
208 setWeights(actualWeight
);
210 int[] actualWeights
= new int[] { 3000, 7000 };
211 setWeights(actualWeights
);
214 setMaximizedControl(editorC
);
216 GridLayout editorAreaLayout
= CmsSwtUtils
.noSpaceGridLayout();
217 // editorAreaLayout.verticalSpacing = 0;
218 // editorAreaLayout.marginBottom = 0;
219 // editorAreaLayout.marginHeight = 0;
220 // editorAreaLayout.marginLeft = 0;
221 // editorAreaLayout.marginRight = 0;
222 editorC
.setLayout(editorAreaLayout
);
224 tabbedArea
= createTabbedArea(editorC
, theme
);
227 SwtTabbedArea
getTabbedArea() {
231 Composite
getEntryArea() {
237 class FixedEditionArea
extends Composite
{
238 private static final long serialVersionUID
= -5525672639277322465L;
239 private SwtTabbedArea tabbedArea
;
240 private Composite entryC
;
242 public FixedEditionArea(Composite parent
, int style
) {
243 super(parent
, style
);
244 CmsSwtTheme theme
= CmsSwtUtils
.getCmsTheme(parent
);
246 setLayout(CmsSwtUtils
.noSpaceGridLayout(2));
249 if (SWT
.RIGHT_TO_LEFT
== (style
& SWT
.RIGHT_TO_LEFT
)) {// arabic, hebrew, etc.
250 editorC
= new Composite(this, SWT
.NONE
);
251 entryC
= new Composite(this, SWT
.NONE
);
253 entryC
= new Composite(this, SWT
.NONE
);
254 editorC
= new Composite(this, SWT
.NONE
);
256 entryC
.setLayoutData(CmsSwtUtils
.fillHeight());
258 GridLayout editorAreaLayout
= CmsSwtUtils
.noSpaceGridLayout();
259 // editorAreaLayout.verticalSpacing = 0;
260 // editorAreaLayout.marginBottom = 0;
261 // editorAreaLayout.marginHeight = 0;
262 // editorAreaLayout.marginLeft = 0;
263 // editorAreaLayout.marginRight = 0;
264 editorC
.setLayout(editorAreaLayout
);
265 editorC
.setLayoutData(CmsSwtUtils
.fillAll());
267 tabbedArea
= createTabbedArea(editorC
, theme
);
270 SwtTabbedArea
getTabbedArea() {
274 Composite
getEntryArea() {