Merge pull request #64 in ITERATE/cyberduck from feature/windows/9074 to master
[cyberduck.git] / source / ch / cyberduck / ui / cocoa / threading / AlertTransferErrorCallback.java
blob0efcbb3d7f877d9e74b4502c3caa44f3be0ca5b2
1 package ch.cyberduck.ui.cocoa.threading;
3 /*
4 * Copyright (c) 2002-2013 David Kocher. All rights reserved.
5 * http://cyberduck.ch/
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * Bug fixes, suggestions and comments should be sent to:
18 * feedback@cyberduck.ch
21 import ch.cyberduck.binding.application.NSAlert;
22 import ch.cyberduck.binding.application.NSCell;
23 import ch.cyberduck.binding.application.SheetCallback;
24 import ch.cyberduck.core.LocaleFactory;
25 import ch.cyberduck.core.exception.BackgroundException;
26 import ch.cyberduck.core.transfer.TransferErrorCallback;
27 import ch.cyberduck.ui.cocoa.AlertController;
28 import ch.cyberduck.ui.cocoa.WindowController;
30 import java.util.concurrent.atomic.AtomicBoolean;
32 /**
33 * @version $Id$
35 public class AlertTransferErrorCallback implements TransferErrorCallback {
37 private final WindowController controller;
39 private boolean suppressed;
41 private boolean option;
43 public AlertTransferErrorCallback(final WindowController controller) {
44 this.controller = controller;
47 @Override
48 public boolean prompt(final BackgroundException failure) {
49 if(suppressed) {
50 return option;
52 if(controller.isVisible()) {
53 final AtomicBoolean c = new AtomicBoolean(true);
54 final NSAlert alert = NSAlert.alert(
55 null == failure.getMessage() ? LocaleFactory.localizedString("Unknown") : failure.getMessage(),
56 null == failure.getDetail() ? LocaleFactory.localizedString("Unknown") : failure.getDetail(),
57 LocaleFactory.localizedString("Cancel"), // default button
58 null, //other button
59 LocaleFactory.localizedString("Continue", "Credentials") // alternate button
61 alert.setShowsSuppressionButton(true);
62 alert.suppressionButton().setTitle(LocaleFactory.localizedString("Always"));
63 final AlertController controller = new AlertController(AlertTransferErrorCallback.this.controller, alert) {
64 @Override
65 public void callback(final int returncode) {
66 if(returncode == SheetCallback.DEFAULT_OPTION) {
67 c.set(false);
69 if(alert.suppressionButton().state() == NSCell.NSOnState) {
70 suppressed = true;
71 option = c.get();
75 controller.beginSheet();
76 return c.get();
78 // Abort
79 return false;