1 package org
.argeo
.cms
.ui
.script
;
3 import java
.util
.HashMap
;
7 import javax
.jcr
.Repository
;
8 import javax
.jcr
.RepositoryException
;
9 import javax
.script
.Invocable
;
10 import javax
.script
.ScriptException
;
12 import org
.argeo
.cms
.ui
.CmsUiProvider
;
13 import org
.argeo
.cms
.ui
.util
.CmsPane
;
14 import org
.argeo
.cms
.ui
.util
.CmsUiUtils
;
15 import org
.argeo
.cms
.ui
.util
.SimpleErgonomics
;
16 import org
.argeo
.eclipse
.ui
.Selected
;
17 import org
.eclipse
.rap
.rwt
.RWT
;
18 import org
.eclipse
.rap
.rwt
.application
.Application
;
19 import org
.eclipse
.rap
.rwt
.application
.EntryPoint
;
20 import org
.eclipse
.rap
.rwt
.application
.EntryPointFactory
;
21 import org
.eclipse
.rap
.rwt
.client
.WebClient
;
22 import org
.eclipse
.rap
.rwt
.client
.service
.JavaScriptExecutor
;
23 import org
.eclipse
.swt
.SWT
;
24 import org
.eclipse
.swt
.events
.SelectionEvent
;
25 import org
.eclipse
.swt
.widgets
.Button
;
26 import org
.eclipse
.swt
.widgets
.Composite
;
27 import org
.eclipse
.swt
.widgets
.Control
;
28 import org
.eclipse
.swt
.widgets
.Label
;
29 import org
.osgi
.framework
.BundleContext
;
31 public class AppUi
implements CmsUiProvider
, Branding
{
32 private final CmsScriptApp app
;
34 private CmsUiProvider ui
;
35 private String createUi
;
37 private String script
;
38 // private Branding branding = new Branding();
40 private EntryPointFactory factory
;
43 private String themeId
;
44 private String additionalHeaders
;
45 private String bodyHtml
;
46 private String pageTitle
;
47 private String pageOverflow
;
48 private String favicon
;
50 public AppUi(CmsScriptApp app
) {
54 public AppUi(CmsScriptApp app
, String scriptPath
) {
56 this.ui
= new ScriptUi((BundleContext
) app
.getScriptEngine().get(CmsScriptRwtApplication
.BC
), app
.getScriptEngine(), scriptPath
);
59 public AppUi(CmsScriptApp app
, CmsUiProvider uiProvider
) {
64 public AppUi(CmsScriptApp app
, EntryPointFactory factory
) {
66 this.factory
= factory
;
69 public void apply(Repository repository
, Application application
, Branding appBranding
, String path
) {
70 Map
<String
, String
> factoryProperties
= new HashMap
<>();
71 if (appBranding
!= null)
72 appBranding
.applyBranding(factoryProperties
);
73 applyBranding(factoryProperties
);
74 if (factory
!= null) {
75 application
.addEntryPoint("/" + path
, factory
, factoryProperties
);
77 EntryPointFactory entryPointFactory
= new EntryPointFactory() {
79 public EntryPoint
create() {
80 SimpleErgonomics ergonomics
= new SimpleErgonomics(repository
, "main", "/home/root/argeo:keyring",
81 AppUi
.this, factoryProperties
);
82 // CmsUiProvider header = app.getHeader();
83 // if (header != null)
84 // ergonomics.setHeader(header);
85 app
.applySides(ergonomics
);
86 Integer headerHeight
= app
.getHeaderHeight();
87 if (headerHeight
!= null)
88 ergonomics
.setHeaderHeight(headerHeight
);
92 application
.addEntryPoint("/" + path
, entryPointFactory
, factoryProperties
);
96 public void setUi(CmsUiProvider uiProvider
) {
100 public void applyBranding(Map
<String
, String
> properties
) {
102 properties
.put(WebClient
.THEME_ID
, themeId
);
103 if (additionalHeaders
!= null)
104 properties
.put(WebClient
.HEAD_HTML
, additionalHeaders
);
105 if (bodyHtml
!= null)
106 properties
.put(WebClient
.BODY_HTML
, bodyHtml
);
107 if (pageTitle
!= null)
108 properties
.put(WebClient
.PAGE_TITLE
, pageTitle
);
109 if (pageOverflow
!= null)
110 properties
.put(WebClient
.PAGE_OVERFLOW
, pageOverflow
);
112 properties
.put(WebClient
.FAVICON
, favicon
);
115 // public Branding getBranding() {
120 public Control
createUi(Composite parent
, Node context
) throws RepositoryException
{
121 CmsPane cmsPane
= new CmsPane(parent
, SWT
.NONE
);
125 CmsUiUtils
.style(cmsPane
.getQaArea(), "qa");
126 Button reload
= new Button(cmsPane
.getQaArea(), SWT
.FLAT
);
127 CmsUiUtils
.style(reload
, "qa");
128 reload
.setText("Reload");
129 reload
.addSelectionListener(new Selected() {
130 private static final long serialVersionUID
= 1L;
133 public void widgetSelected(SelectionEvent e
) {
140 RWT
.getClient().getService(JavaScriptExecutor
.class)
141 .execute("setTimeout('location.reload()',1000)");
146 CmsUiUtils
.style(cmsPane
.getSupportArea(), "support");
147 Label msg
= new Label(cmsPane
.getSupportArea(), SWT
.NONE
);
148 CmsUiUtils
.style(msg
, "support");
149 msg
.setText("UNSUPPORTED DEVELOPMENT VERSION");
153 ui
.createUi(cmsPane
.getMainArea(), context
);
155 if (createUi
!= null) {
156 Invocable invocable
= (Invocable
) app
.getScriptEngine();
158 invocable
.invokeFunction(createUi
, cmsPane
.getMainArea(), context
);
160 } catch (NoSuchMethodException e
) {
161 // TODO Auto-generated catch block
163 } catch (ScriptException e
) {
164 // TODO Auto-generated catch block
169 Invocable invocable
= (Invocable
) app
.getScriptEngine();
171 invocable
.invokeMethod(impl
, "createUi", cmsPane
.getMainArea(), context
);
173 } catch (NoSuchMethodException e
) {
174 // TODO Auto-generated catch block
176 } catch (ScriptException e
) {
177 // TODO Auto-generated catch block
182 // Invocable invocable = (Invocable) app.getScriptEngine();
184 // invocable.invokeMethod(AppUi.this, "initUi", parent, context);
186 // } catch (NoSuchMethodException e) {
187 // // TODO Auto-generated catch block
188 // e.printStackTrace();
189 // } catch (ScriptException e) {
190 // // TODO Auto-generated catch block
191 // e.printStackTrace();
197 public void setCreateUi(String createUi
) {
198 this.createUi
= createUi
;
201 public void setImpl(Object impl
) {
205 public Object
getImpl() {
209 public String
getScript() {
213 public void setScript(String script
) {
214 this.script
= script
;
218 public String
getThemeId() {
222 public void setThemeId(String themeId
) {
223 this.themeId
= themeId
;
226 public String
getAdditionalHeaders() {
227 return additionalHeaders
;
230 public void setAdditionalHeaders(String additionalHeaders
) {
231 this.additionalHeaders
= additionalHeaders
;
234 public String
getBodyHtml() {
238 public void setBodyHtml(String bodyHtml
) {
239 this.bodyHtml
= bodyHtml
;
242 public String
getPageTitle() {
246 public void setPageTitle(String pageTitle
) {
247 this.pageTitle
= pageTitle
;
250 public String
getPageOverflow() {
254 public void setPageOverflow(String pageOverflow
) {
255 this.pageOverflow
= pageOverflow
;
258 public String
getFavicon() {
262 public void setFavicon(String favicon
) {
263 this.favicon
= favicon
;