Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
388 additions
and
0 deletions.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
ui/api/src/main/java/org/jboss/forge/addon/ui/controller/CommandController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/** | ||
* 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 | ||
*/ | ||
|
||
package org.jboss.forge.addon.ui.controller; | ||
|
||
import java.util.List; | ||
|
||
import org.jboss.forge.addon.ui.UICommand; | ||
import org.jboss.forge.addon.ui.result.Result; | ||
|
||
/** | ||
* A Controller for a specific {@link UICommand} | ||
* | ||
* @author <a href="ggastald@redhat.com">George Gastaldi</a> | ||
*/ | ||
public interface CommandController | ||
{ | ||
/** | ||
* Returns the initial {@link UICommand} | ||
*/ | ||
public UICommand getInitialCommand(); | ||
|
||
/** | ||
* Launch the currrent wizard execution | ||
* | ||
* @throws Exception | ||
*/ | ||
public void launch() throws Exception; | ||
|
||
/** | ||
* Is the wizard allowed to finish? | ||
*/ | ||
public boolean canFinish(); | ||
|
||
/** | ||
* Lets the controller know that some value in the Wizard was modified, so it should invalidate subsequent pages. | ||
*/ | ||
public void valueChanged(); | ||
|
||
/** | ||
* Finish clicked | ||
* | ||
* @throws Exception if anything wrong happens | ||
*/ | ||
public Result finish() throws Exception; | ||
|
||
/** | ||
* Is the current wizard page valid ? | ||
* | ||
* @return true if valid, false otherwise | ||
*/ | ||
public boolean isValid(); | ||
|
||
/** | ||
* The validation errors for the current page | ||
*/ | ||
public List<String> getErrorMessages(); | ||
} |
30 changes: 30 additions & 0 deletions
30
ui/api/src/main/java/org/jboss/forge/addon/ui/controller/CommandControllerFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/** | ||
* 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 | ||
*/ | ||
|
||
package org.jboss.forge.addon.ui.controller; | ||
|
||
import org.jboss.forge.addon.ui.UICommand; | ||
import org.jboss.forge.addon.ui.spi.UIContextFactory; | ||
import org.jboss.forge.addon.ui.wizard.UIWizard; | ||
|
||
/** | ||
* Creates {@link CommandController} objects | ||
* | ||
* @author <a href="ggastald@redhat.com">George Gastaldi</a> | ||
*/ | ||
public interface CommandControllerFactory | ||
{ | ||
/** | ||
* Create a {@link SingleCommandController}. Should be called when a single command execution must be performed. | ||
*/ | ||
CommandController createSingleController(Class<? extends UICommand> command, UIContextFactory uiFactory); | ||
|
||
/** | ||
* Create a {@link WizardCommandController}. Should be called when a wizard (multisteps) execution must be performed. | ||
*/ | ||
WizardCommandController createWizardController(Class<? extends UIWizard> wizard, UIContextFactory uiFactory); | ||
} |
43 changes: 43 additions & 0 deletions
43
ui/api/src/main/java/org/jboss/forge/addon/ui/controller/WizardCommandController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/** | ||
* 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 | ||
*/ | ||
|
||
package org.jboss.forge.addon.ui.controller; | ||
|
||
import org.jboss.forge.addon.ui.UICommand; | ||
|
||
/** | ||
* | ||
* @author <a href="ggastald@redhat.com">George Gastaldi</a> | ||
*/ | ||
public interface WizardCommandController extends CommandController | ||
{ | ||
/** | ||
* Returns the current {@link UICommand} based on the navigation | ||
*/ | ||
public UICommand getCurrentCommand(); | ||
|
||
/** | ||
* Is it possible to navigate to the next page ? | ||
*/ | ||
public boolean canFlipToNextPage(); | ||
|
||
/** | ||
* Is it possible to navigate to the previous page ? | ||
* | ||
*/ | ||
public boolean canFlipToPreviousPage(); | ||
|
||
/** | ||
* Navigate to the next page. Throws {@link IllegalStateException} if navigation is not possible | ||
*/ | ||
public UICommand next() throws IllegalStateException; | ||
|
||
/** | ||
* Navigate to the previous visited page | ||
*/ | ||
public UICommand previous() throws IllegalStateException; | ||
} |
41 changes: 41 additions & 0 deletions
41
ui/api/src/main/java/org/jboss/forge/addon/ui/spi/UIContextFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/** | ||
* 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 | ||
*/ | ||
|
||
package org.jboss.forge.addon.ui.spi; | ||
|
||
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.UIValidationContext; | ||
|
||
/** | ||
* Creates UI objects. Should be implemented by UI Providers | ||
* | ||
* @author <a href="ggastald@redhat.com">George Gastaldi</a> | ||
*/ | ||
public interface UIContextFactory | ||
{ | ||
/** | ||
* Creates the {@link UIContext} used | ||
*/ | ||
UIContext createUIContext(); | ||
|
||
/** | ||
* Creates a {@link UIBuilder} when needed | ||
*/ | ||
UIBuilder createUIBuilder(UIContext context); | ||
|
||
/** | ||
* Creates a new {@link UIValidationContext} | ||
*/ | ||
UIValidationContext createUIValidationContext(UIContext context); | ||
|
||
/** | ||
* Creates a new {@link UIExecutionContext} | ||
*/ | ||
UIExecutionContext createUIExecutionContext(UIContext context); | ||
} |
34 changes: 34 additions & 0 deletions
34
...mpl/src/main/java/org/jboss/forge/addon/ui/impl/controller/AbstractCommandController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** | ||
* 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 | ||
*/ | ||
|
||
package org.jboss.forge.addon.ui.impl.controller; | ||
|
||
import org.jboss.forge.addon.ui.UICommand; | ||
import org.jboss.forge.addon.ui.controller.CommandController; | ||
import org.jboss.forge.furnace.addons.AddonRegistry; | ||
|
||
/** | ||
* | ||
* @author <a href="ggastald@redhat.com">George Gastaldi</a> | ||
*/ | ||
public abstract class AbstractCommandController implements CommandController | ||
{ | ||
protected final AddonRegistry addonRegistry; | ||
private final UICommand initialCommand; | ||
|
||
protected AbstractCommandController(AddonRegistry addonRegistry, UICommand initialCommand) | ||
{ | ||
this.addonRegistry = addonRegistry; | ||
this.initialCommand = initialCommand; | ||
} | ||
|
||
@Override | ||
public UICommand getInitialCommand() | ||
{ | ||
return this.initialCommand; | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
.../src/main/java/org/jboss/forge/addon/ui/impl/controller/CommandControllerFactoryImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/** | ||
* 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 | ||
*/ | ||
|
||
package org.jboss.forge.addon.ui.impl.controller; | ||
|
||
import javax.inject.Inject; | ||
import javax.inject.Singleton; | ||
|
||
import org.jboss.forge.addon.ui.UICommand; | ||
import org.jboss.forge.addon.ui.context.UIContext; | ||
import org.jboss.forge.addon.ui.controller.CommandController; | ||
import org.jboss.forge.addon.ui.controller.CommandControllerFactory; | ||
import org.jboss.forge.addon.ui.controller.WizardCommandController; | ||
import org.jboss.forge.addon.ui.spi.UIContextFactory; | ||
import org.jboss.forge.addon.ui.wizard.UIWizard; | ||
import org.jboss.forge.addon.ui.wizard.UIWizardStep; | ||
import org.jboss.forge.furnace.addons.AddonRegistry; | ||
|
||
/** | ||
* Creates {@link CommandController} objects | ||
* | ||
* @author <a href="ggastald@redhat.com">George Gastaldi</a> | ||
*/ | ||
@Singleton | ||
public class CommandControllerFactoryImpl implements CommandControllerFactory | ||
{ | ||
private final AddonRegistry addonRegistry; | ||
|
||
@Inject | ||
public CommandControllerFactoryImpl(AddonRegistry addonRegistry) | ||
{ | ||
this.addonRegistry = addonRegistry; | ||
} | ||
|
||
@Override | ||
public CommandController createSingleController(Class<? extends UICommand> command, UIContextFactory uiFactory) | ||
{ | ||
return null; | ||
} | ||
|
||
@Override | ||
public WizardCommandController createWizardController(Class<? extends UIWizard> wizard, UIContextFactory uiFactory) | ||
{ | ||
return null; | ||
} | ||
|
||
public CommandController create(Class<? extends UICommand> command, UIContext context) | ||
{ | ||
if (UIWizardStep.class.isAssignableFrom(command)) | ||
{ | ||
throw new IllegalArgumentException("Class " + command.getName() | ||
+ " implements UIWizardStep, and it's not possible to start from a step"); | ||
} | ||
else if (UIWizard.class.isAssignableFrom(command)) | ||
{ | ||
return null; | ||
} | ||
else if (UICommand.class.isAssignableFrom(command)) | ||
{ | ||
// return new SingleCommandController(addonRegistry, addonRegistry.getServices(command).get()); | ||
} | ||
throw new IllegalArgumentException(command + " is not a valid UICommand"); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
ui/impl/src/main/java/org/jboss/forge/addon/ui/impl/controller/SingleCommandController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
* 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 | ||
*/ | ||
|
||
package org.jboss.forge.addon.ui.impl.controller; | ||
|
||
import org.jboss.forge.addon.ui.UICommand; | ||
import org.jboss.forge.furnace.addons.AddonRegistry; | ||
|
||
/** | ||
* | ||
* @author <a href="ggastald@redhat.com">George Gastaldi</a> | ||
*/ | ||
abstract class SingleCommandController extends AbstractCommandController | ||
{ | ||
|
||
public SingleCommandController(AddonRegistry addonRegistry, UICommand initialCommand) | ||
{ | ||
super(addonRegistry, initialCommand); | ||
} | ||
|
||
} |
85 changes: 85 additions & 0 deletions
85
...l/src/main/java/org/jboss/forge/addon/ui/impl/controller/WizardCommandControllerImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/** | ||
* 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 | ||
*/ | ||
|
||
package org.jboss.forge.addon.ui.impl.controller; | ||
|
||
import org.jboss.forge.addon.ui.UICommand; | ||
import org.jboss.forge.addon.ui.controller.WizardCommandController; | ||
import org.jboss.forge.addon.ui.wizard.UIWizard; | ||
import org.jboss.forge.furnace.addons.AddonRegistry; | ||
|
||
/** | ||
* | ||
* @author <a href="ggastald@redhat.com">George Gastaldi</a> | ||
*/ | ||
abstract class WizardCommandControllerImpl extends AbstractCommandController implements WizardCommandController | ||
{ | ||
|
||
public WizardCommandControllerImpl(AddonRegistry addonRegistry, UIWizard initialCommand) | ||
{ | ||
super(addonRegistry, initialCommand); | ||
} | ||
|
||
@Override | ||
public UIWizard getInitialCommand() | ||
{ | ||
return (UIWizard) super.getInitialCommand(); | ||
} | ||
|
||
@Override | ||
public UICommand getCurrentCommand() | ||
{ | ||
return null; | ||
} | ||
|
||
@Override | ||
public void launch() throws Exception | ||
{ | ||
|
||
} | ||
|
||
@Override | ||
public boolean canFlipToNextPage() | ||
{ | ||
// TODO Auto-generated method stub | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean canFlipToPreviousPage() | ||
{ | ||
// TODO Auto-generated method stub | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean canFinish() | ||
{ | ||
// TODO Auto-generated method stub | ||
return false; | ||
} | ||
|
||
@Override | ||
public UICommand next() throws IllegalStateException | ||
{ | ||
return null; | ||
} | ||
|
||
@Override | ||
public UICommand previous() throws IllegalStateException | ||
{ | ||
return null; | ||
} | ||
|
||
@Override | ||
public void valueChanged() | ||
{ | ||
// TODO Auto-generated method stub | ||
|
||
} | ||
|
||
} |