]> git.argeo.org Git - lgpl/argeo-commons.git/blob - AbstractCmsApp.java
c2d52f3d0c5eb4e2ae63ccec4838e68a001d5e94
[lgpl/argeo-commons.git] / AbstractCmsApp.java
1 package org.argeo.cms;
2
3 import java.util.ArrayList;
4 import java.util.Collections;
5 import java.util.HashMap;
6 import java.util.List;
7 import java.util.Map;
8
9 import org.argeo.api.cms.CmsApp;
10 import org.argeo.api.cms.CmsAppListener;
11 import org.argeo.api.cms.CmsContext;
12 import org.argeo.api.cms.CmsTheme;
13
14 /** Base class for {@link CmsApp}s. */
15 public abstract class AbstractCmsApp implements CmsApp {
16 private CmsContext cmsContext;
17
18 private Map<String, CmsTheme> themes = Collections.synchronizedMap(new HashMap<>());
19
20 private List<CmsAppListener> cmsAppListeners = new ArrayList<>();
21
22 /** To be overridden in order to provide themes. */
23 protected String getThemeId(String uiName) {
24 return null;
25 }
26
27 @Override
28 public CmsTheme getTheme(String uiName) {
29 String themeId = getThemeId(uiName);
30 if (themeId == null)
31 return null;
32 if (!themes.containsKey(themeId))
33 throw new IllegalArgumentException("Theme " + themeId + " not found.");
34 return themes.get(themeId);
35 }
36
37 @Override
38 public boolean allThemesAvailable() {
39 boolean themeMissing = false;
40 uiNames: for (String uiName : getUiNames()) {
41 String themeId = getThemeId(uiName);
42 if ("org.eclipse.rap.rwt.theme.Default".equals(themeId))
43 continue uiNames;
44 if (themeId != null && !themes.containsKey(themeId)) {
45 themeMissing = true;
46 break uiNames;
47 }
48 }
49 return !themeMissing;
50 }
51
52 public void addTheme(CmsTheme theme, Map<String, String> properties) {
53 themes.put(theme.getThemeId(), theme);
54 if (allThemesAvailable())
55 for (CmsAppListener listener : cmsAppListeners)
56 listener.themingUpdated();
57 }
58
59 public void removeTheme(CmsTheme theme, Map<String, String> properties) {
60 themes.remove(theme.getThemeId());
61 }
62
63 @Override
64 public void addCmsAppListener(CmsAppListener listener) {
65 cmsAppListeners.add(listener);
66 if (allThemesAvailable())
67 listener.themingUpdated();
68 }
69
70 @Override
71 public void removeCmsAppListener(CmsAppListener listener) {
72 cmsAppListeners.remove(listener);
73 }
74
75 @Override
76 public CmsContext getCmsContext() {
77 return cmsContext;
78 }
79
80 public void setCmsContext(CmsContext cmsContext) {
81 this.cmsContext = cmsContext;
82 }
83
84
85
86 }