1 package ch
.cyberduck
.ui
.cocoa
.delegate
;
4 * Copyright (c) 2002-2009 David Kocher. All rights reserved.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * Bug fixes, suggestions and comments should be sent to:
19 * dkocher@cyberduck.ch
22 import ch
.cyberduck
.binding
.application
.NSMenu
;
23 import ch
.cyberduck
.core
.Collection
;
24 import ch
.cyberduck
.core
.CollectionListener
;
26 import org
.rococoa
.cocoa
.foundation
.NSInteger
;
31 public abstract class CollectionMenuDelegate
<T
> extends AbstractMenuDelegate
implements CollectionListener
<T
> {
33 private Collection
<T
> collection
;
35 public CollectionMenuDelegate(Collection
<T
> c
) {
37 this.collection
.addListener(this);
41 public NSInteger
numberOfItemsInMenu(NSMenu menu
) {
42 if(this.isPopulated()) {
43 // If you return a negative value, the number of items is left unchanged
44 // and menu:updateItem:atIndex:shouldCancel: is not called.
45 return new NSInteger(-1);
47 if(collection
.size() > 0) {
48 // The number of history plus a delimiter and the 'Clear' menu
49 return new NSInteger(collection
.size());
51 return new NSInteger(1);
55 public void collectionItemAdded(T item
) {
56 this.setNeedsUpdate(true);
60 public void collectionItemRemoved(T item
) {
61 this.setNeedsUpdate(true);
65 public void collectionItemChanged(T item
) {
66 this.setNeedsUpdate(true);
70 public void collectionLoaded() {
71 this.setNeedsUpdate(true);
75 public void invalidate() {
76 this.collection
.removeListener(this);