Skip to content

Commit

Permalink
FORGE-2757: WizardController.getStepsMetadata returns the whole flow now
Browse files Browse the repository at this point in the history
  • Loading branch information
gastaldi committed Jul 19, 2017
1 parent 96e6f79 commit 53bf2bb
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@

import org.jboss.forge.addon.ui.command.AbstractUICommand;
import org.jboss.forge.addon.ui.context.UIBuilder;
import org.jboss.forge.addon.ui.context.UIContext;
import org.jboss.forge.addon.ui.context.UIExecutionContext;
import org.jboss.forge.addon.ui.context.UINavigationContext;
import org.jboss.forge.addon.ui.input.UIInput;
import org.jboss.forge.addon.ui.metadata.UICommandMetadata;
import org.jboss.forge.addon.ui.metadata.WithAttributes;
import org.jboss.forge.addon.ui.result.NavigationResult;
import org.jboss.forge.addon.ui.result.Result;
import org.jboss.forge.addon.ui.result.Results;
import org.jboss.forge.addon.ui.util.Categories;
import org.jboss.forge.addon.ui.util.Metadata;
import org.jboss.forge.addon.ui.wizard.UIWizardStep;

/**
Expand Down Expand Up @@ -48,4 +52,11 @@ public Result execute(UIExecutionContext context) throws Exception
return Results.success();
}

@Override
public UICommandMetadata getMetadata(UIContext context)
{
return Metadata.from(super.getMetadata(context), getClass()).name("flow-one-one")
.category(Categories.create("Example"));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@

import org.jboss.forge.addon.ui.command.AbstractUICommand;
import org.jboss.forge.addon.ui.context.UIBuilder;
import org.jboss.forge.addon.ui.context.UIContext;
import org.jboss.forge.addon.ui.context.UIExecutionContext;
import org.jboss.forge.addon.ui.context.UINavigationContext;
import org.jboss.forge.addon.ui.input.UIInput;
import org.jboss.forge.addon.ui.metadata.UICommandMetadata;
import org.jboss.forge.addon.ui.metadata.WithAttributes;
import org.jboss.forge.addon.ui.result.NavigationResult;
import org.jboss.forge.addon.ui.result.Result;
import org.jboss.forge.addon.ui.result.Results;
import org.jboss.forge.addon.ui.util.Categories;
import org.jboss.forge.addon.ui.util.Metadata;
import org.jboss.forge.addon.ui.wizard.UIWizardStep;

/**
Expand Down Expand Up @@ -48,4 +52,11 @@ public Result execute(UIExecutionContext context) throws Exception
return Results.success();
}

@Override
public UICommandMetadata getMetadata(UIContext context)
{
return Metadata.from(super.getMetadata(context), getClass()).name("flow-one")
.category(Categories.create("Example"));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@

import org.jboss.forge.addon.ui.command.AbstractUICommand;
import org.jboss.forge.addon.ui.context.UIBuilder;
import org.jboss.forge.addon.ui.context.UIContext;
import org.jboss.forge.addon.ui.context.UIExecutionContext;
import org.jboss.forge.addon.ui.context.UINavigationContext;
import org.jboss.forge.addon.ui.input.UIInput;
import org.jboss.forge.addon.ui.metadata.UICommandMetadata;
import org.jboss.forge.addon.ui.metadata.WithAttributes;
import org.jboss.forge.addon.ui.result.NavigationResult;
import org.jboss.forge.addon.ui.result.Result;
import org.jboss.forge.addon.ui.result.Results;
import org.jboss.forge.addon.ui.util.Categories;
import org.jboss.forge.addon.ui.util.Metadata;
import org.jboss.forge.addon.ui.wizard.UIWizardStep;

/**
Expand Down Expand Up @@ -48,4 +52,11 @@ public Result execute(UIExecutionContext context) throws Exception
return Results.success();
}

@Override
public UICommandMetadata getMetadata(UIContext context)
{
return Metadata.from(super.getMetadata(context), getClass()).name("flow-two")
.category(Categories.create("Example"));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -482,23 +482,22 @@ public WizardCommandController previous() throws IllegalStateException
public List<UICommandMetadata> getWizardStepsMetadata()
{
List<UICommandMetadata> stepsMetadata = new ArrayList<>();
refreshFlow();
if (flow.size() == 1)
{
stepsMetadata.add(flow.get(0).controller.getMetadata());
}
else
addCommandMetadata(stepsMetadata, initialCommand);
return stepsMetadata;
}

private void addCommandMetadata(List<UICommandMetadata> stepsMetadata, UICommand command)
{
UIContext context = getContext();
stepsMetadata.add(command.getMetadata(context));
NavigationResultEntry[] nextEntries = getNextFrom(command);
if (nextEntries != null)
{
for (WizardStepEntry entry : flow)
for (NavigationResultEntry nextEntry : nextEntries)
{
// Entries without inputs are not shown
if (!entry.controller.getInputs().isEmpty())
{
stepsMetadata.add(entry.controller.getMetadata());
}
addCommandMetadata(stepsMetadata, nextEntry.getCommand(addonRegistry, context));
}
}
return stepsMetadata;
}

protected int getFlowPointer()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import static org.hamcrest.CoreMatchers.not;

import java.util.List;
import java.util.stream.Collectors;

import javax.inject.Inject;

Expand All @@ -25,6 +26,7 @@
import org.jboss.forge.addon.ui.example.wizards.subflow.FlowOneOneStep;
import org.jboss.forge.addon.ui.example.wizards.subflow.FlowOneStep;
import org.jboss.forge.addon.ui.example.wizards.subflow.FlowTwoStep;
import org.jboss.forge.addon.ui.metadata.UICommandMetadata;
import org.jboss.forge.addon.ui.result.CompositeResult;
import org.jboss.forge.addon.ui.result.Failed;
import org.jboss.forge.addon.ui.result.Result;
Expand Down Expand Up @@ -242,18 +244,10 @@ public void testStepsMetadata() throws Exception
try (WizardCommandController controller = testHarness.createWizardController(ExampleFlow.class))
{
controller.initialize();
assertThat(controller.getWizardStepsMetadata()).hasSize(1);
controller.setValueFor("name", "Forge");
controller.setValueFor("number", 42);
controller.next().initialize();
assertThat(controller.getWizardStepsMetadata()).hasSize(2);
controller.setValueFor("flowOneInput", "Value");
controller.next().initialize();
assertThat(controller.getWizardStepsMetadata()).hasSize(3);
controller.setValueFor("flowOneOneInput", "Value Two");
controller.next().initialize();
assertThat(controller.getWizardStepsMetadata()).hasSize(4);
controller.setValueFor("flowTwoInput", "Value Three");
List<UICommandMetadata> wizardStepsMetadata = controller.getWizardStepsMetadata();
assertThat(wizardStepsMetadata).hasSize(4);
assertThat(wizardStepsMetadata.stream().map(UICommandMetadata::getName).collect(Collectors.toList()))
.containsExactly("flow", "flow-one", "flow-one-one", "flow-two");
}
}

Expand Down

0 comments on commit 53bf2bb

Please sign in to comment.