Search in sources :

Example 56 with IInputValidator

use of org.eclipse.jface.dialogs.IInputValidator in project tmdm-studio-se by Talend.

the class XSDEditFacetAction method editMaxInclusive.

private void editMaxInclusive() {
    XSDMaxInclusiveFacet currentValue = std.getMaxInclusiveFacet();
    String stringValue = null;
    if (currentValue != null) {
        stringValue = currentValue.getLexicalValue();
    }
    boolean isDateType = true;
    dialog = getInputDialog4Date(Messages.XSDEditFacetAction_DialogTitle8, Messages.XSDEditFacetAction_DialogTitle8Tip, stringValue);
    if (dialog == null) {
        isDateType = false;
        dialog = new InputDialog(page.getSite().getShell(), Messages.XSDEditFacetAction_DialogTitle8, Messages.XSDEditFacetAction_DialogTitle8Tip, stringValue == null ? "" : stringValue, new // $NON-NLS-1$
        IInputValidator() {

            public String isValid(String newText) {
                if (newText.trim().isEmpty()) {
                    return null;
                }
                return isValidBoundaryNumber(std, newText);
            }
        });
    }
    dialog.setBlockOnOpen(true);
    int ret = dialog.open();
    if (ret == Dialog.CANCEL) {
        return;
    }
    if (currentValue != null) {
        std.getFacetContents().remove(currentValue);
    }
    String input = ((InputDialog) dialog).getValue();
    if (!input.trim().isEmpty()) {
        XSDMaxInclusiveFacet f = (XSDSchemaBuildingTools.getXSDFactory()).createXSDMaxInclusiveFacet();
        if (isDateType) {
            f.setLexicalValue(input.trim());
            std.getFacetContents().add(f);
        } else if (Double.parseDouble(input) >= 0) {
            // $NON-NLS-1$
            f.setLexicalValue("" + getValidBoundaryNumber(std, input));
            std.getFacetContents().add(f);
        }
    }
}
Also used : InputDialog(org.eclipse.jface.dialogs.InputDialog) FacetsListInputDialog(com.amalto.workbench.dialogs.FacetsListInputDialog) XSDMaxInclusiveFacet(org.eclipse.xsd.XSDMaxInclusiveFacet) IInputValidator(org.eclipse.jface.dialogs.IInputValidator)

Example 57 with IInputValidator

use of org.eclipse.jface.dialogs.IInputValidator in project jbosstools-hibernate by jbosstools.

the class NameValidator method renameLaunchConfiguration.

public boolean renameLaunchConfiguration(ILaunchConfiguration launchConfiguration) {
    Shell mParentShell = null;
    IInputValidator inputValidator = new NameValidator();
    InputDialog d = new InputDialog(mParentShell, HibernateConsoleMessages.RenameAction_dialog_title, HibernateConsoleMessages.RenameAction_dialog_message, launchConfiguration.getName(), inputValidator);
    if (d.open() == Window.OK) {
        try {
            ILaunchConfigurationWorkingCopy wc = launchConfiguration.getWorkingCopy();
            wc.rename(d.getValue());
            wc.doSave();
            return true;
        } catch (CoreException e) {
            HibernateConsolePlugin.getDefault().showError(mParentShell, HibernateConsoleMessages.RenameAction_error_title, e);
        }
    }
    return false;
}
Also used : Shell(org.eclipse.swt.widgets.Shell) InputDialog(org.eclipse.jface.dialogs.InputDialog) CoreException(org.eclipse.core.runtime.CoreException) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy) IInputValidator(org.eclipse.jface.dialogs.IInputValidator)

Example 58 with IInputValidator

use of org.eclipse.jface.dialogs.IInputValidator in project egit by eclipse.

the class BranchRenameDialog method create.

