[1] | 1 | package de.ugoe.cs.eventbench;
|
---|
| 2 |
|
---|
[247] | 3 | import java.io.IOException;
|
---|
| 4 | import java.util.List;
|
---|
| 5 |
|
---|
| 6 | import joptsimple.OptionException;
|
---|
| 7 | import joptsimple.OptionParser;
|
---|
| 8 | import joptsimple.OptionSet;
|
---|
| 9 | import joptsimple.OptionSpec;
|
---|
[207] | 10 | import de.ugoe.cs.eventbench.log4j.Log4JLogger;
|
---|
[188] | 11 | import de.ugoe.cs.eventbench.swt.MainWindow;
|
---|
[1] | 12 | import de.ugoe.cs.util.console.CommandExecuter;
|
---|
[171] | 13 | import de.ugoe.cs.util.console.Console;
|
---|
[1] | 14 | import de.ugoe.cs.util.console.TextConsole;
|
---|
| 15 |
|
---|
[171] | 16 | /**
|
---|
| 17 | * <p>
|
---|
| 18 | * Start-up class of the application.
|
---|
| 19 | * </p>
|
---|
| 20 | * <p>
|
---|
| 21 | * It sets up and starts the {@link Console}.
|
---|
| 22 | * </p>
|
---|
| 23 | *
|
---|
| 24 | * @author Steffen Herbold
|
---|
| 25 | * @version 1.0
|
---|
| 26 | */
|
---|
[1] | 27 | public class Runner {
|
---|
| 28 |
|
---|
[247] | 29 | public enum UITYPE {
|
---|
| 30 | text, swt
|
---|
| 31 | };
|
---|
| 32 |
|
---|
[1] | 33 | /**
|
---|
[171] | 34 | * <p>
|
---|
| 35 | * Main method of the application.
|
---|
| 36 | * </p>
|
---|
| 37 | *
|
---|
[1] | 38 | * @param args
|
---|
[171] | 39 | * if parameters are defined, they are interpreted as commands
|
---|
| 40 | * for the {@link Console} and executed before the user can use
|
---|
| 41 | * the console; can be used to perform batch operations
|
---|
[1] | 42 | */
|
---|
| 43 | public static void main(String[] args) {
|
---|
[171] | 44 | CommandExecuter.getInstance().addCommandPackage(
|
---|
| 45 | "de.ugoe.cs.eventbench.commands");
|
---|
| 46 | CommandExecuter.getInstance().addCommandPackage(
|
---|
| 47 | "de.ugoe.cs.eventbench.windows.commands");
|
---|
| 48 | CommandExecuter.getInstance().addCommandPackage(
|
---|
| 49 | "de.ugoe.cs.eventbench.web.commands");
|
---|
[196] | 50 | CommandExecuter.getInstance().addCommandPackage(
|
---|
| 51 | "de.ugoe.cs.eventbench.efg.commands");
|
---|
[299] | 52 | CommandExecuter.getInstance().addCommandPackage(
|
---|
| 53 | "de.ugoe.cs.eventbench.jfc.commands");
|
---|
[207] | 54 | new Log4JLogger();
|
---|
[247] | 55 |
|
---|
| 56 | OptionParser parser = new OptionParser();
|
---|
| 57 | OptionSpec<UITYPE> ui = parser.accepts("ui", "Allowed values: text, swt").withRequiredArg()
|
---|
| 58 | .ofType(UITYPE.class).defaultsTo(UITYPE.text);
|
---|
| 59 | OptionSet options = parser.parse(args);
|
---|
| 60 |
|
---|
| 61 | List<String> startupCommands = options.nonOptionArguments();
|
---|
| 62 | try {
|
---|
| 63 | switch (options.valueOf(ui)) {
|
---|
| 64 | case text:
|
---|
| 65 | TextConsole textConsole = new TextConsole();
|
---|
| 66 | for (String command : startupCommands) {
|
---|
| 67 | CommandExecuter.getInstance().exec(command);
|
---|
[112] | 68 | }
|
---|
[188] | 69 | textConsole.run(true);
|
---|
[247] | 70 | break;
|
---|
| 71 | case swt:
|
---|
| 72 | MainWindow mainWindow = new MainWindow(startupCommands);
|
---|
| 73 | mainWindow.open();
|
---|
| 74 | break;
|
---|
[188] | 75 | }
|
---|
[247] | 76 | } catch (OptionException e) {
|
---|
| 77 | System.err.println("Invalid Parameters: " + e.getMessage());
|
---|
| 78 | try {
|
---|
| 79 | parser.printHelpOn(System.out);
|
---|
| 80 | } catch (IOException e1) {
|
---|
| 81 | // ignore exception.
|
---|
| 82 | }
|
---|
| 83 | }
|
---|
[1] | 84 | }
|
---|
| 85 |
|
---|
| 86 | }
|
---|