Search in sources :

Example 1 with DefaultMainAction

use of ch.cyberduck.core.threading.DefaultMainAction in project cyberduck by iterate-ch.

the class SheetInvoker method beginSheet.

public int beginSheet() {
    if (NSThread.isMainThread()) {
        // No need to call invoke on main thread
        if (controller != null) {
            controller.loadBundle();
            this.beginSheet(controller.window());
        } else {
            this.beginSheet(window);
        }
    } else {
        final SheetInvoker invoker = this;
        invoke(new DefaultMainAction() {

            @Override
            public void run() {
                // Invoke again on main thread
                if (controller != null) {
                    controller.loadBundle();
                    invoker.beginSheet(controller.window());
                } else {
                    invoker.beginSheet(window);
                }
            }
        }, true);
        if (log.isDebugEnabled()) {
            log.debug("Await sheet dismiss");
        }
        // Synchronize on parent controller. Only display one sheet at once.
        Uninterruptibles.awaitUninterruptibly(signal);
        // Close window in case signal was count down prior closing window
        invoke(new DefaultMainAction() {

            @Override
            public void run() {
                // Invoke again on main thread
                if (controller != null) {
                    controller.window().orderOut(null);
                } else {
                    window.orderOut(null);
                }
            }
        }, true);
    }
    return returncode;
}
Also used : DefaultMainAction(ch.cyberduck.core.threading.DefaultMainAction)

Example 2 with DefaultMainAction

use of ch.cyberduck.core.threading.DefaultMainAction in project cyberduck by iterate-ch.

the class MoveController method rename.

/**
 * @param selected A map with the original files as the key and the destination
 *                 files as the value
 */
public void rename(final Map<Path, Path> selected) {
    final DefaultMainAction action = new DefaultMainAction() {

        @Override
        public void run() {
            final SessionPool pool = parent.getSession();
            final MoveWorker move = new MoveWorker(selected, pool.getHost().getProtocol().getStatefulness() == Protocol.Statefulness.stateful ? SessionPoolFactory.create(parent, pool.getHost()) : pool, cache, parent, LoginCallbackFactory.get(parent)) {

                @Override
                public void cleanup(final Map<Path, Path> result) {
                    final List<Path> changed = new ArrayList<>();
                    changed.addAll(selected.keySet());
                    changed.addAll(selected.values());
                    parent.reload(parent.workdir(), changed, new ArrayList<>(selected.values()));
                }
            };
            parent.background(new WorkerBackgroundAction<Map<Path, Path>>(parent, parent.getSession(), move));
        }
    };
    this.rename(selected, action);
}
Also used : Path(ch.cyberduck.core.Path) SessionPool(ch.cyberduck.core.pool.SessionPool) MoveWorker(ch.cyberduck.core.worker.MoveWorker) DefaultMainAction(ch.cyberduck.core.threading.DefaultMainAction) ArrayList(java.util.ArrayList) Map(java.util.Map)

Example 3 with DefaultMainAction

use of ch.cyberduck.core.threading.DefaultMainAction in project cyberduck by iterate-ch.

the class ProgressController method transferDidProgress.

@Override
public void transferDidProgress(final Transfer transfer, final TransferProgress progress) {
    this.setProgress(progress.getProgress());
    final double transferred = progress.getTransferred();
    final double size = progress.getSize();
    invoke(new DefaultMainAction() {

        @Override
        public void run() {
            if (transferred > 0 && size > 0) {
                progressBar.setIndeterminate(false);
                progressBar.setMaxValue(size);
                progressBar.setDoubleValue(transferred);
            } else {
                progressBar.setIndeterminate(true);
            }
        }
    });
}
Also used : DefaultMainAction(ch.cyberduck.core.threading.DefaultMainAction)

Example 4 with DefaultMainAction

use of ch.cyberduck.core.threading.DefaultMainAction in project cyberduck by iterate-ch.

the class TransferController method transferDidStart.

/**
 * @param transfer Transfer
 */
public void transferDidStart(final Transfer transfer) {
    final ProgressController progress = transferTableModel.getController(transfer);
    progress.transferDidStart(transfer);
    this.invoke(new DefaultMainAction() {

        @Override
        public void run() {
            toolbar.validateVisibleItems();
        }
    });
}
Also used : DefaultMainAction(ch.cyberduck.core.threading.DefaultMainAction)

Example 5 with DefaultMainAction

use of ch.cyberduck.core.threading.DefaultMainAction in project cyberduck by iterate-ch.

the class ArchiveController method unarchive.

public void unarchive(final List<Path> selected) {
    final List<Path> expanded = new ArrayList<Path>();
    for (final Path s : selected) {
        final Archive archive = Archive.forName(s.getName());
        if (null == archive) {
            continue;
        }
        new OverwriteController(parent).overwrite(archive.getExpanded(Collections.singletonList(s)), new DefaultMainAction() {

            @Override
            public void run() {
                parent.background(new RegistryBackgroundAction<Boolean>(parent, parent.getSession()) {

                    @Override
                    public Boolean run(final Session<?> session) throws BackgroundException {
                        final Compress feature = session.getFeature(Compress.class);
                        feature.unarchive(archive, s, parent, parent);
                        return true;
                    }

                    @Override
                    public void cleanup() {
                        super.cleanup();
                        expanded.addAll(archive.getExpanded(Collections.singletonList(s)));
                        // Update Selection
                        parent.reload(parent.workdir(), selected, expanded);
                    }

                    @Override
                    public String getActivity() {
                        return archive.getDecompressCommand(s);
                    }
                });
            }
        });
    }
}
Also used : Path(ch.cyberduck.core.Path) Compress(ch.cyberduck.core.features.Compress) RegistryBackgroundAction(ch.cyberduck.core.threading.RegistryBackgroundAction) Archive(ch.cyberduck.core.Archive) ArrayList(java.util.ArrayList) DefaultMainAction(ch.cyberduck.core.threading.DefaultMainAction) Session(ch.cyberduck.core.Session)

Aggregations

DefaultMainAction (ch.cyberduck.core.threading.DefaultMainAction)17 ArrayList (java.util.ArrayList)4 Path (ch.cyberduck.core.Path)3 MainAction (ch.cyberduck.core.threading.MainAction)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 Test (org.junit.Test)3 ProxyController (ch.cyberduck.binding.ProxyController)2 NSArray (ch.cyberduck.binding.foundation.NSArray)2 Session (ch.cyberduck.core.Session)2 ConnectionCanceledException (ch.cyberduck.core.exception.ConnectionCanceledException)2 Compress (ch.cyberduck.core.features.Compress)2 SecPolicyRef (ch.cyberduck.core.keychain.SecPolicyRef)2 SessionPool (ch.cyberduck.core.pool.SessionPool)2 RegistryBackgroundAction (ch.cyberduck.core.threading.RegistryBackgroundAction)2 Map (java.util.Map)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 Action (ch.cyberduck.binding.Action)1 NSOpenPanel (ch.cyberduck.binding.application.NSOpenPanel)1 NSEnumerator (ch.cyberduck.binding.foundation.NSEnumerator)1