@Override
public void create() {
    super.create();
    setTitle(UIText.BranchRenameDialog_Title);
    String oldName = branchToRename.getName();
    String prefix;
    if (oldName.startsWith(Constants.R_HEADS))
        prefix = Constants.R_HEADS;
    else if (oldName.startsWith(Constants.R_REMOTES))
        prefix = Constants.R_REMOTES;
    else
        prefix = null;
    String shortName = null;
    if (prefix != null) {
        shortName = Repository.shortenRefName(branchToRename.getName());
        setMessage(NLS.bind(UIText.BranchRenameDialog_Message, shortName));
    } else
        setErrorMessage(NLS.bind(UIText.BranchRenameDialog_WrongPrefixErrorMessage, oldName));
    if (shortName != null) {
        name.setText(shortName);
        name.setSelection(0, shortName.length());
    }
    final IInputValidator inputValidator = ValidationUtils.getRefNameInputValidator(repository, prefix, true);
    name.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            String error = inputValidator.isValid(name.getText());
            setErrorMessage(error);
            getButton(OK).setEnabled(error == null);
        }
    });
    BranchNameNormalizer normalizer = new BranchNameNormalizer(name);
    normalizer.setVisible(false);
    getButton(OK).setEnabled(false);
}
Also used : BranchNameNormalizer(org.eclipse.egit.ui.internal.components.BranchNameNormalizer) ModifyEvent(org.eclipse.swt.events.ModifyEvent) ModifyListener(org.eclipse.swt.events.ModifyListener) IInputValidator(org.eclipse.jface.dialogs.IInputValidator)

Example 59 with IInputValidator

use of org.eclipse.jface.dialogs.IInputValidator in project portfolio by buchen.

the class StartYearSelectionDropDown method menuAboutToShow.

@Override
public void menuAboutToShow(IMenuManager manager) {
    int now = LocalDate.now().getYear();
    for (int ii = 0; ii < 10; ii++) {
        int year = now - ii;
        Action action = new Action(String.valueOf(year)) {

            @Override
            public void run() {
                model.updateWith(year);
                setLabel(String.valueOf(year));
            }
        };
        action.setChecked(year == model.getStartYear());
        manager.add(action);
    }
    manager.add(new Separator());
    manager.add(new SimpleAction(Messages.LabelSelectYear, a -> {
        IInputValidator validator = newText -> {
            try {
                int year = Integer.parseInt(newText);
                return year >= 1900 && year <= now ? null : MessageFormat.format(Messages.MsgErrorDividendsYearBetween1900AndNow, String.valueOf(now));
            } catch (NumberFormatException nfe) {
                return MessageFormat.format(Messages.MsgErrorDividendsYearBetween1900AndNow, String.valueOf(now));
            }
        };
        InputDialog dialog = new InputDialog(Display.getDefault().getActiveShell(), Messages.LabelYear, Messages.LabelDividendsSelectStartYear, String.valueOf(model.getStartYear()), validator);
        if (dialog.open() == InputDialog.OK) {
            int year = Integer.parseInt(dialog.getValue());
            model.updateWith(year);
            setLabel(String.valueOf(year));
        }
    }));
}
Also used : InputDialog(org.eclipse.jface.dialogs.InputDialog) Separator(org.eclipse.jface.action.Separator) MessageFormat(com.ibm.icu.text.MessageFormat) IMenuManager(org.eclipse.jface.action.IMenuManager) Messages(name.abuchen.portfolio.ui.Messages) LocalDate(java.time.LocalDate) IInputValidator(org.eclipse.jface.dialogs.IInputValidator) ToolBar(org.eclipse.swt.widgets.ToolBar) SimpleAction(name.abuchen.portfolio.ui.util.SimpleAction) Action(org.eclipse.jface.action.Action) Display(org.eclipse.swt.widgets.Display) AbstractDropDown(name.abuchen.portfolio.ui.util.AbstractDropDown) SimpleAction(name.abuchen.portfolio.ui.util.SimpleAction) Action(org.eclipse.jface.action.Action) InputDialog(org.eclipse.jface.dialogs.InputDialog) SimpleAction(name.abuchen.portfolio.ui.util.SimpleAction) Separator(org.eclipse.jface.action.Separator) IInputValidator(org.eclipse.jface.dialogs.IInputValidator)

Example 60 with IInputValidator

use of org.eclipse.jface.dialogs.IInputValidator in project titan.EclipsePlug-ins by eclipse.

