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

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

Introduction

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

Prototype

IInputValidator

Source Link

Usage

From source file:au.gov.ga.earthsci.catalog.ui.handler.AddCatalogHandler.java

License:Apache License

@Execute
public void execute(final IEclipseContext context, @Named(IServiceConstants.ACTIVE_SHELL) final Shell shell) {
    BrowseInputDialog dialog = new BrowseInputDialog(shell, "Add catalog", "Enter the catalog URL:", "",
            new IInputValidator() {
                @Override//from   ww w . j  av  a  2 s.  c om
                public String isValid(String newText) {
                    try {
                        new URL(newText);
                    } catch (MalformedURLException e) {
                        return "URL error: " + e.getLocalizedMessage();
                    }
                    return null;
                }
            });
    int result = dialog.open();
    if (result != Window.OK) {
        return;
    }

    URI uri = null;
    try {
        String value = dialog.getValue();
        value = value.replace(" ", "%20"); //$NON-NLS-1$ //$NON-NLS-2$
        URL url = new URL(value);
        uri = url.toURI();
    } catch (Exception e) {
        IStatus status = new Status(IStatus.ERROR, Activator.getBundleName(), e.getLocalizedMessage(), e);
        StackTraceDialog.openError(shell, "Error", "Error opening catalog.", status);
        return;
    }

    Intent intent = new Intent();
    intent.setURI(uri);
    intent.setRequiredReturnType(ICatalogTreeNode.class);
    IIntentCallback callback = new AbstractIntentCallback() {
        @Override
        public void error(final Exception e, Intent intent) {
            shell.getDisplay().asyncExec(new Runnable() {
                @Override
                public void run() {
                    IStatus status = new Status(IStatus.ERROR, Activator.getBundleName(),
                            e.getLocalizedMessage(), e);
                    StackTraceDialog.openError(shell, "Error", "Error opening catalog.", status);
                }
            });
        }

        @Override
        public void completed(Object result, Intent intent) {
            Dispatcher.getInstance().dispatch(result, intent, context);
        }
    };
    IntentManager.getInstance().start(intent, callback, context);
}

From source file:au.gov.ga.earthsci.core.proxy.NonProxyHostsListEditor.java

License:Apache License

@Override
protected String getNewInputObject() {
    InputDialog inputDialog = new InputDialog(getShell(), "New non-proxy host", "Enter a new non-proxy host.",
            "", new IInputValidator() {
                @Override/*from   ww w  .j  ava  2 s.c  o  m*/
                public String isValid(String s) {
                    if (s != null && s.length() > 0) {
                        return null;
                    }
                    return "Please enter a value";
                }
            });
    inputDialog.open();

    if (inputDialog.getReturnCode() != Window.OK) {
        return null;
    }
    return inputDialog.getValue();
}

From source file:br.ufmg.dcc.tabuleta.actions.NewConcernAction.java

License:Open Source License

/**
 * @see org.eclipse.jface.action.IAction#run()
 *//*from  ww w.  j a va  2s  .  c  om*/
public void run() {
    InputDialog lDialog = new InputDialog(aViewer.getViewSite().getShell(),
            Tabuleta.getResourceString("actions.NewConcernAction.DialogTitle"),
            Tabuleta.getResourceString("actions.NewConcernAction.DialogLabel"), "", new IInputValidator() {
                public String isValid(String pName) {
                    String lReturn = null;
                    if (Tabuleta.getDefault().getConcernModel().exists(pName)) {
                        lReturn = Tabuleta.getResourceString("actions.NewConcernAction.NameInUse");
                    } else if (pName.length() < 1) {
                        lReturn = Tabuleta.getResourceString("actions.NewConcernAction.NoName");
                    }
                    return lReturn;
                }
            });

    int lAction = lDialog.open();

    if (lAction == Window.OK) {
        Tabuleta.getDefault().getConcernModel().newConcern(lDialog.getValue());
        aViewer.setConcernSelection(lDialog.getValue());
    }
}

From source file:br.ufmg.dcc.tabuleta.actions.RenameConcernAction.java

License:Open Source License

/**
 * @see org.eclipse.jface.action.IAction#run()
 *///from www.  j a  v  a  2 s  . c  om
