]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics/src/org/simantics/ConsoleUserAgent.java
Include acorn db in db.client feature and make it the default db driver
[simantics/platform.git] / bundles / org.simantics / src / org / simantics / ConsoleUserAgent.java
1 /*******************************************************************************\r
2  * Copyright (c) 2011 Association for Decentralized Information Management in\r
3  * Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics;\r
13 \r
14 import java.io.IOException;\r
15 \r
16 import org.simantics.databoard.util.binary.InputStreamReadable;\r
17 \r
18 /**\r
19  * @author Tuukka Lehtonen\r
20  */\r
21 public class ConsoleUserAgent implements PlatformUserAgent {\r
22 \r
23     @Override\r
24     public int showPrompt(String title, String message, String[] options, int defaultChoice) {\r
25         try {\r
26             boolean ok = false;\r
27             while (!ok) {\r
28                 System.out.println("== " + title + " ==\n");\r
29                 System.out.println(message + "\n");\r
30                 for (int i = 0; i < options.length; ++i)\r
31                     System.out.println("[" + i + "] " + options[i]);\r
32                 System.out.print("Select [");\r
33                 for (int i = 0; i < options.length; ++i)\r
34                     System.out.print(i);\r
35                 System.out.println("] (default = " + defaultChoice + ") ? ");\r
36 \r
37                 InputStreamReadable rdr  = new InputStreamReadable(System.in, 1);\r
38                 String str = rdr.readLine();\r
39                 //System.out.println("READ: '" + str + "'");\r
40                 try {\r
41                     int choice = Integer.parseInt(str);\r
42                     if (choice >= 0 && choice < options.length) {\r
43                         ok = true;\r
44                         return choice;\r
45                     }\r
46                 } catch (NumberFormatException e) {\r
47                     // Just repeat the question if input is unintelligible\r
48                 }\r
49             }\r
50         } catch (IOException e) {\r
51             e.printStackTrace();\r
52         }\r
53         return defaultChoice;\r
54     }\r
55 \r
56 }\r