use of org.eclipse.jface.dialogs.IInputValidator in project netxms-ocilib by stevemqeen.
the class ScriptEditorView method goToLine.
/**
* Go to specific line
*/
private void goToLine() {
StyledText textControl = editor.getTextWidget();
final int maxLine = textControl.getLineCount();
InputDialog dlg = new InputDialog(getSite().getShell(), Messages.get().ScriptEditorView_GoToLine_DlgTitle, String.format(Messages.get().ScriptEditorView_EnterLineNumber, maxLine), Integer.toString(textControl.getLineAtOffset(textControl.getCaretOffset()) + 1), new IInputValidator() {
@Override
public String isValid(String newText) {
try {
int n = Integer.parseInt(newText);
if ((n < 1) || (n > maxLine))
return Messages.get().ScriptEditorView_NumberOutOfRange;
return null;
} catch (NumberFormatException e) {
return Messages.get().ScriptEditorView_InvalidNumber;
}
}
});
if (dlg.open() != Window.OK)
return;
int line = Integer.parseInt(dlg.getValue());
textControl.setCaretOffset(textControl.getOffsetAtLine(line - 1));
}
use of org.eclipse.jface.dialogs.IInputValidator in project titan.EclipsePlug-ins by eclipse.
the class StringListEditor method init.
@Override
protected void init(final String name, final String text) {
super.init(name, text);
inputValidator = new IInputValidator() {
@Override
public String isValid(final String newText) {
final String tempText = newText.trim();
if (Constants.MTC.equals(tempText)) {
// $NON-NLS-1$
return Messages.getString("StringListEditor.5");
}
if (Constants.SUT.equals(tempText)) {
// $NON-NLS-1$
return Messages.getString("StringListEditor.5");
}
if (tempText.length() > Constants.MAX_COMP_NAME) {
// $NON-NLS-1$
return Messages.getString("StringListEditor.3");
}
if ("".equals(tempText)) {
// $NON-NLS-1$
return "";
}
final String[] elements = getElements();
for (final String element : elements) {
if (element.contentEquals(tempText)) {
// $NON-NLS-1$
return Messages.getString("StringListEditor.6");
}
}
return null;
}
};
}
use of org.eclipse.jface.dialogs.IInputValidator in project netxms by netxms.
the class FileDeliveryPolicyEditor method addElement.
/**
* Add new element
*/
private void addElement(PathElement parent) {
InputDialog dlg = new InputDialog(getShell(), (parent == null) ? "New root directory" : "New directory", "Enter name for new directory", "", new IInputValidator() {
@Override
public String isValid(String newText) {
if (newText.isEmpty())
return "Name cannot be empty";
if (parent != null)
for (PathElement el : parent.getChildren()) {
if (newText.equalsIgnoreCase(el.getName()))
return "Object with this name already exists";
}
return null;
}
});
if (dlg.open() != Window.OK)
return;
PathElement e = new PathElement(parent, dlg.getValue());
if (parent == null) {
rootElements.add(e);
fileTree.refresh(true);
} else {
fileTree.refresh();
}
fireModifyListeners();
}
use of org.eclipse.jface.dialogs.IInputValidator in project netxms by netxms.
the class FileDeliveryPolicyEditor method renameElement.
/**
* Rename selected element
*/
private void renameElement() {
IStructuredSelection selection = fileTree.getStructuredSelection();
if (selection.size() != 1)
return;
PathElement element = (PathElement) selection.getFirstElement();
InputDialog dlg = new InputDialog(getShell(), element.isFile() ? "Rename file" : "Rename directory", "Enter new name", element.getName(), new IInputValidator() {
@Override
public String isValid(String newText) {
if (newText.isEmpty())
return "Name cannot be empty";
if (element.getParent() != null)
for (PathElement el : element.getParent().getChildren()) {
if (!el.equals(element) && newText.equalsIgnoreCase(el.getName()))
return "Object with this name already exists";
}
return null;
}
});
if (dlg.open() != Window.OK)
return;
((PathElement) selection.getFirstElement()).updateCreationTime();
if (element.getParent() == null) {
rootElements.remove(element);
element.setName(dlg.getValue());
rootElements.add(element);
fileTree.refresh();
} else {
element.setName(dlg.getValue());
fileTree.update(element, null);
}
fireModifyListeners();
}
use of org.eclipse.jface.dialogs.IInputValidator in project netxms by netxms.
the class RuleTimerCancellations method addTimerKey.
/**
* Add new timer key
*/
private void addTimerKey() {
InputDialog dlg = new InputDialog(getShell(), "Add Timer Key", "Timer key", "", new IInputValidator() {
@Override
public String isValid(String newText) {
return newText.trim().isEmpty() ? "Timer key must not be empty" : null;
}
});
if (dlg.open() == Window.OK) {
timerKeys.add(dlg.getValue().trim());
}
viewer.setInput(timerKeys.toArray());
}
Aggregations