-
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.
Merge pull request #541 from agoncal/FORGE-2261
FORGE-2261: Refactoring the Bean Validation Commands
- Loading branch information
Showing
11 changed files
with
345 additions
and
64 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
10 changes: 10 additions & 0 deletions
10
...src/main/java/org/jboss/forge/addon/javaee/validation/ui/ValidationNewPayloadCommand.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,10 @@ | ||
package org.jboss.forge.addon.javaee.validation.ui; | ||
|
||
import org.jboss.forge.addon.ui.command.UICommand; | ||
|
||
/** | ||
* @author <a href="antonio.goncalves@gmail.com">Antonio Goncalves</a> | ||
*/ | ||
public interface ValidationNewPayloadCommand extends UICommand | ||
{ | ||
} |
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
58 changes: 58 additions & 0 deletions
58
...l/src/main/java/org/jboss/forge/addon/javaee/validation/ui/AbstractValidationCommand.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 @@ | ||
package org.jboss.forge.addon.javaee.validation.ui; | ||
|
||
import static org.jboss.forge.addon.javaee.JavaEEFacet.DEFAULT_CONSTRAINT_PACKAGE; | ||
|
||
import org.jboss.forge.addon.javaee.validation.ValidationFacet; | ||
import org.jboss.forge.addon.parser.java.facets.JavaSourceFacet; | ||
import org.jboss.forge.addon.parser.java.ui.AbstractJavaSourceCommand; | ||
import org.jboss.forge.addon.projects.Project; | ||
import org.jboss.forge.addon.ui.command.PrerequisiteCommandsProvider; | ||
import org.jboss.forge.addon.ui.context.UIContext; | ||
import org.jboss.forge.addon.ui.result.NavigationResult; | ||
import org.jboss.forge.addon.ui.result.navigation.NavigationResultBuilder; | ||
import org.jboss.forge.addon.ui.util.Categories; | ||
import org.jboss.forge.addon.ui.util.Metadata; | ||
import org.jboss.forge.roaster.model.source.JavaSource; | ||
|
||
/** | ||
* @author <a href="antonio.goncalves@gmail.com">Antonio Goncalves</a> | ||
*/ | ||
public abstract class AbstractValidationCommand<T extends JavaSource<?>> extends AbstractJavaSourceCommand<T> | ||
implements PrerequisiteCommandsProvider | ||
{ | ||
|
||
@Override | ||
public Metadata getMetadata(UIContext context) | ||
{ | ||
return Metadata.from(super.getMetadata(context), getClass()) | ||
.category(Categories.create(Categories.create("Java EE"), "Bean Validation")); | ||
} | ||
|
||
@Override | ||
protected boolean isProjectRequired() | ||
{ | ||
return true; | ||
} | ||
|
||
@Override | ||
protected String calculateDefaultPackage(UIContext context) | ||
{ | ||
return getSelectedProject(context).getFacet(JavaSourceFacet.class).getBasePackage() + "." | ||
+ DEFAULT_CONSTRAINT_PACKAGE; | ||
} | ||
|
||
@Override | ||
public NavigationResult getPrerequisiteCommands(UIContext context) | ||
{ | ||
NavigationResultBuilder builder = NavigationResultBuilder.create(); | ||
Project project = getSelectedProject(context); | ||
if (project != null) | ||
{ | ||
if (!project.hasFacet(ValidationFacet.class)) | ||
{ | ||
builder.add(ValidationProviderSetupCommand.class); | ||
} | ||
} | ||
return builder.build(); | ||
} | ||
} |
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
42 changes: 42 additions & 0 deletions
42
...main/java/org/jboss/forge/addon/javaee/validation/ui/ValidationNewPayloadCommandImpl.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,42 @@ | ||
package org.jboss.forge.addon.javaee.validation.ui; | ||
|
||
import org.jboss.forge.addon.projects.Project; | ||
import org.jboss.forge.addon.ui.context.UIContext; | ||
import org.jboss.forge.addon.ui.context.UIExecutionContext; | ||
import org.jboss.forge.addon.ui.util.Categories; | ||
import org.jboss.forge.addon.ui.util.Metadata; | ||
import org.jboss.forge.roaster.model.source.JavaClassSource; | ||
|
||
import javax.validation.Payload; | ||
|
||
/** | ||
* @author <a href="antonio.goncalves@gmail.com">Antonio Goncalves</a> | ||
*/ | ||
public class ValidationNewPayloadCommandImpl extends AbstractValidationCommand<JavaClassSource> implements ValidationNewPayloadCommand | ||
{ | ||
@Override | ||
public Metadata getMetadata(UIContext context) | ||
{ | ||
return Metadata.from(super.getMetadata(context), getClass()) | ||
.name("Constraint: New Payload") | ||
.description("Create a Bean Validation payload"); | ||
} | ||
|
||
@Override | ||
protected String getType() | ||
{ | ||
return "Constraint Payload"; | ||
} | ||
|
||
@Override | ||
protected Class<JavaClassSource> getSourceType() | ||
{ | ||
return JavaClassSource.class; | ||
} | ||
|
||
@Override | ||
public JavaClassSource decorateSource(UIExecutionContext context, Project project, JavaClassSource source) throws Exception { | ||
source.addInterface(Payload.class); | ||
return source; | ||
} | ||
} |
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
Oops, something went wrong.