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
.Constants
;
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
{
26 private SwtUiProvider entryArea
;
27 private SwtUiProvider defaultView
;
28 private SwtUiProvider workArea
;
29 private List
<String
> weights
= new ArrayList
<>();
30 private boolean startMaximized
= false;
31 private boolean fixedEntryArea
= false;
32 private boolean singleTab
= false;
33 private Localized title
= null;
36 public Control
createUiPart(Composite parent
, Content context
) {
37 // TODO Factorize more, or split into more specialised classes?
38 if (entryArea
!= null) {
40 FixedEditionArea editionArea
= new FixedEditionArea(parent
, parent
.getStyle());
41 Control entryAreaC
= entryArea
.createUiPart(editionArea
.getEntryArea(), context
);
42 CmsSwtUtils
.style(entryAreaC
, SuiteStyle
.entryArea
);
43 if (this.defaultView
!= null) {
44 editionArea
.getTabbedArea().view(defaultView
, context
);
48 SashFormEditionArea editionArea
= new SashFormEditionArea(parent
, parent
.getStyle());
49 entryArea
.createUiPart(editionArea
.getEntryArea(), context
);
50 if (this.defaultView
!= null) {
51 editionArea
.getTabbedArea().view(defaultView
, context
);
56 if (this.workArea
!= null) {
57 Composite area
= new Composite(parent
, SWT
.NONE
);
58 this.workArea
.createUiPart(area
, context
);
61 CmsSwtTheme theme
= CmsSwtUtils
.getCmsTheme(parent
);
62 SwtTabbedArea tabbedArea
= createTabbedArea(parent
, theme
);
68 public void view(SwtUiProvider uiProvider
, Composite workAreaC
, Content context
) {
69 if (workArea
!= null) {
70 CmsSwtUtils
.clear(workAreaC
);
71 workArea
.createUiPart(workAreaC
, context
);
72 workAreaC
.layout(true, true);
77 SwtTabbedArea tabbedArea
= findTabbedArea(workAreaC
);
78 if (tabbedArea
== null)
79 throw new IllegalArgumentException("Unsupported work area " + workAreaC
.getClass().getName());
80 if (uiProvider
== null) {
82 tabbedArea
.closeAllTabs();
83 if (this.defaultView
!= null) {
84 tabbedArea
.view(defaultView
, context
);
87 tabbedArea
.view(uiProvider
, context
);
92 public Content
getCurrentContext(Composite workArea
) {
93 SwtTabbedArea tabbedArea
= findTabbedArea(workArea
);
94 if (tabbedArea
== null)
96 return tabbedArea
.getCurrentContext();
99 private SwtTabbedArea
findTabbedArea(Composite workArea
) {
100 SwtTabbedArea tabbedArea
= null;
101 if (workArea
instanceof SashFormEditionArea
) {
102 tabbedArea
= ((SashFormEditionArea
) workArea
).getTabbedArea();
103 } else if (workArea
instanceof FixedEditionArea
) {
104 tabbedArea
= ((FixedEditionArea
) workArea
).getTabbedArea();
105 } else if (workArea
instanceof SwtTabbedArea
) {
106 tabbedArea
= (SwtTabbedArea
) workArea
;
112 public void open(SwtUiProvider uiProvider
, Composite workArea
, Content context
) {
113 SwtTabbedArea tabbedArea
= ((SashFormEditionArea
) workArea
).getTabbedArea();
114 tabbedArea
.open(uiProvider
, context
);
118 public Localized
getTitle() {
123 public String
getId() {
127 public void init(BundleContext bundleContext
, Map
<String
, Object
> properties
) {
128 String pid
= (String
) properties
.get(Constants
.SERVICE_PID
);
131 weights
= LangUtils
.toStringList(properties
.get(Property
.weights
.name()));
132 startMaximized
= properties
.containsKey(Property
.startMaximized
.name())
133 && "true".equals(properties
.get(Property
.startMaximized
.name()));
134 fixedEntryArea
= properties
.containsKey(Property
.fixedEntryArea
.name())
135 && "true".equals(properties
.get(Property
.fixedEntryArea
.name()));
136 if (fixedEntryArea
&& weights
.size() != 0) {
137 throw new IllegalArgumentException("Property " + Property
.weights
.name() + " should not be set if property "
138 + Property
.fixedEntryArea
.name() + " is set.");
140 singleTab
= properties
.containsKey(Property
.singleTab
.name())
141 && "true".equals(properties
.get(Property
.singleTab
.name()));
143 String titleStr
= (String
) properties
.get(SuiteLayer
.Property
.title
.name());
144 if (titleStr
!= null) {
145 if (titleStr
.startsWith("%")) {
146 title
= new Localized() {
149 public String
name() {
154 public ClassLoader
getL10nClassLoader() {
155 return bundleContext
!= null
156 ? bundleContext
.getBundle().adapt(BundleWiring
.class).getClassLoader()
157 : getClass().getClassLoader();
161 title
= new Localized
.Untranslated(titleStr
);
166 public void destroy(BundleContext bundleContext
, Map
<String
, String
> properties
) {
170 public void setEntryArea(SwtUiProvider entryArea
) {
171 this.entryArea
= entryArea
;
174 public void setWorkArea(SwtUiProvider workArea
) {
175 this.workArea
= workArea
;
178 public void setDefaultView(SwtUiProvider defaultView
) {
179 this.defaultView
= defaultView
;
182 SwtTabbedArea
createTabbedArea(Composite parent
, CmsSwtTheme theme
) {
183 SwtTabbedArea tabbedArea
= new SwtTabbedArea(parent
, SWT
.NONE
);
184 tabbedArea
.setSingleTab(singleTab
);
185 tabbedArea
.setBodyStyle(SuiteStyle
.mainTabBody
.style());
186 tabbedArea
.setTabStyle(SuiteStyle
.mainTab
.style());
187 tabbedArea
.setTabSelectedStyle(SuiteStyle
.mainTabSelected
.style());
188 tabbedArea
.setCloseIcon(theme
.getSmallIcon(SuiteIcon
.close
));
189 tabbedArea
.setLayoutData(CmsSwtUtils
.fillAll());
193 // /** A work area based on an entry area and and a tabbed area. */
194 class SashFormEditionArea
extends SashForm
{
195 private static final long serialVersionUID
= 2219125778722702618L;
196 private SwtTabbedArea tabbedArea
;
197 private Composite entryC
;
199 SashFormEditionArea(Composite parent
, int style
) {
200 super(parent
, SWT
.HORIZONTAL
);
201 CmsSwtTheme theme
= CmsSwtUtils
.getCmsTheme(parent
);
204 if (SWT
.RIGHT_TO_LEFT
== (style
& SWT
.RIGHT_TO_LEFT
)) {// arabic, hebrew, etc.
205 editorC
= new Composite(this, SWT
.BORDER
);
206 entryC
= new Composite(this, SWT
.BORDER
);
208 entryC
= new Composite(this, SWT
.NONE
);
209 editorC
= new Composite(this, SWT
.NONE
);
212 // sash form specific
213 if (weights
.size() != 0) {
214 int[] actualWeight
= new int[weights
.size()];
215 for (int i
= 0; i
< weights
.size(); i
++) {
216 actualWeight
[i
] = Integer
.parseInt(weights
.get(i
));
218 setWeights(actualWeight
);
220 int[] actualWeights
= new int[] { 3000, 7000 };
221 setWeights(actualWeights
);
224 setMaximizedControl(editorC
);
226 GridLayout editorAreaLayout
= CmsSwtUtils
.noSpaceGridLayout();
227 // editorAreaLayout.verticalSpacing = 0;
228 // editorAreaLayout.marginBottom = 0;
229 // editorAreaLayout.marginHeight = 0;
230 // editorAreaLayout.marginLeft = 0;
231 // editorAreaLayout.marginRight = 0;
232 editorC
.setLayout(editorAreaLayout
);
234 tabbedArea
= createTabbedArea(editorC
, theme
);
237 SwtTabbedArea
getTabbedArea() {
241 Composite
getEntryArea() {
247 class FixedEditionArea
extends Composite
{
248 private static final long serialVersionUID
= -5525672639277322465L;
249 private SwtTabbedArea tabbedArea
;
250 private Composite entryC
;
252 public FixedEditionArea(Composite parent
, int style
) {
253 super(parent
, style
);
254 CmsSwtTheme theme
= CmsSwtUtils
.getCmsTheme(parent
);
256 setLayout(CmsSwtUtils
.noSpaceGridLayout(2));
259 if (SWT
.RIGHT_TO_LEFT
== (style
& SWT
.RIGHT_TO_LEFT
)) {// arabic, hebrew, etc.
260 editorC
= new Composite(this, SWT
.NONE
);
261 entryC
= new Composite(this, SWT
.NONE
);
263 entryC
= new Composite(this, SWT
.NONE
);
264 editorC
= new Composite(this, SWT
.NONE
);
266 entryC
.setLayoutData(CmsSwtUtils
.fillHeight());
268 GridLayout editorAreaLayout
= CmsSwtUtils
.noSpaceGridLayout();
269 // editorAreaLayout.verticalSpacing = 0;
270 // editorAreaLayout.marginBottom = 0;
271 // editorAreaLayout.marginHeight = 0;
272 // editorAreaLayout.marginLeft = 0;
273 // editorAreaLayout.marginRight = 0;
274 editorC
.setLayout(editorAreaLayout
);
275 editorC
.setLayoutData(CmsSwtUtils
.fillAll());
277 tabbedArea
= createTabbedArea(editorC
, theme
);
280 SwtTabbedArea
getTabbedArea() {
284 Composite
getEntryArea() {