use of ch.cyberduck.binding.ListDataSource 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.ListDataSource 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.ListDataSource 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