public void run() {
    InputDialog lDialog = new InputDialog(aViewer.getViewSite().getShell(),
            Tabuleta.getResourceString("actions.RenameConcernAction.DialogTitle"),
            Tabuleta.getResourceString("actions.RenameConcernAction.DialogLabel"), aConcern,
            new IInputValidator() {
                public String isValid(String pName) {
                    String lReturn = null;
                    if (pName.equals(aConcern)) {
                        return null;
                    }
                    if (Tabuleta.getDefault().getConcernModel().exists(pName)) {
                        lReturn = Tabuleta.getResourceString("actions.RenameConcernAction.NameInUse");
                    } else if (pName.length() < 1) {
                        lReturn = Tabuleta.getResourceString("actions.RenameConcernAction.NoName");
                    }
                    return lReturn;
                }
            });

    int lAction = lDialog.open();

    if ((lAction == Window.OK) && !(lDialog.getValue().equals(aConcern))) {
        Tabuleta.getDefault().getConcernModel().renameConcern(aConcern, lDialog.getValue());
    }
}

From source file:byke.preferences.PatternExcludeListEditor.java

License:Open Source License

@Override
protected String getNewInputObject() {
    InputDialog dialog = new InputDialog(getShell(), "Input full qualified class name pattern",
            "Enter a regex pattern to be excluded:", "", new IInputValidator() {
                @Override/*  w  w  w . j  a  v  a 2  s  .  c  om*/
                public String isValid(String newText) {
                    try {
                        Pattern.compile(newText);
                        return null;
                    } catch (PatternSyntaxException e) {
                        return e.getLocalizedMessage();
                    }
                }
            });
    if (dialog.open() == Window.OK) {
        return dialog.getValue();
    }
    return null;
}

From source file:carisma.ui.eclipse.dialogs.parameters.ParameterDialogUtil.java

License:Open Source License

/**
 * Getter for a Float Parameter./*from   ww w.  j a va 2s  .  co m*/
 * @param parameter Float Parameter
 * @return the new value of the Float Parameter
 */
public final float queryFloatParameter(final FloatParameter parameter) {
    final InputDialog inputDialog;

    IInputValidator inputValidator = new IInputValidator() {
        @Override
        public String isValid(final String newText) {
            try {
                Float.parseFloat(newText);
                return null;
            } catch (Exception e) {
                return "Please insert a float value!";
            }
        }
    };

    inputDialog = new InputDialog(super.getShell(), this.checkDescriptor.getName(),
            DIALOG_TEXT + "\"" + parameter.getDescriptor().getName() + "\" (FLOAT)",
            String.valueOf(parameter.getValue()), inputValidator);
    int result = inputDialog.open();
    if (result == 0) { // OK-Button
        return Float.parseFloat(inputDialog.getValue());
    }
    // Cancel
    return parameter.getValue();
}

From source file:carisma.ui.eclipse.dialogs.parameters.ParameterDialogUtil.java

License:Open Source License

/**
 * Getter for a Integer Parameter./* w w w .  jav a  2s .c  o m*/
 * @param parameter Integer Parameter
 * @return the new value of the Integer Parameter
 */
public final int queryIntegerParameter(final IntegerParameter parameter) {
    final InputDialog id;
    IInputValidator iv = new IInputValidator() {
        @Override
        public String isValid(final String newText) {
            try {
                Integer.parseInt(newText);
                return null;
            } catch (Exception e) {
                return "Please insert an integer value!";
            }
        }
    };

    id = new InputDialog(super.getShell(), this.checkDescriptor.getName(),
            DIALOG_TEXT + "\"" + parameter.getDescriptor().getName() + "\" (INTEGER)",
            String.valueOf(parameter.getValue()), iv);

    boolean isANumber = false;

    while (!isANumber) {
        isANumber = true;
        int result = id.open();
        if (result == 1) { // Cancel
            return parameter.getValue();
        }
        // OK-Button
        String value = id.getValue();
        Integer valueInt = null;
        try {
            valueInt = Integer.valueOf(value);
        } catch (NumberFormatException nfe) {
            isANumber = false;
        }
        if (isANumber) {
            return valueInt.intValue();
        }
    }
    return parameter.getValue();
}

From source file:ch.elexis.commands.FallPlaneRechnung.java

License:Open Source License

public Object execute(ExecutionEvent arg0) throws ExecutionException {
    InputDialog dlg = new InputDialog(Desk.getTopShell(), Messages.FallPlaneRechnung_PlanBillingHeading,
            Messages.FallPlaneRechnung_PlanBillingAfterDays, "30", new IInputValidator() { //$NON-NLS-1$

                public String isValid(String newText) {
                    if (newText.matches("[0-9]*")) { //$NON-NLS-1$
                        return null;
                    }/*  w w  w .j a  v  a2s. co m*/
                    return Messages.FallPlaneRechnung_PlanBillingPleaseEnterPositiveInteger;
                }
            });
    if (dlg.open() == Dialog.OK) {
        return dlg.getValue();
    }
    return null;
}

