Beta2 relase
[jvcard.git] / src / be / nikiroo / jvcard / tui / panes / MainContentList.java
index cac03e2426c615b9e61b2420d049408ed4d15f67..4b6d8ad13b2ad40d77d1f0f02caf90b645638210 100644 (file)
@@ -4,6 +4,7 @@ import java.util.LinkedList;
 import java.util.List;
 
 import be.nikiroo.jvcard.i18n.Trans.StringId;
+import be.nikiroo.jvcard.tui.Main;
 import be.nikiroo.jvcard.tui.StringUtils;
 import be.nikiroo.jvcard.tui.UiColors;
 import be.nikiroo.jvcard.tui.UiColors.Element;
@@ -55,8 +56,7 @@ abstract public class MainContentList extends MainContent implements Runnable {
                }
        }
 
-       public MainContentList(final UiColors.Element normalStyle,
-                       final UiColors.Element selectedStyle) {
+       public MainContentList() {
                super(Direction.VERTICAL);
 
                lines = new ActionListBox();
@@ -125,6 +125,39 @@ abstract public class MainContentList extends MainContent implements Runnable {
                lines.addItem(line, this);
        }
 
+       /**
+        * Delete the given item.
+        * 
+        * Remark: it will only delete the first found instance if multiple
+        * instances of this item are present.
+        * 
+        * @param line
+        *            the line to delete
+        * 
+        * @return TRUE if the item was deleted
+        */
+       public boolean removeItem(String line) {
+               boolean deleted = false;
+
+               List<Runnable> copy = lines.getItems();
+               for (int index = 0; index < copy.size(); index++) {
+                       if (copy.get(index).toString().equals(line)) {
+                               deleted = true;
+                               copy.remove(index);
+                               break;
+                       }
+               }
+
+               int index = getSelectedIndex();
+               clearItems();
+               for (Runnable run : copy) {
+                       addItem(run.toString());
+               }
+               setSelectedIndex(index);
+               
+               return deleted;
+       }
+
        /**
         * Clear all the items in this {@link MainContentList}
         */
@@ -157,7 +190,7 @@ abstract public class MainContentList extends MainContent implements Runnable {
         * @return the separator
         */
        public String getSeparator() {
-               return StringId.DEAULT_FIELD_SEPARATOR.trans();
+               return Main.trans(StringId.DEAULT_FIELD_SEPARATOR);
        }
 
        @Override