@Override public void awakeFromNib() { super.awakeFromNib(); // Initialize to listen for background tasks registry.addListener(backgroundActionListener); // Add already running background actions final BackgroundAction[] actions = registry.toArray( new BackgroundAction[registry.size()]); for(final BackgroundAction action : actions) { tasks.put(action, new TaskController(action)); } this.reload(); }
@Action public void disconnectButtonClicked(final ID sender) { // Remove all pending actions for(BackgroundAction action : registry.toArray( new BackgroundAction[registry.size()])) { action.cancel(); } this.disconnect(new Runnable() { @Override public void run() { if(preferences.getBoolean("browser.disconnect.bookmarks.show")) { selectBookmarks(BookmarkSwitchSegement.bookmarks); } else { selectBrowser(BrowserSwitchSegement.byPosition(preferences.getInteger("browser.view"))); } } }); }
@Override public void callback(int returncode) { if(returncode == DEFAULT_OPTION) { //Quit final BackgroundActionRegistry registry = shared.getRegistry(); for(BackgroundAction action : registry.toArray(new BackgroundAction[registry.size()])) { action.cancel(); } app.replyToApplicationShouldTerminate(true); } if(returncode == CANCEL_OPTION) { //Cancel app.replyToApplicationShouldTerminate(false); } } });
@Action public void stopAllButtonClicked(final ID sender) { final Collection<Transfer> transfers = transferTableModel.getSource(); for(final Transfer transfer : transfers) { if(transfer.isRunning()) { // Find matching background task for(BackgroundAction action : registry.toArray(new BackgroundAction[registry.size()])) { if(action instanceof TransferBackgroundAction) { final TransferBackgroundAction t = (TransferBackgroundAction) action; if(t.getTransfer().equals(transfer)) { t.cancel(); } } } } } }
@Action public void bandwidthPopupChanged(NSMenuItem sender) { final NSIndexSet selected = transferTable.selectedRowIndexes(); final float bandwidth = Float.valueOf(sender.representedObject()); for(NSUInteger index = selected.firstIndex(); !index.equals(NSIndexSet.NSNotFound); index = selected.indexGreaterThanIndex(index)) { final Transfer transfer = collection.get(index.intValue()); transfer.setBandwidth(bandwidth); if(transfer.isRunning()) { // Find matching background task for(BackgroundAction action : registry.toArray(new BackgroundAction[registry.size()])) { if(action instanceof TransferBackgroundAction) { final TransferBackgroundAction t = (TransferBackgroundAction) action; if(t.getTransfer().equals(transfer)) { final TransferSpeedometer meter = t.getMeter(); meter.reset(); } } } } } }
@Action public void stopButtonClicked(final ID sender) { final NSIndexSet selected = transferTable.selectedRowIndexes(); for(NSUInteger index = selected.firstIndex(); !index.equals(NSIndexSet.NSNotFound); index = selected.indexGreaterThanIndex(index)) { final Transfer transfer = transferTableModel.getSource().get(index.intValue()); if(transfer.isRunning()) { // Find matching background task for(BackgroundAction action : registry.toArray(new BackgroundAction[registry.size()])) { if(action instanceof TransferBackgroundAction) { final TransferBackgroundAction t = (TransferBackgroundAction) action; if(t.getTransfer().equals(transfer)) { t.cancel(); } } } } } }