Fix transcript in transfer window.
[cyberduck.git] / source / ch / cyberduck / ui / cocoa / delegate / CollectionMenuDelegate.java
blobf3c9aa1208ac8bde2ecf035387c4685a3730a63c
1 package ch.cyberduck.ui.cocoa.delegate;
3 /*
4 * Copyright (c) 2002-2009 David Kocher. All rights reserved.
6 * http://cyberduck.ch/
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;
28 /**
29 * @version $Id$
31 public abstract class CollectionMenuDelegate<T> extends AbstractMenuDelegate implements CollectionListener<T> {
33 private Collection<T> collection;
35 public CollectionMenuDelegate(Collection<T> c) {
36 this.collection = c;
37 this.collection.addListener(this);
40 @Override
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);
54 @Override
55 public void collectionItemAdded(T item) {
56 this.setNeedsUpdate(true);
59 @Override
60 public void collectionItemRemoved(T item) {
61 this.setNeedsUpdate(true);
64 @Override
65 public void collectionItemChanged(T item) {
66 this.setNeedsUpdate(true);
69 @Override
70 public void collectionLoaded() {
71 this.setNeedsUpdate(true);
74 @Override
75 public void invalidate() {
76 this.collection.removeListener(this);
77 super.invalidate();