Skip to content

Commit

Permalink
WizardID is now UICommandID and must be specified for each UICommand …
Browse files Browse the repository at this point in the history
…instance.
  • Loading branch information
lincolnthree committed Jan 17, 2013
1 parent 8952e2b commit 16fbf4c
Show file tree
Hide file tree
Showing 21 changed files with 442 additions and 265 deletions.
6 changes: 0 additions & 6 deletions aesh/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@
<artifactId>ui-api</artifactId>
<scope>provided</scope>
<version>2.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.jboss.forge</groupId>
<artifactId>ui-impl</artifactId>
<scope>provided</scope>
<version>2.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.jboss.forge</groupId>
Expand Down
5 changes: 2 additions & 3 deletions aesh/src/main/java/org/jboss/forge/aesh/ShellCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
*/
package org.jboss.forge.aesh;

import java.util.List;

import org.jboss.aesh.cl.CommandLine;
import org.jboss.aesh.cl.CommandLineParser;
import org.jboss.aesh.cl.ParserBuilder;
import org.jboss.aesh.cl.ParserGenerator;
import org.jboss.aesh.cl.internal.ParameterInt;
import org.jboss.aesh.complete.CompleteOperation;
import org.jboss.aesh.complete.Completion;
Expand All @@ -19,8 +20,6 @@
import org.jboss.forge.ui.UICommand;
import org.jboss.forge.ui.UIInput;

import java.util.List;

/**
* @author <a href="mailto:stale.pedersen@jboss.org">Ståle W. Pedersen</a>
*/
Expand Down
7 changes: 3 additions & 4 deletions aesh/src/main/java/org/jboss/forge/aesh/ShellContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@
*/
package org.jboss.forge.aesh;

import java.util.ArrayList;
import java.util.List;

import org.jboss.aesh.cl.CommandLine;
import org.jboss.aesh.cl.CommandLineParser;
import org.jboss.forge.ui.UIBuilder;
import org.jboss.forge.ui.UIContext;
import org.jboss.forge.ui.UIInput;
import org.jboss.forge.ui.UIValidationContext;

import java.util.ArrayList;
import java.util.List;

/**
* @author <a href="mailto:stale.pedersen@jboss.org">Ståle W. Pedersen</a>
*/
Expand Down
86 changes: 51 additions & 35 deletions aesh/src/main/java/org/jboss/forge/aesh/commands/ClearCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,45 +6,61 @@
*/
package org.jboss.forge.aesh.commands;

import org.jboss.aesh.cl.CommandLineParser;
import javax.inject.Inject;

import org.jboss.aesh.console.Console;
import org.jboss.forge.ui.*;
import org.jboss.forge.ui.impl.UIInputImpl;
import org.jboss.forge.ui.Result;
import org.jboss.forge.ui.UICommand;
import org.jboss.forge.ui.UICommandID;
import org.jboss.forge.ui.UIContext;
import org.jboss.forge.ui.UIInput;
import org.jboss.forge.ui.UIValidationContext;
import org.jboss.forge.ui.base.SimpleUICommandID;

