Skip to content

Commit

Permalink
Moved Autocomplete with spaces example to FooCommand
Browse files Browse the repository at this point in the history
  • Loading branch information
gastaldi committed Aug 26, 2013
1 parent cc91dc2 commit bac6873
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package org.jboss.forge.addon.shell.mock.command;

import java.util.ArrayList;
import java.util.Arrays;

import javax.inject.Inject;

Expand All @@ -18,6 +19,7 @@
import org.jboss.forge.addon.ui.input.InputComponent;
import org.jboss.forge.addon.ui.input.UICompleter;
import org.jboss.forge.addon.ui.input.UIInput;
import org.jboss.forge.addon.ui.input.UISelectOne;
import org.jboss.forge.addon.ui.metadata.UICommandMetadata;
import org.jboss.forge.addon.ui.metadata.WithAttributes;
import org.jboss.forge.addon.ui.result.Result;
Expand Down Expand Up @@ -54,6 +56,9 @@ public class FooCommand implements UICommand
@Inject
@WithAttributes(label = "target location")
private UIInput<DirectoryResource> targetLocation;

@Inject
private UISelectOne<String> valueWithSpaces;

@Override
public UICommandMetadata getMetadata()
Expand All @@ -70,6 +75,7 @@ public boolean isEnabled(UIContext context)
@Override
public void initializeUI(UIBuilder builder) throws Exception
{
valueWithSpaces.setValueChoices(Arrays.asList("Value 1", "Value 2", "Value 10", "Value 100"));
help.setCompleter(new UICompleter<String>()
{
@Override
Expand All @@ -86,7 +92,7 @@ public Iterable<String> getCompletionProposals(UIContext context, InputComponent
}
});

builder.add(name).add(help).add(bool).add(bar).add(bar2).add(targetLocation);
builder.add(name).add(help).add(bool).add(bar).add(bar2).add(targetLocation).add(valueWithSpaces);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
*/
package org.jboss.forge.addon.shell.mock.wizard;

import java.util.Arrays;

import javax.inject.Inject;

import org.jboss.forge.addon.resource.Resource;
Expand All @@ -18,7 +16,6 @@
import org.jboss.forge.addon.ui.context.UIValidationContext;
import org.jboss.forge.addon.ui.input.UIInput;
import org.jboss.forge.addon.ui.input.UIInputMany;
import org.jboss.forge.addon.ui.input.UISelectOne;
import org.jboss.forge.addon.ui.metadata.WithAttributes;
import org.jboss.forge.addon.ui.result.Result;
import org.jboss.forge.addon.ui.result.Results;
Expand All @@ -41,9 +38,6 @@ public class MockCommand extends AbstractUICommand implements UICommand
@SuppressWarnings("rawtypes")
private UIInputMany<Resource> values;

@Inject
private UISelectOne<String> valueWithSpaces;

@Override
public Metadata getMetadata()
{
Expand All @@ -53,8 +47,7 @@ public Metadata getMetadata()
@Override
public void initializeUI(UIBuilder builder) throws Exception
{
valueWithSpaces.setValueChoices(Arrays.asList("Value 1", "Value 2", "Value 10", "Value 100"));
builder.add(key).add(values).add(proceed).add(valueWithSpaces);
builder.add(key).add(values).add(proceed);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,11 @@ public void testQuotes() throws Exception
@Test
public void testValuesWithSpaceCompletion() throws Exception
{
test.waitForCompletion("mock-command --valueWithSpaces \"Value 2\" ", "mock-command --valueWithSpaces Value 2",
5, TimeUnit.SECONDS);
test.waitForCompletion("foocommand --valueWithSpaces \"Value 2\" ", "foocommand --valueWithSpaces Value",
5, TimeUnit.MINUTES);

test.waitForCompletion("mock-command --valueWithSpaces \"Value 1\" ", "mock-command --valueWithSpaces Value 1",
5, TimeUnit.SECONDS);
test.waitForCompletion("foocommand --valueWithSpaces \"Value 1\" ", "foocommand --valueWithSpaces Value",
5, TimeUnit.MINUTES);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
*/
package org.jboss.forge.addon.ui.example.wizards;

import java.util.Arrays;

import javax.inject.Inject;

import org.jboss.forge.addon.resource.DirectoryResource;
Expand All @@ -14,6 +16,7 @@
import org.jboss.forge.addon.ui.context.UIContext;
import org.jboss.forge.addon.ui.context.UIValidationContext;
import org.jboss.forge.addon.ui.input.UIInput;
import org.jboss.forge.addon.ui.input.UISelectOne;
import org.jboss.forge.addon.ui.metadata.WithAttributes;
import org.jboss.forge.addon.ui.result.NavigationResult;
import org.jboss.forge.addon.ui.result.Result;
Expand All @@ -40,6 +43,10 @@ public class ExampleWizard extends AbstractUICommand implements UIWizard
@WithAttributes(label = "Go to Last Step", shortName = 'g')
private UIInput<Boolean> goToLastStep;

@Inject
private UISelectOne<String> valueWithSpaces;


@Override
public Metadata getMetadata()
{
Expand All @@ -50,7 +57,8 @@ public Metadata getMetadata()
public void initializeUI(UIBuilder builder) throws Exception
{
firstName.setRequired(true).setRequiredMessage("First Name must be informed !");
builder.add(firstName).add(showSelectComponents).add(goToLastStep).add(directory);
valueWithSpaces.setValueChoices(Arrays.asList("Value 1", "Value 2", "Value 10", "Value 100"));
builder.add(firstName).add(showSelectComponents).add(goToLastStep).add(directory).add(valueWithSpaces);
}

@Override
Expand Down

0 comments on commit bac6873

Please sign in to comment.