use of org.eclipse.jface.dialogs.IInputValidator in project OpenTCS-4 by touchmii.
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 Pydev by fabioz.
the class CopyFilesAndFoldersOperation method getNewNameFor.
/**
* Returns a new name for a copy of the resource at the given path in the
* given workspace.
*
* @param originalName
* the full path of the resource
* @param workspace
* the workspace
* @return the new full path for the copy, or <code>null</code> if the
* resource should not be copied
*/
private IPath getNewNameFor(final IPath originalName, final IWorkspace workspace) {
final IResource resource = workspace.getRoot().findMember(originalName);
final IPath prefix = resource.getFullPath().removeLastSegments(1);
// $NON-NLS-1$
final String[] returnValue = { "" };
messageShell.getDisplay().syncExec(new Runnable() {
@Override
public void run() {
IInputValidator validator = new IInputValidator() {
@Override
public String isValid(String string) {
if (resource.getName().equals(string)) {
return IDEWorkbenchMessages.CopyFilesAndFoldersOperation_nameMustBeDifferent;
}
IStatus status = workspace.validateName(string, resource.getType());
if (!status.isOK()) {
return status.getMessage();
}
if (workspace.getRoot().exists(prefix.append(string))) {
return IDEWorkbenchMessages.CopyFilesAndFoldersOperation_nameExists;
}
return null;
}
};
InputDialog dialog = new InputDialog(messageShell, IDEWorkbenchMessages.CopyFilesAndFoldersOperation_inputDialogTitle, NLS.bind(IDEWorkbenchMessages.CopyFilesAndFoldersOperation_inputDialogMessage, resource.getName()), getAutoNewNameFor(originalName, workspace).lastSegment().toString(), validator);
dialog.setBlockOnOpen(true);
dialog.open();
if (dialog.getReturnCode() == Window.CANCEL) {
returnValue[0] = null;
} else {
returnValue[0] = dialog.getValue();
}
}
});
if (returnValue[0] == null) {
throw new OperationCanceledException();
}
return prefix.append(returnValue[0]);
}
use of org.eclipse.jface.dialogs.IInputValidator in project Pydev by fabioz.
the class AbstractPyCreateClassOrMethodOrField method execute.
@Override
public void execute(RefactoringInfo refactoringInfo, int locationStrategy) {
try {
String creationStr = this.getCreationStr();
final String asTitle = StringUtils.getWithFirstUpper(creationStr);
PySelection pySelection = refactoringInfo.getPySelection();
Tuple<String, Integer> currToken = pySelection.getCurrToken();
String actTok = currToken.o1;
List<String> parametersAfterCall = null;
if (actTok.length() == 0) {
InputDialog dialog = new InputDialog(EditorUtils.getShell(), asTitle + " name", "Please enter the name of the " + asTitle + " to be created.", "", new IInputValidator() {
@Override
public String isValid(String newText) {
if (newText.length() == 0) {
return "The " + asTitle + " name may not be empty";
}
if (StringUtils.containsWhitespace(newText)) {
return "The " + asTitle + " name may not contain whitespaces.";
}
return null;
}
});
if (dialog.open() != InputDialog.OK) {
return;
}
actTok = dialog.getValue();
} else {
parametersAfterCall = pySelection.getParametersAfterCall(currToken.o2 + actTok.length());
}
execute(refactoringInfo, actTok, parametersAfterCall, locationStrategy);
} catch (BadLocationException e) {
Log.log(e);
}
}
use of org.eclipse.jface.dialogs.IInputValidator in project tdq-studio-se by Talend.
the class TOPRepositoryService method getInputDialog.
/**
* Comment method "getInputDialog".
*
* @param get input dialog
* @return inputDialog
*/
@Override
public InputDialog getInputDialog(final Item newItem) {
Shell parentShell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
// $NON-NLS-1$
String dialogTitle = DefaultMessagesImpl.getString("TOPRepositoryService.InputDialog.Title");
// $NON-NLS-1$
String dialogMessage = DefaultMessagesImpl.getString("TOPRepositoryService.InputDialog.Message");
final InputDialog inputDialog = new InputDialog(parentShell, dialogTitle, dialogMessage, newItem.getProperty().getLabel() + DateUtils.formatTimeStamp(DateUtils.PATTERN_6, System.currentTimeMillis()), new IInputValidator() {
@Override
public String isValid(String newText) {
String returnStr = null;
Item item = newItem;
ERepositoryObjectType type = ERepositoryObjectType.getItemType(item);
// String pattern = RepositoryConstants.getPattern(type);
// $NON-NLS-1$
String pattern = "[_A-Za-z0-9-][a-zA-Z0-9\\\\.\\\\-_(), ]*";
boolean matches = Pattern.matches(pattern, newText);
boolean nameAvailable = false;
try {
List<IRepositoryViewObject> listExistingObjects = ProxyRepositoryFactory.getInstance().getAll(type, true, false);
nameAvailable = ProxyRepositoryFactory.getInstance().isNameAvailable(item, newText, listExistingObjects);
} catch (PersistenceException e) {
log.error(e, e);
return e.getMessage();
}
if (!matches) {
returnStr = DefaultMessagesImpl.getString(// $NON-NLS-1$
"TOPRepositoryService.InputDialog.ErrorMessage1");
} else if (!nameAvailable) {
returnStr = DefaultMessagesImpl.getString(// $NON-NLS-1$
"TOPRepositoryService.InputDialog.ErrorMessage2");
}
return returnStr;
}
});
return inputDialog;
}
use of org.eclipse.jface.dialogs.IInputValidator in project subclipse by subclipse.
the class CopyAction method execute.
protected void execute(IAction action) throws InvocationTargetException, InterruptedException {
final IResource[] resources = getSelectedResources();
final IProject project = resources[0].getProject();
ContainerSelectionDialog dialog = new ContainerSelectionDialog(getShell(), project, false, // $NON-NLS-1$
Policy.bind("CopyAction.selectionLabel"));
if (dialog.open() == ContainerSelectionDialog.CANCEL)
return;
Object[] result = dialog.getResult();
if (result == null || result.length == 0)
return;
final Path path = (Path) result[0];
IProject selectedProject;
File target = null;
if (path.segmentCount() == 1) {
selectedProject = ResourcesPlugin.getWorkspace().getRoot().getProject(path.toString());
target = selectedProject.getLocation().toFile();
} else {
IFile targetFile = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
selectedProject = targetFile.getProject();
target = targetFile.getLocation().toFile();
}
final IProject targetProject = selectedProject;
final File destPath = target;
BusyIndicator.showWhile(Display.getCurrent(), new Runnable() {
public void run() {
ISVNClientAdapter client = null;
ISVNRepositoryLocation repository = null;
try {
ISVNLocalResource svnTargetResource = SVNWorkspaceRoot.getSVNResourceFor(targetProject);
for (int i = 0; i < resources.length; i++) {
final IResource resource = resources[i];
if (client == null) {
repository = SVNWorkspaceRoot.getSVNResourceFor(resources[i]).getRepository();
client = repository.getSVNClient();
}
File checkFile = new File(destPath.getPath() + File.separator + resource.getName());
File srcPath = new File(resource.getLocation().toString());
File newDestPath = new File(destPath.getPath() + File.separator + resource.getName());
if (checkFile.exists()) {
IInputValidator inputValidator = new IInputValidator() {
public String isValid(String newText) {
if (newText.equals(resource.getName()))
// $NON-NLS-1$
return Policy.bind("CopyAction.nameConflictSame");
return null;
}
};
InputDialog inputDialog = new InputDialog(getShell(), Policy.bind("CopyAction.nameConflictTitle"), Policy.bind("CopyAction.nameConflictMessage", resource.getName()), "Copy of " + resource.getName(), // $NON-NLS-1$
inputValidator);
if (inputDialog.open() == InputDialog.CANCEL)
return;
String newName = inputDialog.getValue();
if (newName == null || newName.trim().length() == 0)
return;
newDestPath = new File(destPath.getPath() + File.separator + newName);
}
ISVNLocalResource svnResource = SVNWorkspaceRoot.getSVNResourceFor(resource);
boolean sameRepository = svnTargetResource != null && svnTargetResource.getRepository() != null && svnTargetResource.getRepository().getLocation().equals(svnResource.getRepository().getLocation());
if (sameRepository)
client.copy(srcPath, newDestPath);
else
client.doExport(srcPath, newDestPath, true);
SVNUIPlugin.getPlugin().getRepositoryManager().resourceCreated(null, null);
}
targetProject.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
} catch (Exception e) {
MessageDialog.openError(getShell(), Policy.bind("CopyAction.copy"), // $NON-NLS-1$
e.getMessage());
} finally {
if (repository != null) {
repository.returnSVNClient(client);
}
}
}
});
}
Aggregations