Colours are now taken from a .properties file
[jvcard.git] / src / be / nikiroo / jvcard / tui / panes / ContactDetailsRaw.java
index 506eeff96f28481b2c5a9c0303ccde3e40e6ad83..ec1a13640beffc4c001a4341a2dfdbe61e94f405 100644 (file)
@@ -3,34 +3,116 @@ package be.nikiroo.jvcard.tui.panes;
 import java.util.LinkedList;
 import java.util.List;
 
-import com.googlecode.lanterna.input.KeyType;
-
 import be.nikiroo.jvcard.Contact;
 import be.nikiroo.jvcard.Data;
 import be.nikiroo.jvcard.TypeInfo;
 import be.nikiroo.jvcard.i18n.Trans;
 import be.nikiroo.jvcard.tui.KeyAction;
-import be.nikiroo.jvcard.tui.UiColors;
 import be.nikiroo.jvcard.tui.KeyAction.DataType;
 import be.nikiroo.jvcard.tui.KeyAction.Mode;
 import be.nikiroo.jvcard.tui.StringUtils;
+import be.nikiroo.jvcard.tui.UiColors;
 import be.nikiroo.jvcard.tui.UiColors.Element;
 
+import com.googlecode.lanterna.input.KeyType;
+
 public class ContactDetailsRaw extends MainContentList {
        private Contact contact;
        private int mode;
 
        public ContactDetailsRaw(Contact contact) {
-               super(null, null);
-
                this.contact = contact;
                this.mode = 0;
 
-               for (int i = 0; i < contact.getContent().size(); i++) {
+               for (int i = 0; i < contact.size(); i++) {
                        addItem("[detail line]");
                }
        }
 
+       @Override
+       public DataType getDataType() {
+               return DataType.DATA;
+       }
+
+       @Override
+       public List<KeyAction> getKeyBindings() {
+               // TODO Auto-generated method stub
+               List<KeyAction> actions = new LinkedList<KeyAction>();
+
+               // TODO: add, remove
+               actions.add(new KeyAction(Mode.ASK_USER, KeyType.Enter,
+                               Trans.StringId.DUMMY) {
+                       @Override
+                       public Object getObject() {
+                               return contact.get(getSelectedIndex());
+                       }
+
+                       @Override
+                       public String getQuestion() {
+                               Data data = getData();
+                               if (data != null) {
+                                       return data.getName();
+                               }
+
+                               return null;
+                       }
+
+                       @Override
+                       public String getDefaultAnswer() {
+                               Data data = getData();
+                               if (data != null) {
+                                       return data.getValue();
+                               }
+
+                               return null;
+                       }
+
+                       @Override
+                       public String callback(String answer) {
+                               Data data = getData();
+                               if (data != null) {
+                                       data.setValue(answer);
+                                       return null;
+                               }
+
+                               // TODO: i18n
+                               return "Cannot modify value";
+                       }
+               });
+               actions.add(new KeyAction(Mode.NONE, KeyType.Tab,
+                               Trans.StringId.KEY_ACTION_SWITCH_FORMAT) {
+                       @Override
+                       public boolean onAction() {
+                               mode++;
+                               if (mode > 1)
+                                       mode = 0;
+
+                               return false;
+                       }
+               });
+
+               return actions;
+       }
+
+       @Override
+       public String getTitle() {
+               String title = null;
+
+               if (contact != null) {
+                       title = contact.getPreferredDataValue("FN");
+                       if (title == null || title.length() == 0)
+                               title = contact.getPreferredDataValue("N");
+               }
+
+               return title;
+       }
+
+       @Override
+       public String move(int x, int y) {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
        @Override
        protected List<TextPart> getLabel(int index, int width, boolean selected,
                        boolean focused) {
@@ -44,7 +126,7 @@ public class ContactDetailsRaw extends MainContentList {
                Element elDirty = (focused && selected) ? Element.CONTACT_LINE_DIRTY_SELECTED
                                : Element.CONTACT_LINE_DIRTY;
 
-               Data data = contact.getContent().get(index);
+               Data data = contact.get(index);
 
                List<TextPart> parts = new LinkedList<TextPart>();
                if (data.isDirty()) {
@@ -67,7 +149,8 @@ public class ContactDetailsRaw extends MainContentList {
                        }
                        break;
                case 1:
-                       for (TypeInfo type : data.getTypes()) {
+                       for (int indexType = 0; indexType < data.size(); indexType++) {
+                               TypeInfo type = data.get(indexType);
                                if (valueBuilder.length() > 1)
                                        valueBuilder.append(", ");
                                valueBuilder.append(type.getName());
@@ -94,65 +177,4 @@ public class ContactDetailsRaw extends MainContentList {
                return parts;
        };
 
-       @Override
-       public DataType getDataType() {
-               return DataType.DATA;
-       }
-
-       @Override
-       public String getExitWarning() {
-               // TODO Auto-generated method stub
-               return null;
-       }
-
-       @Override
-       public List<KeyAction> getKeyBindings() {
-               // TODO Auto-generated method stub
-               List<KeyAction> actions = new LinkedList<KeyAction>();
-
-               // TODO: add, remove
-               actions.add(new KeyAction(Mode.EDIT_DETAIL, 'd', Trans.StringId.DUMMY) {
-                       @Override
-                       public Object getObject() {
-                               return contact.getContent().get(getSelectedIndex());
-                       }
-               });
-               actions.add(new KeyAction(Mode.NONE, KeyType.Tab,
-                               Trans.StringId.KEY_ACTION_SWITCH_FORMAT) {
-                       @Override
-                       public boolean onAction() {
-                               mode++;
-                               if (mode > 1)
-                                       mode = 0;
-
-                               return false;
-                       }
-               });
-
-               return actions;
-       }
-
-       @Override
-       public Mode getMode() {
-               return Mode.CONTACT_DETAILS;
-       }
-
-       @Override
-       public String getTitle() {
-               String title = null;
-
-               if (contact != null) {
-                       title = contact.getPreferredDataValue("FN");
-                       if (title == null || title.length() == 0)
-                               title = contact.getPreferredDataValue("N");
-               }
-
-               return title;
-       }
-
-       @Override
-       public String move(int x, int y) {
-               // TODO Auto-generated method stub
-               return null;
-       }
 }