Skip to content

Commit

Permalink
Add the command listener showcase
Browse files Browse the repository at this point in the history
  • Loading branch information
ivannov committed Nov 7, 2014
1 parent 1b3415e commit 35658fc
Showing 1 changed file with 53 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package org.jboss.forge.addons.envers.commands;

import org.jboss.forge.addon.configuration.Configuration;
import org.jboss.forge.addon.configuration.facets.ConfigurationFacet;
import org.jboss.forge.addon.projects.ProjectFactory;
import org.jboss.forge.addon.projects.Projects;
import org.jboss.forge.addon.ui.command.CommandExecutionListener;
import org.jboss.forge.addon.ui.command.UICommand;
import org.jboss.forge.addon.ui.context.UIExecutionContext;
import org.jboss.forge.addon.ui.context.UISelection;
import org.jboss.forge.addon.ui.result.Result;

import javax.inject.Inject;

/**
* @author Ivan St. Ivanov
*/
public class JpaEntityCreationListener implements CommandExecutionListener
{
@Override public void preCommandExecuted(UICommand uiCommand, UIExecutionContext uiExecutionContext)
{

}

@Inject
private ProjectFactory projectFactory;

@Override public void postCommandExecuted(UICommand uiCommand, UIExecutionContext uiExecutionContext, Result result)
{
String commandName = uiCommand
.getMetadata(uiExecutionContext.getUIContext())
.getName();
if (commandName.equals("JPA: New Entity") && projectFactory != null)
{

Configuration configuration = Projects
.getSelectedProject(projectFactory, uiExecutionContext.getUIContext())
.getFacet(ConfigurationFacet.class)
.getConfiguration();
if ((Boolean) configuration.getProperty(Constants.AUTO_AUDIT_CONFIG_ENTRY))
{
uiExecutionContext.getUIContext().getSelection();
}

}
}

@Override public void postCommandFailure(UICommand uiCommand, UIExecutionContext uiExecutionContext,
Throwable throwable)
{

}
}

0 comments on commit 35658fc

Please sign in to comment.