Skip to content

Commit

Permalink
Revert "Merged UIInput and UIInputImpl"
Browse files Browse the repository at this point in the history
This reverts commit fbb876b.
  • Loading branch information
lincolnthree committed Jan 11, 2013
1 parent 0c4d26f commit 1597619
Show file tree
Hide file tree
Showing 3 changed files with 165 additions and 97 deletions.
122 changes: 28 additions & 94 deletions ui/api/src/main/java/org/jboss/forge/ui/UIInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,102 +10,36 @@
import java.util.concurrent.Callable;

import org.jboss.forge.container.services.Remote;
import org.jboss.forge.ui.util.Callables;

@Remote
public class UIInput<T>
public interface UIInput<T>
{
private final String name;
private final Class<T> type;

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

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

public String getLabel()
{
return label;
}

public String getName()
{
return name;
}

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

public Class<T> getValueType()
{
return type;
}

public boolean isEnabled()
{
return Callables.call(enabled);
}

public boolean isRequired()
{
return Callables.call(required);
}

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

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

public UIInput<T> setEnabled(boolean enabled)
{
this.enabled = Callables.returning(enabled);
return this;
}

public UIInput<T> setEnabled(Callable<Boolean> callback)
{
enabled = callback;
return this;
}

public UIInput<T> setLabel(String label)
{
this.label = label;
return this;
}

public UIInput<T> setRequired(boolean required)
{
this.required = Callables.returning(required);
return this;
}

public UIInput<T> setRequired(Callable<Boolean> required)
{
this.required = required;
return this;
}

public UIInput<T> setValue(T value)
{
this.value = value;
return this;
}
String getLabel();

String getName();

Class<T> getValueType();

T getValue();

boolean isEnabled();

boolean isRequired();

UIInput<T> setDefaultValue(T value);

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

UIInput<T> setEnabled(boolean b);

UIInput<T> setEnabled(Callable<Boolean> callable);

UIInput<T> setLabel(String label);

UIInput<T> setRequired(boolean required);

UIInput<T> setRequired(Callable<Boolean> required);

UIInput<T> setValue(T value);

}
134 changes: 134 additions & 0 deletions ui/impl/src/main/java/org/jboss/forge/ui/impl/UIInputImpl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
/*
* Copyright 2012 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Eclipse Public License version 1.0, available at
* http://www.eclipse.org/legal/epl-v10.html
*/

package org.jboss.forge.ui.impl;

import java.util.concurrent.Callable;

import javax.enterprise.inject.Typed;

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

/**
* Implementation of a {@link UIInput} object
*
* @author <a href="mailto:ggastald@redhat.com">George Gastaldi</a>
*
* @param <T>
*/
@Typed()
public class UIInputImpl<T> implements UIInput<T>
{
private final String name;
private final Class<T> type;

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

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

@Override
public String getLabel()
{
return label;
}

@Override
public String getName()
{
return name;
}

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

@Override
public Class<T> getValueType()
{
return type;
}

@Override
public boolean isEnabled()
{
return Callables.call(enabled);
}

@Override
public boolean isRequired()
{
return Callables.call(required);
}

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

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

@Override
public UIInput<T> setEnabled(boolean enabled)
{
this.enabled = Callables.returning(enabled);
return this;
}

@Override
public UIInput<T> setEnabled(Callable<Boolean> callback)
{
enabled = callback;
return this;
}

@Override
public UIInput<T> setLabel(String label)
{
this.label = label;
return this;
}

@Override
public UIInput<T> setRequired(boolean required)
{
this.required = Callables.returning(required);
return this;
}

@Override
public UIInput<T> setRequired(Callable<Boolean> required)
{
this.required = required;
return this;
}

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

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

/**
* Produces UIInput objects
*
*
* @author <a href="mailto:ggastald@redhat.com">George Gastaldi</a>
*
*
*/
public class UIInputProducer
{
Expand All @@ -29,6 +29,6 @@ public <T> UIInput<T> produceInput(InjectionPoint injectionPoint)
String name = injectionPoint.getMember().getName();
ParameterizedType ptype = (ParameterizedType) injectionPoint.getType();
Class<T> c = (Class<T>) ptype.getActualTypeArguments()[0];
return new UIInput<T>(name, c);
return new UIInputImpl<T>(name, c);
}
}

0 comments on commit 1597619

Please sign in to comment.