Search in sources :

Example 36 with IInputValidator

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()));
}
Also used : InputDialog(org.eclipse.jface.dialogs.InputDialog) IInputValidator(org.eclipse.jface.dialogs.IInputValidator)

Example 37 with IInputValidator

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));
}
Also used : StyledText(org.eclipse.swt.custom.StyledText) InputDialog(org.eclipse.jface.dialogs.InputDialog) IInputValidator(org.eclipse.jface.dialogs.IInputValidator)

Example 38 with IInputValidator

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();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) InputDialog(org.eclipse.jface.dialogs.InputDialog) Job(org.netxms.nxmc.base.jobs.Job) NXCException(org.netxms.client.NXCException) IInputValidator(org.eclipse.jface.dialogs.IInputValidator)

Example 39 with IInputValidator

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());
}
Also used : InputDialog(org.eclipse.jface.dialogs.InputDialog) IInputValidator(org.eclipse.jface.dialogs.IInputValidator)

Example 40 with IInputValidator

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());
}
Also used : InputDialog(org.eclipse.jface.dialogs.InputDialog) IInputValidator(org.eclipse.jface.dialogs.IInputValidator)

Aggregations

IInputValidator (org.eclipse.jface.dialogs.IInputValidator)101 InputDialog (org.eclipse.jface.dialogs.InputDialog)88 Composite (org.eclipse.swt.widgets.Composite)20 IStatus (org.eclipse.core.runtime.IStatus)16 SelectionEvent (org.eclipse.swt.events.SelectionEvent)13 ArrayList (java.util.ArrayList)12 Button (org.eclipse.swt.widgets.Button)12 GridData (org.eclipse.swt.layout.GridData)11 GridLayout (org.eclipse.swt.layout.GridLayout)10 FacetsListInputDialog (com.amalto.workbench.dialogs.FacetsListInputDialog)9 List (java.util.List)8 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)8 Label (org.eclipse.swt.widgets.Label)8 SelectionListener (org.eclipse.swt.events.SelectionListener)7 Control (org.eclipse.swt.widgets.Control)7 Display (org.eclipse.swt.widgets.Display)7 IResource (org.eclipse.core.resources.IResource)6 CoreException (org.eclipse.core.runtime.CoreException)6 Window (org.eclipse.jface.window.Window)6 Event (org.eclipse.swt.widgets.Event)6