Search in sources :

Example 1 with RegistryBackgroundAction

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

the class CommandController method sendButtonClicked.

@Action
public void sendButtonClicked(final NSButton sender) {
    final String command = this.inputField.stringValue();
    if (StringUtils.isNotBlank(command)) {
        progress.startAnimation(null);
        sender.setEnabled(false);
        parent.background(new RegistryBackgroundAction<Void>(this, session) {

            @Override
            public boolean alert(final BackgroundException e) {
                return false;
            }

            @Override
            public Void run(final Session<?> session) throws BackgroundException {
                final Command feature = session.getFeature(Command.class);
                feature.send(command, parent, CommandController.this);
                return null;
            }

            @Override
            public void cleanup() {
                super.cleanup();
                progress.stopAnimation(null);
                sender.setEnabled(true);
            }

            @Override
            public String getActivity() {
                return command;
            }
        });
    }
}
Also used : Command(ch.cyberduck.core.features.Command) NSAttributedString(ch.cyberduck.binding.foundation.NSAttributedString) BackgroundException(ch.cyberduck.core.exception.BackgroundException) Action(ch.cyberduck.binding.Action) RegistryBackgroundAction(ch.cyberduck.core.threading.RegistryBackgroundAction) WindowMainAction(ch.cyberduck.core.threading.WindowMainAction)

Example 2 with RegistryBackgroundAction

use of ch.cyberduck.core.threading.RegistryBackgroundAction 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)

Example 3 with RegistryBackgroundAction

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

the class ArchiveController method archive.

public void archive(final Archive format, final List<Path> selected) {
    new OverwriteController(parent).overwrite(Collections.singletonList(format.getArchive(selected)), 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.archive(format, parent.workdir(), selected, parent, parent);
                    return true;
                }

                @Override
                public void cleanup() {
                    super.cleanup();
                    // Update Selection
                    parent.reload(parent.workdir(), selected, Collections.singletonList(format.getArchive(selected)));
                }

                @Override
                public String getActivity() {
                    return format.getCompressCommand(parent.workdir(), selected);
                }
            });
        }
    });
}
Also used : Compress(ch.cyberduck.core.features.Compress) RegistryBackgroundAction(ch.cyberduck.core.threading.RegistryBackgroundAction) DefaultMainAction(ch.cyberduck.core.threading.DefaultMainAction) Session(ch.cyberduck.core.Session)

Aggregations

RegistryBackgroundAction (ch.cyberduck.core.threading.RegistryBackgroundAction)3 Session (ch.cyberduck.core.Session)2 Compress (ch.cyberduck.core.features.Compress)2 DefaultMainAction (ch.cyberduck.core.threading.DefaultMainAction)2 Action (ch.cyberduck.binding.Action)1 NSAttributedString (ch.cyberduck.binding.foundation.NSAttributedString)1 Archive (ch.cyberduck.core.Archive)1 Path (ch.cyberduck.core.Path)1 BackgroundException (ch.cyberduck.core.exception.BackgroundException)1 Command (ch.cyberduck.core.features.Command)1 WindowMainAction (ch.cyberduck.core.threading.WindowMainAction)1 ArrayList (java.util.ArrayList)1