Skip to content

Commit

Permalink
Improved RestSetup for non-gui environments
Browse files Browse the repository at this point in the history
  • Loading branch information
gastaldi committed Sep 20, 2013
1 parent ab23d7e commit 94c641a
Showing 1 changed file with 17 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public Metadata getMetadata(UIContext context)

@Inject
@WithAttributes(required = true, label = "JAX-RS Version")
private UISelectOne<RestFacet> versions;
private UISelectOne<RestFacet> version;

@Inject
@WithAttributes(required = true, label = "Configuration Strategy", type = InputType.RADIO)
Expand All @@ -76,7 +76,7 @@ public void initializeUI(UIBuilder builder) throws Exception
{
configureVersions();
configureActivationStrategy(builder.getUIContext());
builder.add(versions).add(applicationPath).add(config).add(packageName).add(className);
builder.add(version).add(applicationPath).add(config).add(packageName).add(className);
}

private void configureActivationStrategy(UIContext context)
Expand All @@ -90,14 +90,17 @@ public Boolean call() throws Exception
return RestActivatorType.APP_CLASS == config.getValue();
}
};
config.setItemLabelConverter(new Converter<RestActivatorType, String>()
if (context.getProvider().isGUI())
{
@Override
public String convert(RestActivatorType source)
config.setItemLabelConverter(new Converter<RestActivatorType, String>()
{
return source != null ? source.getDescription() : null;
}
});
@Override
public String convert(RestActivatorType source)
{
return source != null ? source.getDescription() : null;
}
});
}
packageName.setRequired(appClassChosen).setEnabled(appClassChosen);
className.setRequired(appClassChosen).setEnabled(appClassChosen);
Project project = getSelectedProject(context);
Expand All @@ -106,7 +109,7 @@ public String convert(RestActivatorType source)

private void configureVersions()
{
versions.setItemLabelConverter(new Converter<RestFacet, String>()
version.setItemLabelConverter(new Converter<RestFacet, String>()
{
@Override
public String convert(RestFacet source)
Expand All @@ -115,12 +118,12 @@ public String convert(RestFacet source)
}
});

for (RestFacet choice : versions.getValueChoices())
for (RestFacet choice : version.getValueChoices())
{
if (versions.getValue() == null
|| choice.getSpecVersion().compareTo(versions.getValue().getSpecVersion()) >= 1)
if (version.getValue() == null
|| choice.getSpecVersion().compareTo(version.getValue().getSpecVersion()) >= 1)
{
versions.setDefaultValue(choice);
version.setDefaultValue(choice);
}
}
}
Expand All @@ -134,7 +137,7 @@ public void validate(UIValidationContext validator)
@Override
public Result execute(final UIContext context) throws Exception
{
RestFacet facet = versions.getValue();
RestFacet facet = version.getValue();
if (facetFactory.install(getSelectedProject(context), facet))
{
String path = applicationPath.getValue();
Expand Down

0 comments on commit 94c641a

Please sign in to comment.