use of org.eclipse.jface.dialogs.IInputValidator in project usbdm-eclipse-plugins by podonoghue.
the class OpenGdbConsoleHandler method execute.
public Object execute(ExecutionEvent event) throws ExecutionException {
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
InputDialog dialog = new InputDialog(window.getShell(), "TTY Port Number", "Port number for TTY console", portNum, new IInputValidator() {
@Override
public String isValid(String arg0) {
try {
int num = Integer.parseInt(arg0);
if (num <= 0) {
return "Must not be zero";
}
if (num >= 65536) {
return "Too large";
}
} catch (Exception e) {
return "Invalid integer";
}
return null;
}
});
int rc = dialog.open();
if (rc != InputDialog.OK) {
return null;
}
portNum = dialog.getValue();
try {
MyConsoleInterface.startServer(Integer.parseInt(portNum));
} catch (Exception e) {
MessageBox mb = new MessageBox(window.getShell());
mb.setMessage(e.getMessage());
mb.setText("Error opening TTY");
mb.open();
}
return null;
}
use of org.eclipse.jface.dialogs.IInputValidator in project netxms by netxms.
the class ObjectFinder method saveQuery.
/**
* Save query as predefined
*/
private void saveQuery() {
if (tabFolder.getSelectionIndex() != 1)
return;
InputDialog dlg = new InputDialog(getSite().getShell(), "Save Object Query", "Query name", "", new IInputValidator() {
@Override
public String isValid(String newText) {
if (newText.trim().isEmpty())
return "Query name must not be empty";
return null;
}
});
if (dlg.open() != Window.OK)
return;
final ObjectQuery query = new ObjectQuery(dlg.getValue(), "", queryEditor.getText());
new ConsoleJob("Save object query", this, Activator.PLUGIN_ID) {
@Override
protected void runInternal(IProgressMonitor monitor) throws Exception {
boolean found = false;
for (ObjectQuery q : session.getObjectQueries()) if (q.getName().equalsIgnoreCase(query.getName())) {
query.setId(q.getId());
found = true;
break;
}
if (found) {
final boolean[] overwrite = new boolean[1];
getDisplay().syncExec(new Runnable() {
@Override
public void run() {
overwrite[0] = MessageDialogHelper.openQuestion(getSite().getShell(), "Confirm Overwrite", String.format("Object query named \"%s\" already exists. Do you want to overwrite it?", query.getName()));
}
});
if (!overwrite[0])
return;
}
session.modifyObjectQuery(query);
runInUIThread(new Runnable() {
@Override
public void run() {
loadQueries();
queryModified = false;
}
});
}
@Override
protected String getErrorMessage() {
return "Cannot save object query";
}
}.start();
}
use of org.eclipse.jface.dialogs.IInputValidator in project netxms by netxms.
the class SshKeyConfigurator method generateKeys.
/**
* Generate new keys
*/
private void generateKeys() {
final InputDialog dlg = new InputDialog(getSite().getShell(), "Generate SSH Key", "Key name", "", new IInputValidator() {
@Override
public String isValid(String newText) {
return newText.isBlank() ? "Key name should not be empty" : null;
}
});
if (dlg.open() != Window.OK)
return;
new ConsoleJob("Generate SSH keys", this, Activator.PLUGIN_ID, null) {
@Override
protected void runInternal(IProgressMonitor monitor) throws Exception {
session.generateSshKeys(dlg.getValue().trim());
}
@Override
protected String getErrorMessage() {
return "Cannot generate SSH keys";
}
}.start();
}
use of org.eclipse.jface.dialogs.IInputValidator in project eclipse.platform.ui by eclipse-platform.
the class FiltersConfigurationDialog method renameFilter.
private void renameFilter() {
MarkerFieldFilterGroup filterGroup = getSelectionFromTable();
IInputValidator nameValidator = getNameValidator(filterGroup.getName(), getCurrentConfigurationNames());
InputDialog inputDialog = new InputDialog(getShell(), MarkerMessages.MarkerFilterDialog_title, MarkerMessages.MarkerFilterDialog_message, filterGroup.getName(), nameValidator);
if (inputDialog.open() == Window.OK) {
filterGroup.setName(inputDialog.getValue());
configsTable.refresh(filterGroup);
}
}
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(createLabelTextForYear(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.LabelPaymentsSelectStartYear, String.valueOf(model.getStartYear()), validator);
if (dialog.open() == InputDialog.OK) {
int year = Integer.parseInt(dialog.getValue());
model.updateWith(year);
setLabel(createLabelTextForYear(year));
}
}));
}
Aggregations