@Override public void actionPerformed(final ActionEvent e) { final int picturesToUpload = core.countPicturesToBeUploaded(); if (picturesToUpload == 0) { JOptionPane.showMessageDialog( SwingUtilities.getWindowAncestor((Component) e.getSource()), UI.BUNDLE.getString("action.upload.none")); } else { final int choice = JOptionPane.showConfirmDialog( SwingUtilities.getWindowAncestor((Component) e.getSource()), MessageFormat.format( UI.BUNDLE.getString("action.upload.confirm"), picturesToUpload, wikis.getActiveWiki().getName()), UIManager.getString("OptionPane.titleText"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, ICON); if (JOptionPane.OK_OPTION == choice) { new SwingWorker<Void, Void>() { @Override protected Void doInBackground() throws Exception { core.uploadPictures(); return null; } }.execute(); } } }
/* * (non-Javadoc) * * @see comeon.commons.Commons#upload(comeon.model.Picture, * in.yuvi.http.fluent.ProgressListener) */ @Override public void upload(final Picture picture, final ProgressListener listener) throws NotLoggedInException, FailedLoginException, FailedUploadException, IOException { synchronized (this) { if (!this.api.isLoggedIn) { LOGGER.debug("Not logged in"); this.login(); } } final InputStream stream = Files.asByteSource(picture.getFile()).openBufferedStream(); try { LOGGER.debug("Uploading"); final ApiResult result = this.api.upload( picture.getFile().getName(), stream, picture.getFile().length(), picture.getRenderedTemplate(), MessageFormat.format( UI.BUNDLE.getString("upload.comment"), UI.BUNDLE.getString("comeon")), true, listener); final ApiResult error = result.getNode("/api/error"); if (error.getDocument() != null) { final String code = error.getString("@code"); final String info = error.getString("@info"); throw new FailedUploadException(code, info); } final List<ApiResult> warnings = result.getNodes("/api/warning"); if (warnings != null && !warnings.isEmpty()) { for (final ApiResult warning : warnings) { final String code = warning.getString("@code"); final String info = warning.getString("@info"); LOGGER.warn("Upload warning. MediaWiki says: {}: {}", code, info); } } } catch (final IOException e) { throw new FailedUploadException(e); } }
@Inject public TemplateSubPanel( final TemplateSubController templateSubController, final Templates templates) { this.nameField = new JTextField(COLUMNS); this.nameField.setName(UI.BUNDLE.getString("prefs.templates.name")); this.nameField.requestFocusInWindow(); this.descriptionField = new JTextArea(3, 0); this.descriptionField.setName(UI.BUNDLE.getString("prefs.templates.description")); this.descriptionPane = new JScrollPane( descriptionField, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); this.fileField = new JTextField(COLUMNS); this.fileField.setName(UI.BUNDLE.getString("prefs.templates.path")); this.fileField.setEditable(false); this.fileButton = new JButton(UI.BUNDLE.getString("prefs.templates.path.pick.title")); this.fileButton.setMnemonic(UI.BUNDLE.getString("prefs.templates.path.pick.mnemo").charAt(0)); this.charsetField = new JComboBox<>(templates.getSupportedCharsets()); this.charsetField.setName(UI.BUNDLE.getString("prefs.templates.charset")); this.kindField = new JComboBox<>(templates.getTemplateKinds().toArray(new TemplateKind[0])); this.kindField.setName(UI.BUNDLE.getString("prefs.templates.kind")); this.fileChooser = new JFileChooser(); this.fileChooser.setMultiSelectionEnabled(false); this.fileButton.addActionListener( new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { SwingUtilities.invokeLater( new Runnable() { @Override public void run() { final int option = fileChooser.showOpenDialog(SwingUtilities.getRoot(TemplateSubPanel.this)); switch (option) { case JFileChooser.APPROVE_OPTION: final File selectedFile = fileChooser.getSelectedFile(); TemplateSubPanel.this.firePropertyChange( SELECTED_FILE_PROPERTY, null, selectedFile); break; default: break; } } }); } }); this.layoutComponents(); templateSubController.setView(this); }