@Action public void aclRemoveButtonClicked(ID sender) { List<Acl.UserAndRole> updated = new ArrayList<Acl.UserAndRole>(acl); NSIndexSet iterator = aclTable.selectedRowIndexes(); List<Acl.UserAndRole> remove = new ArrayList<Acl.UserAndRole>(); for(NSUInteger index = iterator.firstIndex(); !index.equals(NSIndexSet.NSNotFound); index = iterator.indexGreaterThanIndex(index)) { remove.add(updated.get(index.intValue())); } updated.removeAll(remove); this.setAcl(updated); this.aclInputDidEndEditing(); }
@Action public void metadataRemoveButtonClicked(ID sender) { List<Header> updated = new ArrayList<Header>(metadata); NSIndexSet iterator = metadataTable.selectedRowIndexes(); List<Header> remove = new ArrayList<Header>(); for(NSUInteger index = iterator.firstIndex(); !index.equals(NSIndexSet.NSNotFound); index = iterator.indexGreaterThanIndex(index)) { remove.add(updated.get(index.intValue())); } updated.removeAll(remove); this.setMetadata(updated); this.metadataInputDidEndEditing(); }
NSIndexSet iterator = bookmarkTable.selectedRowIndexes(); final List<Host> selected = new ArrayList<Host>(); for(NSUInteger index = iterator.firstIndex(); !index.equals(NSIndexSet.NSNotFound); index = iterator.indexGreaterThanIndex(index)) { selected.add(bookmarkModel.getSource().get(index.intValue()));
/** * @return All selected paths or an empty list if there is no selection */ public List<Path> getSelectedPaths() { final AbstractBrowserTableDelegate delegate = this.getSelectedBrowserDelegate(); final NSTableView view = this.getSelectedBrowserView(); final NSIndexSet iterator = view.selectedRowIndexes(); final List<Path> selected = new ArrayList<Path>(); for(NSUInteger index = iterator.firstIndex(); !index.equals(NSIndexSet.NSNotFound); index = iterator.indexGreaterThanIndex(index)) { final Path file = delegate.pathAtRow(index.intValue()); if(null == file) { break; } selected.add(file); } return selected; }
@Override public void callback(final int returncode) { if(returncode == DEFAULT_OPTION) { //Disconnect controller.window().close(); if(NSApplication.NSTerminateNow.equals(BrowserController.applicationShouldTerminate(app))) { app.replyToApplicationShouldTerminate(true); } } else { app.replyToApplicationShouldTerminate(false); } } }, new Runnable() {
/** * Invoked by view after it has been determined that a drag should begin, but before the drag has been started. * The drag image and other drag-related information will be set up and provided by the table view once this call * returns with true. * * @param rowIndexes is the list of row numbers that will be participating in the drag. * @return To refuse the drag, return false. To start a drag, return true and place the drag data onto pboard (data, owner, and so on). */ @Override public boolean tableView_writeRowsWithIndexes_toPasteboard(final NSTableView view, final NSIndexSet rowIndexes, final NSPasteboard pboard) { if(controller.isMounted()) { final AttributedList<Path> children = this.get(controller.workdir()); final List<Path> selected = new ArrayList<Path>(); for(NSUInteger index = rowIndexes.firstIndex(); !index.equals(NSIndexSet.NSNotFound); index = rowIndexes.indexGreaterThanIndex(index)) { selected.add(children.get(index.intValue())); } return super.writeItemsToPasteBoard(view, selected, pboard); } return false; }
@Action public void deleteButtonClicked(final ID sender) { final NSIndexSet selected = transferTable.selectedRowIndexes(); final Collection<Transfer> transfers = transferTableModel.getSource(); int i = 0; final List<Transfer> remove = new ArrayList<Transfer>(); for(NSUInteger index = selected.firstIndex(); !index.equals(NSIndexSet.NSNotFound); index = selected.indexGreaterThanIndex(index)) { final Transfer t = transfers.get(index.intValue() - i); if(!t.isRunning()) { remove.add(t); } } collection.removeAll(remove); collection.save(); }
@Action public void trashButtonClicked(final ID sender) { final NSIndexSet selected = transferTable.selectedRowIndexes(); final Collection<Transfer> transfers = transferTableModel.getSource(); for(NSUInteger index = selected.firstIndex(); !index.equals(NSIndexSet.NSNotFound); index = selected.indexGreaterThanIndex(index)) { final Transfer transfer = transfers.get(index.intValue()); if(!transfer.isRunning()) { for(TransferItem l : transfer.getRoots()) { try { LocalTrashFactory.get().trash(l.local); } catch(AccessDeniedException e) { log.warn(String.format("Failure trashing file %s %s", l.local, e.getMessage())); } } } } this.updateIcon(); }
@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(); } } } } } }
@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 revealButtonClicked(final ID sender) { final NSIndexSet selected = transferTable.selectedRowIndexes(); final Collection<Transfer> transfers = transferTableModel.getSource(); final RevealService reveal = RevealServiceFactory.get(); for(NSUInteger index = selected.firstIndex(); !index.equals(NSIndexSet.NSNotFound); index = selected.indexGreaterThanIndex(index)) { final Transfer transfer = transfers.get(index.intValue()); for(TransferItem l : transfer.getRoots()) { reveal.reveal(l.local); } } }
/** * Validates the selected items in the transfer window against the toolbar validator * * @param validator The validator to use * @return True if one or more of the selected items passes the validation test */ private boolean validate(final InnerTransferValidator validator) { final NSIndexSet iterator = controller.getTransferTable().selectedRowIndexes(); final Collection<Transfer> transfers = controller.getTransferTableModel().getSource(); for(NSUInteger index = iterator.firstIndex(); !index.equals(NSIndexSet.NSNotFound); index = iterator.indexGreaterThanIndex(index)) { final Transfer transfer = transfers.get(index.intValue()); if(validator.validate(transfer)) { return true; } } return false; }
@Action public void resumeButtonClicked(final ID sender) { final NSIndexSet selected = transferTable.selectedRowIndexes(); for(NSUInteger index = selected.firstIndex(); !index.equals(NSIndexSet.NSNotFound); index = selected.indexGreaterThanIndex(index)) { final Collection<Transfer> transfers = transferTableModel.getSource(); final Transfer transfer = transfers.get(index.intValue()); if(!transfer.isRunning()) { final TransferOptions options = new TransferOptions(); options.resumeRequested = true; options.reloadRequested = false; this.start(transfer, options); } } }
@Action public void reloadButtonClicked(final ID sender) { final NSIndexSet selected = transferTable.selectedRowIndexes(); for(NSUInteger index = selected.firstIndex(); !index.equals(NSIndexSet.NSNotFound); index = selected.indexGreaterThanIndex(index)) { final Collection<Transfer> transfers = transferTableModel.getSource(); final Transfer transfer = transfers.get(index.intValue()); if(!transfer.isRunning()) { final TransferOptions options = new TransferOptions(); options.resumeRequested = false; options.reloadRequested = true; this.start(transfer, options); } } }
final int bytes = Integer.valueOf(item.representedObject()); final NSIndexSet iterator = transferTable.selectedRowIndexes(); for(NSUInteger index = iterator.firstIndex(); !index.equals(NSIndexSet.NSNotFound); index = iterator.indexGreaterThanIndex(index)) { final Transfer transfer = collection.get(index.intValue()); if(BandwidthThrottle.UNLIMITED == transfer.getBandwidth().getRate()) {
/** * @param rowIndexes is the list of row numbers that will be participating in the drag. * @return To refuse the drag, return false. To start a drag, return true and place * the drag data onto pboard (data, owner, and so on). * @see NSTableView.DataSource * Invoked by view after it has been determined that a drag should begin, but before the drag has been started. * The drag image and other drag-related information will be set up and provided by the table view once this call * returns with true. */ @Override public boolean tableView_writeRowsWithIndexes_toPasteboard(final NSTableView view, final NSIndexSet rowIndexes, final NSPasteboard pboard) { for(NSUInteger index = rowIndexes.firstIndex(); !index.equals(NSIndexSet.NSNotFound); index = rowIndexes.indexGreaterThanIndex(index)) { pasteboard.add(this.getSource().get(index.intValue())); } NSEvent event = NSApplication.sharedApplication().currentEvent(); if(event != null) { NSPoint dragPosition = view.convertPoint_fromView(event.locationInWindow(), null); NSRect imageRect = new NSRect(new NSPoint(dragPosition.x.doubleValue() - 16, dragPosition.y.doubleValue() - 16), new NSSize(32, 32)); // Writing a promised file of the host as a bookmark file to the clipboard view.dragPromisedFilesOfTypes(NSArray.arrayWithObject("duck"), imageRect, this.id(), true, event); return true; } return false; }