Skip to content

Commit

Permalink
Refactored UIInput* hierarchy to support getValueType()
Browse files Browse the repository at this point in the history
  • Loading branch information
lincolnthree committed Feb 7, 2013
1 parent 1b8ec30 commit 19f8ece
Show file tree
Hide file tree
Showing 12 changed files with 193 additions and 64 deletions.
4 changes: 2 additions & 2 deletions ui/api/src/main/java/org/jboss/forge/ui/UICompleter.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* @param VALUETYPE The value type to be provided by completion.
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
*/
public interface UICompleter<T>
public interface UICompleter<VALUETYPE>
{
/**
* Get completion proposals for the provided {@link UIInput} and un-converted partial {@link String} value.
Expand All @@ -19,5 +19,5 @@ public interface UICompleter<T>
* @param value The user input value requiring completion, or null, if no value yet exists. These values will undergo
* conversion to fit the type required by the corresponding {@link UIInput}.
*/
Iterable<String> getCompletionProposals(UIInputComponent<?, T> input, String value);
Iterable<String> getCompletionProposals(UIInputComponent<?, VALUETYPE> input, String value);
}
10 changes: 10 additions & 0 deletions ui/api/src/main/java/org/jboss/forge/ui/UIInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,19 @@

package org.jboss.forge.ui;

import java.util.concurrent.Callable;

public interface UIInput<VALUETYPE> extends UIInputComponent<UIInput<VALUETYPE>, VALUETYPE>
{
UICompleter<VALUETYPE> getCompleter();

UIInput<VALUETYPE> setCompleter(UICompleter<VALUETYPE> completer);

VALUETYPE getValue();

UIInput<VALUETYPE> setDefaultValue(VALUETYPE value);

UIInput<VALUETYPE> setDefaultValue(Callable<VALUETYPE> callback);

UIInput<VALUETYPE> setValue(VALUETYPE value);
}
9 changes: 0 additions & 9 deletions ui/api/src/main/java/org/jboss/forge/ui/UIInputComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,16 @@
@Exported
public interface UIInputComponent<IMPLTYPE, VALUETYPE> extends Faceted
{

String getLabel();

String getName();

Class<VALUETYPE> getValueType();

VALUETYPE getValue();

boolean isEnabled();

boolean isRequired();

IMPLTYPE setDefaultValue(VALUETYPE value);

IMPLTYPE setDefaultValue(Callable<VALUETYPE> callback);

IMPLTYPE setEnabled(boolean b);

IMPLTYPE setEnabled(Callable<Boolean> callable);
Expand All @@ -43,6 +36,4 @@ public interface UIInputComponent<IMPLTYPE, VALUETYPE> extends Faceted
IMPLTYPE setRequired(boolean required);

IMPLTYPE setRequired(Callable<Boolean> required);

IMPLTYPE setValue(VALUETYPE value);
}
12 changes: 11 additions & 1 deletion ui/api/src/main/java/org/jboss/forge/ui/UIInputMany.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,19 @@

package org.jboss.forge.ui;

public interface UIInputMany<VALUETYPE> extends UIInputComponent<UIInputMany<VALUETYPE>, Iterable<VALUETYPE>>
import java.util.concurrent.Callable;

public interface UIInputMany<VALUETYPE> extends UIInputComponent<UIInputMany<VALUETYPE>, VALUETYPE>
{
UICompleter<VALUETYPE> getCompleter();

UIInputMany<VALUETYPE> setCompleter(UICompleter<VALUETYPE> completer);

Iterable<VALUETYPE> getValue();

UIInputMany<VALUETYPE> setDefaultValue(Iterable<VALUETYPE> value);

UIInputMany<VALUETYPE> setDefaultValue(Callable<Iterable<VALUETYPE>> callback);

UIInputMany<VALUETYPE> setValue(Iterable<VALUETYPE> value);
}
11 changes: 10 additions & 1 deletion ui/api/src/main/java/org/jboss/forge/ui/UISelectMany.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,19 @@
*/
package org.jboss.forge.ui;

