Search in sources :

Example 86 with IInputValidator

use of org.eclipse.jface.dialogs.IInputValidator in project Pydev by fabioz.

the class InterativeConsoleCommandsPreferencesEditor method createContents.

public Control createContents(Composite parent) {
    parent = new Composite(parent, SWT.FLAT);
    parent.setLayout(new GridLayout(4, false));
    Label label = new Label(parent, SWT.NONE);
    label.setLayoutData(createGridData());
    label.setText("Command");
    combo = new Combo(parent, SWT.DROP_DOWN | SWT.READ_ONLY);
    combo.setLayoutData(createComboGridData());
    final Button button = new Button(parent, SWT.PUSH);
    button.setLayoutData(createGridData());
    button.setText("Add");
    button.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            String[] items = combo.getItems();
            final Set<String> set = new HashSet<>(Arrays.asList(items));
            IInputValidator validator = new IInputValidator() {

                @Override
                public String isValid(String newText) {
                    if (newText.length() == 0) {
                        return "At least 1 char must be provided.";
                    }
                    if (set.contains(newText)) {
                        return "A command named: " + newText + " already exists.";
                    }
                    return null;
                }
            };
            String name = DialogHelpers.openInputRequest("Command name", "Please enter the name of the command", button.getShell(), validator);
            if (name != null && name.length() > 0) {
                InteractiveConsoleCommand cmd = new InteractiveConsoleCommand(name);
                addCommand(cmd);
                comboSelectionChanged();
            }
        }
    });
    Button buttonRemove = new Button(parent, SWT.PUSH);
    buttonRemove.setLayoutData(createGridData());
    buttonRemove.setText("Remove");
    buttonRemove.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            removeSelectedCommand();
            comboSelectionChanged();
        }
    });
    label = new Label(parent, SWT.NONE);
    label.setLayoutData(GridDataFactory.fillDefaults().span(1, 1).create());
    label.setText("Keybinding");
    textKeybinding = new Text(parent, SWT.SINGLE | SWT.BORDER);
    textKeybinding.setLayoutData(GridDataFactory.fillDefaults().span(3, 1).create());
    textKeybindingListener = new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            String comboText = combo.getText();
            InteractiveConsoleCommand interactiveConsoleCommand = nameToCommand.get(comboText);
            if (interactiveConsoleCommand == null) {
                Log.log("Expected a command to be bound to: " + comboText);
                return;
            }
            validateAndSetKeybinding(comboText, interactiveConsoleCommand);
        }
    };
    label = new Label(parent, SWT.NONE);
    label.setLayoutData(GridDataFactory.fillDefaults().span(4, 1).create());
    label.setText("Command text.\n\n${text} is replaced by the currently selected text\nor the full line if no text is selected.");
    textCommand = new Text(parent, SWT.MULTI | SWT.BORDER);
    textCommand.setLayoutData(createTextGridData());
    textCommandListener = new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            String comboText = combo.getText();
            InteractiveConsoleCommand interactiveConsoleCommand = nameToCommand.get(comboText);
            if (interactiveConsoleCommand == null) {
                Log.log("Expected a command to be bound to: " + comboText);
                return;
            }
            interactiveConsoleCommand.commandText = textCommand.getText();
        }
    };
    combo.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            comboSelectionChanged();
        }
    });
    errorLabel = new Label(parent, SWT.NONE);
    errorLabel.setLayoutData(GridDataFactory.fillDefaults().span(4, 1).create());
    errorLabel.setText("Command text.\n\n${text} is replaced by the currently selected text\nor the full line if no text is selected.");
    errorLabel.setVisible(false);
    red = new Color(Display.getCurrent(), 255, 0, 0);
    errorLabel.setForeground(red);
    this.loadCommands();
    addTextListeners();
    return parent;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) Composite(org.eclipse.swt.widgets.Composite) ModifyListener(org.eclipse.swt.events.ModifyListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Color(org.eclipse.swt.graphics.Color) Label(org.eclipse.swt.widgets.Label) Combo(org.eclipse.swt.widgets.Combo) Text(org.eclipse.swt.widgets.Text) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) IInputValidator(org.eclipse.jface.dialogs.IInputValidator)

