Change-Id: I6bda7ff2a66a9ad172c899d855ca868881600be4tags/7.4.0.beta1
@@ -1502,25 +1502,12 @@ public abstract class AbstractField<T> extends AbstractComponent implements | |||
markAsDirty(); | |||
} | |||
/** | |||
* Is the field empty? | |||
* | |||
* In general, "empty" state is same as null. As an exception, TextField | |||
* also treats empty string as "empty". | |||
*/ | |||
protected boolean isEmpty() { | |||
@Override | |||
public boolean isEmpty() { | |||
return (getFieldValue() == null); | |||
} | |||
/** | |||
* Clear the value of the field. | |||
* <p> | |||
* The field value is typically reset to the initial value of the field but | |||
* this is not mandatory. Calling {@link #isEmpty()} on a cleared field must | |||
* always returns true. | |||
* | |||
* @since | |||
*/ | |||
@Override | |||
public void clear() { | |||
setValue(null); | |||
} |
@@ -1782,7 +1782,7 @@ public abstract class AbstractSelect extends AbstractField<Object> implements | |||
* @see AbstractField#isEmpty(). | |||
*/ | |||
@Override | |||
protected boolean isEmpty() { | |||
public boolean isEmpty() { | |||
if (!multiSelect) { | |||
return super.isEmpty(); | |||
} else { |
@@ -317,7 +317,7 @@ public abstract class AbstractTextField extends AbstractField<String> implements | |||
} | |||
@Override | |||
protected boolean isEmpty() { | |||
public boolean isEmpty() { | |||
return super.isEmpty() || getValue().length() == 0; | |||
} | |||
@@ -113,4 +113,26 @@ public interface Field<T> extends Component, BufferedValidatable, Property<T>, | |||
return (Property) getSource(); | |||
} | |||
} | |||
/** | |||
* Is the field empty? | |||
* | |||
* In general, "empty" state is same as null. As an exception, TextField | |||
* also treats empty string as "empty". | |||
* | |||
* @since | |||
* @return true if the field is empty, false otherwise | |||
*/ | |||
public boolean isEmpty(); | |||
/** | |||
* Clears the value of the field. | |||
* <p> | |||
* The field value is typically reset to the initial value of the field. | |||
* Calling {@link #isEmpty()} on a cleared field must always returns true. | |||
* | |||
* @since | |||
*/ | |||
public void clear(); | |||
} |
@@ -1186,9 +1186,14 @@ public class Form extends AbstractField<Object> implements Item.Editor, | |||
} | |||
} | |||
/** Form is empty if all of its fields are empty. */ | |||
/** | |||
* {@inheritDoc} | |||
* <p> | |||
* A Form is empty if all of its fields are empty. | |||
* | |||
*/ | |||
@Override | |||
protected boolean isEmpty() { | |||
public boolean isEmpty() { | |||
for (Iterator<Field<?>> i = fields.values().iterator(); i.hasNext();) { | |||
Field<?> f = i.next(); |
@@ -285,7 +285,7 @@ public class RichTextArea extends AbstractField<String> implements | |||
} | |||
@Override | |||
protected boolean isEmpty() { | |||
public boolean isEmpty() { | |||
return super.isEmpty() || getValue().length() == 0; | |||
} | |||
@@ -16,10 +16,13 @@ | |||
package com.vaadin.ui; | |||
import java.util.ArrayList; | |||
import java.util.HashSet; | |||
import org.junit.Assert; | |||
import org.junit.Test; | |||
import com.vaadin.data.util.ObjectProperty; | |||
public class AbstractSelectTest { | |||
@Test | |||
@@ -73,4 +76,72 @@ public class AbstractSelectTest { | |||
.toArray()); | |||
} | |||
@Test | |||
public void singleSelectInitiallyEmpty() { | |||
AbstractSelect s = new ListSelect(); | |||
Assert.assertTrue(s.isEmpty()); | |||
} | |||
@Test | |||
public void singleSelectEmptyAfterClearUsingPDS() { | |||
AbstractSelect s = new ListSelect(); | |||
s.addItem("foo"); | |||
s.addItem("bar"); | |||
s.setPropertyDataSource(new ObjectProperty<String>("foo")); | |||
Assert.assertFalse(s.isEmpty()); | |||
s.clear(); | |||
Assert.assertTrue(s.isEmpty()); | |||
} | |||
@Test | |||
public void singleSelectEmptyAfterClear() { | |||
AbstractSelect s = new ListSelect(); | |||
s.addItem("foo"); | |||
s.addItem("bar"); | |||
s.setValue("bar"); | |||
Assert.assertFalse(s.isEmpty()); | |||
s.clear(); | |||
Assert.assertTrue(s.isEmpty()); | |||
} | |||
@Test | |||
public void multiSelectInitiallyEmpty() { | |||
AbstractSelect s = new ListSelect(); | |||
s.setMultiSelect(true); | |||
Assert.assertTrue(s.isEmpty()); | |||
} | |||
@Test | |||
public void multiSelectEmptyAfterClearUsingPDS() { | |||
AbstractSelect s = new ListSelect(); | |||
s.setMultiSelect(true); | |||
s.addItem("foo"); | |||
s.addItem("bar"); | |||
HashSet<String> sel = new HashSet<String>(); | |||
sel.add("foo"); | |||
sel.add("bar"); | |||
s.setPropertyDataSource(new ObjectProperty<HashSet>(sel)); | |||
Assert.assertFalse(s.isEmpty()); | |||
s.clear(); | |||
Assert.assertTrue(s.isEmpty()); | |||
} | |||
@Test | |||
public void multiSelectEmptyAfterClear() { | |||
AbstractSelect s = new ListSelect(); | |||
s.setMultiSelect(true); | |||
s.addItem("foo"); | |||
s.addItem("bar"); | |||
s.select("foo"); | |||
s.select("bar"); | |||
Assert.assertFalse(s.isEmpty()); | |||
s.clear(); | |||
Assert.assertTrue(s.isEmpty()); | |||
} | |||
} |
@@ -0,0 +1,47 @@ | |||
/* | |||
* Copyright 2000-2014 Vaadin Ltd. | |||
* | |||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | |||
* use this file except in compliance with the License. You may obtain a copy of | |||
* the License at | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | |||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | |||
* License for the specific language governing permissions and limitations under | |||
* the License. | |||
*/ | |||
package com.vaadin.ui; | |||
import org.junit.Assert; | |||
import org.junit.Test; | |||
import com.vaadin.data.util.ObjectProperty; | |||
public class RichTextAreaTest { | |||
@Test | |||
public void initiallyEmpty() { | |||
RichTextArea tf = new RichTextArea(); | |||
Assert.assertTrue(tf.isEmpty()); | |||
} | |||
@Test | |||
public void emptyAfterClearUsingPDS() { | |||
RichTextArea tf = new RichTextArea(new ObjectProperty<String>("foo")); | |||
Assert.assertFalse(tf.isEmpty()); | |||
tf.clear(); | |||
Assert.assertTrue(tf.isEmpty()); | |||
} | |||
@Test | |||
public void emptyAfterClear() { | |||
RichTextArea tf = new RichTextArea(); | |||
tf.setValue("foobar"); | |||
Assert.assertFalse(tf.isEmpty()); | |||
tf.clear(); | |||
Assert.assertTrue(tf.isEmpty()); | |||
} | |||
} |
@@ -0,0 +1,47 @@ | |||
/* | |||
* Copyright 2000-2014 Vaadin Ltd. | |||
* | |||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | |||
* use this file except in compliance with the License. You may obtain a copy of | |||
* the License at | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | |||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | |||
* License for the specific language governing permissions and limitations under | |||
* the License. | |||
*/ | |||
package com.vaadin.ui; | |||
import org.junit.Assert; | |||
import org.junit.Test; | |||
import com.vaadin.data.util.ObjectProperty; | |||
public class TextAreaTest { | |||
@Test | |||
public void initiallyEmpty() { | |||
TextArea tf = new TextArea(); | |||
Assert.assertTrue(tf.isEmpty()); | |||
} | |||
@Test | |||
public void emptyAfterClearUsingPDS() { | |||
TextArea tf = new TextArea(new ObjectProperty<String>("foo")); | |||
Assert.assertFalse(tf.isEmpty()); | |||
tf.clear(); | |||
Assert.assertTrue(tf.isEmpty()); | |||
} | |||
@Test | |||
public void emptyAfterClear() { | |||
TextArea tf = new TextArea(); | |||
tf.setValue("foobar"); | |||
Assert.assertFalse(tf.isEmpty()); | |||
tf.clear(); | |||
Assert.assertTrue(tf.isEmpty()); | |||
} | |||
} |