Example usage for org.eclipse.jface.dialogs IInputValidator isValid

List of usage examples for org.eclipse.jface.dialogs IInputValidator isValid

Introduction

In this page you can find the example usage for org.eclipse.jface.dialogs IInputValidator isValid.

Prototype

public String isValid(String newText);

Source Link

Document

Validates the given string.

Usage

From source file:ch.netcetera.eclipse.common.validator.AbstractInputValidatorTest.java

License:Open Source License

/**
 * Helper method doing the boring work of calling isValid().
 *
 * @param url the url to test/*from  www  .j  a  va 2s.  co m*/
 * @param existingItems the existing items
 * @param textLookupKey the text lookup key
 * @param textLookupValue the text lookup value
 * @param itemToEdit the item to edit
 * @return the validation result
 */
String runIsValid(String url, List<String> existingItems, String textLookupKey, String textLookupValue,
        String itemToEdit) {
    ITextAccessor textAccessor = EasyMock.createMock(ITextAccessor.class);
    if (textLookupKey.length() > 0) {
        EasyMock.expect(textAccessor.getText(textLookupKey)).andReturn(textLookupValue);
    }
    EasyMock.replay(textAccessor);
    IInputValidator validator = getInputValidatorInstance(existingItems, itemToEdit, textAccessor);
    String result = validator.isValid(url);
    EasyMock.verify(textAccessor);
    return result;
}

From source file:com.android.ide.eclipse.adt.internal.editors.layout.refactoring.ExtractIncludeRefactoring.java

License:Open Source License

String getInitialName() {
    String defaultName = ""; //$NON-NLS-1$
    Element primary = getPrimaryElement();
    if (primary != null) {
        String id = primary.getAttributeNS(ANDROID_URI, ATTR_ID);
        // id null check for https://bugs.eclipse.org/bugs/show_bug.cgi?id=272378
        if (id != null && (id.startsWith(ID_PREFIX) || id.startsWith(NEW_ID_PREFIX))) {
            // Use everything following the id/, and make it lowercase since that is
            // the convention for layouts (and use Locale.US to ensure that "Image" becomes
            // "image" etc)
            defaultName = id.substring(id.indexOf('/') + 1).toLowerCase(Locale.US);

            IInputValidator validator = ResourceNameValidator.create(true, mProject, LAYOUT);

            if (validator.isValid(defaultName) != null) { // Already exists?
                defaultName = ""; //$NON-NLS-1$
            }//w  w  w  .  j  a  v  a  2s. com
        }
    }

    return defaultName;
}

From source file:com.android.ide.eclipse.adt.internal.wizards.templates.NewTemplatePage.java

License:Open Source License

private void validatePage() {
    int minSdk = getMinSdk();
    int buildApi = getBuildApi();
    IStatus status = mValues.getTemplateHandler().validateTemplate(minSdk, buildApi);

    if (status == null || status.isOK()) {
        if (mChooseProject && mValues.project == null) {
            status = new Status(IStatus.ERROR, AdtPlugin.PLUGIN_ID, "Please select an Android project.");
        }/* w w  w  .  ja  va  2  s.com*/
    }

    for (Parameter parameter : mShowingTemplate.getParameters()) {
        if (parameter.type == Parameter.Type.SEPARATOR) {
            continue;
        }
        IInputValidator validator = parameter.getValidator(mValues.project);
        if (validator != null) {
            ControlDecoration decoration = mDecorations.get(parameter.id);
            String value = parameter.value == null ? "" : parameter.value.toString();
            String error = validator.isValid(value);
            if (error != null) {
                IStatus s = new Status(IStatus.ERROR, AdtPlugin.PLUGIN_ID, error);
                if (decoration != null) {
                    updateDecorator(decoration, s, parameter.help);
                }
                if (status == null || status.isOK()) {
                    status = s;
                }
            } else if (decoration != null) {
                updateDecorator(decoration, null, parameter.help);
            }
        }

        if (status == null || status.isOK()) {
            if (parameter.control instanceof Combo) {
                status = validateCombo(status, parameter, minSdk, buildApi);
            }
        }
    }

    setPageComplete(status == null || status.getSeverity() != IStatus.ERROR);
    if (status != null) {
        setMessage(status.getMessage(),
                status.getSeverity() == IStatus.ERROR ? IMessageProvider.ERROR : IMessageProvider.WARNING);
    } else {
        setErrorMessage(null);
        setMessage(null);
    }
}

From source file:com.android.ide.eclipse.auidt.internal.wizards.templates.NewTemplatePage.java

License:Open Source License

