1 /*
2 * Copyright 2003 - 2013 The eFaps Team
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 * Revision: $Rev$
17 * Last Changed: $Date$
18 * Last Changed By: $Author$
19 */
20
21 package org.efaps.admin.datamodel.ui;
22
23 import java.util.List;
24
25 import org.efaps.admin.ui.field.Field;
26 import org.efaps.util.EFapsException;
27
28 /**
29 * Class to represent a String for the user interface.
30 *
31 * @author The eFaps Team
32 * @version $Id$
33 *
34 */
35 public class FormatedStringUI
36 extends AbstractUI
37 {
38
39 /**
40 * Needed for serialization.
41 */
42 private static final long serialVersionUID = 1L;
43
44 /**
45 * {@inheritDoc}
46 */
47 @Override
48 public String getReadOnlyHtml(final FieldValue _fieldValue)
49 {
50 final StringBuilder ret = new StringBuilder();
51 final Field field = _fieldValue.getField();
52 final Object value = _fieldValue.getValue();
53
54 if (value instanceof List<?>) {
55 final List<?> values = (List<?>) value;
56 boolean first = true;
57 for (final Object obj : values) {
58 final String tmp = obj.toString();
59 if (tmp != null) {
60 if (first) {
61 first = false;
62 } else {
63 ret.append("<br/>");
64 }
65 ret.append(tmp);
66 }
67 }
68 } else {
69 final String tmp = value != null ? value.toString() : "";
70 if (tmp != null) {
71 ret.append("<span name=\"").append(field.getName()).append("\" ").append(UIInterface.EFAPSTMPTAG)
72 .append(">").append(tmp).append("</span>");
73 }
74 }
75 return ret.toString();
76 }
77
78 /**
79 * {@inheritDoc}
80 */
81 @Override
82 public String getEditHtml(final FieldValue _fieldValue)
83 throws EFapsException
84 {
85 return (String) (_fieldValue.getValue() == null ? "" : _fieldValue.getValue());
86 }
87 }