1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.primefaces.extensions.component.suneditor;
23
24 import java.util.Collection;
25 import java.util.Locale;
26
27 import javax.faces.application.ResourceDependency;
28 import javax.faces.component.behavior.ClientBehaviorHolder;
29 import javax.faces.context.FacesContext;
30
31 import org.primefaces.extensions.component.base.AbstractEditorInputTextArea;
32 import org.primefaces.util.LangUtils;
33 import org.primefaces.util.LocaleUtils;
34
35
36
37
38
39
40
41
42 @ResourceDependency(library = "primefaces", name = "jquery/jquery.js")
43 @ResourceDependency(library = "primefaces", name = "jquery/jquery-plugins.js")
44 @ResourceDependency(library = "primefaces", name = "core.js")
45 @ResourceDependency(library = "primefaces-extensions", name = "primefaces-extensions.js")
46 @ResourceDependency(library = "primefaces-extensions", name = "suneditor/suneditor.css")
47 @ResourceDependency(library = "primefaces-extensions", name = "suneditor/suneditor.js")
48 public class SunEditor extends AbstractEditorInputTextArea implements ClientBehaviorHolder {
49 public static final String EDITOR_CLASS = "ui-suneditor";
50 public static final String COMPONENT_TYPE = "org.primefaces.extensions.component.SunEditor";
51 public static final String COMPONENT_FAMILY = "org.primefaces.extensions.component";
52 private static final String DEFAULT_RENDERER = "org.primefaces.extensions.component.SunEditorRenderer";
53
54 private static final Collection<String> EVENT_NAMES = LangUtils.unmodifiableList("change", "scroll", "mousedown", "click", "input", "keydown", "keyup",
55 "focus", "blur", "paste", "copy", "cut", "drop", "save", "initialize");
56
57 @SuppressWarnings("java:S115")
58 protected enum PropertyKeys {
59
60 width,
61 height,
62 mode,
63 locale,
64
65 }
66
67 private Locale appropriateLocale;
68
69 public SunEditor() {
70 setRendererType(DEFAULT_RENDERER);
71 }
72
73 @Override
74 public Collection<String> getEventNames() {
75 return EVENT_NAMES;
76 }
77
78 @Override
79 public String getDefaultEventName() {
80 return "change";
81 }
82
83 @Override
84 public String getFamily() {
85 return COMPONENT_FAMILY;
86 }
87
88 public String getWidth() {
89 return (String) getStateHelper().eval(PropertyKeys.width, "100%");
90 }
91
92 public void setWidth(String width) {
93 getStateHelper().put(PropertyKeys.width, width);
94 }
95
96 public String getHeight() {
97 return (String) getStateHelper().eval(PropertyKeys.height, "auto");
98 }
99
100 public void setHeight(String height) {
101 getStateHelper().put(PropertyKeys.height, height);
102 }
103
104 public String getMode() {
105 return (String) getStateHelper().eval(PropertyKeys.mode, "classic");
106 }
107
108 public void setMode(String mode) {
109 getStateHelper().put(PropertyKeys.mode, mode);
110 }
111
112 public Object getLocale() {
113 return getStateHelper().eval(PropertyKeys.locale, null);
114 }
115
116 public void setLocale(final Object locale) {
117 getStateHelper().put(PropertyKeys.locale, locale);
118 }
119
120 public Locale calculateLocale() {
121 if (appropriateLocale == null) {
122 final FacesContext fc = FacesContext.getCurrentInstance();
123 appropriateLocale = LocaleUtils.resolveLocale(fc, getLocale(), getClientId(fc));
124 }
125 return appropriateLocale;
126 }
127
128 @Override
129 public Object saveState(FacesContext context) {
130
131 appropriateLocale = null;
132
133 return super.saveState(context);
134 }
135
136 }