Search in sources :

Example 1 with CancelCallback

use of org.eclipse.che.ide.api.dialogs.CancelCallback in project che by eclipse.

the class SshKeyManagerPresenterTest method testOnDeleteClickedWhenDeleteKeyCanceled.

@Test
public void testOnDeleteClickedWhenDeleteKeyCanceled() {
    SafeHtml safeHtml = mock(SafeHtml.class);
    ConfirmDialog confirmDialog = mock(ConfirmDialog.class);
    when(constant.deleteSshKeyQuestion(anyString())).thenReturn(safeHtml);
    when(safeHtml.asString()).thenReturn("");
    when(dialogFactory.createConfirmDialog(anyString(), anyString(), (ConfirmCallback) anyObject(), (CancelCallback) anyObject())).thenReturn(confirmDialog);
    presenter.onDeleteClicked(sshPairDto);
    verify(dialogFactory).createConfirmDialog(anyString(), anyString(), (ConfirmCallback) anyObject(), cancelCallbackCaptor.capture());
    CancelCallback cancelCallback = cancelCallbackCaptor.getValue();
    cancelCallback.cancelled();
    verify(confirmDialog).show();
    verify(service, never()).deletePair(Matchers.eq(SshKeyManagerPresenter.VCS_SSH_SERVICE), anyString());
}
Also used : SafeHtml(com.google.gwt.safehtml.shared.SafeHtml) CancelCallback(org.eclipse.che.ide.api.dialogs.CancelCallback) ConfirmDialog(org.eclipse.che.ide.api.dialogs.ConfirmDialog) Test(org.junit.Test)

Example 2 with CancelCallback

use of org.eclipse.che.ide.api.dialogs.CancelCallback in project che by eclipse.

the class CopyPasteManager method moveResource.

private Promise<Void> moveResource(final Resource resource, final Path destination) {
    //simple move without overwriting
    return resource.move(destination).thenPromise(new Function<Resource, Promise<Void>>() {

        @Override
        public Promise<Void> apply(Resource resource) throws FunctionException {
            eventBus.fireEvent(new RevealResourceEvent(resource));
            return promises.resolve(null);
        }
    }).catchErrorPromise(new Function<PromiseError, Promise<Void>>() {

        @Override
        public Promise<Void> apply(final PromiseError error) throws FunctionException {
            //resource may already exists
            if (error.getMessage().contains("exists")) {
                //create dialog with overwriting option
                return createFromAsyncRequest(new RequestCall<Void>() {

                    @Override
                    public void makeCall(final AsyncCallback<Void> callback) {
                        //handle overwrite operation
                        final ConfirmCallback overwrite = new ConfirmCallback() {

                            @Override
                            public void accepted() {
                                //copy with overwriting
                                resource.move(destination, true).then(new Operation<Resource>() {

                                    @Override
                                    public void apply(Resource ignored) throws OperationException {
                                        callback.onSuccess(null);
                                    }
                                }).catchError(new Operation<PromiseError>() {

                                    @Override
                                    public void apply(PromiseError error) throws OperationException {
                                        callback.onFailure(error.getCause());
                                    }
                                });
                            }
                        };
                        //skip this resource
                        final ConfirmCallback skip = new ConfirmCallback() {

                            @Override
                            public void accepted() {
                                callback.onSuccess(null);
                            }
                        };
                        //change destination name
                        final ConfirmCallback rename = new ConfirmCallback() {

                            @Override
                            public void accepted() {
                                dialogFactory.createInputDialog("Enter new name", "Enter new name", new InputCallback() {

                                    @Override
                                    public void accepted(String value) {
                                        final Path newPath = destination.parent().append(value);
                                        moveResource(resource, newPath).then(new Operation<Void>() {

                                            @Override
                                            public void apply(Void result) throws OperationException {
                                                callback.onSuccess(result);
                                            }
                                        }).catchError(new Operation<PromiseError>() {

                                            @Override
                                            public void apply(PromiseError error) throws OperationException {
                                                callback.onFailure(error.getCause());
                                            }
                                        });
                                    }
                                }, new CancelCallback() {

                                    @Override
                                    public void cancelled() {
                                    }
                                }).show();
                            }
                        };
                        dialogFactory.createChoiceDialog("Error", error.getMessage(), "Overwrite", "Skip", "Change Name", overwrite, skip, rename).show();
                    }
                });
            } else {
                //notify user about failed copying
                notificationManager.notify("Error moving resource", error.getMessage(), FAIL, FLOAT_MODE);
                return promises.resolve(null);
            }
        }
    });
}
Also used : Path(org.eclipse.che.ide.resource.Path) ConfirmCallback(org.eclipse.che.ide.api.dialogs.ConfirmCallback) RequestCall(org.eclipse.che.api.promises.client.callback.AsyncPromiseHelper.RequestCall) InputCallback(org.eclipse.che.ide.api.dialogs.InputCallback) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) Resource(org.eclipse.che.ide.api.resources.Resource) FunctionException(org.eclipse.che.api.promises.client.FunctionException) Operation(org.eclipse.che.api.promises.client.Operation) Function(org.eclipse.che.api.promises.client.Function) Promise(org.eclipse.che.api.promises.client.Promise) PromiseError(org.eclipse.che.api.promises.client.PromiseError) CancelCallback(org.eclipse.che.ide.api.dialogs.CancelCallback) RevealResourceEvent(org.eclipse.che.ide.resources.reveal.RevealResourceEvent) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 3 with CancelCallback

