X-Git-Url: http://git.nikiroo.be/?p=jvcard.git;a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Fjvcard%2Ftui%2Fpanes%2FMainContentList.java;h=4b6d8ad13b2ad40d77d1f0f02caf90b645638210;hp=e1358eff66f9659ada469ade30dc0a0f97d886d8;hb=176a83279a5aafb7e44cc7c34bf78f0bc35225fe;hpb=adf9c44949504512002cff293641225b31ec568a diff --git a/src/be/nikiroo/jvcard/tui/panes/MainContentList.java b/src/be/nikiroo/jvcard/tui/panes/MainContentList.java index e1358ef..4b6d8ad 100644 --- a/src/be/nikiroo/jvcard/tui/panes/MainContentList.java +++ b/src/be/nikiroo/jvcard/tui/panes/MainContentList.java @@ -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 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} */