Skip to content

Commit

Permalink
HintsLookup is functional and used when producing UIInput instances.
Browse files Browse the repository at this point in the history
  • Loading branch information
lincolnthree committed Jan 24, 2013
1 parent 9e0f438 commit 2d6d2e1
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 30 deletions.
45 changes: 21 additions & 24 deletions ui-hints/src/main/java/org/jboss/forge/ui/hints/HintsLookup.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,30 @@
*/
package org.jboss.forge.ui.hints;

import org.jboss.forge.environment.Category;
import org.jboss.forge.environment.Environment;

/**
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
* Look up UI Hints. This allows manipulation of default UI type to render for a given input value type.
*
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
*/
public class HintsLookup
public class HintsLookup implements Category
{
// private static String INPUT_TYPE_MAP_KEY = HintsLookup.class.getName() + "_INPUT_TYPE_MAP_KEY";
//
// public static InputType getInputType(Environment environment, Class<?> valueType)
// {
// return getCategoryMap(environment, INPUT_TYPE_MAP_KEY).get(valueType);
// }
//
// public static void setInputType(Environment environment, Class<?> valueType, InputType type)
// {
// return getCategoryMap(environment, INPUT_TYPE_MAP_KEY).set(valueType, hint);
// }
//
// private static Map<?, ?> getCategoryMap(Environment environment, String mapKey)
// {
// Map<?, ?> map = environment.get(mapKey);
// if (map == null)
// {
// map = new HashMap<Object, Object>();
// environment.set(mapKey, map);
// }
// return map;
// }
private final Environment environment;

public HintsLookup(Environment environment)
{
this.environment = environment;
}

public InputType getInputType(Class<?> valueType)
{
return (InputType) environment.get(HintsLookup.class).get(valueType);
}

public void setInputType(Class<?> valueType, InputType type)
{
environment.get(HintsLookup.class).put(valueType, type);
}
}
1 change: 0 additions & 1 deletion ui/addon/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
<artifactId>ui-hints</artifactId>
<version>2.0.0-SNAPSHOT</version>
<classifier>forge-addon</classifier>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
Expand Down
9 changes: 9 additions & 0 deletions ui/impl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@
<groupId>org.jboss.forge</groupId>
<artifactId>ui-api</artifactId>
</dependency>

<dependency>
<groupId>org.jboss.forge</groupId>
<artifactId>ui-hints</artifactId>
<version>2.0.0-SNAPSHOT</version>
<classifier>forge-addon</classifier>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.jboss.forge</groupId>
<artifactId>forge-test-harness</artifactId>
Expand Down
22 changes: 17 additions & 5 deletions ui/impl/src/main/java/org/jboss/forge/ui/impl/UIInputProducer.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,40 @@

import javax.enterprise.inject.Produces;
import javax.enterprise.inject.spi.InjectionPoint;
import javax.inject.Inject;

import org.jboss.forge.environment.Environment;
import org.jboss.forge.ui.UIInput;
import org.jboss.forge.ui.hints.HintsLookup;
import org.jboss.forge.ui.hints.InputType;

/**
* Produces UIInput objects
*
*
* @author <a href="mailto:ggastald@redhat.com">George Gastaldi</a>
*
*
*/
public class UIInputProducer
{
@SuppressWarnings("unchecked")
@Inject
private Environment environment;

@Produces
@SuppressWarnings("unchecked")
public <T> UIInput<T> produceInput(InjectionPoint injectionPoint)
{
String name = injectionPoint.getMember().getName();
Type type = injectionPoint.getAnnotated().getTypeClosure().iterator().next();
if (type instanceof ParameterizedType)
{
Type[] typeArguments = ((ParameterizedType) type).getActualTypeArguments();
Class<T> target = (Class<T>) typeArguments[0];
return new UIInputImpl<T>(name, target);
Class<T> valueType = (Class<T>) typeArguments[0];
UIInputImpl<T> input = new UIInputImpl<T>(name, valueType);

HintsLookup hints = new HintsLookup(environment);
input.getMetadata().set(InputType.class, hints.getInputType(valueType));

return input;
}
else
{
Expand Down

0 comments on commit 2d6d2e1

Please sign in to comment.