import java.util.concurrent.Callable;

public interface UISelectMany<VALUETYPE> extends UIInputComponent<UISelectMany<VALUETYPE>, Iterable<VALUETYPE>>
public interface UISelectMany<VALUETYPE> extends UIInputComponent<UISelectMany<VALUETYPE>, VALUETYPE>
{
Iterable<VALUETYPE> getValueChoices();

UISelectMany<VALUETYPE> setValueChoices(Iterable<VALUETYPE> values);

Iterable<VALUETYPE> getValue();

UISelectMany<VALUETYPE> setDefaultValue(Iterable<VALUETYPE> value);

UISelectMany<VALUETYPE> setDefaultValue(Callable<Iterable<VALUETYPE>> callback);

UISelectMany<VALUETYPE> setValue(Iterable<VALUETYPE> value);
}
10 changes: 10 additions & 0 deletions ui/api/src/main/java/org/jboss/forge/ui/UISelectOne.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,19 @@
*/
package org.jboss.forge.ui;

import java.util.concurrent.Callable;

public interface UISelectOne<VALUETYPE> extends UIInputComponent<UISelectOne<VALUETYPE>, VALUETYPE>
{
Iterable<VALUETYPE> getValueChoices();

UISelectOne<VALUETYPE> setValueChoices(Iterable<VALUETYPE> values);

VALUETYPE getValue();

UISelectOne<VALUETYPE> setDefaultValue(VALUETYPE value);

UISelectOne<VALUETYPE> setDefaultValue(Callable<VALUETYPE> callback);

UISelectOne<VALUETYPE> setValue(VALUETYPE value);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
public class NoopCompleter implements UICompleter
{
@Override
public Iterable getCompletionProposals(UIInputComponent input, String value)
public Iterable<String> getCompletionProposals(UIInputComponent input, String value)
{
return Collections.emptyList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,17 @@ public abstract class UIInputComponentBase<IMPLTYPE extends UIInputComponent<IMP
implements UIInputComponent<IMPLTYPE, VALUETYPE>
{
private final String name;
private final Class<VALUETYPE> type;

private String label;
private Callable<Boolean> enabled;
private VALUETYPE value;
private Callable<Boolean> required;
private Callable<VALUETYPE> defaultValue;

@SuppressWarnings("unchecked")
public UIInputComponentBase(String name, Class<?> type)
private Class<VALUETYPE> type;

public UIInputComponentBase(String name, Class<VALUETYPE> type)
{
this.name = name;
this.type = (Class<VALUETYPE>) type;
this.type = type;
}

@Override
Expand All @@ -57,12 +55,6 @@ public String getName()
return name;
}

@Override
public VALUETYPE getValue()
{
return (value == null) ? Callables.call(defaultValue) : value;
}

@Override
public Class<VALUETYPE> getValueType()
{
Expand All @@ -81,22 +73,6 @@ public boolean isRequired()
return Callables.call(required);
}

@SuppressWarnings("unchecked")
@Override
public IMPLTYPE setDefaultValue(Callable<VALUETYPE> callback)
{
this.defaultValue = callback;
return (IMPLTYPE) this;
}

@SuppressWarnings("unchecked")
@Override
public IMPLTYPE setDefaultValue(VALUETYPE value)
{
this.defaultValue = Callables.returning(value);
return (IMPLTYPE) this;
}

@SuppressWarnings("unchecked")
@Override
public IMPLTYPE setEnabled(boolean enabled)
Expand Down Expand Up @@ -137,14 +113,6 @@ public IMPLTYPE setRequired(Callable<Boolean> required)
return (IMPLTYPE) this;
}

@SuppressWarnings("unchecked")
@Override
public IMPLTYPE setValue(VALUETYPE value)
{
this.value = value;
return (IMPLTYPE) this;
}

@Override
public boolean supports(Class<? extends Facet<?>> type)
{
Expand Down
35 changes: 34 additions & 1 deletion ui/impl/src/main/java/org/jboss/forge/ui/impl/UIInputImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@

package org.jboss.forge.ui.impl;

import java.util.concurrent.Callable;

import javax.enterprise.inject.Vetoed;

import org.jboss.forge.ui.UICompleter;
import org.jboss.forge.ui.UIInput;
import org.jboss.forge.ui.util.Callables;

/**
* Implementation of a {@link UIInput} object
Expand All @@ -23,7 +26,10 @@
public class UIInputImpl<VALUETYPE> extends UIInputComponentBase<UIInput<VALUETYPE>, VALUETYPE> implements
UIInput<VALUETYPE>
{
public UIInputImpl(String name, Class<?> type)
private VALUETYPE value;
private Callable<VALUETYPE> defaultValue;

public UIInputImpl(String name, Class<VALUETYPE> type)
{
super(name, type);
}
Expand All @@ -43,4 +49,31 @@ public UIInput<VALUETYPE> setCompleter(UICompleter<VALUETYPE> completer)
this.completer = completer;
return this;
}

@Override
public UIInput<VALUETYPE> setValue(VALUETYPE value)
{
this.value = value;
return this;
}

@Override
public UIInput<VALUETYPE> setDefaultValue(Callable<VALUETYPE> callback)
{
this.defaultValue = callback;
return this;
}

@Override
public UIInput<VALUETYPE> setDefaultValue(VALUETYPE value)
{
this.defaultValue = Callables.returning(value);
return this;
}

@Override
public VALUETYPE getValue()
{
return (value == null) ? Callables.call(defaultValue) : value;
}
}
38 changes: 36 additions & 2 deletions ui/impl/src/main/java/org/jboss/forge/ui/impl/UIInputManyImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@

package org.jboss.forge.ui.impl;

import java.util.concurrent.Callable;

import javax.enterprise.inject.Vetoed;

import org.jboss.forge.ui.UICompleter;
import org.jboss.forge.ui.UIInput;
import org.jboss.forge.ui.UIInputMany;
import org.jboss.forge.ui.util.Callables;

/**
* Implementation of a {@link UIInput} object
Expand All @@ -21,10 +24,13 @@
* @param <VALUETYPE>
*/
@Vetoed
public class UIInputManyImpl<VALUETYPE> extends UIInputComponentBase<UIInputMany<VALUETYPE>, Iterable<VALUETYPE>>
public class UIInputManyImpl<VALUETYPE> extends UIInputComponentBase<UIInputMany<VALUETYPE>, VALUETYPE>
implements UIInputMany<VALUETYPE>
{
public UIInputManyImpl(String name, Class<?> type)
private Iterable<VALUETYPE> value;
private Callable<Iterable<VALUETYPE>> defaultValue;

public UIInputManyImpl(String name, Class<VALUETYPE> type)
{
super(name, type);
}
Expand All @@ -44,4 +50,32 @@ public UIInputMany<VALUETYPE> setCompleter(UICompleter<VALUETYPE> completer)
this.completer = completer;
return this;
}

@Override
public UIInputMany<VALUETYPE> setValue(Iterable<VALUETYPE> value)
{
this.value = value;
return this;
}

@Override
public UIInputMany<VALUETYPE> setDefaultValue(Callable<Iterable<VALUETYPE>> callback)
{
this.defaultValue = callback;
return this;
}

@Override
public UIInputMany<VALUETYPE> setDefaultValue(Iterable<VALUETYPE> value)
{
this.defaultValue = Callables.returning(value);
return this;
}

@Override
public Iterable<VALUETYPE> getValue()
{
return (value == null) ? Callables.call(defaultValue) : value;
}

}
Loading

0 comments on commit 19f8ece

Please sign in to comment.