Search in sources :

Example 1 with NSInteger

use of org.rococoa.cocoa.foundation.NSInteger in project cyberduck by iterate-ch.

the class InfoController method addMetadataItem.

/**
 * @param name        HTTP header name
 * @param value       HTTP header value
 * @param selectValue Select the value field or the name header field
 */
private void addMetadataItem(String name, String value, boolean selectValue) {
    int row = metadata.size();
    List<Header> updated = new ArrayList<>(metadata);
    updated.add(row, new Header(name, value));
    this.setMetadata(updated);
    metadataTable.selectRowIndexes(NSIndexSet.indexSetWithIndex(new NSInteger(row)), false);
    metadataTable.editRow(selectValue ? metadataTable.columnWithIdentifier(MetadataColumn.VALUE.name()) : metadataTable.columnWithIdentifier(MetadataColumn.NAME.name()), new NSInteger(row), true);
}
Also used : NSInteger(org.rococoa.cocoa.foundation.NSInteger) ArrayList(java.util.ArrayList) NSPoint(org.rococoa.cocoa.foundation.NSPoint)

Example 2 with NSInteger

use of org.rococoa.cocoa.foundation.NSInteger 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();
}
Also used : NSObject(ch.cyberduck.binding.foundation.NSObject) NSNotification(ch.cyberduck.binding.foundation.NSNotification) NSPoint(org.rococoa.cocoa.foundation.NSPoint) AbstractTableDelegate(ch.cyberduck.binding.AbstractTableDelegate) NSMutableAttributedString(ch.cyberduck.binding.foundation.NSMutableAttributedString) NSString(ch.cyberduck.binding.foundation.NSString) NSAttributedString(ch.cyberduck.binding.foundation.NSAttributedString) ListDataSource(ch.cyberduck.binding.ListDataSource) NSInteger(org.rococoa.cocoa.foundation.NSInteger) ID(org.rococoa.ID)

Example 3 with NSInteger

use of org.rococoa.cocoa.foundation.NSInteger in project cyberduck by iterate-ch.

the class TransferController method add.

private void add(final Transfer transfer) {
    collection.add(transfer);
    final int row = collection.size() - 1;
    final NSInteger index = new NSInteger(row);
    transferTable.selectRowIndexes(NSIndexSet.indexSetWithIndex(index), false);
    transferTable.scrollRowToVisible(index);
}
Also used : NSInteger(org.rococoa.cocoa.foundation.NSInteger)

Example 4 with NSInteger

use of org.rococoa.cocoa.foundation.NSInteger 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();
}
Also used : NSInteger(org.rococoa.cocoa.foundation.NSInteger) NSNotification(ch.cyberduck.binding.foundation.NSNotification) TransferTableDataSource(ch.cyberduck.ui.cocoa.datasource.TransferTableDataSource) DownloadTransfer(ch.cyberduck.core.transfer.DownloadTransfer) Transfer(ch.cyberduck.core.transfer.Transfer) AbstractTableDelegate(ch.cyberduck.binding.AbstractTableDelegate) ID(org.rococoa.ID) NSUInteger(org.rococoa.cocoa.foundation.NSUInteger) CGFloat(org.rococoa.cocoa.CGFloat)

Example 5 with NSInteger

use of org.rococoa.cocoa.foundation.NSInteger in project cyberduck by iterate-ch.

the class PreferencesController method downloadPathPanelDidEnd_returnCode_contextInfo.

public void downloadPathPanelDidEnd_returnCode_contextInfo(NSOpenPanel sheet, int returncode, ID contextInfo) {
    if (returncode == SheetCallback.DEFAULT_OPTION) {
        NSObject selected = sheet.URLs().lastObject();
        if (selected != null) {
            final Local folder = LocalFactory.get(Rococoa.cast(selected, NSURL.class).path());
            preferences.setProperty("queue.download.folder", folder.getAbbreviatedPath());
            preferences.setProperty("queue.download.folder.bookmark", folder.getBookmark());
        }
    }
    final Local custom = LocalFactory.get(preferences.getProperty("queue.download.folder"));
    final NSMenuItem item = downloadPathPopup.itemAtIndex(new NSInteger(0));
    item.setTitle(custom.getDisplayName());
    item.setRepresentedObject(custom.getAbsolute());
    item.setImage(IconCacheFactory.<NSImage>get().fileIcon(custom, 16));
    downloadPathPopup.selectItem(item);
    downloadPathPanel = null;
}
Also used : NSInteger(org.rococoa.cocoa.foundation.NSInteger) NSObject(ch.cyberduck.binding.foundation.NSObject)

Aggregations

NSInteger (org.rococoa.cocoa.foundation.NSInteger)34 NSObject (ch.cyberduck.binding.foundation.NSObject)9 NSPoint (org.rococoa.cocoa.foundation.NSPoint)9 NSAttributedString (ch.cyberduck.binding.foundation.NSAttributedString)8 ID (org.rococoa.ID)8 NSMutableAttributedString (ch.cyberduck.binding.foundation.NSMutableAttributedString)7 NSNotification (ch.cyberduck.binding.foundation.NSNotification)7 CGFloat (org.rococoa.cocoa.CGFloat)6 AbstractTableDelegate (ch.cyberduck.binding.AbstractTableDelegate)5 DefaultMainAction (ch.cyberduck.core.threading.DefaultMainAction)4 WindowMainAction (ch.cyberduck.core.threading.WindowMainAction)4 Action (ch.cyberduck.binding.Action)3 ListDataSource (ch.cyberduck.binding.ListDataSource)3 NSImage (ch.cyberduck.binding.application.NSImage)3 NSMenuItem (ch.cyberduck.binding.application.NSMenuItem)3 NSArray (ch.cyberduck.binding.foundation.NSArray)3 NSString (ch.cyberduck.binding.foundation.NSString)3 Path (ch.cyberduck.core.Path)3 BackgroundAction (ch.cyberduck.core.threading.BackgroundAction)3 BrowserTransferBackgroundAction (ch.cyberduck.core.threading.BrowserTransferBackgroundAction)3