Search in sources :

Example 6 with InputCallback

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

the class NewFolderAction method actionPerformed.

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

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

Example 7 with InputCallback

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

the class SshKeyManagerPresenterTest method testOnGenerateClickedWhenGenerateKeyIsFailed.

@Test
public void testOnGenerateClickedWhenGenerateKeyIsFailed() throws OperationException {
    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).catchError(operationErrorCapture.capture());
    operationErrorCapture.getValue().apply(JsPromiseError.create(""));
    verify(service).generatePair(Matchers.eq(SshKeyManagerPresenter.VCS_SSH_SERVICE), eq(GITHUB_HOST));
    verify(service, never()).getPairs(Matchers.eq(SshKeyManagerPresenter.VCS_SSH_SERVICE));
    verify(view, never()).setPairs((List<SshPairDto>) anyObject());
    verify(notificationManager).notify(anyString(), anyString(), any(StatusNotification.Status.class), (DisplayMode) anyObject());
}
Also used : SshPairDto(org.eclipse.che.api.ssh.shared.dto.SshPairDto) InputCallback(org.eclipse.che.ide.api.dialogs.InputCallback) Test(org.junit.Test)

Example 8 with InputCallback

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

the class SshKeyManagerPresenterTest method testOnGenerateClickedWhenUserConfirmGenerateKey.

@Test
public void testOnGenerateClickedWhenUserConfirmGenerateKey() {
    when(dialogFactory.createInputDialog(anyString(), anyString(), (InputCallback) anyObject(), (CancelCallback) anyObject())).thenReturn(inputDialog);
    presenter.onGenerateClicked();
    verify(dialogFactory).createInputDialog(anyString(), anyString(), inputCallbackCaptor.capture(), (CancelCallback) anyObject());
    InputCallback inputCallback = inputCallbackCaptor.getValue();
    inputCallback.accepted(GITHUB_HOST);
    verify(service).generatePair(Matchers.eq(SshKeyManagerPresenter.VCS_SSH_SERVICE), eq(GITHUB_HOST));
}
Also used : InputCallback(org.eclipse.che.ide.api.dialogs.InputCallback) Test(org.junit.Test)

Example 9 with InputCallback

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

the class RenameItemAction method actionPerformed.

/** {@inheritDoc} */
@Override
public void actionPerformed(ActionEvent e) {
    final Resource resource = appContext.getResource();
    checkState(resource != null, "Null resource occurred");
    final String resourceName = resource.getName();
    final int selectionLength = resourceName.indexOf('.') >= 0 ? resourceName.lastIndexOf('.') : resourceName.length();
    final InputValidator validator;
    final String dialogTitle;
    if (resource.getResourceType() == FILE) {
        validator = new FileNameValidator(resourceName);
        dialogTitle = localization.renameFileDialogTitle(resourceName);
    } else if (resource.getResourceType() == FOLDER) {
        validator = new FolderNameValidator(resourceName);
        dialogTitle = localization.renameFolderDialogTitle(resourceName);
    } else if (resource.getResourceType() == PROJECT) {
        validator = new ProjectNameValidator(resourceName);
        dialogTitle = localization.renameProjectDialogTitle(resourceName);
    } else {
        throw new IllegalStateException("Not a resource");
    }
    final InputCallback inputCallback = new InputCallback() {

        @Override
        public void accepted(final String value) {
            //we shouldn't perform renaming file with the same name
            if (!value.trim().equals(resourceName)) {
                closeRelatedEditors(resource);
                final Path destination = resource.getLocation().parent().append(value);
                resource.move(destination).catchError(new Operation<PromiseError>() {

                    @Override
                    public void apply(PromiseError arg) throws OperationException {
                        notificationManager.notify("", arg.getMessage(), FAIL, EMERGE_MODE);
                    }
                });
            }
        }
    };
    InputDialog inputDialog = dialogFactory.createInputDialog(dialogTitle, localization.renameDialogNewNameLabel(), resource.getName(), 0, selectionLength, inputCallback, null);
    inputDialog.withValidator(validator);
    inputDialog.show();
}
Also used : Path(org.eclipse.che.ide.resource.Path) InputDialog(org.eclipse.che.ide.api.dialogs.InputDialog) InputCallback(org.eclipse.che.ide.api.dialogs.InputCallback) Resource(org.eclipse.che.ide.api.resources.Resource) InputValidator(org.eclipse.che.ide.api.dialogs.InputValidator) PromiseError(org.eclipse.che.api.promises.client.PromiseError) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 10 with InputCallback

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

the class BranchPresenterTest method testOnRenameClickedWhenRemoteBranchSelectedAndUserConfirmRename.

@Test
public void testOnRenameClickedWhenRemoteBranchSelectedAndUserConfirmRename() throws Exception {
    reset(selectedBranch);
    when(service.branchRename(anyObject(), anyObject(), anyString(), anyString())).thenReturn(voidPromise);
    when(voidPromise.then(any(Operation.class))).thenReturn(voidPromise);
    when(voidPromise.catchError(any(Operation.class))).thenReturn(voidPromise);
    when(selectedBranch.getDisplayName()).thenReturn(REMOTE_BRANCH_NAME);
    when(selectedBranch.isRemote()).thenReturn(true);
    InputDialog inputDialog = mock(InputDialog.class);
    when(dialogFactory.createInputDialog(anyString(), anyString(), anyString(), anyInt(), anyInt(), anyObject(), anyObject())).thenReturn(inputDialog);
    ConfirmDialog confirmDialog = mock(ConfirmDialog.class);
    when(dialogFactory.createConfirmDialog(anyString(), anyString(), anyObject(), anyObject())).thenReturn(confirmDialog);
    selectBranch();
    presenter.onRenameClicked();
    verify(dialogFactory).createConfirmDialog(anyString(), anyString(), confirmCallbackCaptor.capture(), anyObject());
    ConfirmCallback confirmCallback = confirmCallbackCaptor.getValue();
    confirmCallback.accepted();
    verify(dialogFactory).createInputDialog(anyString(), anyString(), anyString(), anyInt(), anyInt(), inputCallbackCaptor.capture(), anyObject());
    InputCallback inputCallback = inputCallbackCaptor.getValue();
    inputCallback.accepted(RETURNED_MESSAGE);
    verify(voidPromise).then(voidPromiseCaptor.capture());
    voidPromiseCaptor.getValue().apply(null);
    verify(selectedBranch, times(2)).getDisplayName();
    verify(service, times(2)).branchList(anyObject(), anyObject(), eq(LIST_ALL));
    verify(console, never()).printError(anyString());
    verify(notificationManager, never()).notify(anyString());
    verify(constant, never()).branchRenameFailed();
}
Also used : ConfirmCallback(org.eclipse.che.ide.api.dialogs.ConfirmCallback) InputDialog(org.eclipse.che.ide.api.dialogs.InputDialog) InputCallback(org.eclipse.che.ide.api.dialogs.InputCallback) Operation(org.eclipse.che.api.promises.client.Operation) ConfirmDialog(org.eclipse.che.ide.api.dialogs.ConfirmDialog) BaseTest(org.eclipse.che.ide.ext.git.client.BaseTest) Test(org.junit.Test)

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