1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.student.common.ui.client.configurable.mvc.binding; |
17 | |
|
18 | |
import org.kuali.student.common.ui.client.mvc.DataModel; |
19 | |
import org.kuali.student.common.ui.client.widgets.RichTextEditor; |
20 | |
import org.kuali.student.core.assembly.data.QueryPath; |
21 | |
|
22 | 0 | public class RichTextBinding extends ModelWidgetBindingSupport<RichTextEditor> { |
23 | 0 | public static RichTextBinding INSTANCE = new RichTextBinding(); |
24 | |
|
25 | 0 | private RichTextBinding() {} |
26 | |
|
27 | |
@Override |
28 | |
public void setModelValue(RichTextEditor object, DataModel model, String path) { |
29 | 0 | String richTextRoot = path + QueryPath.getPathSeparator(); |
30 | |
|
31 | 0 | QueryPath qPath = QueryPath.parse(richTextRoot + "plain"); |
32 | |
|
33 | 0 | String oldValue = model.get(qPath); |
34 | 0 | String newValue = object.getText(); |
35 | |
|
36 | 0 | if (!nullsafeEquals(oldValue, newValue)) { |
37 | 0 | model.set(qPath, newValue); |
38 | 0 | setDirtyFlag(model, qPath); |
39 | |
} |
40 | |
|
41 | 0 | qPath = QueryPath.parse(richTextRoot + "formatted"); |
42 | |
|
43 | 0 | oldValue = model.get(qPath); |
44 | 0 | newValue = object.getHTML(); |
45 | |
|
46 | 0 | if (!nullsafeEquals(oldValue, newValue)) { |
47 | 0 | model.set(qPath, newValue); |
48 | 0 | setDirtyFlag(model, qPath); |
49 | |
} |
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | 0 | } |
59 | |
|
60 | |
@Override |
61 | |
public void setWidgetValue(RichTextEditor object, DataModel model, String path) { |
62 | 0 | String richTextRoot = path + QueryPath.getPathSeparator(); |
63 | |
|
64 | 0 | QueryPath qPath = QueryPath.parse(richTextRoot + "plain"); |
65 | 0 | String formatted = model.get(qPath); |
66 | |
|
67 | 0 | qPath = QueryPath.parse(richTextRoot + "formatted"); |
68 | 0 | String plain = model.get(qPath); |
69 | |
|
70 | 0 | if (formatted != null) { |
71 | 0 | object.setHTML(formatted); |
72 | 0 | } else if (plain != null) { |
73 | 0 | object.setText(plain); |
74 | |
} else { |
75 | 0 | object.setHTML(""); |
76 | |
} |
77 | 0 | } |
78 | |
|
79 | |
} |