-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FORGE-1479: Introduced JavaEEUICommandEnricher
- Loading branch information
Showing
6 changed files
with
184 additions
and
0 deletions.
There are no files selected for viewing
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
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
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
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
60 changes: 60 additions & 0 deletions
60
javaee/impl/src/main/java/org/jboss/forge/addon/javaee/ui/CompositeWizard.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,60 @@ | ||
/** | ||
* Copyright 2014 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.javaee.ui; | ||
|
||
import org.jboss.forge.addon.ui.command.AbstractUICommand; | ||
import org.jboss.forge.addon.ui.command.UICommand; | ||
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.metadata.UICommandMetadata; | ||
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.wizard.UIWizard; | ||
|
||
/** | ||
* | ||
* @author <a href="ggastald@redhat.com">George Gastaldi</a> | ||
*/ | ||
public class CompositeWizard extends AbstractUICommand implements UIWizard | ||
{ | ||
private final UICommand originalCmd; | ||
private final Class<? extends UICommand>[] steps; | ||
|
||
public CompositeWizard(UICommand originalCmd, Class<? extends UICommand>[] steps) | ||
{ | ||
this.originalCmd = originalCmd; | ||
this.steps = steps; | ||
} | ||
|
||
@Override | ||
public UICommandMetadata getMetadata(UIContext context) | ||
{ | ||
return originalCmd.getMetadata(context); | ||
} | ||
|
||
@Override | ||
public NavigationResult next(UINavigationContext context) throws Exception | ||
{ | ||
return Results.navigateTo(steps); | ||
} | ||
|
||
@Override | ||
public Result execute(UIExecutionContext context) throws Exception | ||
{ | ||
return Results.success(); | ||
} | ||
|
||
@Override | ||
public void initializeUI(UIBuilder builder) throws Exception | ||
{ | ||
// no UI | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
javaee/impl/src/main/java/org/jboss/forge/addon/javaee/ui/JavaEEUICommandEnricher.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,58 @@ | ||
/** | ||
* Copyright 2014 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.javaee.ui; | ||
|
||
import java.util.List; | ||
|
||
import javax.inject.Inject; | ||
import javax.inject.Singleton; | ||
|
||
import org.jboss.forge.addon.projects.ProjectFactory; | ||
import org.jboss.forge.addon.projects.Projects; | ||
import org.jboss.forge.addon.ui.command.UICommand; | ||
import org.jboss.forge.addon.ui.command.UICommandEnricher; | ||
import org.jboss.forge.addon.ui.context.UIContext; | ||
|
||
/** | ||
* Adds the Setup steps on {@link AbstractJavaEECommand} | ||
* | ||
* @author <a href="ggastald@redhat.com">George Gastaldi</a> | ||
*/ | ||
@Singleton | ||
public class JavaEEUICommandEnricher implements UICommandEnricher | ||
{ | ||
@Inject | ||
private ProjectFactory projectFactory; | ||
|
||
@SuppressWarnings("unchecked") | ||
@Override | ||
public UICommand enrich(UIContext context, UICommand original) | ||
{ | ||
final UICommand result; | ||
if (original instanceof AbstractJavaEECommand && Projects.containsProject(projectFactory, context)) | ||
{ | ||
List<Class<? extends UICommand>> previousSteps = ((AbstractJavaEECommand) original).getSetupSteps(context); | ||
if (previousSteps.isEmpty()) | ||
{ | ||
result = original; | ||
} | ||
else | ||
{ | ||
Class<? extends UICommand> classes[] = new Class[previousSteps.size() + 1]; | ||
previousSteps.toArray(classes); | ||
classes[classes.length - 1] = (Class<? extends UICommand>) original.getMetadata(context).getType(); | ||
result = new CompositeWizard(original, classes); | ||
} | ||
} | ||
else | ||
{ | ||
result = original; | ||
} | ||
return result; | ||
} | ||
} |