Search in sources :

Example 1 with BookmarkTableDataSource

use of ch.cyberduck.ui.cocoa.datasource.BookmarkTableDataSource in project cyberduck by iterate-ch.

the class BrowserController method setBookmarkTable.

// ----------------------------------------------------------
// Manage Bookmarks
// ----------------------------------------------------------
@Action
public void setBookmarkTable(NSTableView view) {
    bookmarkTable = view;
    bookmarkTable.setSelectionHighlightStyle(NSTableView.NSTableViewSelectionHighlightStyleSourceList);
    bookmarkTable.setDataSource((this.bookmarkModel = new BookmarkTableDataSource(this)).id());
    {
        NSTableColumn c = bookmarkTableColumnFactory.create(BookmarkColumn.icon.name());
        c.headerCell().setStringValue(StringUtils.EMPTY);
        c.setResizingMask(NSTableColumn.NSTableColumnNoResizing);
        c.setDataCell(imageCellPrototype);
        bookmarkTable.addTableColumn(c);
    }
    {
        NSTableColumn c = bookmarkTableColumnFactory.create(BookmarkColumn.bookmark.name());
        c.headerCell().setStringValue(LocaleFactory.localizedString("Bookmarks", "Browser"));
        c.setMinWidth(150);
        c.setResizingMask(NSTableColumn.NSTableColumnAutoresizingMask);
        c.setDataCell(BookmarkCell.bookmarkCell());
        bookmarkTable.addTableColumn(c);
    }
    {
        NSTableColumn c = bookmarkTableColumnFactory.create(BookmarkColumn.status.name());
        c.headerCell().setStringValue(StringUtils.EMPTY);
        c.setMinWidth(40);
        c.setWidth(40);
        c.setMaxWidth(40);
        c.setResizingMask(NSTableColumn.NSTableColumnAutoresizingMask);
        c.setDataCell(imageCellPrototype);
        c.dataCell().setAlignment(TEXT_ALIGNMENT_CENTER);
        bookmarkTable.addTableColumn(c);
    }
    bookmarkTable.setDelegate((bookmarkTableDelegate = new AbstractTableDelegate<Host, BookmarkColumn>(bookmarkTable.tableColumnWithIdentifier(BookmarkColumn.bookmark.name())) {

        private static final double kSwipeGestureLeft = 1.000000;

        private static final double kSwipeGestureRight = -1.000000;

        private static final double kSwipeGestureUp = 1.000000;

        private static final double kSwipeGestureDown = -1.000000;

        @Override
        public String tooltip(Host bookmark, final BookmarkColumn column) {
            return new HostUrlProvider().get(bookmark);
        }

        @Override
        public void tableRowDoubleClicked(final ID sender) {
            BrowserController.this.connectBookmarkButtonClicked(sender);
        }

        @Override
        public void enterKeyPressed(final ID sender) {
            this.tableRowDoubleClicked(sender);
        }

        @Override
        public void deleteKeyPressed(final ID sender) {
            if (bookmarkModel.getSource().allowsDelete()) {
                BrowserController.this.deleteBookmarkButtonClicked(sender);
            }
        }

        @Override
        public void tableColumnClicked(NSTableView view, NSTableColumn tableColumn) {
        }

        @Override
        public void selectionDidChange(final NSNotification notification) {
            addBookmarkButton.setEnabled(bookmarkModel.getSource().allowsAdd());
            final int selected = bookmarkTable.numberOfSelectedRows().intValue();
            editBookmarkButton.setEnabled(bookmarkModel.getSource().allowsEdit() && selected == 1);
            deleteBookmarkButton.setEnabled(bookmarkModel.getSource().allowsDelete() && selected > 0);
        }

        @Action
        public CGFloat tableView_heightOfRow(NSTableView view, NSInteger row) {
            final int size = preferences.getInteger("bookmark.icon.size");
            if (BookmarkCell.SMALL_BOOKMARK_SIZE == size) {
                return new CGFloat(18);
            }
            if (BookmarkCell.MEDIUM_BOOKMARK_SIZE == size) {
                return new CGFloat(45);
            }
            return new CGFloat(70);
        }

        @Override
        public boolean isTypeSelectSupported() {
            return true;
        }

        @Action
        public String tableView_typeSelectStringForTableColumn_row(NSTableView view, NSTableColumn tableColumn, NSInteger row) {
            return BookmarkNameProvider.toString(bookmarkModel.getSource().get(row.intValue()));
        }

        @Action
        public boolean tableView_isGroupRow(NSTableView view, NSInteger row) {
            return false;
        }

        /**
         * Available in Mac OS X v10.6 and later.
         *
         * @param event Swipe event
         */
        @Action
        public void swipeWithEvent(NSEvent event) {
            if (event.deltaY().doubleValue() == kSwipeGestureUp) {
                NSInteger row = bookmarkTable.selectedRow();
                NSInteger next;
                if (-1 == row.intValue()) {
                    // No current selection
                    next = new NSInteger(0);
                } else {
                    next = new NSInteger(row.longValue() - 1);
                }
                bookmarkTable.selectRowIndexes(NSIndexSet.indexSetWithIndex(next), false);
            } else if (event.deltaY().doubleValue() == kSwipeGestureDown) {
                NSInteger row = bookmarkTable.selectedRow();
                NSInteger next;
                if (-1 == row.intValue()) {
                    // No current selection
                    next = new NSInteger(0);
                } else {
                    next = new NSInteger(row.longValue() + 1);
                }
                bookmarkTable.selectRowIndexes(NSIndexSet.indexSetWithIndex(next), false);
            }
        }
    }).id());
    // receive drag events from types
    bookmarkTable.registerForDraggedTypes(NSArray.arrayWithObjects(NSPasteboard.URLPboardType, NSPasteboard.StringPboardType, // Accept bookmark files dragged from the Finder
    NSPasteboard.FilenamesPboardType, // Accept file promises made myself
    NSPasteboard.FilesPromisePboardType));
    this._updateBookmarkCell();
    final int size = preferences.getInteger("bookmark.icon.size");
    if (BookmarkCell.SMALL_BOOKMARK_SIZE == size) {
        bookmarkTable.setRowHeight(new CGFloat(18));
    } else if (BookmarkCell.MEDIUM_BOOKMARK_SIZE == size) {
        bookmarkTable.setRowHeight(new CGFloat(45));
    } else {
        bookmarkTable.setRowHeight(new CGFloat(70));
    }
    // setting appearance attributes()
    bookmarkTable.setUsesAlternatingRowBackgroundColors(preferences.getBoolean("browser.alternatingRows"));
    bookmarkTable.setGridStyleMask(NSTableView.NSTableViewGridNone);
    // selection properties
    bookmarkTable.setAllowsMultipleSelection(true);
    bookmarkTable.setAllowsEmptySelection(true);
    bookmarkTable.setAllowsColumnResizing(false);
    bookmarkTable.setAllowsColumnSelection(false);
    bookmarkTable.setAllowsColumnReordering(false);
    bookmarkTable.sizeToFit();
}
Also used : NSNotification(ch.cyberduck.binding.foundation.NSNotification) AbstractTableDelegate(ch.cyberduck.binding.AbstractTableDelegate) NSPoint(org.rococoa.cocoa.foundation.NSPoint) CGFloat(org.rococoa.cocoa.CGFloat) BookmarkTableDataSource(ch.cyberduck.ui.cocoa.datasource.BookmarkTableDataSource) NSInteger(org.rococoa.cocoa.foundation.NSInteger) ID(org.rococoa.ID) BookmarkColumn(ch.cyberduck.ui.browser.BookmarkColumn) WindowMainAction(ch.cyberduck.core.threading.WindowMainAction) BackgroundAction(ch.cyberduck.core.threading.BackgroundAction) DisconnectBackgroundAction(ch.cyberduck.core.threading.DisconnectBackgroundAction) TransferAction(ch.cyberduck.core.transfer.TransferAction) Action(ch.cyberduck.binding.Action) DefaultMainAction(ch.cyberduck.core.threading.DefaultMainAction) WorkerBackgroundAction(ch.cyberduck.core.threading.WorkerBackgroundAction) BrowserTransferBackgroundAction(ch.cyberduck.core.threading.BrowserTransferBackgroundAction)

