1 package org
.argeo
.cms
.util
;
6 import javax
.jcr
.Repository
;
7 import javax
.jcr
.RepositoryException
;
9 import org
.apache
.commons
.logging
.Log
;
10 import org
.apache
.commons
.logging
.LogFactory
;
11 import org
.argeo
.cms
.CmsException
;
12 import org
.argeo
.cms
.ui
.AbstractCmsEntryPoint
;
13 import org
.argeo
.cms
.ui
.CmsImageManager
;
14 import org
.argeo
.cms
.ui
.CmsStyles
;
15 import org
.argeo
.cms
.ui
.CmsUiProvider
;
16 import org
.argeo
.cms
.ui
.UxContext
;
17 import org
.argeo
.cms
.ui
.internal
.ImageManagerImpl
;
18 import org
.eclipse
.rap
.rwt
.RWT
;
19 import org
.eclipse
.swt
.SWT
;
20 import org
.eclipse
.swt
.layout
.FillLayout
;
21 import org
.eclipse
.swt
.layout
.GridData
;
22 import org
.eclipse
.swt
.widgets
.Composite
;
23 import org
.eclipse
.swt
.widgets
.Control
;
25 /** Simple header/body ergonomics. */
26 public class SimpleErgonomics
extends AbstractCmsEntryPoint
{
27 private static final long serialVersionUID
= 8743413921359548523L;
29 private final static Log log
= LogFactory
.getLog(SimpleErgonomics
.class);
31 private boolean uiInitialized
= false;
32 private Composite headerArea
;
33 private Composite bodyArea
;
34 private final CmsUiProvider uiProvider
;
36 private CmsUiProvider header
;
37 private Integer headerHeight
= 40;
39 private CmsImageManager imageManager
= new ImageManagerImpl();
40 private UxContext uxContext
= null;
42 public SimpleErgonomics(Repository repository
, String workspace
, String defaultPath
, CmsUiProvider uiProvider
,
43 Map
<String
, String
> factoryProperties
) {
44 super(repository
, workspace
, defaultPath
, factoryProperties
);
45 this.uiProvider
= uiProvider
;
49 protected void initUi(Composite parent
) {
50 parent
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
51 parent
.setLayout(CmsUtils
.noSpaceGridLayout());
53 uxContext
= new SimpleUxContext();
54 if (!getUxContext().isMasterData())
55 createAdminArea(parent
);
56 headerArea
= new Composite(parent
, SWT
.NONE
);
57 headerArea
.setLayout(new FillLayout());
58 GridData headerData
= new GridData(SWT
.FILL
, SWT
.FILL
, false, false);
59 headerData
.heightHint
= headerHeight
;
60 headerArea
.setLayoutData(headerData
);
62 bodyArea
= new Composite(parent
, SWT
.NONE
);
63 bodyArea
.setData(RWT
.CUSTOM_VARIANT
, CmsStyles
.CMS_BODY
);
64 bodyArea
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
65 bodyArea
.setLayout(CmsUtils
.noSpaceGridLayout());
71 protected void refresh() {
74 if (getState() == null)
78 if (log
.isTraceEnabled())
79 log
.trace("UI refreshed " + getNode());
82 protected void createAdminArea(Composite parent
) {
85 protected void refreshHeader() {
86 for (Control child
: headerArea
.getChildren())
89 header
.createUi(headerArea
, getNode());
90 } catch (RepositoryException e
) {
91 throw new CmsException("Cannot refresh header", e
);
93 headerArea
.layout(true, true);
96 protected void refreshBody() {
98 Throwable exception
= getException();
99 if (exception
!= null) {
100 SystemNotifications systemNotifications
= new SystemNotifications(bodyArea
);
101 systemNotifications
.notifyException(exception
);
108 for (Control child
: bodyArea
.getChildren())
110 bodyArea
.setLayout(CmsUtils
.noSpaceGridLayout());
113 Node node
= getNode();
115 log
.error("Context cannot be null");
117 uiProvider
.createUi(bodyArea
, node
);
118 } catch (RepositoryException e
) {
119 throw new CmsException("Cannot refresh body", e
);
122 bodyArea
.layout(true, true);
126 public UxContext
getUxContext() {
131 public CmsImageManager
getImageManager() {
135 public void setHeader(CmsUiProvider header
) {
136 this.header
= header
;
139 public void setHeaderHeight(Integer headerHeight
) {
140 this.headerHeight
= headerHeight
;
143 public void setImageManager(CmsImageManager imageManager
) {
144 this.imageManager
= imageManager
;