/** * @return The filtered collection currently to be displayed within the constraints */ public Collection<Transfer> getSource() { if(filter instanceof NullTransferFilter) { return collection; } final Collection<Transfer> filtered = new Collection<Transfer>(collection); // Temporarily remove the transfer from the collection copy filtered.removeIf(transfer -> !filter.accept(transfer)); return filtered; }
/** * Actions added are automatically removed when canceled or stopped. * * @param action Action to run in background * @return True */ @Override public synchronized boolean add(final BackgroundAction action) { action.addListener(this); return super.add(action); }
public T itemForIndex(final NSInteger index) { return collection.get(index.intValue()); }
@Override public Collection<S> readCollection(final Local file) throws AccessDeniedException { final Collection<S> c = new Collection<S>(); final NSArray list = (NSArray) this.parse(file.getInputStream()); if(null == list) { log.error(String.format("Invalid bookmark file %s", file)); return c; } for(int i = 0; i < list.count(); i++) { NSObject next = list.objectAtIndex(i); if(next instanceof NSDictionary) { final NSDictionary dict = (NSDictionary) next; final S object = this.deserialize(dict); if(null == object) { continue; } c.add(object); } } return c; }
@Override public String[] availableCharsets() { List<String> charsets = new Collection<String>(); for(Charset charset : Charset.availableCharsets().values()) { final String name = charset.displayName(); if(!(name.startsWith("IBM") || ((name.startsWith("x-") && !name.startsWith("x-Mac"))))) { charsets.add(name); } } return charsets.toArray(new String[charsets.size()]); } }
@Override public NSInteger numberOfItemsInMenu(final NSMenu menu) { if(this.isPopulated()) { // If you return a negative value, the number of items is left unchanged // and menu:updateItem:atIndex:shouldCancel: is not called. return new NSInteger(-1); } if(collection.size() > 0) { // The number of history plus a delimiter and the 'Clear' menu return new NSInteger(collection.size()); } return new NSInteger(1); }
@Override public boolean addAll(java.util.Collection<? extends E> es) { super.addAll(es); for(E item : es) { this.collectionItemAdded(item); } return true; }
@Override public boolean remove(Object item) { boolean previous = super.remove(item); this.collectionItemRemoved((E) item); return previous; }
@Override public boolean addAll(final java.util.Collection<? extends Host> c) { List<Host> temporary = new ArrayList<Host>(); for(Host host : c) { if(temporary.contains(host)) { log.warn(String.format("Reset UUID of duplicate in collection for %s", host)); host.setUuid(null); } temporary.add(host); } return super.addAll(temporary); }
public CollectionMenuDelegate(Collection<T> c) { this.collection = c; this.collection.addListener(this); }
@Override public void collectionItemChanged(final Transfer transfer) { try { this.save(transfer); } finally { super.collectionItemChanged(transfer); } }
@Override public Collection<S> readCollection(final Local file) throws AccessDeniedException { if(!file.exists()) { throw new LocalAccessDeniedException(file.getAbsolute()); } final Collection<S> c = new Collection<S>(); NSArray list = NSArray.arrayWithContentsOfFile(file.getAbsolute()); if(null == list) { log.error(String.format("Invalid bookmark file %s", file)); return c; } final NSEnumerator i = list.objectEnumerator(); NSObject next; while(((next = i.nextObject()) != null)) { if(next.isKindOfClass(Rococoa.createClass("NSDictionary", NSDictionary._Class.class))) { final NSDictionary dict = Rococoa.cast(next, NSDictionary.class); final S object = this.deserialize(dict); if(null == object) { continue; } c.add(object); } } return c; }
/** * Prunes the list of selected files. Files which are a child of an already included directory * are removed from the returned list. * * @param selected Selected files for transfer * @return Normalized */ public static List<Path> normalize(final List<Path> selected) { final List<Path> normalized = new Collection<Path>(); for(Path f : selected) { boolean duplicate = false; for(Path n : normalized) { if(f.isChild(n)) { // The selected file is a child of a directory already included duplicate = true; break; } } if(!duplicate) { normalized.add(f); } } return normalized; } }
@Override public NSInteger numberOfRowsInTableView(NSTableView view) { return new NSInteger(this.getSource().size()); }
@Override public boolean add(E object) { super.add(object); this.collectionItemAdded(object); return true; }
/** * @param row Index in collection * @return the element that was removed from the list. */ @Override public E remove(int row) { E previous = super.remove(row); this.collectionItemRemoved(previous); return previous; }
@Override public boolean addAll(java.util.Collection<? extends Transfer> c) { final List<Transfer> temporary = new ArrayList<Transfer>(); for(Transfer transfer : c) { if(temporary.contains(transfer)) { log.warn(String.format("Reset UUID of duplicate in collection for %s", transfer)); transfer.setUuid(new UUIDRandomStringService().random()); } temporary.add(transfer); } return super.addAll(temporary); }
public ProgressController getController(final int row) { return this.getController(this.getSource().get(row)); }