Example 87 with IInputValidator

use of org.eclipse.jface.dialogs.IInputValidator in project Pydev by fabioz.

the class SourceLocatorPrefsPage method createFieldEditors.

/**
 * Creates the editors
 */
@Override
protected void createFieldEditors() {
    Composite p = getFieldEditorParent();
    LinkFieldEditor linkEditor = new LinkFieldEditor("UNUSED", "These preferences are used solely for mapping a path which arrives in the IDE.\n" + "For by-directional client <-> debugger translations please use the settings at: <a>Path Mappings</a>", p, new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            String id = "org.python.pydev.editor.preferences.PyTabPreferencesPage";
            IWorkbenchPreferenceContainer workbenchPreferenceContainer = ((IWorkbenchPreferenceContainer) getContainer());
            workbenchPreferenceContainer.openPage(id, null);
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });
    addField(linkEditor);
    addField(new ComboFieldEditor(PySourceLocatorPrefs.ON_SOURCE_NOT_FOUND, "Action when source is not directly found:", ENTRIES_AND_VALUES, p));
    addField(new IntegerFieldEditor(PySourceLocatorPrefs.FILE_CONTENTS_TIMEOUT, "Timeout to get file contents (millis):", p));
    addField(new TableEditor(PyDevEditorPreferences.SOURCE_LOCATION_PATHS, "Translation paths to use:", p) {

        @Override
        protected String createTable(List<String[]> items) {
            return PySourceLocatorPrefs.wordsAsString(items);
        }

        @Override
        protected String[] getNewInputObject() {
            InputDialog d = new InputDialog(getShell(), "New entry", "Add the entry in the format path_to_replace,new_path or path,DONTASK.", "", new IInputValidator() {

                @Override
                public String isValid(String newText) {
                    String[] splitted = StringUtils.splitAndRemoveEmptyTrimmed(newText, ',').toArray(new String[0]);
                    if (splitted.length != 2) {
                        return "Input must have 2 paths separated by a comma.";
                    }
                    return PySourceLocatorPrefs.isValid(splitted);
                }
            });
            int retCode = d.open();
            if (retCode == InputDialog.OK) {
                return StringUtils.splitAndRemoveEmptyTrimmed(d.getValue(), ',').toArray(new String[0]);
            }
            return null;
        }

        @Override
        protected List<String[]> parseString(String stringList) {
            return PySourceLocatorPrefs.stringAsWords(stringList);
        }

        @Override
        protected void doFillIntoGrid(Composite parent, int numColumns) {
            super.doFillIntoGrid(parent, numColumns);
            Table table = getTableControl(parent);
            GridData layoutData = (GridData) table.getLayoutData();
            layoutData.heightHint = 300;
        }
    });
}
Also used : LinkFieldEditor(org.python.pydev.shared_ui.field_editors.LinkFieldEditor) InputDialog(org.eclipse.jface.dialogs.InputDialog) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) ComboFieldEditor(org.python.pydev.shared_ui.field_editors.ComboFieldEditor) IWorkbenchPreferenceContainer(org.eclipse.ui.preferences.IWorkbenchPreferenceContainer) SelectionEvent(org.eclipse.swt.events.SelectionEvent) GridData(org.eclipse.swt.layout.GridData) IntegerFieldEditor(org.eclipse.jface.preference.IntegerFieldEditor) List(java.util.List) SelectionListener(org.eclipse.swt.events.SelectionListener) IInputValidator(org.eclipse.jface.dialogs.IInputValidator)

Example 88 with IInputValidator

use of org.eclipse.jface.dialogs.IInputValidator in project Pydev by fabioz.

the class DialogHelpers method openAskInt.

