2 * Copyright (C) 2011 Openismus GmbH
4 * This file is part of GWT-Glom.
6 * GWT-Glom is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
11 * GWT-Glom is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with GWT-Glom. If not, see <http://www.gnu.org/licenses/>.
20 package org.glom.web.shared;
22 import java.util.Date;
24 import org.glom.web.shared.libglom.Field.GlomFieldType;
27 * This specialization of DataItem can hold a primary key item.
29 @SuppressWarnings("serial")
30 public class TypedDataItem extends DataItem {
31 private boolean empty = true;
32 private GlomFieldType type = GlomFieldType.TYPE_INVALID;
33 private String unknown = null;
35 public TypedDataItem() {
38 public boolean isEmpty() {
42 public boolean isUnknownType() {
43 return (type == GlomFieldType.TYPE_INVALID);
48 * This is a generic alternative to getNumber(), getText(), etc.
51 public Object getValue() {
59 //TODO: case TYPE_TIME:
64 return getImageData();
66 return "value-with-invalid-type";
68 return "value-with-unknown-type";
72 //TODO: Why is this override necessary?
76 * @see org.glom.web.shared.DataItem#setBoolean(boolean)
79 public void setBoolean(final boolean bool) {
81 this.type = GlomFieldType.TYPE_BOOLEAN;
82 super.setBoolean(bool);
88 * @see org.glom.web.shared.DataItem#setNumber(double)
91 public void setNumber(final double number) {
93 this.type = GlomFieldType.TYPE_NUMERIC;
94 super.setNumber(number);
100 * @see org.glom.web.shared.DataItem#setText(java.lang.String)
103 public void setText(final String text) {
105 this.type = GlomFieldType.TYPE_TEXT;
112 * @see org.glom.web.shared.DataItem#setNumber(double)
115 public void setDate(final Date date) {
117 this.type = GlomFieldType.TYPE_DATE;
121 public void setImageData(final byte[] imageData) {
123 this.type = GlomFieldType.TYPE_IMAGE;
124 super.setImageData(imageData);
127 public void setImageDataUrl(final String image) {
129 this.type = GlomFieldType.TYPE_IMAGE;
130 super.setImageDataUrl(image);
137 * @see org.glom.web.shared.DataItem#setText(java.lang.String)
139 public void setUnknown(final String value) {
141 this.type = GlomFieldType.TYPE_INVALID;
142 this.unknown = value;
145 public String getUnknown() {
149 public GlomFieldType getType() {