]> git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.cms/src/org/argeo/cms/AbstractCmsApp.java
Make time based UUID generation more robust.
[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 protected abstract String getThemeId(String uiName);
20
21 @Override
22 public CmsTheme getTheme(String uiName) {
23 String themeId = getThemeId(uiName);
24 if (themeId == null)
25 return null;
26 if (!themes.containsKey(themeId))
27 throw new IllegalArgumentException("Theme " + themeId + " not found.");
28 return themes.get(themeId);
29 }
30
31 @Override
32 public boolean allThemesAvailable() {
33 boolean themeMissing = false;
34 uiNames: for (String uiName : getUiNames()) {
35 String themeId = getThemeId(uiName);
36 if ("org.eclipse.rap.rwt.theme.Default".equals(themeId))
37 continue uiNames;
38 if (!themes.containsKey(themeId)) {
39 themeMissing = true;
40 break uiNames;
41 }
42 }
43 return !themeMissing;
44 }
45
46 public void addTheme(CmsTheme theme, Map<String, String> properties) {
47 themes.put(theme.getThemeId(), theme);
48 if (allThemesAvailable())
49 for (CmsAppListener listener : cmsAppListeners)
50 listener.themingUpdated();
51 }
52
53 public void removeTheme(CmsTheme theme, Map<String, String> properties) {
54 themes.remove(theme.getThemeId());
55 }
56
57 @Override
58 public void addCmsAppListener(CmsAppListener listener) {
59 cmsAppListeners.add(listener);
60 if (allThemesAvailable())
61 listener.themingUpdated();
62 }
63
64 @Override
65 public void removeCmsAppListener(CmsAppListener listener) {
66 cmsAppListeners.remove(listener);
67 }
68
69 }