1 package ch
.cyberduck
.ui
.cocoa
;
4 * Copyright (c) 2005 David Kocher. All rights reserved.
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
;
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
;
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();
61 * @return By default no column is editable. To be overriden in subclasses
63 public boolean isColumnRowEditable(final NSTableColumn column
, final int row
) {
68 * @see NSTableView.DataSource
70 public boolean tableView_shouldSelectRow(final NSTableView view
, final NSInteger row
) {
75 * @see NSTableView.DataSource
77 public boolean outlineView_shouldSelectItem(final NSOutlineView view
, final NSObject item
) {
82 * @see NSTableView.DataSource
84 public boolean tableView_shouldEditTableColumn_row(final NSTableView view
, final NSTableColumn c
, final NSInteger row
) {
85 return this.isColumnRowEditable(c
, row
.intValue());
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() {
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 // ----------------------------------------------------------
169 // ----------------------------------------------------------
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
;
182 PreferencesFactory
.get().setProperty("browser.sort.ascending", this.sortAscending
);
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 final NSTableView view
, final NSEvent event
, final String searchString
) {
196 return this.isTypeSelectSupported();
199 public boolean outlineView_shouldTypeSelectForEvent_withCurrentSearchString(
200 final NSOutlineView view
, final NSEvent event
, final String searchString
) {
201 return this.isTypeSelectSupported();
204 protected abstract boolean isTypeSelectSupported();
207 * You should implement this method if your table supports varying row heights.
209 * Although table views may cache the returned values, you should ensure that this
210 * method is efficient. When you change a row's height you must invalidate the
211 * existing row height by calling noteHeightOfRowsWithIndexesChanged:. NSTableView
212 * automatically invalidates its entire row height cache when reloadData and
213 * noteNumberOfRowsChanged are called.
215 * @param tableView The table view that sent the message.
216 * @param row The row index.
217 * @return The height of the row. The height should not include intercell spacing and must be greater than zero.
219 // public CGFloat tableView_heightOfRow(NSTableView tableView, NSInteger row);
222 * Values returned by this method should not include intercell spacing and must be greater than 0. Implement
223 * this method to support an outline view with varying row heights.
225 * Special Considerations. For large tables in particular, you should make sure that this method is
226 * efficient. NSTableView
227 * may cache the values this method returns, so if you would like to change a row's height
228 * make sure to invalidate the row height by calling noteHeightOfRowsWithIndexesChanged:. NSTableView
229 * automatically invalidates its entire row height cache in reloadData and noteNumberOfRowsChanged.
235 // public CGFloat outlineView_heightOfRowByItem(NSOutlineView outlineView, NSObject item);