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
.application
.NSDraggingInfo
;
22 import ch
.cyberduck
.binding
.application
.NSPasteboard
;
23 import ch
.cyberduck
.binding
.application
.NSTableColumn
;
24 import ch
.cyberduck
.binding
.application
.NSTableView
;
25 import ch
.cyberduck
.binding
.foundation
.NSArray
;
26 import ch
.cyberduck
.binding
.foundation
.NSIndexSet
;
27 import ch
.cyberduck
.binding
.foundation
.NSMutableArray
;
28 import ch
.cyberduck
.binding
.foundation
.NSObject
;
29 import ch
.cyberduck
.binding
.foundation
.NSURL
;
30 import ch
.cyberduck
.core
.AttributedList
;
31 import ch
.cyberduck
.core
.Cache
;
32 import ch
.cyberduck
.core
.Path
;
34 import org
.apache
.log4j
.Logger
;
35 import org
.rococoa
.cocoa
.foundation
.NSInteger
;
36 import org
.rococoa
.cocoa
.foundation
.NSUInteger
;
38 import java
.util
.ArrayList
;
39 import java
.util
.List
;
44 public class BrowserListViewModel
extends BrowserTableDataSource
implements NSTableView
.DataSource
{
45 private static final Logger log
= Logger
.getLogger(BrowserListViewModel
.class);
47 public BrowserListViewModel(final BrowserController controller
, final Cache
<Path
> cache
) {
48 super(controller
, cache
);
52 public void render(final NSTableView view
, final List
<Path
> folders
) {
53 if(log
.isDebugEnabled()) {
54 log
.debug(String
.format("Reload table view %s for changes files %s", view
, folders
));
57 controller
.setStatus();
61 public NSInteger
numberOfRowsInTableView(final NSTableView view
) {
62 if(controller
.isMounted()) {
63 return new NSInteger(this.get(controller
.workdir()).size());
65 return new NSInteger(0);
69 public void tableView_setObjectValue_forTableColumn_row(final NSTableView view
, final NSObject value
,
70 final NSTableColumn column
, final NSInteger row
) {
71 super.setObjectValueForItem(this.get(controller
.workdir()).get(row
.intValue()),
72 value
, column
.identifier());
76 public NSObject
tableView_objectValueForTableColumn_row(final NSTableView view
,
77 final NSTableColumn column
, final NSInteger row
) {
78 if(controller
.isMounted()) {
79 final List
<Path
> children
= this.get(controller
.workdir());
80 return super.objectValueForItem(children
.get(row
.intValue()), column
.identifier());
85 // ----------------------------------------------------------
87 // ----------------------------------------------------------
90 public NSUInteger
tableView_validateDrop_proposedRow_proposedDropOperation(final NSTableView view
,
91 final NSDraggingInfo draggingInfo
,
92 final NSInteger row
, final NSUInteger operation
) {
93 if(controller
.isMounted()) {
94 Path destination
= controller
.workdir();
95 if(row
.intValue() < this.numberOfRowsInTableView(view
).intValue()) {
96 int draggingColumn
= view
.columnAtPoint(draggingInfo
.draggingLocation()).intValue();
97 if(-1 == draggingColumn
|| 0 == draggingColumn
|| 1 == draggingColumn
) {
98 // Allow drags to icon and filename column
99 if(row
.intValue() != -1) {
100 Path p
= this.get(controller
.workdir()).get(row
.intValue());
101 if(p
.isDirectory()) {
106 return super.validateDrop(view
, destination
, row
, draggingInfo
);
108 // Draging to empty area in browser
109 return super.validateDrop(view
, destination
, row
, draggingInfo
);
111 // Passing to super to look for URLs to mount
112 return super.validateDrop(view
, null, row
, draggingInfo
);
116 public boolean tableView_acceptDrop_row_dropOperation(final NSTableView view
, final NSDraggingInfo draggingInfo
,
117 final NSInteger row
, final NSUInteger operation
) {
118 if(controller
.isMounted()) {
119 Path destination
= controller
.workdir();
120 if(row
.intValue() != -1) {
121 destination
= this.get(controller
.workdir()).get(row
.intValue());
123 return super.acceptDrop(view
, destination
, draggingInfo
);
125 return super.acceptDrop(view
, null, draggingInfo
);
128 // ----------------------------------------------------------
130 // ----------------------------------------------------------
133 * Invoked by view after it has been determined that a drag should begin, but before the drag has been started.
134 * The drag image and other drag-related information will be set up and provided by the table view once this call
137 * @param rowIndexes is the list of row numbers that will be participating in the drag.
138 * @return To refuse the drag, return false. To start a drag, return true and place the drag data onto pboard (data, owner, and so on).
141 public boolean tableView_writeRowsWithIndexes_toPasteboard(final NSTableView view
, final NSIndexSet rowIndexes
,
142 final NSPasteboard pboard
) {
143 if(controller
.isMounted()) {
144 NSMutableArray items
= NSMutableArray
.array();
145 final AttributedList
<Path
> children
= this.get(controller
.workdir());
146 final List
<Path
> selected
= new ArrayList
<Path
>();
147 for(NSUInteger index
= rowIndexes
.firstIndex(); !index
.equals(NSIndexSet
.NSNotFound
); index
= rowIndexes
.indexGreaterThanIndex(index
)) {
148 selected
.add(children
.get(index
.intValue()));
150 return super.writeItemsToPasteBoard(view
, selected
, pboard
);
156 public NSArray
tableView_namesOfPromisedFilesDroppedAtDestination_forDraggedRowsWithIndexes(final NSTableView view
,
157 final NSURL dropDestination
,
158 final NSIndexSet rowIndexes
) {
159 return this.namesOfPromisedFilesDroppedAtDestination(dropDestination
);