Changeset 3655


Ignore:
Timestamp:
Aug 10, 2007, 2:22:57 PM (14 years ago)
Author:
Nicklas Nordborg
Message:

Fixes #720: Progress reporter when emptying trashcan

Location:
trunk
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/core/net/sf/basedb/core/Trashcan.java

    r3526 r3655  
    143143    @param items The items to remove
    144144    @param ignoreFlag TRUE to also remove items that hasn't been flagged for removal
     145    @param progress An optional progress reporter
    145146    @return The number of deleted items
    146147    @since 2.4
    147148  */
    148   public static int delete(SessionControl sc, Collection<? extends Identifiable> items, boolean ignoreFlag)
     149  public static int delete(SessionControl sc, Collection<? extends Identifiable> items,
     150    boolean ignoreFlag, ProgressReporter progress)
    149151    throws BaseException
    150152  {
     153    if (progress != null) progress.display(0, "Checking which items to remove...");
     154   
    151155    // Copy items to a set with predictable iteration order
    152156    Set<Identifiable> itemsToRemove = new TreeSet<Identifiable>(Item.DELETION_ORDER);
     
    167171   
    168172    if (itemsToRemove.size() == 0) return 0;
     173    int numToRemove = itemsToRemove.size();
     174    float progressFactor = 100.0f / numToRemove;
    169175    int numRemoved = 0;
    170176    int removedInTransaction = 0;
     
    185191        {
    186192          Identifiable item = iterator.next();
     193          if (progress != null)
     194          {
     195            String name = item instanceof Nameable ? ((Nameable)item).getName() : item.toString();
     196            progress.display((int)(numRemoved * progressFactor), "Remove " +
     197                item.getType() + ": " + name +
     198                " (" + (numRemoved + 1) + " of " + numToRemove + ")");
     199          }
    187200          BasicItem basicItem = item.getType().getById(dc, item.getId());
    188201          if (!basicItem.isUsed())
     
    197210          {
    198211            if (isDebug) log.debug("Item is used: " + basicItem);
     212            if (progress != null) progress.append(" [USED]");
    199213            if (removedInTransaction > 0)
    200214            {
     
    207221          " items scheduled for deletion; " + numRemoved + " total so far; " +
    208222          itemsToRemove.size() + " remains in list");
     223        if (progress != null)
     224        {
     225          progress.display((int)(numRemoved * progressFactor),
     226            numRemoved + " of " + numToRemove + " items removed; flushing to database");
     227        }
    209228        dc.commit();
    210229      }
     
    214233      }
    215234    } while (removedInTransaction > 0 && itemsToRemove.size() > 0);
     235   
     236    if (progress != null)
     237    {
     238      String msg = "";
     239      if (numRemoved < numToRemove)
     240      {
     241        msg = numRemoved + " of " + numToRemove + " items removed. " +
     242          (numToRemove - numRemoved) + " items are used and can't be removed";
     243      }
     244      else
     245      {
     246        msg = "All " + numToRemove + " items removed";
     247      }
     248      progress.display(100, msg);
     249    }
    216250    return numRemoved;
    217251  }
     
    220254    Delete all items in the trashcan of the logged in user. This method
    221255    calls {@link #getItems(DbControl, Item, int, int)} to load all items
    222     that have been flagged for removal and then {@link #delete(SessionControl, Collection, boolean)}
     256    that have been flagged for removal and then
     257    {@link #delete(SessionControl, Collection, boolean, ProgressReporter)}
    223258    to remove those items. See the <code>delete</code> for
    224259    more information about transactions.
    225260   
    226261    @param sc The session control to use for connecting to the database
     262    @param progress An optional progress reporter
    227263    @return The number of deleted items
    228264    @since 2.4
    229265  */
    230   public static int deleteAll(SessionControl sc)
     266  public static int deleteAll(SessionControl sc, ProgressReporter progress)
    231267  {
    232268    DbControl dc = sc.newDbControl();
     
    235271      List<Removable> items = getItems(dc, null, 0, 0);
    236272      dc.close();
    237       return delete(sc, items, false);
     273      return delete(sc, items, false, progress);
    238274    }
    239275    finally
  • trunk/src/plugins/core/net/sf/basedb/plugins/IlluminaRawDataImporter.java

    r3637 r3655  
    473473      if (!success && rawBioAssays != null)
    474474      {
    475         Trashcan.delete(sc, rawBioAssays, true);       
     475        Trashcan.delete(sc, rawBioAssays, true, null);       
    476476      }
    477477      super.end(success);
  • trunk/www/views/trashcan/index.jsp

    r3550 r3655  
    3636  import="net.sf.basedb.core.ItemInUseException"
    3737  import="net.sf.basedb.core.PermissionDeniedException"
     38  import="net.sf.basedb.core.SimpleProgressReporter"
    3839  import="net.sf.basedb.clients.web.Base"
    3940  import="net.sf.basedb.clients.web.WebException"
     
    115116   
    116117    int numTotal = items.size();
    117     int numRemoved = Trashcan.delete(sc, items, false);
     118    SimpleProgressReporter progress = new SimpleProgressReporter(null);
     119    sc.setSessionSetting("progress.trashcan", progress);
     120    int numRemoved = Trashcan.delete(sc, items, false, progress);
    118121
    119122    if (numTotal != numRemoved)
     
    243246    dc.close();
    244247    int numTotal = items.size();
    245     int numRemoved = Trashcan.delete(sc, items, false);
     248    SimpleProgressReporter progress = new SimpleProgressReporter(null);
     249    sc.setSessionSetting("progress.trashcan", progress);
     250    int numRemoved = Trashcan.delete(sc, items, false, progress);
    246251   
    247252    if (numTotal != numRemoved)
  • trunk/www/views/trashcan/list_trash.jsp

    r3549 r3655  
    101101        return;
    102102      }
     103      Main.openPopup('../../common/progress_reporter.jsp?ID=<%=ID%>&progress=trashcan&title=Empty trashcan', 'Progress', 400, 200);
    103104      var frm = document.forms[formId];
    104105      frm.action = submitPage;
     
    123124        }
    124125      }
     126      Main.openPopup('../../common/progress_reporter.jsp?ID=<%=ID%>&progress=trashcan&title=Delete items', 'Progress', 400, 200);
    125127      frm.action = submitPage;
    126128      frm.cmd.value = 'DeleteItemsPermanently';
Note: See TracChangeset for help on using the changeset viewer.