Changeset 3655
- Timestamp:
- Aug 10, 2007, 2:22:57 PM (16 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/core/net/sf/basedb/core/Trashcan.java
r3526 r3655 143 143 @param items The items to remove 144 144 @param ignoreFlag TRUE to also remove items that hasn't been flagged for removal 145 @param progress An optional progress reporter 145 146 @return The number of deleted items 146 147 @since 2.4 147 148 */ 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) 149 151 throws BaseException 150 152 { 153 if (progress != null) progress.display(0, "Checking which items to remove..."); 154 151 155 // Copy items to a set with predictable iteration order 152 156 Set<Identifiable> itemsToRemove = new TreeSet<Identifiable>(Item.DELETION_ORDER); … … 167 171 168 172 if (itemsToRemove.size() == 0) return 0; 173 int numToRemove = itemsToRemove.size(); 174 float progressFactor = 100.0f / numToRemove; 169 175 int numRemoved = 0; 170 176 int removedInTransaction = 0; … … 185 191 { 186 192 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 } 187 200 BasicItem basicItem = item.getType().getById(dc, item.getId()); 188 201 if (!basicItem.isUsed()) … … 197 210 { 198 211 if (isDebug) log.debug("Item is used: " + basicItem); 212 if (progress != null) progress.append(" [USED]"); 199 213 if (removedInTransaction > 0) 200 214 { … … 207 221 " items scheduled for deletion; " + numRemoved + " total so far; " + 208 222 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 } 209 228 dc.commit(); 210 229 } … … 214 233 } 215 234 } 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 } 216 250 return numRemoved; 217 251 } … … 220 254 Delete all items in the trashcan of the logged in user. This method 221 255 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)} 223 258 to remove those items. See the <code>delete</code> for 224 259 more information about transactions. 225 260 226 261 @param sc The session control to use for connecting to the database 262 @param progress An optional progress reporter 227 263 @return The number of deleted items 228 264 @since 2.4 229 265 */ 230 public static int deleteAll(SessionControl sc )266 public static int deleteAll(SessionControl sc, ProgressReporter progress) 231 267 { 232 268 DbControl dc = sc.newDbControl(); … … 235 271 List<Removable> items = getItems(dc, null, 0, 0); 236 272 dc.close(); 237 return delete(sc, items, false );273 return delete(sc, items, false, progress); 238 274 } 239 275 finally -
trunk/src/plugins/core/net/sf/basedb/plugins/IlluminaRawDataImporter.java
r3637 r3655 473 473 if (!success && rawBioAssays != null) 474 474 { 475 Trashcan.delete(sc, rawBioAssays, true );475 Trashcan.delete(sc, rawBioAssays, true, null); 476 476 } 477 477 super.end(success); -
trunk/www/views/trashcan/index.jsp
r3550 r3655 36 36 import="net.sf.basedb.core.ItemInUseException" 37 37 import="net.sf.basedb.core.PermissionDeniedException" 38 import="net.sf.basedb.core.SimpleProgressReporter" 38 39 import="net.sf.basedb.clients.web.Base" 39 40 import="net.sf.basedb.clients.web.WebException" … … 115 116 116 117 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); 118 121 119 122 if (numTotal != numRemoved) … … 243 246 dc.close(); 244 247 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); 246 251 247 252 if (numTotal != numRemoved) -
trunk/www/views/trashcan/list_trash.jsp
r3549 r3655 101 101 return; 102 102 } 103 Main.openPopup('../../common/progress_reporter.jsp?ID=<%=ID%>&progress=trashcan&title=Empty trashcan', 'Progress', 400, 200); 103 104 var frm = document.forms[formId]; 104 105 frm.action = submitPage; … … 123 124 } 124 125 } 126 Main.openPopup('../../common/progress_reporter.jsp?ID=<%=ID%>&progress=trashcan&title=Delete items', 'Progress', 400, 200); 125 127 frm.action = submitPage; 126 128 frm.cmd.value = 'DeleteItemsPermanently';
Note: See TracChangeset
for help on using the changeset viewer.