@Override protected boolean processFile(AbstractFile file, Object recurseParams) { if (getState() == INTERRUPTED) return false; // Send file attachment try { sendAttachment(file); } catch (IOException e) { showErrorDialog(Translator.get("email.send_file_error", file.getName())); return false; } // If this was the last file, notify the mail server that the mail is over if (getCurrentFileIndex() == getNbFiles() - 1) { try { // Say goodbye to the server sayGoodBye(); } catch (IOException e) { showErrorDialog(Translator.get("email.goodbye_failed")); return false; } } return true; }
@Override public void performAction() { FileTable fileTable = mainFrame.getActiveTable(); FileTableModel tableModel = fileTable.getFileTableModel(); // Starts at 1 if current folder is not root so that '..' is not marked AbstractFile file; int nbRows = tableModel.getRowCount(); for (int i = tableModel.getFirstMarkableRow(); i < nbRows; i++) { file = tableModel.getFileAtRow(i); if (!file.isDirectory()) tableModel.setRowMarked(i, !tableModel.isRowMarked(i)); } fileTable.repaint(); // Notify registered listeners that currently marked files have changed on the FileTable fileTable.fireMarkedFilesChangedEvent(); }
/** * Send file as attachment encoded in Base64, and returns true if file was successfully and * completely transferred. */ private void sendAttachment(AbstractFile file) throws IOException { InputStream fileIn = null; try { // Send MIME type of attachment file String mimeType = MimeTypes.getMimeType(file); // Default mime type if (mimeType == null) mimeType = "application/octet-stream"; writeLine("Content-Type:" + mimeType + "; name=" + file.getName()); writeLine("Content-Disposition: attachment;filename=\"" + file.getName() + "\""); writeLine("Content-transfer-encoding: base64\r\n"); fileIn = setCurrentInputStream(file.getInputStream()); // Write file to socket StreamUtils.copyStream(fileIn, out64); // Writes padding bytes without closing the stream. out64.writePadding(); writeLine("\r\n--" + boundary); } finally { if (fileIn != null) fileIn.close(); } }
public ChangePermissionsDialog(MainFrame mainFrame, FileSet files) { super( mainFrame, ActionProperties.getActionLabel(ChangePermissionsAction.Descriptor.ACTION_ID), files); YBoxPanel mainPanel = new YBoxPanel(); mainPanel.add( new JLabel( ActionProperties.getActionLabel(ChangePermissionsAction.Descriptor.ACTION_ID) + " :")); mainPanel.addSpace(10); JPanel gridPanel = new JPanel(new GridLayout(4, 4)); permCheckBoxes = new JCheckBox[5][5]; JCheckBox permCheckBox; AbstractFile firstFile = files.elementAt(0); int permSetMask = firstFile.getChangeablePermissions().getIntValue(); boolean canSetPermission = permSetMask != 0; int defaultPerms = firstFile.getPermissions().getIntValue(); gridPanel.add(new JLabel()); gridPanel.add(new JLabel(Translator.get("permissions.read"))); gridPanel.add(new JLabel(Translator.get("permissions.write"))); gridPanel.add(new JLabel(Translator.get("permissions.executable"))); for (int a = USER_ACCESS; a >= OTHER_ACCESS; a--) { gridPanel.add( new JLabel( Translator.get( a == USER_ACCESS ? "permissions.user" : a == GROUP_ACCESS ? "permissions.group" : "permissions.other"))); for (int p = READ_PERMISSION; p >= EXECUTE_PERMISSION; p = p >> 1) { permCheckBox = new JCheckBox(); permCheckBox.setSelected((defaultPerms & (p << a * 3)) != 0); // Enable the checkbox only if the permission can be set in the destination if ((permSetMask & (p << a * 3)) == 0) permCheckBox.setEnabled(false); else permCheckBox.addItemListener(this); gridPanel.add(permCheckBox); permCheckBoxes[a][p] = permCheckBox; } } mainPanel.add(gridPanel); octalPermTextField = new JTextField(3); // Constrains text field to 3 digits, from 0 to 7 (octal base) Document doc = new SizeConstrainedDocument(3) { @Override public void insertString(int offset, String str, AttributeSet attributeSet) throws BadLocationException { int strLen = str.length(); char c; for (int i = 0; i < strLen; i++) { c = str.charAt(i); if (c < '0' || c > '7') return; } super.insertString(offset, str, attributeSet); } }; octalPermTextField.setDocument(doc); // Initializes the field's value updateOctalPermTextField(); if (canSetPermission) { doc.addDocumentListener(this); } // Disable text field if no permission bit can be set else { octalPermTextField.setEnabled(false); } mainPanel.addSpace(10); JPanel tempPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); tempPanel.add(new JLabel(Translator.get("permissions.octal_notation"))); tempPanel.add(octalPermTextField); mainPanel.add(tempPanel); mainPanel.addSpace(15); recurseDirCheckBox = new JCheckBox(Translator.get("recurse_directories")); // Disable check box if no permission bit can be set recurseDirCheckBox.setEnabled( canSetPermission && (files.size() > 1 || files.elementAt(0).isDirectory())); mainPanel.add(recurseDirCheckBox); // Create file details button and OK/cancel buttons and lay them out a single row JPanel fileDetailsPanel = createFileDetailsPanel(); okButton = new JButton(Translator.get("change")); cancelButton = new JButton(Translator.get("cancel")); mainPanel.add( createButtonsPanel( createFileDetailsButton(fileDetailsPanel), DialogToolkit.createOKCancelPanel(okButton, cancelButton, getRootPane(), this))); mainPanel.add(fileDetailsPanel); getContentPane().add(mainPanel, BorderLayout.NORTH); if (!canSetPermission) { // Disable OK button if no permission bit can be set okButton.setEnabled(false); } getRootPane().setDefaultButton(canSetPermission ? okButton : cancelButton); setResizable(false); }