Skip to content

Commit

Permalink
FORGE-2247: Introduced InputComponent.set/getNote
Browse files Browse the repository at this point in the history
  • Loading branch information
gastaldi committed Feb 18, 2015
1 parent 5e6aa35 commit 6a90202
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,25 @@ public interface InputComponent<IMPLTYPE, VALUETYPE> extends MutableFaceted<Hint
* @param validator the {@link UIValidationContext} object that holds validation errors
*/
void validate(UIValidationContext context);

/**
* A note is a description about the value of this input. in a GUI environment, it is displayed below the input.
*
* @param note to be displayed below the input in GUIs
*/
IMPLTYPE setNote(String note);

/**
* A note is a description about the value of this input. in a GUI environment, it is displayed below the input.
*
* @param note to be displayed below the input in GUIs
*/
IMPLTYPE setNote(Callable<String> note);

/**
* A note is a description about the value of this input. in a GUI environment, it is displayed below the input.
*
* @return the note to be displayed below the input in GUIs
*/
String getNote();
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public abstract class AbstractInputComponent<IMPLTYPE extends InputComponent<IMP

private String label;
private Callable<String> description;
private Callable<String> note;
private Callable<Boolean> enabled = Callables.returning(Boolean.TRUE);
private Callable<Boolean> required = Callables.returning(Boolean.FALSE);
private Callable<String> requiredMessage;
Expand Down Expand Up @@ -131,7 +132,7 @@ public IMPLTYPE setDescription(String description)
this.description = Callables.returning(description);
return (IMPLTYPE) this;
}

@Override
public IMPLTYPE setDescription(Callable<String> description)
{
Expand Down Expand Up @@ -171,7 +172,7 @@ public IMPLTYPE setRequiredMessage(String requiredMessage)
this.requiredMessage = Callables.returning(requiredMessage);
return (IMPLTYPE) this;
}

@Override
public IMPLTYPE setRequiredMessage(Callable<String> requiredMessage)
{
Expand Down Expand Up @@ -239,6 +240,26 @@ public ValueChangeListener removeListener()
};
}

@Override
public IMPLTYPE setNote(Callable<String> note)
{
this.note = note;
return (IMPLTYPE) this;
}

@Override
public IMPLTYPE setNote(String note)
{
this.note = Callables.returning(note);
return (IMPLTYPE) this;
}

@Override
public String getNote()
{
return Callables.call(note);
}

protected Set<ValueChangeListener> getValueChangeListeners()
{
return valueChangeListeners;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import java.util.Arrays;
import java.util.Iterator;
import java.util.concurrent.Callable;

import javax.inject.Inject;

Expand Down Expand Up @@ -267,4 +268,23 @@ public void testNotNullValuesForUISelectComponents()
Assert.assertFalse(unknown.getValue().iterator().hasNext());
}

@Test
public void testNote()
{
// FORGE-2247
Assert.assertNull(firstName.getNote());
firstName.setNote("A Note From String Signature");
Assert.assertEquals("A Note From String Signature", firstName.getNote());
firstName.setNote((String) null);
Assert.assertNull(firstName.getNote());
firstName.setNote(new Callable<String>()
{
@Override
public String call() throws Exception
{
return "A Note from Callable Signature";
}
});
Assert.assertEquals("A Note from Callable Signature", firstName.getNote());
}
}

0 comments on commit 6a90202

Please sign in to comment.