ContactDetailsRaw: list of types on ADD + Main: better syserr
authorNiki Roo <niki@nikiroo.be>
Mon, 4 Apr 2016 18:21:10 +0000 (20:21 +0200)
committerNiki Roo <niki@nikiroo.be>
Mon, 4 Apr 2016 18:21:10 +0000 (20:21 +0200)
src/be/nikiroo/jvcard/launcher/Main.java
src/be/nikiroo/jvcard/tui/panes/ContactDetailsRaw.java

index f96e5581b05f99c12f69c3af4603284f4065815f..6d552febfae8c16955cde0ad95480f32ef5bdc40 100644 (file)
@@ -288,12 +288,17 @@ public class Main {
                                Optional.runServer(port);
                        } catch (Exception e) {
                                if (e instanceof IOException) {
-                                       System.err
-                                                       .println("I/O Exception: Cannot start the server");
-                               } else {
+                                       ERR(StringId.CLI_ERR, StringId.CLI_ERR_CANNOT_START,
+                                                       ERR_INTERNAL);
+                                       return;
+                               } else if (e instanceof ClassNotFoundException) {
                                        ERR(StringId.CLI_ERR, StringId.CLI_ERR_NO_REMOTING,
                                                        ERR_INTERNAL);
                                        return;
+                               } else {
+                                       e.printStackTrace();
+                                       ERR(StringId.CLI_ERR, StringId.CLI_ERR, ERR_INTERNAL);
+                                       return;
                                }
                        }
                        break;
@@ -302,9 +307,9 @@ public class Main {
                        try {
                                transService.updateFile(dir);
                        } catch (IOException e) {
-                               System.err.println(trans(StringId.CLI_ERR_CANNOT_CREATE_LANG,
-                                               dir));
-                               e.printStackTrace();
+                               ERR(StringId.CLI_ERR, StringId.CLI_ERR_CANNOT_CREATE_LANG,
+                                               ERR_INTERNAL);
+                               return;
                        }
                        break;
                }
@@ -392,9 +397,13 @@ public class Main {
                                        ERR(StringId.CLI_ERR, StringId.CLI_ERR_CANNOT_START,
                                                        ERR_NO_FILE);
                                        return;
-                               } else {
+                               } else if (e instanceof ClassNotFoundException) {
                                        ERR(StringId.CLI_ERR, StringId.CLI_ERR_NO_TUI, ERR_INTERNAL);
                                        return;
+                               } else {
+                                       e.printStackTrace();
+                                       ERR(StringId.CLI_ERR, StringId.CLI_ERR, ERR_INTERNAL);
+                                       return;
                                }
                        }
                        break;
index 2de99192050af84249affc547dbaa5a073e596d7..08c0e4aa503ed2eea4c5de195715a9b5cef38857 100644 (file)
@@ -13,7 +13,10 @@ import be.nikiroo.jvcard.resources.enums.StringId;
 import be.nikiroo.jvcard.tui.KeyAction;
 import be.nikiroo.jvcard.tui.KeyAction.DataType;
 import be.nikiroo.jvcard.tui.KeyAction.Mode;
+import be.nikiroo.jvcard.tui.TuiLauncher;
 
+import com.googlecode.lanterna.gui2.MultiWindowTextGUI;
+import com.googlecode.lanterna.gui2.dialogs.ActionListDialogBuilder;
 import com.googlecode.lanterna.input.KeyType;
 
 public class ContactDetailsRaw extends MainContentList {
@@ -112,8 +115,59 @@ public class ContactDetailsRaw extends MainContentList {
                                return null;
                        }
                });
-               // TODO: ui
+               // TODO: ui and i18n
                actions.add(new KeyAction(Mode.ASK_USER, 'a', StringId.KEY_ACTION_ADD) {
+                       private String name;
+
+                       @Override
+                       public boolean onAction() {
+                               new ActionListDialogBuilder()
+                                               .setTitle("New data")
+                                               .setDescription("Choose a data type")
+                                               .addAction("Email address", new Runnable() {
+                                                       @Override
+                                                       public void run() {
+                                                               name = "EMAIL";
+                                                       }
+                                               })
+                                               .addAction("Telephone number", new Runnable() {
+                                                       @Override
+                                                       public void run() {
+                                                               name = "TEL";
+                                                       }
+                                               })
+                                               .addAction("Birthday", new Runnable() {
+                                                       @Override
+                                                       public void run() {
+                                                               name = "BDAY";
+                                                       }
+                                               })
+                                               .addAction("[other]", new Runnable() {
+                                                       @Override
+                                                       public void run() {
+                                                               name = "";
+                                                       }
+                                               })
+                                               .build()
+                                               .showDialog(
+                                                               new MultiWindowTextGUI(TuiLauncher.getScreen()));
+
+                               String name = this.name;
+                               this.name = null;
+
+                               if (name != null) {
+                                       if (name.length() > 0) {
+                                               Data data = new Data(null, name, "", null);
+                                               getContact().add(data);
+                                               addItem("x");
+                                       }
+
+                                       return (name.length() == 0);
+                               }
+
+                               return false;
+                       }
+
                        @Override
                        public Object getObject() {
                                return contact;
@@ -122,27 +176,20 @@ public class ContactDetailsRaw extends MainContentList {
                        @Override
                        public String getQuestion() {
                                // TODO i18n
-                               return "new data (xx.group = yy): ";
+                               if (name == null)
+                                       return "Data name: ";
+
+                               return null;
                        }
 
                        @Override
                        public String callback(String answer) {
-                               int indexEq = answer.indexOf('=');
-                               if (indexEq >= 0) {
-                                       String name = answer.substring(0, indexEq).trim();
-                                       String value = answer.substring(indexEq + 1).trim();
-                                       String group = null;
-
-                                       int indexDt = name.indexOf('.');
-                                       if (indexDt >= 0) {
-                                               group = name.substring(indexDt + 1).trim();
-                                               name = name.substring(0, indexDt).trim();
-                                       }
-
-                                       Data data = new Data(null, name, value, group);
+                               if (answer != null & answer.length() > 0) {
+                                       Data data = new Data(null, answer, "", null);
                                        getContact().add(data);
                                        addItem("x");
                                }
+
                                return null;
                        }
                });