the class DecipheringPreferencePage method createFieldEditors.

@Override
public void createFieldEditors() {
    comboFieldEditor = new MutableComboFieldEditor(getPreferenceKeyForRulesets(), "rulesets", getFieldEditorParent());
    comboFieldEditor.setPreferenceStore(getPreferenceStore());
    addField(comboFieldEditor);
    comboFieldEditor.setInputValidator(new IInputValidator() {

        @Override
        public String isValid(final String newText) {
            if (newText == null || newText.length() == 0) {
                return "The name should contain at least one character.";
            }
            String[] items = DecipheringPreferencePage.this.comboFieldEditor.getItems();
            for (String str : items) {
                if (str.equals(newText)) {
                    return "Ruleset with the given name already exists.";
                }
            }
            return null;
        }
    });
    comboFieldEditor.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            updateMsgTypeEditor();
        }
    });
    comboFieldEditor.addItemListener(new IItemListener() {

        @Override
        public void itemRemoved(final String item) {
            deletedRuleSets.add(item);
            updateMsgTypeEditor();
        }

        @Override
        public void itemAdded(final String item) {
            comboFieldEditor.select(comboFieldEditor.getItemCount() - 1);
            updateMsgTypeEditor();
        }
    });
    messageTypeEditor = new StringListEditor("", "Message types", getFieldEditorParent(), false);
    messageTypeEditor.setPreferenceStore(getPreferenceStore());
    messageTypeEditor.setInputValidator(new IInputValidator() {

        @Override
        public String isValid(final String newText) {
            return MSGTPYE_PATTERN.matcher(newText).matches() ? null : "Invalid message type.";
        }
    });
    messageTypeEditor.setEnabled(false, getFieldEditorParent());
    messageTypeEditor.addSelectionChangedListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            updateRuleEditor();
        }
    });
    addField(messageTypeEditor);
    ruleEditor = new StringListEditor("", "Deciphering rules", getFieldEditorParent(), true);
    ruleEditor.setPreferenceStore(getPreferenceStore());
    ruleEditor.setInputValidator(new IInputValidator() {

        @Override
        public String isValid(final String newText) {
            return RULE_PATTERN.matcher(newText).matches() ? null : "Invalid rule type.";
        }
    });
    ruleEditor.setEnabled(false, getFieldEditorParent());
    addField(ruleEditor);
    updatePage();
}
Also used : MutableComboFieldEditor(org.eclipse.titan.log.viewer.preferences.fieldeditors.MutableComboFieldEditor) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) StringListEditor(org.eclipse.titan.log.viewer.preferences.fieldeditors.StringListEditor) SelectionEvent(org.eclipse.swt.events.SelectionEvent) IItemListener(org.eclipse.titan.log.viewer.preferences.fieldeditors.MutableComboFieldEditor.IItemListener) IInputValidator(org.eclipse.jface.dialogs.IInputValidator)

Aggregations

IInputValidator (org.eclipse.jface.dialogs.IInputValidator)60 InputDialog (org.eclipse.jface.dialogs.InputDialog)51 Composite (org.eclipse.swt.widgets.Composite)11 SelectionEvent (org.eclipse.swt.events.SelectionEvent)10 FacetsListInputDialog (com.amalto.workbench.dialogs.FacetsListInputDialog)9 Button (org.eclipse.swt.widgets.Button)9 ArrayList (java.util.ArrayList)8 GridLayout (org.eclipse.swt.layout.GridLayout)8 IStatus (org.eclipse.core.runtime.IStatus)7 GridData (org.eclipse.swt.layout.GridData)7 Label (org.eclipse.swt.widgets.Label)7 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)6 SelectionListener (org.eclipse.swt.events.SelectionListener)6 Event (org.eclipse.swt.widgets.Event)6 FillLayout (org.eclipse.swt.layout.FillLayout)5 Control (org.eclipse.swt.widgets.Control)5 Group (org.eclipse.swt.widgets.Group)5 MessageBox (org.eclipse.swt.widgets.MessageBox)5 ISelection (org.eclipse.jface.viewers.ISelection)4 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)4