1 | package de.ugoe.cs.eventbench;
|
---|
2 |
|
---|
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;
|
---|
10 | import de.ugoe.cs.eventbench.log4j.Log4JLogger;
|
---|
11 | import de.ugoe.cs.eventbench.swt.MainWindow;
|
---|
12 | import de.ugoe.cs.util.console.CommandExecuter;
|
---|
13 | import de.ugoe.cs.util.console.Console;
|
---|
14 | import de.ugoe.cs.util.console.TextConsole;
|
---|
15 |
|
---|
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 | */
|
---|
27 | public class Runner {
|
---|
28 |
|
---|
29 | public enum UITYPE {
|
---|
30 | text, swt
|
---|
31 | };
|
---|
32 |
|
---|
33 | /**
|
---|
34 | * <p>
|
---|
35 | * Main method of the application.
|
---|
36 | * </p>
|
---|
37 | *
|
---|
38 | * @param args
|
---|
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
|
---|
42 | */
|
---|
43 | public static void main(String[] args) {
|
---|
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");
|
---|
50 | CommandExecuter.getInstance().addCommandPackage(
|
---|
51 | "de.ugoe.cs.eventbench.efg.commands");
|
---|
52 | new Log4JLogger();
|
---|
53 |
|
---|
54 | OptionParser parser = new OptionParser();
|
---|
55 | OptionSpec<UITYPE> ui = parser.accepts("ui", "Allowed values: text, swt").withRequiredArg()
|
---|
56 | .ofType(UITYPE.class).defaultsTo(UITYPE.text);
|
---|
57 | OptionSet options = parser.parse(args);
|
---|
58 |
|
---|
59 | List<String> startupCommands = options.nonOptionArguments();
|
---|
60 | try {
|
---|
61 | switch (options.valueOf(ui)) {
|
---|
62 | case text:
|
---|
63 | TextConsole textConsole = new TextConsole();
|
---|
64 | for (String command : startupCommands) {
|
---|
65 | CommandExecuter.getInstance().exec(command);
|
---|
66 | }
|
---|
67 | textConsole.run(true);
|
---|
68 | break;
|
---|
69 | case swt:
|
---|
70 | MainWindow mainWindow = new MainWindow(startupCommands);
|
---|
71 | mainWindow.open();
|
---|
72 | break;
|
---|
73 | }
|
---|
74 | } catch (OptionException e) {
|
---|
75 | System.err.println("Invalid Parameters: " + e.getMessage());
|
---|
76 | try {
|
---|
77 | parser.printHelpOn(System.out);
|
---|
78 | } catch (IOException e1) {
|
---|
79 | // ignore exception.
|
---|
80 | }
|
---|
81 | }
|
---|
82 | }
|
---|
83 |
|
---|
84 | }
|
---|