fix contrib maanger problems with empty list

This commit is contained in:
benfry
2012-11-25 00:19:47 +00:00
parent 139d44c4b4
commit a04cc2d4d2
4 changed files with 68 additions and 64 deletions

View File

@@ -34,15 +34,10 @@ import processing.core.PApplet;
public class ContributionListing {
ArrayList<ContributionChangeListener> listeners;
ArrayList<AdvertisedContribution> advertisedContributions;
Map<String, List<Contribution>> librariesByCategory;
ArrayList<Contribution> allContributions;
boolean hasDownloadedLatestList;
ReentrantLock downloadingListingLock;
static protected final String validCategories[] = {
@@ -204,19 +199,22 @@ public class ContributionListing {
}
public Set<String> getCategories(Filter filter) {
Set<String> ret = new HashSet<String>();
Set<String> outgoing = new HashSet<String>();
Set<String> cats = librariesByCategory.keySet();
for (String cat : cats) {
for (Contribution contrib : librariesByCategory.get(cat)) {
Set<String> categorySet = librariesByCategory.keySet();
for (String categoryName : categorySet) {
for (Contribution contrib : librariesByCategory.get(categoryName)) {
if (filter.matches(contrib)) {
ret.add(cat);
// TODO still not sure why category would be coming back null [fry]
// http://code.google.com/p/processing/issues/detail?id=1387
if (categoryName != null && categoryName.trim().length() != 0) {
outgoing.add(categoryName);
}
break;
}
}
}
return ret;
return outgoing;
}
public List<Contribution> getAllContributions() {

View File

@@ -249,16 +249,20 @@ public class ContributionManagerDialog {
}
private void updateCategoryChooser() {
if (categoryChooser == null)
return;
ArrayList<String> categories;
categoryChooser.removeAllItems();
categories = new ArrayList<String>(contribListing.getCategories(permaFilter));
Collections.sort(categories);
categories.add(0, ContributionManagerDialog.ANY_CATEGORY);
for (String s : categories) {
categoryChooser.addItem(s);
if (categoryChooser != null) {
ArrayList<String> categories;
categoryChooser.removeAllItems();
categories = new ArrayList<String>(contribListing.getCategories(permaFilter));
// for (int i = 0; i < categories.size(); i++) {
// System.out.println(i + " category: " + categories.get(i));
// }
Collections.sort(categories);
// categories.add(0, ContributionManagerDialog.ANY_CATEGORY);
categoryChooser.addItem(ContributionManagerDialog.ANY_CATEGORY);
for (String s : categories) {
categoryChooser.addItem(s);
}
categoryChooser.setEnabled(categories.size() != 0);
}
}

View File

@@ -34,52 +34,50 @@ import java.net.URLConnection;
public class FileDownloader {
/**
* Blocks until the file is downloaded or an error occurs. Returns true if the
* file was successfully downloaded, false otherwise
* Blocks until the file is downloaded or an error occurs.
* Returns true if the file was successfully downloaded, false otherwise.
*
* @param source
* the URL of the file to donwload
* the URL of the file to download
* @param dest
* the file on the local system where the file will be written. This
* must be a file (not a directory), and must already exist.
* @param progressMonitor
* @param progress
* @throws FileNotFoundException
* if an error occurred downloading the file
*/
static public void downloadFile(URL source, File dest,
ProgressMonitor progressMonitor) {
ProgressMonitor progress) {
try {
URLConnection urlConn = source.openConnection();
urlConn.setConnectTimeout(1000);
urlConn.setReadTimeout(5000);
// System.out.println("downloading file " + source);
URLConnection conn = source.openConnection();
conn.setConnectTimeout(1000);
conn.setReadTimeout(5000);
// String expectedType1 = "application/x-zip-compressed";
// String expectedType2 = "application/zip";
// String type = urlConn.getContentType();
// if (expectedType1.equals(type) || expectedType2.equals(type)) {
// }
// TODO this is often -1, may need to set progress to indeterminate
int fileSize = conn.getContentLength();
// System.out.println("file size is " + fileSize);
progress.startTask("Downloading", fileSize);
int fileSize = urlConn.getContentLength();
progressMonitor.startTask("Downloading", fileSize);
InputStream in = urlConn.getInputStream();
InputStream in = conn.getInputStream();
FileOutputStream out = new FileOutputStream(dest);
byte[] b = new byte[256];
int bytesDownloaded = 0, len;
while (!progressMonitor.isCanceled() && (len = in.read(b)) != -1) {
out.write(b, 0, len);
bytesDownloaded += len;
progressMonitor.setProgress(bytesDownloaded);
byte[] b = new byte[8192];
int amount;
int total = 0;
while (!progress.isCanceled() && (amount = in.read(b)) != -1) {
out.write(b, 0, amount);
total += amount;
progress.setProgress(total);
}
out.flush();
out.close();
} catch (IOException ioe) {
progressMonitor.error(ioe);
progress.error(ioe);
ioe.printStackTrace();
}
progressMonitor.finished();
progress.finished();
// System.out.println("done downloading");
}
}

View File

@@ -25,18 +25,22 @@ X Sketch that exported to Linux doesn't get the command line arguments
X http://code.google.com/p/processing/issues/detail?id=1359
X "electricScroll" feature causing weird jumps when double-clicking
X http://code.google.com/p/processing/issues/detail?id=1055
_ fix the debug stuff before shipping this out
_ DebugMode throwing exception about breakpoints when trying to save
earlier
X The sketch name can't begin with '_' (underscore)
X http://code.google.com/p/processing/issues/detail?id=859
X crash during library download was causing empty library list
X http://code.google.com/p/processing/issues/detail?id=1093
X clientEvent() called even w/o data from server (with fix)
X http://code.google.com/p/processing/issues/detail?id=189
X check on adding ip() method
X http://code.google.com/p/processing/issues/detail?id=1228
_ fix the debug stuff before shipping this out
_ DebugMode throwing exception about breakpoints when trying to save
earlier
X The sketch name can't begin with '_' (underscore)
X http://code.google.com/p/processing/issues/detail?id=859
_ if RuntimeException thrown, needs to check if it's a wrapped exception
_ for instance, if there's a crash inside makeGraphics()
@@ -78,15 +82,12 @@ _ change cmd line for OS X to use symlink?
_ otherwise updates are going to require reinstall..
_ or that it's gonna need to parse and say "update command line?"
_ TextAreaDefaults - is editable in use?
2.0 FINAL / library/tool/mode manager cleanup
_ a couple notes
_ make already installed libraries distinguishable in the list
_ http://code.google.com/p/processing/issues/detail?id=1212
_ complaint that dropdown list is too small
_ http://code.google.com/p/processing/issues/detail?id=1093
_ TextAreaDefaults
_ is editable in use?
_ what's electricScroll?
_ excessive CPU usage of PDE after using library manager
_ http://code.google.com/p/processing/issues/detail?id=1036
_ confirmed to still be a problem with b5/6
@@ -99,6 +100,9 @@ _ list in the PDE would be updated automatically by querying a web service
_ list on the website would be generated using the same web service
_ All I would need to do is update web/contrib_generate/sources.conf
_ and the rest would happen automatically.
_ alternating blue/white backgrounds aren't updated after changing filter
_ using "Add Library" requires restart of Processing before lib recognized
_ http://code.google.com/p/processing/issues/detail?id=1387
2.0 FINAL / new interface