use of org.eclipse.che.ide.api.dialogs.CancelCallback in project che by eclipse.

the class CopyPasteManager method copyResource.

private Promise<Void> copyResource(final Resource resource, final Path destination) {
    //simple copy without overwriting
    return resource.copy(destination).thenPromise(new Function<Resource, Promise<Void>>() {

        @Override
        public Promise<Void> apply(Resource resource) throws FunctionException {
            eventBus.fireEvent(new RevealResourceEvent(resource));
            return promises.resolve(null);
        }
    }).catchErrorPromise(new Function<PromiseError, Promise<Void>>() {

        @Override
        public Promise<Void> apply(final PromiseError error) throws FunctionException {
            //resource may already exists
            if (error.getMessage().contains("exists")) {
                //create dialog with overwriting option
                return createFromAsyncRequest(new RequestCall<Void>() {

                    @Override
                    public void makeCall(final AsyncCallback<Void> callback) {
                        //handle overwrite operation
                        final ConfirmCallback overwrite = new ConfirmCallback() {

                            @Override
                            public void accepted() {
                                //copy with overwriting
                                resource.copy(destination, true).then(new Operation<Resource>() {

                                    @Override
                                    public void apply(Resource ignored) throws OperationException {
                                        callback.onSuccess(null);
                                    }
                                }).catchError(new Operation<PromiseError>() {

                                    @Override
                                    public void apply(PromiseError error) throws OperationException {
                                        callback.onFailure(error.getCause());
                                    }
                                });
                            }
                        };
                        //skip this resource
                        final ConfirmCallback skip = new ConfirmCallback() {

                            @Override
                            public void accepted() {
                                callback.onSuccess(null);
                            }
                        };
                        //change destination name
                        final ConfirmCallback rename = new ConfirmCallback() {

                            @Override
                            public void accepted() {
                                dialogFactory.createInputDialog("Enter new name", "Enter new name", new InputCallback() {

                                    @Override
                                    public void accepted(String value) {
                                        final Path newPath = destination.parent().append(value);
                                        copyResource(resource, newPath).then(new Operation<Void>() {

                                            @Override
                                            public void apply(Void result) throws OperationException {
                                                callback.onSuccess(result);
                                            }
                                        }).catchError(new Operation<PromiseError>() {

                                            @Override
                                            public void apply(PromiseError error) throws OperationException {
                                                callback.onFailure(error.getCause());
                                            }
                                        });
                                    }
                                }, new CancelCallback() {

                                    @Override
                                    public void cancelled() {
                                    }
                                }).show();
                            }
                        };
                        dialogFactory.createChoiceDialog("Error", error.getMessage(), "Overwrite", "Skip", "Change Name", overwrite, skip, rename).show();
                    }
                });
            } else {
                //notify user about failed copying
                notificationManager.notify("Error copying resource", error.getMessage(), FAIL, FLOAT_MODE);
                return promises.resolve(null);
            }
        }
    });
}
Also used : Path(org.eclipse.che.ide.resource.Path) ConfirmCallback(org.eclipse.che.ide.api.dialogs.ConfirmCallback) RequestCall(org.eclipse.che.api.promises.client.callback.AsyncPromiseHelper.RequestCall) InputCallback(org.eclipse.che.ide.api.dialogs.InputCallback) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) Resource(org.eclipse.che.ide.api.resources.Resource) FunctionException(org.eclipse.che.api.promises.client.FunctionException) Operation(org.eclipse.che.api.promises.client.Operation) Function(org.eclipse.che.api.promises.client.Function) Promise(org.eclipse.che.api.promises.client.Promise) PromiseError(org.eclipse.che.api.promises.client.PromiseError) CancelCallback(org.eclipse.che.ide.api.dialogs.CancelCallback) RevealResourceEvent(org.eclipse.che.ide.resources.reveal.RevealResourceEvent) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 4 with CancelCallback

use of org.eclipse.che.ide.api.dialogs.CancelCallback in project che by eclipse.

the class ComparePresenter method onClose.

