use of org.eclipse.che.ide.api.dialogs.InputDialog 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();
}
use of org.eclipse.che.ide.api.dialogs.InputDialog 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();
}
use of org.eclipse.che.ide.api.dialogs.InputDialog in project che by eclipse.
the class BranchPresenterTest method testOnRenameClickedWhenLocalBranchSelected.
@Test
public void testOnRenameClickedWhenLocalBranchSelected() 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(BRANCH_NAME);
when(selectedBranch.isRemote()).thenReturn(false);
InputDialog inputDialog = mock(InputDialog.class);
when(dialogFactory.createInputDialog(anyObject(), anyObject(), anyString(), anyInt(), anyInt(), anyObject(), anyObject())).thenReturn(inputDialog);
selectBranch();
presenter.onRenameClicked();
verify(dialogFactory).createInputDialog(eq(null), eq(null), eq("branchName"), eq(0), eq("branchName".length()), inputCallbackCaptor.capture(), eq(null));
InputCallback inputCallback = inputCallbackCaptor.getValue();
inputCallback.accepted(RETURNED_MESSAGE);
verify(selectedBranch, times(2)).getDisplayName();
verify(dialogFactory, never()).createConfirmDialog(anyString(), anyString(), anyObject(), anyObject());
verify(console, never()).printError(anyString());
verify(notificationManager, never()).notify(anyString());
verify(constant, never()).branchRenameFailed();
}
use of org.eclipse.che.ide.api.dialogs.InputDialog in project che by eclipse.
the class BranchPresenterTest method testOnCreateClickedWhenBranchCreateRequestIsSuccessful.
@Test
public void testOnCreateClickedWhenBranchCreateRequestIsSuccessful() throws Exception {
when(service.branchCreate(anyObject(), any(Path.class), anyString(), anyString())).thenReturn(branchPromise);
when(branchPromise.then(any(Operation.class))).thenReturn(branchPromise);
when(branchPromise.catchError(any(Operation.class))).thenReturn(branchPromise);
InputDialog inputDialog = mock(InputDialog.class);
when(dialogFactory.createInputDialog(anyString(), anyString(), anyObject(), anyObject())).thenReturn(inputDialog);
presenter.showBranches(project);
presenter.onCreateClicked();
verify(dialogFactory).createInputDialog(anyString(), anyString(), inputCallbackCaptor.capture(), anyObject());
InputCallback inputCallback = inputCallbackCaptor.getValue();
inputCallback.accepted(BRANCH_NAME);
verify(branchPromise).then(branchCaptor.capture());
branchCaptor.getValue().apply(selectedBranch);
verify(constant).branchTypeNew();
verify(service).branchCreate(anyObject(), any(Path.class), anyString(), anyString());
verify(service, times(2)).branchList(anyObject(), anyObject(), eq(LIST_ALL));
}
use of org.eclipse.che.ide.api.dialogs.InputDialog 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();
}
Aggregations