Search in sources :

Example 26 with IInputValidator

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

Example 27 with IInputValidator

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

Example 28 with IInputValidator

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();
}
Also used : InputDialog(org.eclipse.jface.dialogs.InputDialog) PathElement(org.netxms.ui.eclipse.datacollection.widgets.helpers.PathElement) IInputValidator(org.eclipse.jface.dialogs.IInputValidator)

Example 29 with IInputValidator

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();
}
Also used : InputDialog(org.eclipse.jface.dialogs.InputDialog) PathElement(org.netxms.ui.eclipse.datacollection.widgets.helpers.PathElement) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IInputValidator(org.eclipse.jface.dialogs.IInputValidator)

Example 30 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)

Aggregations

IInputValidator (org.eclipse.jface.dialogs.IInputValidator)85 InputDialog (org.eclipse.jface.dialogs.InputDialog)74 Composite (org.eclipse.swt.widgets.Composite)16 SelectionEvent (org.eclipse.swt.events.SelectionEvent)13 IStatus (org.eclipse.core.runtime.IStatus)12 GridData (org.eclipse.swt.layout.GridData)11 Button (org.eclipse.swt.widgets.Button)11 ArrayList (java.util.ArrayList)10 FacetsListInputDialog (com.amalto.workbench.dialogs.FacetsListInputDialog)9 GridLayout (org.eclipse.swt.layout.GridLayout)9 Label (org.eclipse.swt.widgets.Label)8 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)7 SelectionListener (org.eclipse.swt.events.SelectionListener)7 Display (org.eclipse.swt.widgets.Display)6 Event (org.eclipse.swt.widgets.Event)6 InvocationTargetException (java.lang.reflect.InvocationTargetException)5 List (java.util.List)5 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)5 File (java.io.File)4 Iterator (java.util.Iterator)4