@Override
public void onClose(final String newContent) {
    if (!compareWithLatest || this.localContent == null || newContent.equals(localContent)) {
        view.hide();
        return;
    }
    ConfirmCallback confirmCallback = new ConfirmCallback() {

        @Override
        public void accepted() {
            comparedFile.updateContent(newContent).then(new Operation<Void>() {

                @Override
                public void apply(Void ignored) throws OperationException {
                    final Container parent = comparedFile.getParent();
                    if (parent != null) {
                        parent.synchronize();
                    }
                    eventBus.fireEvent(new FileContentUpdateEvent(comparedFile.getLocation().toString()));
                    view.hide();
                }
            });
        }
    };
    CancelCallback cancelCallback = new CancelCallback() {

        @Override
        public void cancelled() {
            view.hide();
        }
    };
    dialogFactory.createConfirmDialog(locale.compareSaveTitle(), locale.compareSaveQuestion(), locale.buttonYes(), locale.buttonNo(), confirmCallback, cancelCallback).show();
}
Also used : FileContentUpdateEvent(org.eclipse.che.ide.api.event.FileContentUpdateEvent) ConfirmCallback(org.eclipse.che.ide.api.dialogs.ConfirmCallback) Container(org.eclipse.che.ide.api.resources.Container) CancelCallback(org.eclipse.che.ide.api.dialogs.CancelCallback) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 5 with CancelCallback

use of org.eclipse.che.ide.api.dialogs.CancelCallback in project che by eclipse.

the class RevertPresenter method createConfirmDialog.

private ConfirmDialog createConfirmDialog(final Project project, final Resource[] resources) {
    final ConfirmCallback okCallback = new ConfirmCallback() {

        @Override
        public void accepted() {
            final StatusNotification notification = new StatusNotification(constants.revertStarted(), PROGRESS, FLOAT_MODE);
            notificationManager.notify(notification);
            service.revert(project.getLocation(), toRelative(project, resources), "infinity").then(new Operation<CLIOutputResponse>() {

                @Override
                public void apply(CLIOutputResponse response) throws OperationException {
                    List<String> errOutput = response.getErrOutput();
                    printResponse(response.getCommand(), response.getOutput(), errOutput, "svn revert");
                    if (errOutput == null || errOutput.size() == 0) {
                        notification.setTitle(constants.revertSuccessful());
                        notification.setStatus(SUCCESS);
                    } else {
                        notification.setTitle(constants.revertWarning());
                        notification.setStatus(SUCCESS);
                    }
                }
            }).catchError(new Operation<PromiseError>() {

                @Override
                public void apply(PromiseError error) throws OperationException {
                    notification.setTitle(constants.revertFailed());
                    notification.setStatus(FAIL);
                }
            });
        }
    };
    final CancelCallback cancelCallback = new CancelCallback() {

        @Override
        public void cancelled() {
        }
    };
    String pathsString = null;
    for (Resource resource : resources) {
        if (pathsString == null) {
            pathsString = resource.getLocation().toString();
        } else {
            pathsString += ", " + resource.getLocation().toString();
        }
    }
    String confirmText = resources.length > 0 ? constants.revertConfirmText(" to " + pathsString) : constants.revertConfirmText("");
    return dialogFactory.createConfirmDialog(constants.revertTitle(), confirmText, okCallback, cancelCallback);
}
Also used : ConfirmCallback(org.eclipse.che.ide.api.dialogs.ConfirmCallback) PromiseError(org.eclipse.che.api.promises.client.PromiseError) StatusNotification(org.eclipse.che.ide.api.notification.StatusNotification) Resource(org.eclipse.che.ide.api.resources.Resource) CancelCallback(org.eclipse.che.ide.api.dialogs.CancelCallback) Operation(org.eclipse.che.api.promises.client.Operation) CLIOutputResponse(org.eclipse.che.plugin.svn.shared.CLIOutputResponse) OperationException(org.eclipse.che.api.promises.client.OperationException)

Aggregations

CancelCallback (org.eclipse.che.ide.api.dialogs.CancelCallback)6 OperationException (org.eclipse.che.api.promises.client.OperationException)4 ConfirmCallback (org.eclipse.che.ide.api.dialogs.ConfirmCallback)4 Operation (org.eclipse.che.api.promises.client.Operation)3 PromiseError (org.eclipse.che.api.promises.client.PromiseError)3 Resource (org.eclipse.che.ide.api.resources.Resource)3 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)2 Function (org.eclipse.che.api.promises.client.Function)2 FunctionException (org.eclipse.che.api.promises.client.FunctionException)2 Promise (org.eclipse.che.api.promises.client.Promise)2 RequestCall (org.eclipse.che.api.promises.client.callback.AsyncPromiseHelper.RequestCall)2 InputCallback (org.eclipse.che.ide.api.dialogs.InputCallback)2 Path (org.eclipse.che.ide.resource.Path)2 RevealResourceEvent (org.eclipse.che.ide.resources.reveal.RevealResourceEvent)2 Test (org.junit.Test)2 SafeHtml (com.google.gwt.safehtml.shared.SafeHtml)1 ConfirmDialog (org.eclipse.che.ide.api.dialogs.ConfirmDialog)1 FileContentUpdateEvent (org.eclipse.che.ide.api.event.FileContentUpdateEvent)1 StatusNotification (org.eclipse.che.ide.api.notification.StatusNotification)1 Container (org.eclipse.che.ide.api.resources.Container)1