Skip to content

Commit

Permalink
UIWizard simplified
Browse files Browse the repository at this point in the history
  • Loading branch information
gastaldi committed Feb 8, 2013
1 parent 0963406 commit 42926c1
Show file tree
Hide file tree
Showing 11 changed files with 249 additions and 52 deletions.
12 changes: 12 additions & 0 deletions ui/api/src/main/java/org/jboss/forge/ui/wizard/UIWizard.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@

import org.jboss.forge.ui.UICommand;

/**
* An {@link UICommand} that supports multiple steps.
*
* Eg: Next, Previous buttons are enabled in Eclipse
*
* @author <a href="mailto:ggastald@redhat.com">George Gastaldi</a>
*
*/
public interface UIWizard extends UICommand
{
/**
* Returns the next wizard step, or null if there are no pages to be displayed next
*/
Class<? extends UIWizard> getSuccessor();
}
13 changes: 0 additions & 13 deletions ui/api/src/main/java/org/jboss/forge/ui/wizard/UIWizardBegin.java

This file was deleted.

18 changes: 0 additions & 18 deletions ui/api/src/main/java/org/jboss/forge/ui/wizard/UIWizardEnd.java

This file was deleted.

15 changes: 9 additions & 6 deletions ui/api/src/main/java/org/jboss/forge/ui/wizard/UIWizardStep.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@

package org.jboss.forge.ui.wizard;

import org.jboss.forge.ui.Result;

/**
* Marker interface for wizard steps.
*
* Classes that implement this interface are not considered starting entry points, hence MUST not be shown in the
* available addon list
*
* @author <a href="mailto:ggastald@redhat.com">George Gastaldi</a>
*
*/
public interface UIWizardStep extends UIWizard
{
/*
* Called when user clicks “next” or final confirmation of step completion is received.
*/
public Result next(UIWizardContext context) throws Exception;
}
6 changes: 6 additions & 0 deletions ui/example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@
<version>2.0.0-SNAPSHOT</version>
<classifier>forge-addon</classifier>
</dependency>
<dependency>
<groupId>org.jboss.forge</groupId>
<artifactId>resources</artifactId>
<version>2.0.0-SNAPSHOT</version>
<classifier>forge-addon</classifier>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package org.jboss.forge.ui.example.wizards;

import javax.inject.Inject;

import org.jboss.forge.ui.Result;
import org.jboss.forge.ui.Results;
import org.jboss.forge.ui.UICommand;
import org.jboss.forge.ui.UICommandMetadata;
import org.jboss.forge.ui.UIContext;
import org.jboss.forge.ui.UIInput;
import org.jboss.forge.ui.UISelection;
import org.jboss.forge.ui.UIValidationContext;
import org.jboss.forge.ui.base.UICommandMetadataBase;
import org.jboss.forge.ui.wizard.UIWizard;
import org.jboss.forge.ui.wizard.UIWizardStep;

/*
* Copyright 2013 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Eclipse Public License version 1.0, available at
* http://www.eclipse.org/legal/epl-v10.html
*/

