use of org.eclipse.che.ide.api.dialogs.InputValidator 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();
}
use of org.eclipse.che.ide.api.dialogs.InputValidator in project che by eclipse.
the class InputDialogPresenterTest method onEnterClickedWhenInputValueIsIncorrect.
@Test
public void onEnterClickedWhenInputValueIsIncorrect() throws Exception {
reset(view);
when(view.getValue()).thenReturn(INCORRECT_INPUT_VALUE);
InputValidator inputValidator = mock(InputValidator.class);
InputValidator.Violation violation = mock(InputValidator.Violation.class);
when(inputValidator.validate(INCORRECT_INPUT_VALUE)).thenReturn(violation);
when(violation.getMessage()).thenReturn(ERROR_MESSAGE);
presenter.withValidator(inputValidator);
presenter.onEnterClicked();
verify(view).showErrorHint(anyString());
verify(view, never()).hideErrorHint();
verify(view, never()).setValue(anyString());
verify(inputCallback, never()).accepted(anyString());
}
use of org.eclipse.che.ide.api.dialogs.InputValidator in project che by eclipse.
the class InputDialogPresenterTest method shouldNotShowErrorHintWhenViolationHasCorrectValue.
@Test
public void shouldNotShowErrorHintWhenViolationHasCorrectValue() throws Exception {
reset(view);
when(view.getValue()).thenReturn(INCORRECT_INPUT_VALUE);
InputValidator inputValidator = mock(InputValidator.class);
InputValidator.Violation violation = mock(InputValidator.Violation.class);
when(inputValidator.validate(INCORRECT_INPUT_VALUE)).thenReturn(violation);
when(violation.getMessage()).thenReturn(null);
when(violation.getCorrectedValue()).thenReturn(CORRECT_INPUT_VALUE);
presenter.withValidator(inputValidator);
presenter.inputValueChanged();
verify(view, never()).showErrorHint(anyString());
verify(view).hideErrorHint();
verify(view).setValue(eq(CORRECT_INPUT_VALUE));
}
Aggregations