Fix transcript in transfer window.
[cyberduck.git] / source / ch / cyberduck / ui / cocoa / GotoController.java
blobc3ccd9f23d4c6991d6364592cd134041a50d7fb0
1 package ch.cyberduck.ui.cocoa;
3 /*
4 * Copyright (c) 2005 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.ProxyController;
22 import ch.cyberduck.binding.application.NSAlert;
23 import ch.cyberduck.binding.application.NSComboBox;
24 import ch.cyberduck.binding.application.NSImage;
25 import ch.cyberduck.binding.foundation.NSObject;
26 import ch.cyberduck.binding.foundation.NSString;
27 import ch.cyberduck.core.Cache;
28 import ch.cyberduck.core.Filter;
29 import ch.cyberduck.core.LocaleFactory;
30 import ch.cyberduck.core.NullComparator;
31 import ch.cyberduck.core.Path;
32 import ch.cyberduck.core.Session;
33 import ch.cyberduck.core.features.Home;
34 import ch.cyberduck.core.resources.IconCacheFactory;
36 import org.apache.commons.lang3.StringUtils;
37 import org.rococoa.cocoa.foundation.NSInteger;
38 import org.rococoa.cocoa.foundation.NSRect;
40 import java.util.Comparator;
42 /**
43 * @version $Id$
45 public class GotoController extends AlertController {
47 @Outlet
48 private NSComboBox folderCombobox;
50 @Delegate
51 private ProxyController folderComboboxModel;
53 private Cache<Path> cache;
55 private final class FolderComboboxModel extends ProxyController implements NSComboBox.DataSource {
57 private Path workdir;
59 private final Comparator<Path> comparator = new NullComparator<Path>();
61 private FolderComboboxModel(final Path workdir) {
62 this.workdir = workdir;
65 private final Filter<Path> filter = new Filter<Path>() {
66 @Override
67 public boolean accept(Path p) {
68 return p.isDirectory();
72 @Override
73 public NSInteger numberOfItemsInComboBox(NSComboBox combo) {
74 return new NSInteger(cache.get(workdir).filter(comparator, filter).size());
77 @Override
78 public NSObject comboBox_objectValueForItemAtIndex(final NSComboBox sender, final NSInteger row) {
79 return NSString.stringWithString(cache.get(workdir)
80 .filter(comparator, filter).get(row.intValue()).getName());
84 public GotoController(final BrowserController parent, final Cache<Path> cache) {
85 super(parent, NSAlert.alert(
86 LocaleFactory.localizedString("Go to folder", "Goto"),
87 LocaleFactory.localizedString("Enter the pathname to list:", "Goto"),
88 LocaleFactory.localizedString("Go", "Goto"),
89 null,
90 LocaleFactory.localizedString("Cancel", "Goto")
91 ));
92 this.cache = cache;
93 alert.setIcon(IconCacheFactory.<NSImage>get().folderIcon(64));
94 folderCombobox = NSComboBox.textfieldWithFrame(new NSRect(0, 26));
95 folderCombobox.setCompletes(true);
96 folderCombobox.setUsesDataSource(true);
97 folderComboboxModel = new FolderComboboxModel(parent.workdir());
98 folderCombobox.setDataSource(folderComboboxModel.id());
99 folderCombobox.setStringValue(parent.workdir().getAbsolute());
100 this.setAccessoryView(folderCombobox);
103 @Override
104 protected void focus() {
105 // Focus accessory view.
106 folderCombobox.selectText(null);
107 this.window().makeFirstResponder(folderCombobox);
110 @Override
111 public void invalidate() {
112 folderCombobox.setDelegate(null);
113 folderCombobox.setDataSource(null);
114 super.invalidate();
117 @Override
118 public void callback(final int returncode) {
119 if(returncode == DEFAULT_OPTION) {
120 final String filename = folderCombobox.stringValue();
121 final BrowserController controller = (BrowserController) parent;
122 final Path workdir = controller.workdir();
123 final Path directory = controller.getSession().getFeature(Home.class).find(workdir, filename);
124 if(workdir.getParent().equals(directory)) {
125 controller.setWorkdir(directory, workdir);
127 else {
128 controller.setWorkdir(directory);
133 @Override
134 protected boolean validateInput() {
135 return StringUtils.isNotBlank(folderCombobox.stringValue());
138 protected Session getSession() {
139 return ((BrowserController) parent).getSession();