// Return could be null if user cancelled.
public static Integer openAskInt(String title, String message, int initial) {
    Shell shell = EditorUtils.getShell();
    String initialValue = "" + initial;
    IInputValidator validator = new IInputValidator() {

        @Override
        public String isValid(String newText) {
            if (newText.length() == 0) {
                return "At least 1 char must be provided.";
            }
            try {
                Integer.parseInt(newText);
            } catch (Exception e) {
                return "A number is required.";
            }
            return null;
        }
    };
    InputDialog dialog = new InputDialog(shell, title, message, initialValue, validator);
    dialog.setBlockOnOpen(true);
    if (dialog.open() == Window.OK) {
        return Integer.parseInt(dialog.getValue());
    }
    return null;
}
Also used : Shell(org.eclipse.swt.widgets.Shell) InputDialog(org.eclipse.jface.dialogs.InputDialog) IInputValidator(org.eclipse.jface.dialogs.IInputValidator)

Example 89 with IInputValidator

use of org.eclipse.jface.dialogs.IInputValidator in project Pydev by fabioz.

the class PyRenameResourceAction method queryNewResourceName.

/**
 * Return the new name to be given to the target resource.
 *
 * @return java.lang.String
 * @param resource the resource to query status on
 *
 * Fix from platform: was not checking return from dialog.open
 */
@Override
protected String queryNewResourceName(final IResource resource) {
    final IWorkspace workspace = IDEWorkbenchPlugin.getPluginWorkspace();
    final IPath prefix = resource.getFullPath().removeLastSegments(1);
    IInputValidator validator = new IInputValidator() {

        @Override
        public String isValid(String string) {
            if (resource.getName().equals(string)) {
                return IDEWorkbenchMessages.RenameResourceAction_nameMustBeDifferent;
            }
            IStatus status = workspace.validateName(string, resource.getType());
            if (!status.isOK()) {
                return status.getMessage();
            }
            if (workspace.getRoot().exists(prefix.append(string))) {
                return IDEWorkbenchMessages.RenameResourceAction_nameExists;
            }
            return null;
        }
    };
    InputDialog dialog = new InputDialog(shell, IDEWorkbenchMessages.RenameResourceAction_inputDialogTitle, IDEWorkbenchMessages.RenameResourceAction_inputDialogMessage, resource.getName(), validator);
    dialog.setBlockOnOpen(true);
    if (dialog.open() == Window.OK) {
        return dialog.getValue();
    } else {
        return null;
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) InputDialog(org.eclipse.jface.dialogs.InputDialog) IPath(org.eclipse.core.runtime.IPath) IWorkspace(org.eclipse.core.resources.IWorkspace) IInputValidator(org.eclipse.jface.dialogs.IInputValidator)

Example 90 with IInputValidator

use of org.eclipse.jface.dialogs.IInputValidator in project Pydev by fabioz.

the class PySetupCustomFilters method run.

@Override
public void run(IAction action) {
    final Display display = Display.getDefault();
    display.syncExec(new Runnable() {

        @Override
        public void run() {
            // ask the filters to the user
            IInputValidator validator = null;
            IPreferenceStore prefs = PydevPlugin.getDefault().getPreferenceStore();
            InputDialog dialog = new InputDialog(display.getActiveShell(), "Custom Filters", "Enter the filters (separated by comma. E.g.: \"__init__.py, *.xyz\").\n" + "\n" + "Note 1: Only * and ? may be used for custom matching.\n" + "\n" + "Note 2: it'll only take effect if the 'Pydev: Hide custom specified filters'\n" + "is active in the menu: customize view > filters.", prefs.getString(CUSTOM_FILTERS_PREFERENCE_NAME), validator);
            dialog.setBlockOnOpen(true);
            dialog.open();
            if (dialog.getReturnCode() == Window.OK) {
                // update the preferences and refresh the viewer (when we update the preferences, the
                // filter that uses this will promptly update its values -- just before the refresh).
                prefs.setValue(CUSTOM_FILTERS_PREFERENCE_NAME, dialog.getValue());
                PydevPackageExplorer p = (PydevPackageExplorer) view;
                p.getCommonViewer().refresh();
            }
        }
    });
}
Also used : InputDialog(org.eclipse.jface.dialogs.InputDialog) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) PydevPackageExplorer(org.python.pydev.navigator.ui.PydevPackageExplorer) Display(org.eclipse.swt.widgets.Display) 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