Search in sources :

Example 71 with IInputValidator

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;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) InputDialog(org.eclipse.jface.dialogs.InputDialog) ExecutionException(org.eclipse.core.commands.ExecutionException) IInputValidator(org.eclipse.jface.dialogs.IInputValidator) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 72 with IInputValidator

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();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) InputDialog(org.eclipse.jface.dialogs.InputDialog) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) ObjectQuery(org.netxms.client.objects.queries.ObjectQuery) PartInitException(org.eclipse.ui.PartInitException) UnknownHostException(java.net.UnknownHostException) NXCException(org.netxms.client.NXCException) IInputValidator(org.eclipse.jface.dialogs.IInputValidator)

Example 73 with IInputValidator

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();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) InputDialog(org.eclipse.jface.dialogs.InputDialog) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) PartInitException(org.eclipse.ui.PartInitException) NXCException(org.netxms.client.NXCException) IInputValidator(org.eclipse.jface.dialogs.IInputValidator)

Example 74 with IInputValidator

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

Example 75 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(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));
        }
    }));
}
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) DropDown(name.abuchen.portfolio.ui.util.DropDown) LocalDate(java.time.LocalDate) IInputValidator(org.eclipse.jface.dialogs.IInputValidator) SimpleAction(name.abuchen.portfolio.ui.util.SimpleAction) Action(org.eclipse.jface.action.Action) Display(org.eclipse.swt.widgets.Display) IMenuListener(org.eclipse.jface.action.IMenuListener) 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)

Aggregations

IInputValidator (org.eclipse.jface.dialogs.IInputValidator)101 InputDialog (org.eclipse.jface.dialogs.InputDialog)88 Composite (org.eclipse.swt.widgets.Composite)20 IStatus (org.eclipse.core.runtime.IStatus)16 SelectionEvent (org.eclipse.swt.events.SelectionEvent)13 ArrayList (java.util.ArrayList)12 Button (org.eclipse.swt.widgets.Button)12 GridData (org.eclipse.swt.layout.GridData)11 GridLayout (org.eclipse.swt.layout.GridLayout)10 FacetsListInputDialog (com.amalto.workbench.dialogs.FacetsListInputDialog)9 List (java.util.List)8 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)8 Label (org.eclipse.swt.widgets.Label)8 SelectionListener (org.eclipse.swt.events.SelectionListener)7 Control (org.eclipse.swt.widgets.Control)7 Display (org.eclipse.swt.widgets.Display)7 IResource (org.eclipse.core.resources.IResource)6 CoreException (org.eclipse.core.runtime.CoreException)6 Window (org.eclipse.jface.window.Window)6 Event (org.eclipse.swt.widgets.Event)6