private void validatePage() {
    int currentMinSdk = getMinSdk();
    int minSdk = currentMinSdk;
    IStatus status = mValues.getTemplateHandler().validateTemplate(minSdk);

    if (status == null || status.isOK()) {
        if (mChooseProject && mValues.project == null) {
            status = new Status(IStatus.ERROR, AdtPlugin.PLUGIN_ID, "Please select an Android project.");
        }//  w  w  w  . j a va2  s  . c  o m
    }

    for (Parameter parameter : mParameters) {
        IInputValidator validator = parameter.getValidator(mValues.project);
        if (validator != null) {
            ControlDecoration decoration = mDecorations.get(parameter.id);
            String value = parameter.value == null ? "" : parameter.value.toString();
            String error = validator.isValid(value);
            if (error != null) {
                IStatus s = new Status(IStatus.ERROR, AdtPlugin.PLUGIN_ID, error);
                if (decoration != null) {
                    updateDecorator(decoration, s, parameter.help);
                }
                if (status == null || status.isOK()) {
                    status = s;
                }
            } else if (decoration != null) {
                updateDecorator(decoration, null, parameter.help);
            }
        }

        if (status == null || status.isOK()) {
            if (parameter.control instanceof Combo) {
                Combo combo = (Combo) parameter.control;
                Integer[] optionIds = (Integer[]) combo.getData(ATTR_MIN_API);
                int index = combo.getSelectionIndex();
                if (index != -1 && index < optionIds.length) {
                    Integer requiredMinSdk = optionIds[index];
                    if (requiredMinSdk > currentMinSdk) {
                        status = new Status(IStatus.ERROR, AdtPlugin.PLUGIN_ID,
                                String.format(
                                        "This template requires a minimum SDK version of at "
                                                + "least %1$d, and the current min version is %2$d",
                                        requiredMinSdk, currentMinSdk));
                    }
                }
            }
        }
    }

    setPageComplete(status == null || status.getSeverity() != IStatus.ERROR);
    if (status != null) {
        setMessage(status.getMessage(),
                status.getSeverity() == IStatus.ERROR ? IMessageProvider.ERROR : IMessageProvider.WARNING);
    } else {
        setErrorMessage(null);
        setMessage(null);
    }
}

From source file:de.tub.tfs.henshin.editor.util.validator.InputEditorValidators.java

License:Open Source License

@Override
public String isValid(String newText) {
    for (IInputValidator validator : validators) {
        String result = validator.isValid(newText);
        if (result != null) {
            return result;
        }/* w  w w .  j a  v a  2  s .  c  o  m*/
    }
    return null;
}

From source file:net.the_blue_pla.net.eclipse.validator.MultiValidator.java

License:MIT License

@Override
public String isValid(String newText) {
    for (IInputValidator validator : validators) {
        String message = validator.isValid(newText);
        if (!isNullOrEmpty(message)) {
            return message;
        }/*from w w  w.j a va2s .  c o  m*/
    }
    return null;
}

From source file:org.deidentifier.arx.gui.view.impl.MainWindow.java

License:Open Source License

/**
 * Shows an input dialog for selecting formats string for data types
 * //from  ww w  . j  a  v  a  2s.  c  o  m
 * @param shell
 * @param header
 * @param text
 * @param preselected Preselected format string, can be null
 * @param description
 * @param values
 * @return
 */
public String showFormatInputDialog(final Shell shell, final String header, final String text,
        final String preselected, final DataTypeDescription<?> description, final Collection<String> values) {

    // Check
    if (!description.hasFormat()) {
        throw new RuntimeException("This dialog can only be used for data types with format");
    }

    // Init
    final String DEFAULT = "Default";

    // Validator
    final IInputValidator validator = new IInputValidator() {
        @Override
        public String isValid(final String arg0) {
            DataType<?> type;
            try {
                if (arg0.equals(DEFAULT)) {
                    type = description.newInstance();
                } else {
                    type = description.newInstance(arg0);
                }
            } catch (final Exception e) {
                return Resources.getMessage("MainWindow.11"); //$NON-NLS-1$
            }
            for (final String value : values) {
                if (!type.isValid(value)) {
                    return Resources.getMessage("MainWindow.13"); //$NON-NLS-1$
                }
            }
            return null;
        }
    };

    // Try to find a valid formatter
    String initial = ""; //$NON-NLS-1$
    if (preselected != null && validator.isValid(preselected) == null) {
        initial = preselected;
    } else if (validator.isValid(DEFAULT) == null) {
        initial = DEFAULT;
    } else {
        for (final String format : description.getExampleFormats()) {
            if (validator.isValid(format) == null) {
                initial = format;
                break;
            }
        }
    }

    // Extract list of formats
    List<String> formats = new ArrayList<String>();
    formats.add(DEFAULT);
    formats.addAll(description.getExampleFormats());

    // Open dialog
    final DialogComboSelection dlg = new DialogComboSelection(shell, header, text,
            formats.toArray(new String[] {}), initial, validator);

    // Return value
    if (dlg.open() == Window.OK) {
        return dlg.getValue();
    } else {
        return null;
    }
}

