Search in sources :

Example 1 with InputCallback

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

the class NewPackageAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    InputDialog inputDialog = dialogFactory.createInputDialog("New " + title, "Name:", new InputCallback() {

        @Override
        public void accepted(String value) {
            onAccepted(value);
        }
    }, null).withValidator(nameValidator);
    inputDialog.show();
}
Also used : InputDialog(org.eclipse.che.ide.api.dialogs.InputDialog) InputCallback(org.eclipse.che.ide.api.dialogs.InputCallback)

Example 2 with InputCallback

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

the class SshKeyManagerPresenterTest method testShouldRefreshKeysAfterSuccessfulGenerateKey.

@Test
public void testShouldRefreshKeysAfterSuccessfulGenerateKey() throws OperationException {
    List<SshPairDto> sshPairDtoArray = new ArrayList<>();
    when(dialogFactory.createInputDialog(anyString(), anyString(), (InputCallback) anyObject(), (CancelCallback) anyObject())).thenReturn(inputDialog);
    presenter.onGenerateClicked();
    verify(dialogFactory).createInputDialog(anyString(), anyString(), inputCallbackCaptor.capture(), cancelCallbackCaptor.capture());
    InputCallback inputCallback = inputCallbackCaptor.getValue();
    inputCallback.accepted(GITHUB_HOST);
    verify(sshPairDTOPromise).then(operationSshPairDTOCapture.capture());
    operationSshPairDTOCapture.getValue().apply(null);
    verify(sshPairDTOsPromise).then(operationSshPairDTOsCapture.capture());
    operationSshPairDTOsCapture.getValue().apply(sshPairDtoArray);
    verify(service).generatePair(Matchers.eq(SshKeyManagerPresenter.VCS_SSH_SERVICE), eq(GITHUB_HOST));
    verify(service).getPairs(Matchers.eq(SshKeyManagerPresenter.VCS_SSH_SERVICE));
    verify(view).setPairs(eq(sshPairDtoArray));
}
Also used : SshPairDto(org.eclipse.che.api.ssh.shared.dto.SshPairDto) InputCallback(org.eclipse.che.ide.api.dialogs.InputCallback) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 3 with InputCallback

use of org.eclipse.che.ide.api.dialogs.InputCallback 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 4 with InputCallback

use of org.eclipse.che.ide.api.dialogs.InputCallback 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 5 with InputCallback

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

the class AbstractNewResourceAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    InputDialog inputDialog = dialogFactory.createInputDialog(coreLocalizationConstant.newResourceTitle(title), coreLocalizationConstant.newResourceLabel(title.toLowerCase()), new InputCallback() {

        @Override
        public void accepted(String value) {
            createFile(value);
        }
    }, null).withValidator(fileNameValidator);
    inputDialog.show();
}
Also used : InputDialog(org.eclipse.che.ide.api.dialogs.InputDialog) InputCallback(org.eclipse.che.ide.api.dialogs.InputCallback)

Aggregations

InputCallback (org.eclipse.che.ide.api.dialogs.InputCallback)12 InputDialog (org.eclipse.che.ide.api.dialogs.InputDialog)7 Test (org.junit.Test)6 Operation (org.eclipse.che.api.promises.client.Operation)5 Path (org.eclipse.che.ide.resource.Path)4 OperationException (org.eclipse.che.api.promises.client.OperationException)3 PromiseError (org.eclipse.che.api.promises.client.PromiseError)3 ConfirmCallback (org.eclipse.che.ide.api.dialogs.ConfirmCallback)3 Resource (org.eclipse.che.ide.api.resources.Resource)3 BaseTest (org.eclipse.che.ide.ext.git.client.BaseTest)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 SshPairDto (org.eclipse.che.api.ssh.shared.dto.SshPairDto)2 CancelCallback (org.eclipse.che.ide.api.dialogs.CancelCallback)2 RevealResourceEvent (org.eclipse.che.ide.resources.reveal.RevealResourceEvent)2 ArrayList (java.util.ArrayList)1 ConfirmDialog (org.eclipse.che.ide.api.dialogs.ConfirmDialog)1