Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
309 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.jboss.forge</groupId> | ||
<artifactId>ui-parent</artifactId> | ||
<version>2.0.0-SNAPSHOT</version> | ||
</parent> | ||
<artifactId>ui-impl</artifactId> | ||
<name>Forge - UI Impl</name> | ||
<dependencies> | ||
<dependency> | ||
<groupId>javax.enterprise</groupId> | ||
<artifactId>cdi-api</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jboss.forge</groupId> | ||
<artifactId>ui-api</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jboss.forge</groupId> | ||
<artifactId>forge-test-harness</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jboss.forge</groupId> | ||
<artifactId>arquillian-forge-classpath</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
85 changes: 85 additions & 0 deletions
85
ui/impl/src/main/java/org/jboss/forge/ui/impl/Callables.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* 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; | ||
|
||
/** | ||
* Utilities to handle {@link Callable} objects | ||
* | ||
* @author <a href="mailto:ggastald@redhat.com">George Gastaldi</a> | ||
* | ||
*/ | ||
|
||
public final class Callables | ||
{ | ||
private Callables() | ||
{ | ||
} | ||
|
||
/** | ||
* Wrap a constant value into a Callable Object | ||
* | ||
* @param value | ||
* @return | ||
*/ | ||
public static <T> Callable<T> constant(T value) | ||
{ | ||
return new ConstantCallable<T>(value); | ||
} | ||
|
||
/** | ||
* Calls the {@link Callable} avoiding the checked exception | ||
* | ||
* @param c | ||
* @return | ||
*/ | ||
public static <T> T call(Callable<T> c) | ||
{ | ||
if (c == null) | ||
{ | ||
return null; | ||
} | ||
try | ||
{ | ||
return c.call(); | ||
} | ||
catch (RuntimeException re) | ||
{ | ||
throw re; | ||
} | ||
catch (Exception e) | ||
{ | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
/** | ||
* Simple callable class that returns the same value | ||
* | ||
* @author <a href="mailto:ggastald@redhat.com">George Gastaldi</a> | ||
* | ||
* @param <V> | ||
*/ | ||
static class ConstantCallable<V> implements Callable<V> | ||
{ | ||
private final V value; | ||
|
||
public ConstantCallable(V value) | ||
{ | ||
this.value = value; | ||
} | ||
|
||
@Override | ||
public V call() | ||
{ | ||
return value; | ||
} | ||
} | ||
|
||
} |
95 changes: 95 additions & 0 deletions
95
ui/impl/src/main/java/org/jboss/forge/ui/impl/UIInputImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/* | ||
* 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 org.jboss.forge.ui.UIInput; | ||
|
||
/** | ||
* Implementation of a {@link UIInput} object | ||
* | ||
* @author <a href="mailto:ggastald@redhat.com">George Gastaldi</a> | ||
* | ||
* @param <T> | ||
*/ | ||
public class UIInputImpl<T> implements UIInput<T> | ||
{ | ||
private final String name; | ||
private final Class<T> type; | ||
|
||
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 getName() | ||
{ | ||
return name; | ||
} | ||
|
||
@Override | ||
public Class<T> getType() | ||
{ | ||
return type; | ||
} | ||
|
||
@Override | ||
public T getValue() | ||
{ | ||
return (value == null) ? Callables.call(defaultValue) : value; | ||
} | ||
|
||
@Override | ||
public boolean isRequired() | ||
{ | ||
return Callables.call(required); | ||
} | ||
|
||
@Override | ||
public UIInput<T> setDefaultValue(T value) | ||
{ | ||
this.defaultValue = Callables.constant(value); | ||
return this; | ||
} | ||
|
||
@Override | ||
public UIInput<T> setDefaultValue(Callable<T> callback) | ||
{ | ||
this.defaultValue = callback; | ||
return this; | ||
} | ||
|
||
@Override | ||
public UIInput<T> setRequired(boolean required) | ||
{ | ||
this.required = Callables.constant(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; | ||
} | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
ui/impl/src/main/java/org/jboss/forge/ui/impl/UIInputProducer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* 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.lang.reflect.ParameterizedType; | ||
|
||
import javax.enterprise.inject.Produces; | ||
import javax.enterprise.inject.spi.InjectionPoint; | ||
|
||
import org.jboss.forge.ui.UIInput; | ||
|
||
/** | ||
* Produces UIInput objects | ||
* | ||
* @author <a href="mailto:ggastald@redhat.com">George Gastaldi</a> | ||
* | ||
*/ | ||
public class UIInputProducer | ||
{ | ||
@SuppressWarnings("unchecked") | ||
@Produces | ||
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 UIInputImpl<T>(name, c); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<?xml version="1.0"?> | ||
<beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://jboss.org/schema/cdi/beans_1_0.xsd" /> |
57 changes: 57 additions & 0 deletions
57
ui/impl/src/test/java/org/jboss/forge/ui/impl/UIInputInjectionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* 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 javax.inject.Inject; | ||
|
||
import org.jboss.arquillian.container.test.api.Deployment; | ||
import org.jboss.arquillian.junit.Arquillian; | ||
import org.jboss.forge.arquillian.Addon; | ||
import org.jboss.forge.arquillian.Dependencies; | ||
import org.jboss.forge.arquillian.archive.ForgeArchive; | ||
import org.jboss.forge.ui.UI; | ||
import org.jboss.forge.ui.UIInput; | ||
import org.jboss.shrinkwrap.api.ArchivePaths; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.asset.EmptyAsset; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
@RunWith(Arquillian.class) | ||
public class UIInputInjectionTest | ||
{ | ||
@Deployment | ||
@Dependencies(@Addon(name = "org.jboss.forge:facets", version = "2.0.0-SNAPSHOT")) | ||
public static ForgeArchive getDeployment() | ||
{ | ||
ForgeArchive archive = ShrinkWrap | ||
.create(ForgeArchive.class) | ||
.addPackages(true, UI.class.getPackage()) | ||
.addAsManifestResource(EmptyAsset.INSTANCE, ArchivePaths.create("beans.xml")); | ||
|
||
System.out.println(archive); | ||
return archive; | ||
} | ||
|
||
@Inject | ||
UIInput<String> firstName; | ||
|
||
@Test | ||
public void testInjectionNotNull() | ||
{ | ||
Assert.assertNotNull(firstName); | ||
} | ||
|
||
@Test | ||
public void testInputValues() | ||
{ | ||
Assert.assertEquals("firstName", firstName.getName()); | ||
Assert.assertEquals(String.class, firstName.getType()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters