From 3ca68fef66997aa500f28cd9c1d5ba6d565d004f Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Tue, 5 Aug 2008 14:52:09 +0000 Subject: Client: Fixed yet another client item bug This once was caused by a combination of having more than one subscription in the database and a bug in the subscription retrieval method. The bug has been fixed which allows us to add back the Item buffer (removed in [68] because it was thought to be the cause of another Client Item bug) Fixes #18. --- .../com/fourisland/instadisc/Database/Wrapper.java | 57 ++++++++-------------- .../instadisc/Item/SubscriptionFile.java | 2 +- .../instadisc/ManageSubscriptionsForm.java | 14 +++--- 3 files changed, 26 insertions(+), 47 deletions(-) diff --git a/client/trunk/src/com/fourisland/instadisc/Database/Wrapper.java b/client/trunk/src/com/fourisland/instadisc/Database/Wrapper.java index a5c59e8..6ab0c72 100644 --- a/client/trunk/src/com/fourisland/instadisc/Database/Wrapper.java +++ b/client/trunk/src/com/fourisland/instadisc/Database/Wrapper.java @@ -12,6 +12,7 @@ import com.sleepycat.persist.EntityStore; import com.sleepycat.persist.PrimaryIndex; import com.sleepycat.persist.StoreConfig; import java.io.File; +import java.util.Collection; import java.util.Iterator; import java.util.logging.Level; import java.util.logging.Logger; @@ -169,26 +170,16 @@ public class Wrapper { public static Subscription[] getAllSubscription() { synchronized (subscription) { - try { - Iterator i = subscription.entities().iterator(); - Subscription[] temp = new Subscription[0]; - int len = 0; - - while (i.hasNext()) { - Subscription[] temp2 = new Subscription[len + 1]; - int j = 0; - for (j = 0; j < len; j++) { - temp2[j] = temp[j]; - } - temp2[len] = i.next(); - temp = temp2; - } - - return temp; - } catch (DatabaseException ex) { - Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex); - return new Subscription[0]; + Collection vals = subscription.map().values(); + Subscription subs[] = new Subscription[vals.size()]; + Iterator i = vals.iterator(); + int j=0; + while (i.hasNext()) + { + subs[j] = i.next(); + j++; } + return subs; } } @@ -240,26 +231,16 @@ public class Wrapper { public static Filter[] getAllFilter() { synchronized (filter) { - try { - Iterator i = filter.entities().iterator(); - Filter[] temp = new Filter[0]; - int len = 0; - - while (i.hasNext()) { - Filter[] temp2 = new Filter[len + 1]; - int j = 0; - for (j = 0; j < len; j++) { - temp2[j] = temp[j]; - } - temp2[len] = i.next(); - temp = temp2; - } - - return temp; - } catch (DatabaseException ex) { - Logger.getLogger(Wrapper.class.getName()).log(Level.SEVERE, null, ex); - return new Filter[0]; + Collection vals = filter.map().values(); + Filter fils[] = new Filter[vals.size()]; + Iterator i = vals.iterator(); + int j=0; + while (i.hasNext()) + { + fils[j] = i.next(); + j++; } + return fils; } } } diff --git a/client/trunk/src/com/fourisland/instadisc/Item/SubscriptionFile.java b/client/trunk/src/com/fourisland/instadisc/Item/SubscriptionFile.java index eae52a1..e6ba795 100644 --- a/client/trunk/src/com/fourisland/instadisc/Item/SubscriptionFile.java +++ b/client/trunk/src/com/fourisland/instadisc/Item/SubscriptionFile.java @@ -1,4 +1,4 @@ -/* + /* * To change this template, choose Tools | Templates * and open the template in the editor. */ diff --git a/client/trunk/src/com/fourisland/instadisc/ManageSubscriptionsForm.java b/client/trunk/src/com/fourisland/instadisc/ManageSubscriptionsForm.java index 94a8075..b1190f4 100644 --- a/client/trunk/src/com/fourisland/instadisc/ManageSubscriptionsForm.java +++ b/client/trunk/src/com/fourisland/instadisc/ManageSubscriptionsForm.java @@ -9,6 +9,7 @@ package com.fourisland.instadisc; import com.fourisland.instadisc.Database.Subscription; import com.fourisland.instadisc.Database.Wrapper; import com.fourisland.instadisc.Item.SubscriptionFile; +import java.util.Arrays; import javax.swing.DefaultListModel; /** @@ -23,7 +24,6 @@ public class ManageSubscriptionsForm extends javax.swing.JDialog { initComponents(); jList1.setCellRenderer(new IDSubscriptionListCellRenderer()); - jList1.setModel(lm); refreshSubscriptionPane(); } @@ -156,14 +156,12 @@ public class ManageSubscriptionsForm extends javax.swing.JDialog { DefaultListModel lm = new DefaultListModel(); public void refreshSubscriptionPane() { - lm.clear(); Subscription[] subscriptions = Wrapper.getAllSubscription(); - int i = 0; - for (i = 0; i < subscriptions.length; i++) { - lm.addElement(subscriptions[i]); - } + System.out.println(Arrays.deepToString(subscriptions)); + jList1.setListData(subscriptions); + jList1.repaint(); - jList1.setEnabled(!lm.isEmpty()); - jButton1.setEnabled(!lm.isEmpty()); + jList1.setEnabled((subscriptions.length != 0)); + jButton1.setEnabled((subscriptions.length != 0)); } } -- cgit 1.4.1