Skip to content

Commit

Permalink
UIInput/SelectOne/SelectMany functional
Browse files Browse the repository at this point in the history
  • Loading branch information
lincolnthree committed Feb 5, 2013
1 parent ac1fad5 commit aec8260
Show file tree
Hide file tree
Showing 12 changed files with 380 additions and 67 deletions.
38 changes: 1 addition & 37 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,44 +7,8 @@

package org.jboss.forge.ui;

import java.util.concurrent.Callable;

import org.jboss.forge.container.services.Exported;
import org.jboss.forge.facets.Faceted;

@Exported
public interface UIInput<T> extends Faceted
public interface UIInput<VALUETYPE> extends UIInputComponent<UIInput<VALUETYPE>, VALUETYPE>
{
UICompleter<T> getCompleter();

String getLabel();

String getName();

Class<T> getValueType();

T getValue();

boolean isEnabled();

boolean isRequired();

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

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);

}
51 changes: 51 additions & 0 deletions ui/api/src/main/java/org/jboss/forge/ui/UIInputComponent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* 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;

import java.util.concurrent.Callable;

import org.jboss.forge.container.services.Exported;
import org.jboss.forge.facets.Faceted;

/**
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
*/
@Exported
public interface UIInputComponent<IMPLTYPE, VALUETYPE> extends Faceted
{
UICompleter<VALUETYPE> getCompleter();

String getLabel();

String getName();

Class<VALUETYPE> getValueType();

VALUETYPE getValue();

boolean isEnabled();

boolean isRequired();

IMPLTYPE setCompleter(UICompleter<VALUETYPE> completer);

IMPLTYPE setDefaultValue(VALUETYPE value);

IMPLTYPE setDefaultValue(Callable<VALUETYPE> callback);

IMPLTYPE setEnabled(boolean b);

IMPLTYPE setEnabled(Callable<Boolean> callable);

IMPLTYPE setLabel(String label);

IMPLTYPE setRequired(boolean required);

IMPLTYPE setRequired(Callable<Boolean> required);

IMPLTYPE setValue(VALUETYPE value);
}
7 changes: 3 additions & 4 deletions ui/api/src/main/java/org/jboss/forge/ui/UISelectMany.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
*/
package org.jboss.forge.ui;

import java.util.Set;

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

UISelectMany<T> setValueChoices(Set<T> values);
UISelectMany<VALUETYPE> setValueChoices(Iterable<VALUETYPE> values);
}
6 changes: 3 additions & 3 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,9 @@
*/
package org.jboss.forge.ui;

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

UISelectOne<T> setValueChoices(Iterable<T> values);
UISelectOne<VALUETYPE> setValueChoices(Iterable<VALUETYPE> values);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@

import org.jboss.forge.facets.Facet;
import org.jboss.forge.ui.UIInput;
import org.jboss.forge.ui.UIInputComponent;
import org.jboss.forge.ui.hints.InputType;

/**
* Hints facet
*
*
* @author <a href="mailto:ggastald@redhat.com">George Gastaldi</a>
*
*
*/
public interface HintsFacet extends Facet<UIInput<?>>
public interface HintsFacet extends Facet<UIInputComponent<?, ?>>
{
public abstract InputType getInputType();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
/*
* 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.Vetoed;

import org.jboss.forge.facets.BaseFaceted;
import org.jboss.forge.facets.Facet;
import org.jboss.forge.ui.UICompleter;
import org.jboss.forge.ui.UIInput;
import org.jboss.forge.ui.UIInputComponent;
import org.jboss.forge.ui.facets.HintsFacet;
import org.jboss.forge.ui.util.Callables;

/**
* Implementation of a {@link UIInput} object
*
* @author <a href="mailto:ggastald@redhat.com">George Gastaldi</a>
*
* @param <VALUETYPE>
*/
@Vetoed
public abstract class UIInputComponentBase<IMPLTYPE extends UIInputComponent<IMPLTYPE, VALUETYPE>, VALUETYPE> extends BaseFaceted
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;
private UICompleter<VALUETYPE> completer;

@SuppressWarnings("unchecked")
public UIInputComponentBase(String name, Class<?> type)
{
this.name = name;
this.type = (Class<VALUETYPE>) type;
}

@Override
@SuppressWarnings("unchecked")
public UICompleter<VALUETYPE> getCompleter()
{
return this.completer == null ? new NoopCompleter() : this.completer;
}

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

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

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

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

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

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

@SuppressWarnings("unchecked")
@Override
public IMPLTYPE setCompleter(UICompleter<VALUETYPE> completer)
{
this.completer = completer;
return (IMPLTYPE) this;
}

@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)
{
this.enabled = Callables.returning(enabled);
return (IMPLTYPE) this;
}

@SuppressWarnings("unchecked")
@Override
public IMPLTYPE setEnabled(Callable<Boolean> callback)
{
enabled = callback;
return (IMPLTYPE) this;
}

@SuppressWarnings("unchecked")
@Override
public IMPLTYPE setLabel(String label)
{
this.label = label;
return (IMPLTYPE) this;
}

@SuppressWarnings("unchecked")
@Override
public IMPLTYPE setRequired(boolean required)
{
this.required = Callables.returning(required);
return (IMPLTYPE) this;
}

@SuppressWarnings("unchecked")
@Override
public IMPLTYPE setRequired(Callable<Boolean> required)
{
this.required = 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)
{
return HintsFacet.class.isAssignableFrom(type);
}

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

/**
* Implementation of a {@link UIInput} object
*
*
* @author <a href="mailto:ggastald@redhat.com">George Gastaldi</a>
*
*
* @param <T>
*/
@Vetoed
Expand All @@ -38,10 +38,11 @@ public class UIInputImpl<T> extends BaseFaceted implements UIInput<T>
private Callable<T> defaultValue;
private UICompleter<T> completer;

public UIInputImpl(String name, Class<T> type)
@SuppressWarnings("unchecked")
public UIInputImpl(String name, Class<?> type)
{
this.name = name;
this.type = type;
this.type = (Class<T>) type;
}

@Override
Expand Down
Loading

0 comments on commit aec8260

Please sign in to comment.