/**
* @author <a href="mailto:stale.pedersen@jboss.org">Ståle W. Pedersen</a>
*/
public class ClearCommand implements UICommand {

private Console console;
private CommandLineParser parser;

private UIInput<String> clear;

public ClearCommand(Console console) {
setConsole(console);
}

private void setConsole(Console console) {
this.console = console;
}

@Override
public void initializeUI(UIContext context) throws Exception {
clear = new UIInputImpl<String>("clear", String.class);
clear.setLabel("clear");
clear.setRequired(true);
context.getUIBuilder().add(clear);
}

@Override
public void validate(UIValidationContext context) {
}

@Override
public Result execute(UIContext context) throws Exception {
console.clear();
return Result.success("");
}
public class ClearCommand implements UICommand
{
private Console console;

@Inject
private UIInput<String> clear;

public ClearCommand(Console console)
{
setConsole(console);
}

@Override
public UICommandID getId()
{
return new SimpleUICommandID("clear", "Clear the console");
}

private void setConsole(Console console)
{
this.console = console;
}

@Override
public void initializeUI(UIContext context) throws Exception
{
clear.setLabel("clear");
clear.setRequired(true);
context.getUIBuilder().add(clear);
}

@Override
public void validate(UIValidationContext context)
{
}

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

}
79 changes: 79 additions & 0 deletions aesh/src/main/java/org/jboss/forge/aesh/commands/ExitCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* Copyright 2012 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.aesh.commands;

import javax.inject.Inject;

import org.jboss.aesh.console.Console;
import org.jboss.forge.aesh.ShellContext;
import org.jboss.forge.ui.Result;
import org.jboss.forge.ui.UICommand;
import org.jboss.forge.ui.UICommandID;
import org.jboss.forge.ui.UIContext;
import org.jboss.forge.ui.UIInput;
import org.jboss.forge.ui.UIValidationContext;
import org.jboss.forge.ui.base.SimpleUICommandID;

/**
* @author <a href="mailto:stale.pedersen@jboss.org">Ståle W. Pedersen</a>
*/
public class ExitCommand implements UICommand
{
private Console console;

@Inject
private UIInput<String> exit;

@Inject
private UIInput<String> quit;

public ExitCommand(Console console)
{
setConsole(console);
}

@Override
public UICommandID getId()
{
return new SimpleUICommandID("exit", "Exit the shell");
}

private void setConsole(Console console)
{
this.console = console;
}

@Override
public void initializeUI(UIContext context) throws Exception
{
exit.setLabel("exit");
exit.setRequired(true);
context.getUIBuilder().add(exit);

quit.setLabel("quit");
quit.setRequired(true);
context.getUIBuilder().add(quit);

if (context instanceof ShellContext)
{
((ShellContext) context).setStandalone(false);
}
}

@Override
public void validate(UIValidationContext context)
{
}

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

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,76 +6,88 @@
*/
package org.jboss.forge.aesh.commands;

import java.io.IOException;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import javax.inject.Inject;

import org.jboss.forge.container.Addon;
import org.jboss.forge.container.AddonRegistry;
import org.jboss.forge.container.services.Exported;
import org.jboss.forge.ui.Result;
import org.jboss.forge.ui.UICommand;
import org.jboss.forge.ui.UICommandID;
import org.jboss.forge.ui.UIContext;
import org.jboss.forge.ui.UIInput;
import org.jboss.forge.ui.UIValidationContext;
import org.jboss.forge.ui.impl.UIInputImpl;

import java.io.IOException;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.jboss.forge.ui.base.SimpleUICommandID;

/**
* @author <a href="mailto:stale.pedersen@jboss.org">Ståle W. Pedersen</a>
*/
@Exported
public class ListServicesCommand implements UICommand {
public class ListServicesCommand implements UICommand
{
@Inject
private UIInput<String> name;

private UIInput<String> name;
@Inject
private AddonRegistry registry;

private AddonRegistry registry;
public ListServicesCommand(AddonRegistry registry)
{
this.registry = registry;
}

public ListServicesCommand(AddonRegistry registry) {
this.registry = registry;
}
@Override
public UICommandID getId()
{
return new SimpleUICommandID("list-services", "List all available services");
}

@Override
public void initializeUI(UIContext context) throws Exception {
name = new UIInputImpl<String>("list-services", String.class);
name.setLabel("list-services");
name.setRequired(true);
@Override
public void initializeUI(UIContext context) throws Exception
{
name.setLabel("list-services");
name.setRequired(true);

context.getUIBuilder().add(name);
}
context.getUIBuilder().add(name);
}

@Override
public void validate(UIValidationContext context) {
@Override
public void validate(UIValidationContext context)
{

}
}

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

private String listServices() throws IOException
{
StringBuilder builder = new StringBuilder();
Set<Addon> addons = registry.getRegisteredAddons();
for (Addon addon : addons)
{
Set<Class<?>> serviceClasses = addon.getServiceRegistry().getServices();
for (Class<?> type : serviceClasses)
private String listServices() throws IOException
{
StringBuilder builder = new StringBuilder();
Set<Addon> addons = registry.getRegisteredAddons();
for (Addon addon : addons)
{
Set<Class<?>> serviceClasses = addon.getServiceRegistry().getServices();
for (Class<?> type : serviceClasses)
{
builder.append(type.getName()).append("\n");
for (Method method : type.getMethods())
{
builder.append(type.getName()).append("\n");
for (Method method : type.getMethods())
{
builder.append("\n\type - " + getName(method));
}
builder.append("\n");
builder.append("\n\type - " + getName(method));
}
}
builder.append("\n");
}
}

return builder.toString();
}
return builder.toString();
}

public String getName(Method method)
{
Expand Down
28 changes: 28 additions & 0 deletions aesh/src/main/java/org/jboss/forge/aesh/commands/QuitCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright 2012 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.aesh.commands;

import org.jboss.aesh.console.Console;
import org.jboss.forge.ui.UICommandID;
import org.jboss.forge.ui.base.SimpleUICommandID;

/**
* @author <a href="mailto:stale.pedersen@jboss.org">Ståle W. Pedersen</a>
*/
public class QuitCommand extends ExitCommand
{
public QuitCommand(Console console)
{
super(console);
}

@Override
public UICommandID getId()
{
return new SimpleUICommandID("quit", "Exit the shell");
}
}
Loading

0 comments on commit 16fbf4c

Please sign in to comment.