chiark / gitweb /
check the user has not reorganised the table
authorIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sat, 4 Sep 2010 16:29:42 +0000 (17:29 +0100)
committerIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sat, 4 Sep 2010 16:29:42 +0000 (17:29 +0100)
src/com/tedpearson/ypp/market/MarketUploader.java

index 7632c01..729c686 100644 (file)
@@ -378,12 +378,12 @@ public class MarketUploader implements TopLevelWindowListener, GUIInitializedLis
                        yarrgts = getYarrgTimestamp();
                }
 
-               AccessibleTable t = findMarketTable();
-               if(t == null) {
+               AccessibleTable accesstable = findMarketTable();
+               if(accesstable == null) {
                        error("Market table not found! Please open the Buy/Sell Commodities interface.");
                        return;
                }
-               if(t.getAccessibleRowCount() == 0) {
+               if(accesstable.getAccessibleRowCount() == 0) {
                        error("No data found, please wait for the table to have data first!");
                        return;
                }
@@ -399,7 +399,29 @@ public class MarketUploader implements TopLevelWindowListener, GUIInitializedLis
                    latch.await(2, java.util.concurrent.TimeUnit.SECONDS);
                }
 
-               ArrayList<ArrayList<String>> data = getData(t);
+               String headings_expected[] = new String[]
+                   { "Commodity", "Trading outlet", "Buy price", "Will buy", "Sell price", "Will sell" };
+               ArrayList<ArrayList<String>> headers = getData(accesstable.getAccessibleColumnHeader());
+               if (headers.size() != 1) {
+                   error("Table headings not one row! " + headers.toString());
+                   return;
+               }
+               if (headers.get(0).size() != 6) {
+                   error("Table headings not six columns! " + headers.toString());
+                   return;
+               }
+               for (int col=0; col<headings_expected.length; col++) {
+                   String expd = headings_expected[col];
+                   String got = headers.get(0).get(col);
+                   if (expd.compareTo(got) != 0) {
+                       error("Table heading for column "+col
+                             +" is not \""+expd+"\" but \""+got+"\".\n\n"
+                             +"Please do not reorder the table when using this tool.");
+                       return;
+                   }
+               }
+
+               ArrayList<ArrayList<String>> data = getData(accesstable);
 
                if (uploadToYarrg && yarrgts != null) {
                        pm.setNote("Yarrg: Preparing data");