Fix transcript in transfer window.
[cyberduck.git] / source / ch / cyberduck / ui / cocoa / AbstractTableDelegate.java
blob15d5cb665fd276180f4b71b922dc5f3139919fd2
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.NSEvent;
23 import ch.cyberduck.binding.application.NSOutlineView;
24 import ch.cyberduck.binding.application.NSTableColumn;
25 import ch.cyberduck.binding.application.NSTableView;
26 import ch.cyberduck.binding.foundation.NSNotification;
27 import ch.cyberduck.binding.foundation.NSObject;
28 import ch.cyberduck.core.NullComparator;
29 import ch.cyberduck.core.preferences.PreferencesFactory;
31 import org.rococoa.ID;
32 import org.rococoa.Rococoa;
33 import org.rococoa.cocoa.foundation.NSInteger;
35 import java.util.Comparator;
37 /**
38 * @version $Id$
40 public abstract class AbstractTableDelegate<E> extends ProxyController implements TableDelegate<E> {
42 private NSTableColumn selectedColumn;
44 protected AbstractTableDelegate(final NSTableColumn selectedColumn) {
45 this.selectedColumn = selectedColumn;
48 protected void setSelectedColumn(final NSTableColumn selectedColumn) {
49 this.selectedColumn = selectedColumn;
52 /**
53 * @return The identifier of the column selected or null
55 protected String selectedColumnIdentifier() {
56 // Return previously set custom sorting preference
57 return selectedColumn.identifier();
60 /**
61 * @return By default no column is editable. To be overriden in subclasses
63 public boolean isColumnRowEditable(final NSTableColumn column, final int row) {
64 return false;
67 /**
68 * @see NSTableView.DataSource
70 public boolean tableView_shouldSelectRow(final NSTableView view, final NSInteger row) {
71 return true;
74 /**
75 * @see NSTableView.DataSource
77 public boolean outlineView_shouldSelectItem(final NSOutlineView view, final NSObject item) {
78 return true;
81 /**
82 * @see NSTableView.DataSource
84 public boolean tableView_shouldEditTableColumn_row(NSTableView view, NSTableColumn c, NSInteger row) {
85 return this.isColumnRowEditable(c, row.intValue());
88 /**
89 * @see NSTableView.DataSource
91 public boolean outlineView_shouldEditTableColumn_item(final NSOutlineView view, final NSTableColumn c, final NSObject item) {
92 return this.isColumnRowEditable(c, -1);
95 public boolean selectionShouldChange() {
96 return true;
99 /**
100 * @see NSTableView.DataSource
102 public boolean selectionShouldChangeInTableView(final NSTableView view) {
103 return this.selectionShouldChange();
107 * @see NSOutlineView.DataSource
109 public boolean selectionShouldChangeInOutlineView(final NSTableView view) {
110 return this.selectionShouldChange();
113 public abstract void tableColumnClicked(NSTableView view, NSTableColumn tableColumn);
115 public void tableViewColumnDidResize(final NSNotification notification) {
116 final NSTableColumn column = Rococoa.cast(notification.userInfo().objectForKey("NSTableColumn"), NSTableColumn.class);
117 this.columnDidResize(column.identifier(), column.width().floatValue());
120 public void outlineViewColumnDidResize(final NSNotification notification) {
121 final NSTableColumn column = Rococoa.cast(notification.userInfo().objectForKey("NSTableColumn"), NSTableColumn.class);
122 this.columnDidResize(column.identifier(), column.width().floatValue());
125 public void columnDidResize(final String columnIdentifier, final float width) {
130 * @see NSOutlineView.Delegate
132 public void outlineView_didClickTableColumn(final NSOutlineView view, final NSTableColumn tableColumn) {
133 this.tableColumnClicked(view, tableColumn);
137 * @see NSTableView.Delegate
139 public void tableView_didClickTableColumn(final NSOutlineView view, final NSTableColumn tableColumn) {
140 this.tableColumnClicked(view, tableColumn);
143 public abstract void tableRowDoubleClicked(final ID sender);
145 public void tableViewSelectionDidChange(final NSNotification notification) {
146 this.selectionDidChange(notification);
149 public void tableViewSelectionIsChanging(final NSNotification notification) {
150 this.selectionIsChanging(notification);
153 public void outlineViewSelectionDidChange(final NSNotification notification) {
154 this.selectionDidChange(notification);
157 public void outlineViewSelectionIsChanging(final NSNotification notification) {
158 this.selectionIsChanging(notification);
161 public abstract void selectionDidChange(NSNotification notification);
163 public void selectionIsChanging(final NSNotification notification) {
167 // ----------------------------------------------------------
168 // Sorting
169 // ----------------------------------------------------------
171 @Override
172 public Comparator<E> getSortingComparator() {
173 return new NullComparator<E>();
176 private Boolean sortAscending;
178 public void setSortedAscending(boolean sortAscending) {
179 //cache custom sorting preference
180 this.sortAscending = sortAscending;
181 //set default value
182 PreferencesFactory.get().setProperty("browser.sort.ascending", this.sortAscending);
185 @Override
186 public boolean isSortedAscending() {
187 if(null == sortAscending) {
188 //return default value
189 return PreferencesFactory.get().getBoolean("browser.sort.ascending");
191 return sortAscending;
194 public boolean tableView_shouldTypeSelectForEvent_withCurrentSearchString(
195 NSTableView tableView, NSEvent event, String searchString) {
196 return this.isTypeSelectSupported();
199 protected abstract boolean isTypeSelectSupported();
202 * You should implement this method if your table supports varying row heights.
203 * <p/>
204 * Although table views may cache the returned values, you should ensure that this
205 * method is efficient. When you change a row's height you must invalidate the
206 * existing row height by calling noteHeightOfRowsWithIndexesChanged:. NSTableView
207 * automatically invalidates its entire row height cache when reloadData and
208 * noteNumberOfRowsChanged are called.
210 * @param tableView The table view that sent the message.
211 * @param row The row index.
212 * @return The height of the row. The height should not include intercell spacing and must be greater than zero.
214 // public CGFloat tableView_heightOfRow(NSTableView tableView, NSInteger row);
217 * Values returned by this method should not include intercell spacing and must be greater than 0. Implement
218 * this method to support an outline view with varying row heights.
219 * <p/>
220 * Special Considerations. For large tables in particular, you should make sure that this method is
221 * efficient. NSTableView
222 * may cache the values this method returns, so if you would like to change a row's height
223 * make sure to invalidate the row height by calling noteHeightOfRowsWithIndexesChanged:. NSTableView
224 * automatically invalidates its entire row height cache in reloadData and noteNumberOfRowsChanged.
226 * @param outlineView
227 * @param item
228 * @return
230 // public CGFloat outlineView_heightOfRowByItem(NSOutlineView outlineView, NSObject item);