Skip to content

Commit

Permalink
Extract factoy classes.
Browse files Browse the repository at this point in the history
Former-commit-id: bd7813402d7488c2f44ff0a8d9a130b47c6e74c7
  • Loading branch information
dkocher committed Jun 28, 2013
1 parent 6247122 commit a65bf0b
Show file tree
Hide file tree
Showing 8 changed files with 205 additions and 115 deletions.
27 changes: 1 addition & 26 deletions source/ch/cyberduck/ui/cocoa/BookmarkController.java
Expand Up @@ -53,9 +53,7 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TimeZone;

/**
Expand Down Expand Up @@ -516,29 +514,6 @@ public void setToggleOptionsButton(NSButton toggleOptionsButton) {
this.toggleOptionsButton = toggleOptionsButton;
}

/**
*
*/
public static class Factory {
private static final Map<Host, BookmarkController> open
= new HashMap<Host, BookmarkController>();

public static BookmarkController create(final Host host) {
if(open.containsKey(host)) {
return open.get(host);
}
final BookmarkController c = new BookmarkController(host) {
@Override
public void windowWillClose(NSNotification notification) {
super.windowWillClose(notification);
Factory.open.remove(host);
}
};
open.put(host, c);
return c;
}
}

/**
* The bookmark
*/
Expand All @@ -547,7 +522,7 @@ public void windowWillClose(NSNotification notification) {
/**
* @param host The bookmark to edit
*/
private BookmarkController(final Host host) {
public BookmarkController(final Host host) {
this.host = host;
// Register for bookmark delete event. Will close this window.
BookmarkCollection.defaultCollection().addListener(bookmarkCollectionListener);
Expand Down
53 changes: 53 additions & 0 deletions source/ch/cyberduck/ui/cocoa/BookmarkControllerFactory.java
@@ -0,0 +1,53 @@
package ch.cyberduck.ui.cocoa;

/*
* Copyright (c) 2002-2013 David Kocher. All rights reserved.
* http://cyberduck.ch/
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* Bug fixes, suggestions and comments should be sent to feedback@cyberduck.ch
*/

import ch.cyberduck.core.Host;
import ch.cyberduck.ui.cocoa.application.NSApplication;

import java.util.HashMap;
import java.util.Map;

/**
*
*/
public final class BookmarkControllerFactory {

private static final Map<Host, BookmarkController> open
= new HashMap<Host, BookmarkController>();

private BookmarkControllerFactory() {
//
}

public static BookmarkController create(final Host host) {
synchronized(NSApplication.sharedApplication()) {
if(!open.containsKey(host)) {
final BookmarkController c = new BookmarkController(host) {
@Override
protected void invalidate() {
open.remove(host);
super.invalidate();
}
};
open.put(host, c);
}
return open.get(host);
}
}
}
81 changes: 41 additions & 40 deletions source/ch/cyberduck/ui/cocoa/BrowserController.java
Expand Up @@ -102,6 +102,16 @@ public class BrowserController extends WindowController
NSToolbar.Delegate, QLPreviewPanelController {
private static Logger log = Logger.getLogger(BrowserController.class);

/**
* No file filter.
*/
private static final Filter<Path> NULL_FILTER = new NullPathFilter<Path>();

/**
* Filter hidden files.
*/
private static final Filter<Path> HIDDEN_FILTER = new HiddenFilesPathFilter();

/**
*
*/
Expand All @@ -112,20 +122,10 @@ public class BrowserController extends WindowController
*/
private TranscriptController transcript;

private QuickLook quicklook = QuickLookFactory.get();
private final QuickLook quicklook = QuickLookFactory.get();

private List<Path> selected = Collections.emptyList();

/**
* No file filter.
*/
private static final Filter<Path> NULL_FILTER = new NullPathFilter<Path>();

/**
* Filter hidden files.
*/
private static final Filter<Path> HIDDEN_FILTER = new HiddenFilesPathFilter();

/**
* Hide files beginning with '.'
*/
Expand All @@ -144,10 +144,35 @@ public class BrowserController extends WindowController
}
}

private final NSTextFieldCell outlineCellPrototype = OutlineCell.outlineCell();
private final NSImageCell imageCellPrototype = NSImageCell.imageCell();
private final NSTextFieldCell textCellPrototype = NSTextFieldCell.textFieldCell();
private final NSTextFieldCell filenameCellPrototype = NSTextFieldCell.textFieldCell();

private final TableColumnFactory browserListColumnsFactory = new TableColumnFactory();
private final TableColumnFactory browserOutlineColumnsFactory = new TableColumnFactory();
private final TableColumnFactory bookmarkTableColumnFactory = new TableColumnFactory();

// setting appearance attributes()
private final NSLayoutManager layoutManager = NSLayoutManager.layoutManager();

private BrowserOutlineViewModel browserOutlineModel;
@Outlet
private NSOutlineView browserOutlineView;
private AbstractBrowserTableDelegate<Path> browserOutlineViewDelegate;

private BrowserListViewModel browserListModel;
@Outlet
private NSTableView browserListView;
private AbstractBrowserTableDelegate<Path> browserListViewDelegate;


private NSToolbar toolbar;

/**
* Navigation history
*/
private Navigation navigation = new Navigation();
private final Navigation navigation = new Navigation();

public BrowserController() {
this.loadBundle();
Expand Down Expand Up @@ -188,8 +213,6 @@ public static void updateBrowserTableColumns() {
}
}

private NSToolbar toolbar;

@Override
public void awakeFromNib() {
// Configure Toolbar
Expand Down Expand Up @@ -1171,14 +1194,6 @@ public void endPreviewPanelControl(QLPreviewPanel panel) {
quicklook.didEndQuickLook();
}

// setting appearance attributes()
final NSLayoutManager layoutManager = NSLayoutManager.layoutManager();

private BrowserOutlineViewModel browserOutlineModel;
@Outlet
private NSOutlineView browserOutlineView;
private AbstractBrowserTableDelegate<Path> browserOutlineViewDelegate;

public void setBrowserOutlineView(NSOutlineView view) {
browserOutlineView = view;
// receive drag events from types
Expand Down Expand Up @@ -1301,11 +1316,6 @@ protected boolean isTypeSelectSupported() {
}
}

private BrowserListViewModel browserListModel;
@Outlet
private NSTableView browserListView;
private AbstractBrowserTableDelegate<Path> browserListViewDelegate;

public void setBrowserListView(NSTableView view) {
browserListView = view;
// receive drag events from types
Expand Down Expand Up @@ -1413,16 +1423,7 @@ protected void _updateBookmarkCell() {
NSIndexSet.indexSetWithIndexesInRange(NSRange.NSMakeRange(new NSUInteger(0), new NSUInteger(bookmarkTable.numberOfRows()))));
}

private final NSTextFieldCell outlineCellPrototype = OutlineCell.outlineCell();
private final NSImageCell imageCellPrototype = NSImageCell.imageCell();
private final NSTextFieldCell textCellPrototype = NSTextFieldCell.textFieldCell();
private final NSTextFieldCell filenameCellPrototype = NSTextFieldCell.textFieldCell();

private final TableColumnFactory browserListColumnsFactory = new TableColumnFactory();
private final TableColumnFactory browserOutlineColumnsFactory = new TableColumnFactory();
private final TableColumnFactory bookmarkTableColumnFactory = new TableColumnFactory();

protected void _updateBrowserColumns(NSTableView table) {
private void _updateBrowserColumns(NSTableView table) {
table.removeTableColumn(table.tableColumnWithIdentifier(BrowserTableDataSource.SIZE_COLUMN));
if(Preferences.instance().getBoolean("browser.columnSize")) {
NSTableColumn c = browserListColumnsFactory.create(BrowserTableDataSource.SIZE_COLUMN);
Expand Down Expand Up @@ -1821,7 +1822,7 @@ public void setEditBookmarkButton(NSButton editBookmarkButton) {

@Action
public void editBookmarkButtonClicked(final ID sender) {
BookmarkController c = BookmarkController.Factory.create(
final BookmarkController c = BookmarkControllerFactory.create(
bookmarkModel.getSource().get(bookmarkTable.selectedRow().intValue())
);
c.window().makeKeyAndOrderFront(null);
Expand Down Expand Up @@ -1875,7 +1876,7 @@ public void addBookmark(Host item) {
final NSInteger index = new NSInteger(row);
bookmarkTable.selectRowIndexes(NSIndexSet.indexSetWithIndex(index), false);
bookmarkTable.scrollRowToVisible(index);
BookmarkController c = BookmarkController.Factory.create(item);
final BookmarkController c = BookmarkControllerFactory.create(item);
c.window().makeKeyAndOrderFront(null);
}

Expand Down Expand Up @@ -3001,7 +3002,7 @@ else if(selected.attributes().isFile() || this.getSelectionCount() > 1) {

@Action
public void connectButtonClicked(final ID sender) {
final SheetController controller = ConnectionController.instance(this);
final SheetController controller = ConnectionControllerFactory.create(this);
this.addListener(new WindowListener() {
@Override
public void windowWillClose() {
Expand Down
42 changes: 9 additions & 33 deletions source/ch/cyberduck/ui/cocoa/ConnectionController.java
Expand Up @@ -40,44 +40,12 @@
import org.rococoa.Rococoa;
import org.rococoa.cocoa.foundation.NSInteger;

import java.util.HashMap;
import java.util.Map;

/**
* @version $Id$
*/
public class ConnectionController extends SheetController {
private static Logger log = Logger.getLogger(ConnectionController.class);

private static final Map<WindowController, ConnectionController> controllers
= new HashMap<WindowController, ConnectionController>();

public static ConnectionController instance(final WindowController parent) {
if(!controllers.containsKey(parent)) {
final ConnectionController c = new ConnectionController(parent) {
@Override
protected void invalidate() {
controllers.remove(parent);
super.invalidate();
}
};
c.loadBundle();
controllers.put(parent, c);
}
final ConnectionController c = controllers.get(parent);
c.init();
return c;
}

protected void init() {
passField.setStringValue(StringUtils.EMPTY);
final boolean enabled = Preferences.instance().getBoolean("connection.login.useKeychain");
keychainCheckbox.setEnabled(enabled);
if(!enabled) {
keychainCheckbox.setState(NSCell.NSOffState);
}
}

@Override
protected void invalidate() {
hostField.setDelegate(null);
Expand All @@ -90,8 +58,9 @@ public boolean isSingleton() {
return true;
}

private ConnectionController(final WindowController parent) {
public ConnectionController(final WindowController parent) {
super(parent);
this.loadBundle();
}

@Override
Expand All @@ -106,6 +75,13 @@ public void awakeFromNib() {
super.awakeFromNib();
}

@Override
public void beginSheet() {
// Reset password input
passField.setStringValue(StringUtils.EMPTY);
super.beginSheet();
}

@Override
protected double getMaxWindowHeight() {
return this.window().frame().size.height.doubleValue();
Expand Down
52 changes: 52 additions & 0 deletions source/ch/cyberduck/ui/cocoa/ConnectionControllerFactory.java
@@ -0,0 +1,52 @@
package ch.cyberduck.ui.cocoa;

/*
* Copyright (c) 2002-2013 David Kocher. All rights reserved.
* http://cyberduck.ch/
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* Bug fixes, suggestions and comments should be sent to feedback@cyberduck.ch
*/

import ch.cyberduck.ui.cocoa.application.NSApplication;

import java.util.HashMap;
import java.util.Map;

/**
* @version $Id:$
*/
public final class ConnectionControllerFactory {

private static final Map<WindowController, ConnectionController> open
= new HashMap<WindowController, ConnectionController>();

private ConnectionControllerFactory() {
//
}

public static ConnectionController create(final WindowController parent) {
synchronized(NSApplication.sharedApplication()) {
if(!open.containsKey(parent)) {
final ConnectionController c = new ConnectionController(parent) {
@Override
protected void invalidate() {
open.remove(parent);
super.invalidate();
}
};
open.put(parent, c);
}
return open.get(parent);
}
}
}
3 changes: 1 addition & 2 deletions source/ch/cyberduck/ui/cocoa/MainController.java
Expand Up @@ -499,7 +499,7 @@ public void feedbackMenuClicked(final ID sender) {

@Action
public void preferencesMenuClicked(final ID sender) {
PreferencesController controller = PreferencesController.instance();
PreferencesController controller = PreferencesControllerFactory.instance();
controller.window().makeKeyAndOrderFront(null);
}

Expand Down Expand Up @@ -1323,7 +1323,6 @@ private void terminate() {
app.replyToApplicationShouldTerminate(true);
}
};
donationController.loadBundle();
// Delay application termination. Dismissing the donation dialog will reply to quit.
return NSApplication.NSTerminateLater;
}
Expand Down

0 comments on commit a65bf0b

Please sign in to comment.