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
.jcr
.JcrException
;
15 import org
.argeo
.suite
.ui
.widgets
.TabbedArea
;
16 import org
.argeo
.util
.LangUtils
;
17 import org
.eclipse
.swt
.SWT
;
18 import org
.eclipse
.swt
.custom
.SashForm
;
19 import org
.eclipse
.swt
.layout
.GridLayout
;
20 import org
.eclipse
.swt
.widgets
.Composite
;
21 import org
.eclipse
.swt
.widgets
.Control
;
22 import org
.osgi
.framework
.BundleContext
;
23 import org
.osgi
.framework
.wiring
.BundleWiring
;
25 /** An app layer based on an entry area and an editor area. */
26 public class DefaultEditionLayer
implements SuiteLayer
{
27 private CmsUiProvider entryArea
;
28 private CmsUiProvider defaultView
;
29 private CmsUiProvider workArea
;
30 private List
<String
> weights
= new ArrayList
<>();
31 private boolean startMaximized
= false;
32 private boolean fixedEntryArea
= false;
33 private boolean singleTab
= false;
34 private Localized title
= null;
37 public Control
createUi(Composite parent
, Node context
) throws RepositoryException
{
38 // TODO Factorize more, or split into more specialised classes?
39 if (entryArea
!= null) {
41 FixedEditionArea editionArea
= new FixedEditionArea(parent
, parent
.getStyle());
42 Control entryAreaC
= entryArea
.createUi(editionArea
.getEntryArea(), context
);
43 CmsUiUtils
.style(entryAreaC
, SuiteStyle
.entryArea
);
44 if (this.defaultView
!= null) {
45 editionArea
.getTabbedArea().view(defaultView
, context
);
49 SashFormEditionArea editionArea
= new SashFormEditionArea(parent
, parent
.getStyle());
50 entryArea
.createUi(editionArea
.getEntryArea(), context
);
51 if (this.defaultView
!= null) {
52 editionArea
.getTabbedArea().view(defaultView
, context
);
57 if (this.workArea
!= null) {
58 Composite area
= new Composite(parent
, SWT
.NONE
);
59 this.workArea
.createUi(area
, context
);
62 CmsTheme theme
= CmsTheme
.getCmsTheme(parent
);
63 TabbedArea tabbedArea
= createTabbedArea(parent
, theme
);
69 public void view(CmsUiProvider uiProvider
, Composite workAreaC
, Node context
) {
70 if (workArea
!= null) {
72 CmsUiUtils
.clear(workAreaC
);
73 workArea
.createUi(workAreaC
, context
);
74 workAreaC
.requestLayout();
76 } catch (RepositoryException e
) {
77 throw new JcrException("Cannot rebuild work area", e
);
82 TabbedArea tabbedArea
= findTabbedArea(workAreaC
);
83 if (tabbedArea
== null)
84 throw new IllegalArgumentException("Unsupported work area " + workAreaC
.getClass().getName());
85 if (uiProvider
== null) {
87 tabbedArea
.closeAllTabs();
88 if (this.defaultView
!= null) {
89 tabbedArea
.view(defaultView
, context
);
92 tabbedArea
.view(uiProvider
, context
);
97 public Node
getCurrentContext(Composite workArea
) {
98 TabbedArea tabbedArea
= findTabbedArea(workArea
);
99 if (tabbedArea
== null)
101 return tabbedArea
.getCurrentContext();
104 private TabbedArea
findTabbedArea(Composite workArea
) {
105 TabbedArea tabbedArea
= null;
106 if (workArea
instanceof SashFormEditionArea
) {
107 tabbedArea
= ((SashFormEditionArea
) workArea
).getTabbedArea();
108 } else if (workArea
instanceof FixedEditionArea
) {
109 tabbedArea
= ((FixedEditionArea
) workArea
).getTabbedArea();
110 } else if (workArea
instanceof TabbedArea
) {
111 tabbedArea
= (TabbedArea
) workArea
;
117 public void open(CmsUiProvider uiProvider
, Composite workArea
, Node context
) {
118 TabbedArea tabbedArea
= ((SashFormEditionArea
) workArea
).getTabbedArea();
119 tabbedArea
.open(uiProvider
, context
);
123 public Localized
getTitle() {
127 public void init(BundleContext bundleContext
, Map
<String
, Object
> properties
) {
128 weights
= LangUtils
.toStringList(properties
.get(Property
.weights
.name()));
129 startMaximized
= properties
.containsKey(Property
.startMaximized
.name())
130 && "true".equals(properties
.get(Property
.startMaximized
.name()));
131 fixedEntryArea
= properties
.containsKey(Property
.fixedEntryArea
.name())
132 && "true".equals(properties
.get(Property
.fixedEntryArea
.name()));
133 if (fixedEntryArea
&& weights
.size() != 0) {
134 throw new IllegalArgumentException("Property " + Property
.weights
.name() + " should not be set if property "
135 + Property
.fixedEntryArea
.name() + " is set.");
137 singleTab
= properties
.containsKey(Property
.singleTab
.name())
138 && "true".equals(properties
.get(Property
.singleTab
.name()));
140 String titleStr
= (String
) properties
.get(SuiteLayer
.Property
.title
.name());
141 if (titleStr
!= null) {
142 if (titleStr
.startsWith("%")) {
143 title
= new Localized() {
146 public String
name() {
151 public ClassLoader
getL10nClassLoader() {
152 return bundleContext
!= null
153 ? bundleContext
.getBundle().adapt(BundleWiring
.class).getClassLoader()
154 : getClass().getClassLoader();
158 title
= new Localized
.Untranslated(titleStr
);
163 public void destroy(BundleContext bundleContext
, Map
<String
, String
> properties
) {
167 public void setEntryArea(CmsUiProvider entryArea
) {
168 this.entryArea
= entryArea
;
171 public void setWorkArea(CmsUiProvider workArea
) {
172 this.workArea
= workArea
;
175 public void setDefaultView(CmsUiProvider defaultView
) {
176 this.defaultView
= defaultView
;
179 TabbedArea
createTabbedArea(Composite parent
, CmsTheme theme
) {
180 TabbedArea tabbedArea
= new TabbedArea(parent
, SWT
.NONE
);
181 tabbedArea
.setSingleTab(singleTab
);
182 tabbedArea
.setBodyStyle(SuiteStyle
.mainTabBody
.style());
183 tabbedArea
.setTabStyle(SuiteStyle
.mainTab
.style());
184 tabbedArea
.setTabSelectedStyle(SuiteStyle
.mainTabSelected
.style());
185 tabbedArea
.setCloseIcon(SuiteIcon
.close
.getSmallIcon(theme
));
186 tabbedArea
.setLayoutData(CmsUiUtils
.fillAll());
190 // /** A work area based on an entry area and and a tabbed area. */
191 class SashFormEditionArea
extends SashForm
{
192 private static final long serialVersionUID
= 2219125778722702618L;
193 private TabbedArea tabbedArea
;
194 private Composite entryC
;
196 SashFormEditionArea(Composite parent
, int style
) {
197 super(parent
, SWT
.HORIZONTAL
);
198 CmsTheme theme
= CmsTheme
.getCmsTheme(parent
);
201 if (SWT
.RIGHT_TO_LEFT
== (style
& SWT
.RIGHT_TO_LEFT
)) {// arabic, hebrew, etc.
202 editorC
= new Composite(this, SWT
.BORDER
);
203 entryC
= new Composite(this, SWT
.BORDER
);
205 entryC
= new Composite(this, SWT
.NONE
);
206 editorC
= new Composite(this, SWT
.NONE
);
209 // sash form specific
210 if (weights
.size() != 0) {
211 int[] actualWeight
= new int[weights
.size()];
212 for (int i
= 0; i
< weights
.size(); i
++) {
213 actualWeight
[i
] = Integer
.parseInt(weights
.get(i
));
215 setWeights(actualWeight
);
217 int[] actualWeights
= new int[] { 3000, 7000 };
218 setWeights(actualWeights
);
221 setMaximizedControl(editorC
);
223 GridLayout editorAreaLayout
= CmsUiUtils
.noSpaceGridLayout();
224 // editorAreaLayout.verticalSpacing = 0;
225 // editorAreaLayout.marginBottom = 0;
226 // editorAreaLayout.marginHeight = 0;
227 // editorAreaLayout.marginLeft = 0;
228 // editorAreaLayout.marginRight = 0;
229 editorC
.setLayout(editorAreaLayout
);
231 tabbedArea
= createTabbedArea(editorC
, theme
);
234 TabbedArea
getTabbedArea() {
238 Composite
getEntryArea() {
244 class FixedEditionArea
extends Composite
{
245 private static final long serialVersionUID
= -5525672639277322465L;
246 private TabbedArea tabbedArea
;
247 private Composite entryC
;
249 public FixedEditionArea(Composite parent
, int style
) {
250 super(parent
, style
);
251 CmsTheme theme
= CmsTheme
.getCmsTheme(parent
);
253 setLayout(CmsUiUtils
.noSpaceGridLayout(2));
256 if (SWT
.RIGHT_TO_LEFT
== (style
& SWT
.RIGHT_TO_LEFT
)) {// arabic, hebrew, etc.
257 editorC
= new Composite(this, SWT
.NONE
);
258 entryC
= new Composite(this, SWT
.NONE
);
260 entryC
= new Composite(this, SWT
.NONE
);
261 editorC
= new Composite(this, SWT
.NONE
);
263 entryC
.setLayoutData(CmsUiUtils
.fillHeight());
265 GridLayout editorAreaLayout
= CmsUiUtils
.noSpaceGridLayout();
266 // editorAreaLayout.verticalSpacing = 0;
267 // editorAreaLayout.marginBottom = 0;
268 // editorAreaLayout.marginHeight = 0;
269 // editorAreaLayout.marginLeft = 0;
270 // editorAreaLayout.marginRight = 0;
271 editorC
.setLayout(editorAreaLayout
);
272 editorC
.setLayoutData(CmsUiUtils
.fillAll());
274 tabbedArea
= createTabbedArea(editorC
, theme
);
277 TabbedArea
getTabbedArea() {
281 Composite
getEntryArea() {