]> git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.cms/src/org/argeo/cms/AbstractCmsApp.java
JCR as an ACR backend
[lgpl/argeo-commons.git] / org.argeo.cms / src / org / argeo / cms / 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.CmsTheme;
12
13 /** Base class for {@link CmsApp}s. */
14 public abstract class AbstractCmsApp implements CmsApp {
15 private Map<String, CmsTheme> themes = Collections.synchronizedMap(new HashMap<>());
16
17 private List<CmsAppListener> cmsAppListeners = new ArrayList<>();
18
19 /** To be overridden in order to provide themes. */
20 protected String getThemeId(String uiName) {
21 return null;
22 }
23
24 @Override
25 public CmsTheme getTheme(String uiName) {
26 String themeId = getThemeId(uiName);
27 if (themeId == null)
28 return null;
29 if (!themes.containsKey(themeId))
30 throw new IllegalArgumentException("Theme " + themeId + " not found.");
31 return themes.get(themeId);
32 }
33
34 @Override
35 public boolean allThemesAvailable() {
36 boolean themeMissing = false;
37 uiNames: for (String uiName : getUiNames()) {
38 String themeId = getThemeId(uiName);
39 if ("org.eclipse.rap.rwt.theme.Default".equals(themeId))
40 continue uiNames;
41 if (themeId != null && !themes.containsKey(themeId)) {
42 themeMissing = true;
43 break uiNames;
44 }
45 }
46 return !themeMissing;
47 }
48
49 public void addTheme(CmsTheme theme, Map<String, String> properties) {
50 themes.put(theme.getThemeId(), theme);
51 if (allThemesAvailable())
52 for (CmsAppListener listener : cmsAppListeners)
53 listener.themingUpdated();
54 }
55
56 public void removeTheme(CmsTheme theme, Map<String, String> properties) {
57 themes.remove(theme.getThemeId());
58 }
59
60 @Override
61 public void addCmsAppListener(CmsAppListener listener) {
62 cmsAppListeners.add(listener);
63 if (allThemesAvailable())
64 listener.themingUpdated();
65 }
66
67 @Override
68 public void removeCmsAppListener(CmsAppListener listener) {
69 cmsAppListeners.remove(listener);
70 }
71
72 }