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);
}
}
}
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;
}
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);
}
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));
}
}));
}
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();
}
Aggregations