Skip to content

Commit

Permalink
FORGE-1052: HintsFacet is now installed when component is created using
Browse files Browse the repository at this point in the history
InputComponentFactory.createXXX
  • Loading branch information
gastaldi committed Jul 26, 2013
1 parent 687e9c2 commit c082340
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -157,25 +157,33 @@ public <T> UIInputMany<T> produceInputMany(InjectionPoint injectionPoint)
@Override
public <T> UIInput<T> createInput(String name, Class<T> valueType)
{
return new UIInputImpl<T>(name, valueType);
UIInputImpl<T> input = new UIInputImpl<T>(name, valueType);
configureRequiredFacets(input);
return input;
}

@Override
public <T> UIInputMany<T> createInputMany(String name, Class<T> valueType)
{
return new UIInputManyImpl<T>(name, valueType);
UIInputManyImpl<T> input = new UIInputManyImpl<T>(name, valueType);
configureRequiredFacets(input);
return input;
}

@Override
public <T> UISelectOne<T> createSelectOne(String name, Class<T> valueType)
{
return new UISelectOneImpl<T>(name, valueType);
UISelectOneImpl<T> input = new UISelectOneImpl<T>(name, valueType);
configureRequiredFacets(input);
return input;
}

@Override
public <T> UISelectMany<T> createSelectMany(String name, Class<T> valueType)
{
return new UISelectManyImpl<T>(name, valueType);
UISelectManyImpl<T> input = new UISelectManyImpl<T>(name, valueType);
configureRequiredFacets(input);
return input;
}

/**
Expand All @@ -184,8 +192,6 @@ public <T> UISelectMany<T> createSelectMany(String name, Class<T> valueType)
@SuppressWarnings({ "unchecked", "rawtypes" })
private void preconfigureInput(InputComponent<?, ?> input, WithAttributes atts)
{
HintsFacetImpl hintsFacet = new HintsFacetImpl(input, environment);
input.install(hintsFacet);
if (atts != null)
{
input.setEnabled(atts.enabled());
Expand Down Expand Up @@ -245,4 +251,10 @@ else if (Annotations.isAnnotationPresent(valueType, Exported.class))
selectComponent.setValueChoices(choices);
}
}

private void configureRequiredFacets(InputComponent<?, ?> input)
{
HintsFacetImpl hintsFacet = new HintsFacetImpl(input, environment);
input.install(hintsFacet);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.forge.addon.ui.InputComponentFactory;
import org.jboss.forge.addon.ui.facets.HintsFacet;
import org.jboss.forge.addon.ui.input.UIInput;
import org.jboss.forge.addon.ui.input.UIInputMany;
import org.jboss.forge.addon.ui.input.UISelectMany;
Expand Down Expand Up @@ -51,26 +52,30 @@ public void testCreateUIInput() throws Exception
{
UIInput<String> input = factory.createInput("foo", String.class);
Assert.assertNotNull(input);
Assert.assertTrue(input.hasFacet(HintsFacet.class));
}

@Test
public void testCreateUIInputMany() throws Exception
{
UIInputMany<String> input = factory.createInputMany("foo", String.class);
Assert.assertNotNull(input);
Assert.assertTrue(input.hasFacet(HintsFacet.class));
}

@Test
public void testCreateUISelectMany() throws Exception
{
UISelectMany<String> input = factory.createSelectMany("foo", String.class);
Assert.assertNotNull(input);
Assert.assertTrue(input.hasFacet(HintsFacet.class));
}

@Test
public void testCreateUISelectOne() throws Exception
{
UISelectOne<String> input = factory.createSelectOne("foo", String.class);
Assert.assertNotNull(input);
Assert.assertTrue(input.hasFacet(HintsFacet.class));
}
}

0 comments on commit c082340

Please sign in to comment.