public class ExampleStepOne implements UIWizardStep
{

@Inject
private UIInput<String> address;

@Override
public UICommandMetadata getMetadata()
{
return new UICommandMetadataBase("Step 1", "Enter your Address");
}

@Override
public void initializeUI(UIContext context) throws Exception
{
context.getUIBuilder().add(address);
}

@Override
public void validate(UIValidationContext context)
{
System.out.println("Validate");
}

@Override
public Result execute(UIContext context) throws Exception
{
System.out.println("Step 1 Address: " + address.getValue());
return Results.success();
}

@Override
public boolean isEnabled(UIContext context)
{
UISelection<?> selection = context.getInitialSelection();
return selection != null;
}

@Override
public Class<? extends UIWizard> getSuccessor()
{
return ExampleStepTwo.class;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package org.jboss.forge.ui.example.wizards;

import javax.inject.Inject;

import org.jboss.forge.resource.DirectoryResource;
import org.jboss.forge.ui.Result;
import org.jboss.forge.ui.Results;
import org.jboss.forge.ui.UICommandMetadata;
import org.jboss.forge.ui.UIContext;
import org.jboss.forge.ui.UIInput;
import org.jboss.forge.ui.UISelection;
import org.jboss.forge.ui.UIValidationContext;
import org.jboss.forge.ui.base.UICommandMetadataBase;
import org.jboss.forge.ui.wizard.UIWizard;
import org.jboss.forge.ui.wizard.UIWizardStep;

/*
* Copyright 2013 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Eclipse Public License version 1.0, available at
* http://www.eclipse.org/legal/epl-v10.html
*/

public class ExampleStepTwo implements UIWizardStep
{

@Inject
private UIInput<DirectoryResource> location;

@Override
public UICommandMetadata getMetadata()
{
return new UICommandMetadataBase("Step 2", "Select a folder");
}

@Override
public void initializeUI(UIContext context) throws Exception
{
context.getUIBuilder().add(location);
}

@Override
public void validate(UIValidationContext context)
{
System.out.println("Validate Step Two");
}

@Override
public Result execute(UIContext context) throws Exception
{
System.out.println("Step Two Location: " + location.getValue());
return Results.success();
}

@Override
public boolean isEnabled(UIContext context)
{
UISelection<?> selection = context.getInitialSelection();
return selection != null;
}

@Override
public Class<? extends UIWizard> getSuccessor()
{
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package org.jboss.forge.ui.example.wizards;

import javax.inject.Inject;

import org.jboss.forge.ui.Result;
import org.jboss.forge.ui.Results;
import org.jboss.forge.ui.UICommand;
import org.jboss.forge.ui.UICommandMetadata;
import org.jboss.forge.ui.UIContext;
import org.jboss.forge.ui.UIInput;
import org.jboss.forge.ui.UISelection;
import org.jboss.forge.ui.UIValidationContext;
import org.jboss.forge.ui.base.UICommandMetadataBase;
import org.jboss.forge.ui.wizard.UIWizard;

/*
* Copyright 2013 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Eclipse Public License version 1.0, available at
* http://www.eclipse.org/legal/epl-v10.html
*/

public class ExampleWizard implements UIWizard
{

@Inject
private UIInput<String> firstName;

@Override
public UICommandMetadata getMetadata()
{
return new UICommandMetadataBase("Wizard", "Exit the shell");
}

@Override
public void initializeUI(UIContext context) throws Exception
{
context.getUIBuilder().add(firstName);
}

@Override
public void validate(UIValidationContext context)
{
System.out.println("Validate");
}

@Override
public Result execute(UIContext context) throws Exception
{
return Results.success();
}

@Override
public boolean isEnabled(UIContext context)
{
UISelection<?> selection = context.getInitialSelection();
return selection != null;
}

@Override
public Class<? extends UIWizard> getSuccessor()
{
return ExampleStepOne.class;
}

}
9 changes: 4 additions & 5 deletions ui/tests/src/test/java/org/jboss/forge/ui/MyFirstWizard.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
import javax.inject.Inject;

import org.jboss.forge.ui.util.Categories;
import org.jboss.forge.ui.wizard.UIWizardBegin;
import org.jboss.forge.ui.wizard.UIWizardContext;
import org.jboss.forge.ui.wizard.UIWizard;

/*
* Copyright 2013 Red Hat, Inc. and/or its affiliates.
Expand All @@ -13,7 +12,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*/

public class MyFirstWizard implements UIWizardBegin
public class MyFirstWizard implements UIWizard
{
@Inject
private UIInput<String> firstName;
Expand Down Expand Up @@ -62,9 +61,9 @@ public UICategory getCategory()
}

@Override
public Result next(UIWizardContext context) throws Exception
public Class<? extends UIWizard> getSuccessor()
{
throw new IllegalStateException("not implemented");
return null;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package org.jboss.forge.ui.impl;

import org.jboss.forge.ui.Result;
import org.jboss.forge.ui.UICommand;
import org.jboss.forge.ui.UICommandMetadata;
import org.jboss.forge.ui.UIContext;
import org.jboss.forge.ui.UIValidationContext;
import org.jboss.forge.ui.base.UICommandMetadataBase;
import org.jboss.forge.ui.wizard.UIWizard;
import org.jboss.forge.ui.wizard.UIWizardStep;

public class MockChooseFrameworkStep implements UICommand
public class MockChooseFrameworkStep implements UIWizardStep
{

@Override
Expand Down Expand Up @@ -38,4 +39,12 @@ public Result execute(UIContext context) throws Exception
return null;
}

@Override
public Class<? extends UIWizard> getSuccessor()
{
return null;
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
import org.jboss.forge.ui.Result;
import org.jboss.forge.ui.Results;
import org.jboss.forge.ui.UICommand;
import org.jboss.forge.ui.UICommandMetadata;
import org.jboss.forge.ui.UIContext;
import org.jboss.forge.ui.UIInput;
import org.jboss.forge.ui.UIValidationContext;
import org.jboss.forge.ui.UICommandMetadata;
import org.jboss.forge.ui.wizard.UIWizardContext;
import org.jboss.forge.ui.wizard.UIWizard;
import org.jboss.forge.ui.wizard.UIWizardStep;

@Exported
Expand Down Expand Up @@ -73,23 +73,22 @@ public void validate(UIValidationContext context)
}

/*
*
*
* Defines the action to take once inputs are valid and submitted
*/

@Override
public Result next(UIWizardContext context) throws Exception
public Class<? extends UIWizard> getSuccessor()
{
if (useFramework.getValue())
{
return Results.success(MockChooseFrameworkStep.class);
return MockChooseFrameworkStep.class;
}

return Results.success();
return null;
}

/*
*
*
* Defines the action to take once inputs are valid and submitted
*/

Expand Down

0 comments on commit 42926c1

Please sign in to comment.