From source file:ch.elexis.core.ui.commands.FallPlaneRechnung.java

License:Open Source License

public Object execute(ExecutionEvent arg0) throws ExecutionException {
    InputDialog dlg = new InputDialog(UiDesk.getTopShell(), Messages.FallPlaneRechnung_PlanBillingHeading,
            Messages.FallPlaneRechnung_PlanBillingAfterDays, "30", new IInputValidator() { //$NON-NLS-1$

                public String isValid(String newText) {
                    if (newText.matches("[0-9]*")) { //$NON-NLS-1$
                        return null;
                    }/*from w  w w. j av a2 s  .  c o  m*/
                    return Messages.FallPlaneRechnung_PlanBillingPleaseEnterPositiveInteger;
                }
            });
    if (dlg.open() == Dialog.OK) {
        return dlg.getValue();
    }
    return null;
}

From source file:ch.elexis.core.ui.views.codesystems.BlockSelector.java

License:Open Source License

private void makeActions() {
    deleteAction = new Action("Block lschen") {
        @Override/*www .ja  v  a  2 s . c  om*/
        public void run() {
            Object o = cv.getSelection()[0];
            if (o instanceof Leistungsblock) {
                ((Leistungsblock) o).delete();
                cv.notify(CommonViewer.Message.update);
            }
        }
    };
    createAction = new Action("neu erstellen") {
        {
            setImageDescriptor(Images.IMG_NEW.getImageDescriptor());
            setToolTipText("Neuen Block erstellen");
        }

        @Override
        public void run() {
            String[] v = cv.getConfigurer().getControlFieldProvider().getValues();
            if (v != null && v.length > 0 && v[0] != null && v[0].length() > 0) {
                new Leistungsblock(v[0], ElexisEventDispatcher.getSelectedMandator());
                cv.notify(CommonViewer.Message.update_keeplabels);
            }
        }
    };
    exportAction = new Action("Blcke exportieren") {
        {
            setImageDescriptor(Images.IMG_EXPORT.getImageDescriptor());
            setToolTipText("Exportiert alle Blcke in eine XML-Datei");
        }

        @Override
        public void run() {
            // Handler.execute(null, ExportiereBloeckeCommand.ID, null);
            try {
                new ExportiereBloeckeCommand().execute(null);
            } catch (ExecutionException e) {
                LoggerFactory.getLogger(getClass()).error("Error exporting block", e);
            }
        }
    };
    copyAction = new Action("Block kopieren") {
        {
            setImageDescriptor(Images.IMG_COPY.getImageDescriptor());
            setToolTipText("Den Block umbenennen und kopieren");
        }

        @Override
        public void run() {
            Object o = cv.getSelection()[0];
            if (o instanceof Leistungsblock) {
                Leistungsblock sourceBlock = (Leistungsblock) o;
                InputDialog inputDlg = new InputDialog(Display.getDefault().getActiveShell(), "Block kopieren",
                        "Bitte den Namen der Kopie eingeben bzw. besttigen", sourceBlock.getName() + " Kopie",
                        new IInputValidator() {

                            @Override
                            public String isValid(String newText) {
                                return (newText != null && !newText.isEmpty()) ? null : "Fehler, kein Name.";
                            }
                        }, SWT.BORDER);
                if (inputDlg.open() == Window.OK) {
                    String newName = inputDlg.getValue();
                    Leistungsblock newBlock = new Leistungsblock(newName,
                            Mandant.load(sourceBlock.get(Leistungsblock.FLD_MANDANT_ID)));
                    sourceBlock.getElements().forEach(e -> newBlock.addElement(e));
                    cv.notify(CommonViewer.Message.update);
                }
            }
        }
    };
    searchBlocksOnly = new Action("Blockinhalt nicht durchsuchen", Action.AS_CHECK_BOX) {
        {
            setImageDescriptor(Images.IMG_FILTER.getImageDescriptor());
            setToolTipText("Blockinhalt nicht durchsuchen");
            setChecked(CoreHub.userCfg.get(BLOCK_ONLY_FILTER_ENABLED, false));
        }

        public void run() {
            CoreHub.userCfg.set(BLOCK_ONLY_FILTER_ENABLED, isChecked());
        };
    };
}