Skip to content

Commit

Permalink
Added defaultValue() to @WithAttributes
Browse files Browse the repository at this point in the history
  • Loading branch information
gastaldi committed Jun 12, 2013
1 parent f5610cc commit b328428
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class NewFieldRelationshipWizardStep extends AbstractProjectUICommand imp
private UIInput<String> inverseFieldName;

@Inject
@WithAttributes(label = "Required", description = "Is this field required ?")
@WithAttributes(label = "Required", description = "Is this field required ?", defaultValue = "false")
private UIInput<Boolean> required;

@Inject
Expand All @@ -58,7 +58,6 @@ public void initializeUI(UIBuilder builder) throws Exception
UIContext context = builder.getUIContext();
RelationshipType relationship = RelationshipType.valueOf(context.getAttribute(RelationshipType.class).toString());
cascadeType.setValueChoices(EnumSet.range(CascadeType.PERSIST, CascadeType.DETACH));
required.setDefaultValue(Boolean.FALSE);
switch (relationship)
{
case MANY_TO_MANY:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ public class NewFieldWizard extends AbstractProjectUICommand implements UIWizard
private UISelectOne<RelationshipType> relationshipType;

@Inject
@WithAttributes(label = "Use Primitive Version?", description = "For this field type, use the primitive version")
@WithAttributes(label = "Use Primitive Version?", description = "For this field type, use the primitive version", defaultValue = "false")
private UIInput<Boolean> primitive;

@Inject
@WithAttributes(label = "Is LOB?", description = "If the relationship is a LOB, in this case, it will ignore the value in the Type field")
@WithAttributes(label = "Is LOB?", description = "If the relationship is a LOB, in this case, it will ignore the value in the Type field", defaultValue = "false")
private UIInput<Boolean> lob;

@Inject
Expand All @@ -84,8 +84,6 @@ public void initializeUI(UIBuilder builder) throws Exception
Project project = getSelectedProject(builder.getUIContext());
setupEntities(project);
setupRelationshipType();
lob.setDefaultValue(Boolean.FALSE);
primitive.setDefaultValue(Boolean.FALSE);
lob.setEnabled(new Callable<Boolean>()
{
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,9 @@
* The InputType for this {@link InputComponent}
*/
InputType type() default InputType.DEFAULT;

/**
* The default value for this {@link InputComponent}
*/
String defaultValue() default "";
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import javax.enterprise.inject.spi.InjectionPoint;
import javax.inject.Inject;

import org.jboss.forge.addon.convert.ConverterFactory;
import org.jboss.forge.addon.environment.Environment;
import org.jboss.forge.addon.ui.facets.HintsFacet;
import org.jboss.forge.addon.ui.hints.InputType;
Expand All @@ -28,6 +29,7 @@
import org.jboss.forge.addon.ui.input.UISelectMany;
import org.jboss.forge.addon.ui.input.UISelectOne;
import org.jboss.forge.addon.ui.metadata.WithAttributes;
import org.jboss.forge.addon.ui.util.InputComponents;
import org.jboss.forge.furnace.addons.AddonRegistry;
import org.jboss.forge.furnace.services.Exported;
import org.jboss.forge.furnace.services.ExportedInstance;
Expand Down Expand Up @@ -192,10 +194,29 @@ private void preconfigureInput(InputComponent<?, ?> input, WithAttributes atts)
input.setRequired(atts.required());
input.setRequiredMessage(atts.requiredMessage());
input.setDescription(atts.description());

// Set input type
if (atts.type() != InputType.DEFAULT)
{
input.getFacet(HintsFacet.class).setInputType(atts.type());
}

// Set Default Value
if (!"".equals(atts.defaultValue()))
{
ExportedInstance<ConverterFactory> exportedInstance = addonRegistry
.getExportedInstance(ConverterFactory.class);
ConverterFactory converterFactory = exportedInstance.get();
try
{
InputComponents.setValueFor(converterFactory, (InputComponent<?, Object>) input, atts.defaultValue());
}
finally
{
exportedInstance.release(converterFactory);
}

}
}

if (input instanceof SelectComponent)
Expand Down Expand Up @@ -224,5 +245,4 @@ else if (Annotations.isAnnotationPresent(valueType, Exported.class))
selectComponent.setValueChoices(choices);
}
}

}

0 comments on commit b328428

Please sign in to comment.