Aggregations

AbstractTableDelegate (ch.cyberduck.binding.AbstractTableDelegate)1 Action (ch.cyberduck.binding.Action)1 NSNotification (ch.cyberduck.binding.foundation.NSNotification)1 BackgroundAction (ch.cyberduck.core.threading.BackgroundAction)1 BrowserTransferBackgroundAction (ch.cyberduck.core.threading.BrowserTransferBackgroundAction)1 DefaultMainAction (ch.cyberduck.core.threading.DefaultMainAction)1 DisconnectBackgroundAction (ch.cyberduck.core.threading.DisconnectBackgroundAction)1 WindowMainAction (ch.cyberduck.core.threading.WindowMainAction)1 WorkerBackgroundAction (ch.cyberduck.core.threading.WorkerBackgroundAction)1 TransferAction (ch.cyberduck.core.transfer.TransferAction)1 BookmarkColumn (ch.cyberduck.ui.browser.BookmarkColumn)1 BookmarkTableDataSource (ch.cyberduck.ui.cocoa.datasource.BookmarkTableDataSource)1 ID (org.rococoa.ID)1 CGFloat (org.rococoa.cocoa.CGFloat)1 NSInteger (org.rococoa.cocoa.foundation.NSInteger)1 NSPoint (org.rococoa.cocoa.foundation.NSPoint)1