use of org.eclipse.jface.dialogs.IInputValidator in project netxms by netxms.
the class ScriptEditorView method goToLine.
/**
* Go to specific line
*/
private void goToLine() {
final int maxLine = editor.getLineCount();
InputDialog dlg = new InputDialog(getWindow().getShell(), i18n.tr("Go to Line"), String.format(i18n.tr("Enter line number (1..%d)"), maxLine), Integer.toString(editor.getCurrentLine()), new IInputValidator() {
@Override
public String isValid(String newText) {
try {
int n = Integer.parseInt(newText);
if ((n < 1) || (n > maxLine))
return i18n.tr("Number out of range");
return null;
} catch (NumberFormatException e) {
return i18n.tr("Invalid number");
}
}
});
if (dlg.open() != Window.OK)
return;
editor.setCaretToLine(Integer.parseInt(dlg.getValue()));
}
use of org.eclipse.jface.dialogs.IInputValidator in project netxms by netxms.
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 netxms by netxms.
the class SSHKeys method generateKeys.
/**
* Generate new keys
*/
private void generateKeys() {
final InputDialog dlg = new InputDialog(getWindow().getShell(), i18n.tr("Generate SSH Key"), i18n.tr("Key name"), "", new IInputValidator() {
@Override
public String isValid(String newText) {
return newText.isBlank() ? i18n.tr("Key name should not be empty") : null;
}
});
if (dlg.open() != Window.OK)
return;
new Job(i18n.tr("Generate SSH keys"), this) {
@Override
protected void run(IProgressMonitor monitor) throws Exception {
session.generateSshKeys(dlg.getValue().trim());
}
@Override
protected String getErrorMessage() {
return i18n.tr("Cannot generate SSH keys");
}
}.start();
}
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());
}
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(), i18n.tr("Add Timer Key"), i18n.tr("Timer key"), "", new IInputValidator() {
@Override
public String isValid(String newText) {
return newText.trim().isEmpty() ? i18n.tr("Timer key must not be empty") : null;
}
});
if (dlg.open() == Window.OK) {
timerKeys.add(dlg.getValue().trim());
}
viewer.setInput(timerKeys.toArray());
}
Aggregations