use of ch.cyberduck.binding.AbstractTableDelegate in project cyberduck by iterate-ch.
the class InfoController method setAclTable.
public void setAclTable(final NSTableView t) {
this.aclTable = t;
this.aclTable.setAllowsMultipleSelection(true);
this.aclPermissionCellPrototype.setFont(NSFont.systemFontOfSize(NSFont.smallSystemFontSize()));
this.aclPermissionCellPrototype.setControlSize(NSCell.NSSmallControlSize);
this.aclPermissionCellPrototype.setCompletes(false);
this.aclPermissionCellPrototype.setBordered(false);
this.aclPermissionCellPrototype.setButtonBordered(false);
this.aclTable.setColumnAutoresizingStyle(NSTableView.NSTableViewUniformColumnAutoresizingStyle);
this.aclTable.tableColumnWithIdentifier(AclColumn.PERMISSION.name()).setDataCell(aclPermissionCellPrototype);
this.aclTable.setDataSource((aclTableModel = new ListDataSource() {
@Override
public NSInteger numberOfRowsInTableView(NSTableView view) {
return new NSInteger(acl.size());
}
public NSObject tableView_objectValueForTableColumn_row(NSTableView view, NSTableColumn tableColumn, NSInteger row) {
if (row.intValue() < acl.size()) {
final String identifier = tableColumn.identifier();
final Acl.UserAndRole grant = acl.get(row.intValue());
if (identifier.equals(AclColumn.GRANTEE.name())) {
return NSString.stringWithString(grant.getUser().getDisplayName());
}
if (identifier.equals(AclColumn.PERMISSION.name())) {
return NSString.stringWithString(grant.getRole().getName());
}
}
return null;
}
@Override
public void tableView_setObjectValue_forTableColumn_row(NSTableView view, NSObject value, NSTableColumn c, NSInteger row) {
if (row.intValue() < acl.size()) {
final Acl.UserAndRole grant = acl.get(row.intValue());
if (c.identifier().equals(AclColumn.GRANTEE.name())) {
grant.getUser().setIdentifier(value.toString());
}
if (c.identifier().equals(AclColumn.PERMISSION.name())) {
grant.getRole().setName(value.toString());
}
if (StringUtils.isNotBlank(grant.getUser().getIdentifier()) && StringUtils.isNotBlank(grant.getRole().getName())) {
InfoController.this.aclInputDidEndEditing();
}
}
}
}).id());
this.aclTable.setDelegate((aclTableDelegate = new AbstractTableDelegate<Acl.UserAndRole, AclColumn>(aclTable.tableColumnWithIdentifier(AclColumn.GRANTEE.name())) {
@Override
public boolean isColumnRowEditable(NSTableColumn column, NSInteger row) {
if (column.identifier().equals(AclColumn.GRANTEE.name())) {
final Acl.UserAndRole grant = acl.get(row.intValue());
if (grant.getUser().isEditable()) {
return true;
}
// Group Grantee identifier is not editable
return false;
}
if (column.identifier().equals(AclColumn.PERMISSION.name())) {
final Acl.UserAndRole grant = acl.get(row.intValue());
if (grant.getRole().isEditable()) {
return true;
}
// Static role that cannot be modified
return false;
}
return true;
}
@Override
public void tableRowDoubleClicked(final ID sender) {
this.enterKeyPressed(sender);
}
@Override
public void enterKeyPressed(final ID sender) {
aclTable.editRow(aclTable.columnWithIdentifier(AclColumn.GRANTEE.name()), aclTable.selectedRow(), true);
}
@Override
public void deleteKeyPressed(final ID sender) {
aclRemoveButtonClicked(sender);
}
public String tableView_toolTipForCell_rect_tableColumn_row_mouseLocation(NSTableView t, NSCell cell, ID rect, NSTableColumn c, NSInteger row, NSPoint mouseLocation) {
return this.tooltip(acl.get(row.intValue()), AclColumn.valueOf(c.identifier()));
}
@Override
public String tooltip(Acl.UserAndRole c, final AclColumn column) {
return c.getUser().getIdentifier();
}
@Override
public void tableColumnClicked(NSTableView view, NSTableColumn c) {
//
}
@Override
public void selectionDidChange(final NSNotification notification) {
aclRemoveButton.setEnabled(aclTable.numberOfSelectedRows().intValue() > 0);
}
public void tableView_willDisplayCell_forTableColumn_row(NSTableView view, NSCell cell, NSTableColumn c, NSInteger row) {
final Acl.UserAndRole grant = acl.get(row.intValue());
if (c.identifier().equals(AclColumn.GRANTEE.name())) {
final NSTextFieldCell textFieldCell = Rococoa.cast(cell, NSTextFieldCell.class);
textFieldCell.setPlaceholderString(grant.getUser().getPlaceholder());
if (grant.getUser().isEditable()) {
textFieldCell.setTextColor(NSColor.controlTextColor());
} else {
// Group Grantee identifier is not editable
textFieldCell.setTextColor(NSColor.disabledControlTextColor());
}
}
if (c.identifier().equals(AclColumn.PERMISSION.name())) {
if (grant.getRole().isEditable()) {
cell.setEnabled(true);
} else {
cell.setEnabled(false);
}
}
}
@Override
protected boolean isTypeSelectSupported() {
return false;
}
}).id());
this.aclTable.sizeToFit();
}
use of ch.cyberduck.binding.AbstractTableDelegate in project cyberduck by iterate-ch.
the class TransferController method setQueueTable.
public void setQueueTable(NSTableView view) {
this.transferTable = view;
this.transferTable.setRowHeight(new CGFloat(82));
{
NSTableColumn c = tableColumnsFactory.create(TransferColumn.progress.name());
c.setMinWidth(80f);
c.setWidth(300f);
c.setResizingMask(NSTableColumn.NSTableColumnAutoresizingMask);
this.transferTable.addTableColumn(c);
}
this.transferTable.setDataSource((transferTableModel = new TransferTableDataSource()).id());
this.transferTable.setDelegate((transferTableDelegate = new AbstractTableDelegate<Transfer, TransferColumn>(transferTable.tableColumnWithIdentifier(TransferColumn.progress.name())) {
@Override
public String tooltip(final Transfer t, final TransferColumn column) {
return t.getName();
}
@Override
public void enterKeyPressed(final ID sender) {
this.tableRowDoubleClicked(sender);
}
@Override
public void deleteKeyPressed(final ID sender) {
deleteButtonClicked(sender);
}
@Override
public void tableColumnClicked(NSTableView view, NSTableColumn tableColumn) {
//
}
@Override
public void tableRowDoubleClicked(final ID sender) {
reloadButtonClicked(sender);
}
@Override
public void selectionIsChanging(final NSNotification notification) {
updateHighlight();
}
@Override
public void selectionDidChange(final NSNotification notification) {
updateHighlight();
updateSelection();
transferTable.noteHeightOfRowsWithIndexesChanged(NSIndexSet.indexSetWithIndexesInRange(NSRange.NSMakeRange(new NSUInteger(0), new NSUInteger(transferTable.numberOfRows()))));
}
public NSView tableView_viewForTableColumn_row(final NSTableView view, final NSTableColumn column, final NSInteger row) {
final ProgressController controller = transferTableModel.getController(row.intValue());
return controller.view();
}
@Override
public boolean isTypeSelectSupported() {
return true;
}
public String tableView_typeSelectStringForTableColumn_row(final NSTableView view, final NSTableColumn column, final NSInteger row) {
return transferTableModel.getSource().get(row.intValue()).getName();
}
}).id());
// receive drag events from types
// in fact we are not interested in file promises, but because the browser model can only initiate
// a drag with tableView.dragPromisedFilesOfTypes(), we listens for those events
// and then use the private pasteboard instead.
this.transferTable.registerForDraggedTypes(NSArray.arrayWithObjects(NSPasteboard.StringPboardType, // Accept file promises made myself
NSPasteboard.FilesPromisePboardType));
// No grid lines until list is loaded
this.transferTable.setGridStyleMask(NSTableView.NSTableViewGridNone);
// Set sselection properties
this.transferTable.setAllowsMultipleSelection(true);
this.transferTable.setAllowsEmptySelection(true);
this.transferTable.setAllowsColumnReordering(false);
this.transferTable.sizeToFit();
}
use of ch.cyberduck.binding.AbstractTableDelegate in project cyberduck by iterate-ch.
the class InfoController method setMetadataTable.
public void setMetadataTable(final NSTableView t) {
this.metadataTable = t;
this.metadataTable.setAllowsMultipleSelection(true);
this.metadataTable.setColumnAutoresizingStyle(NSTableView.NSTableViewUniformColumnAutoresizingStyle);
this.metadataTable.setDataSource((metadataTableModel = new ListDataSource() {
@Override
public NSInteger numberOfRowsInTableView(NSTableView view) {
return new NSInteger(metadata.size());
}
public NSObject tableView_objectValueForTableColumn_row(NSTableView view, NSTableColumn tableColumn, NSInteger row) {
if (row.intValue() < metadata.size()) {
final String identifier = tableColumn.identifier();
if (identifier.equals(MetadataColumn.NAME.name())) {
final String name = metadata.get(row.intValue()).getName();
return NSAttributedString.attributedString(StringUtils.isNotEmpty(name) ? name : StringUtils.EMPTY);
}
if (identifier.equals(MetadataColumn.VALUE.name())) {
final String value = metadata.get(row.intValue()).getValue();
return NSAttributedString.attributedString(value != null ? value : LocaleFactory.localizedString("Multiple files"));
}
}
return null;
}
@Override
public void tableView_setObjectValue_forTableColumn_row(NSTableView view, NSObject value, NSTableColumn c, NSInteger row) {
if (row.intValue() < metadata.size()) {
Header header = metadata.get(row.intValue());
if (c.identifier().equals(MetadataColumn.NAME.name())) {
header.setName(value.toString());
}
if (c.identifier().equals(MetadataColumn.VALUE.name())) {
header.setValue(value.toString());
}
if (StringUtils.isNotBlank(header.getName()) && StringUtils.isNotBlank(header.getValue())) {
// Only update if both fields are set
metadataInputDidEndEditing();
}
}
}
}).id());
this.metadataTable.setDelegate((metadataTableDelegate = new AbstractTableDelegate<String, MetadataColumn>(metadataTable.tableColumnWithIdentifier(MetadataColumn.NAME.name())) {
@Override
public boolean isColumnRowEditable(NSTableColumn column, NSInteger row) {
return true;
}
@Override
public void tableRowDoubleClicked(final ID sender) {
this.enterKeyPressed(sender);
}
@Override
public void enterKeyPressed(final ID sender) {
metadataTable.editRow(metadataTable.columnWithIdentifier(MetadataColumn.VALUE.name()), metadataTable.selectedRow(), true);
}
@Override
public void deleteKeyPressed(final ID sender) {
metadataRemoveButtonClicked(sender);
}
@Override
public String tooltip(String c, final MetadataColumn column) {
return c;
}
@Override
public void tableColumnClicked(NSTableView view, NSTableColumn c) {
//
}
@Override
public void selectionDidChange(final NSNotification notification) {
metadataRemoveButton.setEnabled(metadataTable.numberOfSelectedRows().intValue() > 0);
}
@Override
protected boolean isTypeSelectSupported() {
return false;
}
public void tableView_willDisplayCell_forTableColumn_row(NSTableView view, NSTextFieldCell cell, NSTableColumn c, NSInteger row) {
if (c.identifier().equals(MetadataColumn.VALUE.name())) {
final String value = metadata.get(row.intValue()).getValue();
if (null == value) {
cell.setPlaceholderString(LocaleFactory.localizedString("Multiple files"));
}
}
}
}).id());
this.metadataTable.sizeToFit();
}
use of ch.cyberduck.binding.AbstractTableDelegate 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();
}
use of ch.cyberduck.binding.AbstractTableDelegate in project cyberduck by iterate-ch.
the class ActivityController method setTable.
public void setTable(NSTableView table) {
this.table = table;
this.table.setRowHeight(new CGFloat(42));
{
final NSTableColumn c = tableColumnsFactory.create(ActivityColumn.single.name());
c.setMinWidth(80f);
c.setWidth(300f);
c.setResizingMask(NSTableColumn.NSTableColumnAutoresizingMask);
this.table.addTableColumn(c);
}
this.table.setDataSource((model = new ListDataSource() {
@Override
public NSObject tableView_objectValueForTableColumn_row(final NSTableView view, final NSTableColumn tableColumn, final NSInteger row) {
return null;
}
@Override
public NSInteger numberOfRowsInTableView(NSTableView view) {
return new NSInteger(tasks.size());
}
}).id());
this.table.setDelegate((delegate = new AbstractTableDelegate<TaskController, ActivityColumn>(table.tableColumnWithIdentifier("Default")) {
@Override
public void enterKeyPressed(final ID sender) {
}
@Override
public void deleteKeyPressed(final ID sender) {
}
@Override
public String tooltip(final TaskController c, final ActivityColumn column) {
return null;
}
@Override
public boolean tableView_shouldSelectRow(final NSTableView view, final NSInteger row) {
return false;
}
@Override
public void tableColumnClicked(final NSTableView view, final NSTableColumn tableColumn) {
}
@Override
public void tableRowDoubleClicked(final ID sender) {
}
@Override
public void selectionDidChange(final NSNotification notification) {
}
@Override
protected boolean isTypeSelectSupported() {
return false;
}
public NSView tableView_viewForTableColumn_row(final NSTableView view, final NSTableColumn column, final NSInteger row) {
final TaskController controller = getController(row);
return controller.view();
}
}).id());
this.table.sizeToFit();
}
Aggregations