use of org.eclipse.jface.dialogs.IInputValidator in project eclipse.platform.ui by eclipse-platform.
the class RenameResourceAction method queryNewResourceName.
/**
* Return the new name to be given to the target resource.
*
* @return java.lang.String
* @param resource
* the resource to query status on
*/
protected String queryNewResourceName(final IResource resource) {
final IWorkspace workspace = IDEWorkbenchPlugin.getPluginWorkspace();
final IPath prefix = resource.getFullPath().removeLastSegments(1);
IInputValidator validator = string -> {
if (resource.getName().equals(string)) {
return IDEWorkbenchMessages.RenameResourceAction_nameMustBeDifferent;
}
IStatus status = workspace.validateName(string, resource.getType());
if (!status.isOK()) {
return status.getMessage();
}
if (workspace.getRoot().exists(prefix.append(string))) {
return IDEWorkbenchMessages.RenameResourceAction_nameExists;
}
return null;
};
InputDialog dialog = new InputDialog(getShell(), IDEWorkbenchMessages.RenameResourceAction_inputDialogTitle, IDEWorkbenchMessages.RenameResourceAction_inputDialogMessage, resource.getName(), validator);
dialog.setBlockOnOpen(true);
int result = dialog.open();
if (result == Window.OK)
return dialog.getValue();
return null;
}
use of org.eclipse.jface.dialogs.IInputValidator in project jbosstools-hibernate by jbosstools.
the class NameValidator method renameLaunchConfiguration.
public boolean renameLaunchConfiguration(ILaunchConfiguration launchConfiguration) {
Shell mParentShell = null;
IInputValidator inputValidator = new NameValidator();
InputDialog d = new InputDialog(mParentShell, HibernateConsoleMessages.RenameAction_dialog_title, HibernateConsoleMessages.RenameAction_dialog_message, launchConfiguration.getName(), inputValidator);
if (d.open() == Window.OK) {
try {
ILaunchConfigurationWorkingCopy wc = launchConfiguration.getWorkingCopy();
wc.rename(d.getValue());
wc.doSave();
return true;
} catch (CoreException e) {
HibernateConsolePlugin.getDefault().showError(mParentShell, HibernateConsoleMessages.RenameAction_error_title, e);
}
}
return false;
}
use of org.eclipse.jface.dialogs.IInputValidator in project org.eclipse.rap by eclipse-rap.
the class DialogsTab method showInputDialog.
private void showInputDialog() {
final IInputValidator val = new IInputValidator() {
@Override
public String isValid(final String newText) {
String result = null;
if (newText.length() < 5) {
result = "Input text too short!";
}
return result;
}
};
String title = "Input Dialog";
String mesg = "Enter at least five characters";
String def = "default text";
final InputDialog dlg;
dlg = new InputDialog(getShell(), title, mesg, def, val);
int returnCode = dlg.open();
String resultText = "Result: " + getReturnCodeText(returnCode);
if (returnCode == Window.OK) {
resultText += ", value: " + dlg.getValue();
}
inputDlgResLabel.setText(resultText);
inputDlgResLabel.pack();
}
use of org.eclipse.jface.dialogs.IInputValidator in project org.eclipse.rap by eclipse-rap.
the class DialogExamplePage method showInputDialog.
private void showInputDialog() {
final IInputValidator val = new IInputValidator() {
public String isValid(String newText) {
String result = null;
if (newText.length() < 5) {
result = "Input text too short!";
}
return result;
}
};
String title = "Input Dialog";
String mesg = "Enter at least five characters";
String def = "default text";
final InputDialog dialog = new InputDialog(getShell(), title, mesg, def, val) {
@Override
public boolean close() {
boolean result = super.close();
int returnCode = getReturnCode();
String resultText = "Result: " + getReturnCodeText(returnCode);
if (returnCode == Window.OK) {
resultText += ", value: " + getValue();
}
showResult(resultText);
return result;
}
};
dialog.setBlockOnOpen(false);
dialog.open();
}
use of org.eclipse.jface.dialogs.IInputValidator in project jbosstools-server by jbosstools.
the class ArchivesActionProvider method createFolder.
/*
* Methods below are called from the standard actions,
* the implementations of the action, where the action does its work etc
*/
private void createFolder() {
IInputValidator validator = new IInputValidator() {
public String isValid(String newText) {
IArchiveNode selected = getSelectedNode(site);
boolean folderExists = false;
IArchiveNode[] folders = selected.getChildren(IArchiveNode.TYPE_ARCHIVE_FOLDER);
for (int i = 0; i < folders.length; i++) {
IArchiveFolder folder = (IArchiveFolder) folders[i];
if (folder.getName().equals(newText)) {
folderExists = true;
break;
}
}
if (folderExists) {
return NLS.bind(ArchivesUIMessages.ProjectPackagesView_createFolderDialog_warnFolderExists, newText);
}
if ("".equals(newText)) {
// $NON-NLS-1$
return ArchivesUIMessages.ProjectPackagesView_createFolderDialog_blank;
}
return null;
}
};
InputDialog dialog = new InputDialog(getShell(), ArchivesUIMessages.ProjectPackagesView_createFolderDialog_title, ArchivesUIMessages.ProjectPackagesView_createFolderDialog_message, "", // $NON-NLS-1$
validator);
int response = dialog.open();
if (response == Dialog.OK) {
// $NON-NLS-1$
String[] folderPaths = dialog.getValue().split("[\\\\/]");
IArchiveNode selected = getSelectedNode(site);
IArchiveFolder current = null;
IArchiveFolder temp = null;
for (int i = folderPaths.length - 1; i >= 0; i--) {
temp = ArchivesCore.getInstance().getNodeFactory().createFolder();
temp.setName(folderPaths[i]);
if (current == null)
current = temp;
else {
temp.addChild(current);
current = temp;
}
}
selected.addChild(current);
new SaveArchivesJob(selected.getProjectPath()).schedule();
}
}
Aggregations