Merge pull request #64 in ITERATE/cyberduck from feature/windows/9074 to master
[cyberduck.git] / source / ch / cyberduck / ui / cocoa / delegate / RendezvousMenuDelegate.java
blob5b334f41855e4239760f027ed832b84822dd97ce
1 package ch.cyberduck.ui.cocoa.delegate;
3 /*
4 * Copyright (c) 2006 David Kocher. All rights reserved.
5 * http://cyberduck.ch/
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * Bug fixes, suggestions and comments should be sent to:
18 * dkocher@cyberduck.ch
21 import ch.cyberduck.binding.application.NSImage;
22 import ch.cyberduck.binding.application.NSMenu;
23 import ch.cyberduck.binding.application.NSMenuItem;
24 import ch.cyberduck.core.AbstractHostCollection;
25 import ch.cyberduck.core.BookmarkNameProvider;
26 import ch.cyberduck.core.Host;
27 import ch.cyberduck.core.LocaleFactory;
28 import ch.cyberduck.core.bonjour.RendezvousCollection;
29 import ch.cyberduck.core.preferences.Preferences;
30 import ch.cyberduck.core.preferences.PreferencesFactory;
31 import ch.cyberduck.core.resources.IconCacheFactory;
32 import ch.cyberduck.ui.cocoa.Action;
33 import ch.cyberduck.ui.cocoa.MainController;
35 import org.apache.log4j.Logger;
36 import org.rococoa.Foundation;
37 import org.rococoa.Selector;
38 import org.rococoa.cocoa.foundation.NSInteger;
40 /**
41 * @version $Id$
43 public class RendezvousMenuDelegate extends CollectionMenuDelegate<Host> {
44 private static final Logger log = Logger.getLogger(RendezvousMenuDelegate.class);
46 private AbstractHostCollection collection;
48 private MenuCallback callback;
50 private final Preferences preferences
51 = PreferencesFactory.get();
53 public RendezvousMenuDelegate() {
54 this(new MenuCallback() {
55 @Override
56 public void selected(final NSMenuItem sender) {
57 MainController.newDocument().mount(RendezvousCollection.defaultCollection().lookup(sender.representedObject()));
59 });
62 public RendezvousMenuDelegate(final MenuCallback callback) {
63 this(RendezvousCollection.defaultCollection(), callback);
66 public RendezvousMenuDelegate(final AbstractHostCollection collection, final MenuCallback callback) {
67 super(collection);
68 this.collection = collection;
69 this.callback = callback;
72 @Override
73 public boolean menuUpdateItemAtIndex(NSMenu menu, NSMenuItem item, NSInteger index, boolean cancel) {
74 if(collection.size() == 0) {
75 item.setTitle(LocaleFactory.localizedString("No Bonjour services available"));
76 item.setTarget(null);
77 item.setAction(null);
78 item.setImage(null);
79 item.setEnabled(false);
81 else {
82 final Host h = this.itemForIndex(index);
83 item.setTitle(BookmarkNameProvider.toString(h));
84 item.setTarget(this.id());
85 item.setEnabled(true);
86 item.setImage(IconCacheFactory.<NSImage>get().iconNamed(h.getProtocol().icon(), preferences.getInteger("bookmark.menu.icon.size")));
87 item.setTarget(this.id());
88 item.setAction(this.getDefaultAction());
89 item.setRepresentedObject(h.getUuid());
91 return super.menuUpdateItemAtIndex(menu, item, index, cancel);
94 @Action
95 public void menuItemClicked(NSMenuItem sender) {
96 if(log.isDebugEnabled()) {
97 log.debug(String.format("Menu item clicked %s", sender));
99 callback.selected(sender);
102 @Override
103 public Selector getDefaultAction() {
104 return Foundation.selector("menuItemClicked:");