From source file:org.eclipse.andmore.internal.wizards.templates.NewTemplatePage.java

License:Open Source License

private void validatePage() {
    int minSdk = getMinSdk();
    int buildApi = getBuildApi();
    IStatus status = mValues.getTemplateHandler().validateTemplate(minSdk, buildApi);

    if (status == null || status.isOK()) {
        if (mChooseProject && mValues.project == null) {
            status = new Status(IStatus.ERROR, AndmoreAndroidPlugin.PLUGIN_ID,
                    "Please select an Android project.");
        }//from w  w w  .j  a v a  2 s. c o  m
    }

    for (Parameter parameter : mShowingTemplate.getParameters()) {
        if (parameter.type == Parameter.Type.SEPARATOR) {
            continue;
        }
        IInputValidator validator = parameter.getValidator(mValues.project);
        if (validator != null) {
            ControlDecoration decoration = mDecorations.get(parameter.id);
            String value = parameter.value == null ? "" : parameter.value.toString();
            String error = validator.isValid(value);
            if (error != null) {
                IStatus s = new Status(IStatus.ERROR, AndmoreAndroidPlugin.PLUGIN_ID, error);
                if (decoration != null) {
                    updateDecorator(decoration, s, parameter.help);
                }
                if (status == null || status.isOK()) {
                    status = s;
                }
            } else if (decoration != null) {
                updateDecorator(decoration, null, parameter.help);
            }
        }

        if (status == null || status.isOK()) {
            if (parameter.control instanceof Combo) {
                status = validateCombo(status, parameter, minSdk, buildApi);
            }
        }
    }

    setPageComplete(status == null || status.getSeverity() != IStatus.ERROR);
    if (status != null) {
        setMessage(status.getMessage(),
                status.getSeverity() == IStatus.ERROR ? IMessageProvider.ERROR : IMessageProvider.WARNING);
    } else {
        setErrorMessage(null);
        setMessage(null);
    }
}

From source file:org.eclipse.bpel.ui.wizards.CreatePartnerLinkTypeWizardNamePage.java

License:Open Source License

/**
 * Returns whether this page's controls currently all contain valid values.
 * /*from  w w w.ja  v a 2s .  c  om*/
 * @return <code>true</code> if all controls are valid, and
 *         <code>false</code> if at least one is invalid
 */
protected boolean validatePage() {

    String pltName = partnerLinkTypeName.getText();

    IInputValidator validator = BPELUtil.getNCNameValidator();
    String pltMsg = validator.isValid(pltName);

    if (pltMsg != null) {
        // all is OK
        setMessage(pltMsg, ERROR);
        return false;
    }
    if (fDefinitions != null) {
        // This is silly, it has to belong someplace else.
        Iterator it = fDefinitions.getEExtensibilityElements().iterator();
        while (it.hasNext()) {
            Object element = it.next();
            if (element instanceof PartnerLinkType) {
                PartnerLinkType plt = (PartnerLinkType) element;
                if (pltName.equals(plt.getName())) {
                    setMessage(Messages.CreatePartnerLinkTypeWizardNamePage_4, ERROR);
                    return false;
                }
            }

        }
    }
    setMessage(null, NONE);

    return true;
}

From source file:org.eclipse.bpel.ui.wizards.CreatePartnerLinkTypeWizardRolePage.java

License:Open Source License

boolean validatePage() {
    String roleNCName = roleName.getText();

    if (fOptional) {
        if (portType == null && roleNCName.length() == 0) {
            setMessage(Messages.CreatePartnerLinkTypeWizardRolePage_2, INFORMATION);
            return true;
        }//from   ww w  . j  av  a2 s.c  o  m
    }

    if (portType == null) {
        setMessage(Messages.CreatePartnerLinkTypeWizardRolePage_3, ERROR);
        return false;
    }

    IInputValidator validator = BPELUtil.getNCNameValidator();
    String msg = validator.isValid(roleNCName);
    if (msg != null) {
        setMessage(msg, ERROR);
        return false;
    }

    if (fOtherRolePage != null) {
        if (roleNCName.equals(fOtherRolePage.getRoleName())) {
            setMessage(Messages.CreatePartnerLinkTypeWizardRolePage_4, ERROR);
            return false;
        }
    }

    setMessage(null, NONE);
    return true;
}