Search in sources :

Example 41 with IInputValidator

use of org.eclipse.jface.dialogs.IInputValidator in project netxms by netxms.

the class FileDeliveryPolicyEditor method addElement.

/**
 * Add new element
 */
private void addElement(PathElement parent) {
    InputDialog dlg = new InputDialog(getShell(), (parent == null) ? "New root directory" : "New directory", "Enter name for new directory", "", new IInputValidator() {

        @Override
        public String isValid(String newText) {
            if (newText.isEmpty())
                return "Name cannot be empty";
            if (parent != null)
                for (PathElement el : parent.getChildren()) {
                    if (newText.equalsIgnoreCase(el.getName()))
                        return "Object with this name already exists";
                }
            return null;
        }
    });
    if (dlg.open() != Window.OK)
        return;
    PathElement e = new PathElement(parent, dlg.getValue());
    if (parent == null) {
        rootElements.add(e);
        fileTree.refresh(true);
    } else {
        fileTree.refresh();
    }
    fireModifyListeners();
}
Also used : InputDialog(org.eclipse.jface.dialogs.InputDialog) PathElement(org.netxms.ui.eclipse.datacollection.widgets.helpers.PathElement) IInputValidator(org.eclipse.jface.dialogs.IInputValidator)

Example 42 with IInputValidator

use of org.eclipse.jface.dialogs.IInputValidator in project netxms by netxms.

the class FileDeliveryPolicyEditor method renameElement.

/**
 * Rename selected element
 */
private void renameElement() {
    IStructuredSelection selection = fileTree.getStructuredSelection();
    if (selection.size() != 1)
        return;
    PathElement element = (PathElement) selection.getFirstElement();
    InputDialog dlg = new InputDialog(getShell(), element.isFile() ? "Rename file" : "Rename directory", "Enter new name", element.getName(), new IInputValidator() {

        @Override
        public String isValid(String newText) {
            if (newText.isEmpty())
                return "Name cannot be empty";
            if (element.getParent() != null)
                for (PathElement el : element.getParent().getChildren()) {
                    if (!el.equals(element) && newText.equalsIgnoreCase(el.getName()))
                        return "Object with this name already exists";
                }
            return null;
        }
    });
    if (dlg.open() != Window.OK)
        return;
    ((PathElement) selection.getFirstElement()).updateCreationTime();
    if (element.getParent() == null) {
        rootElements.remove(element);
        element.setName(dlg.getValue());
        rootElements.add(element);
        fileTree.refresh();
    } else {
        element.setName(dlg.getValue());
        fileTree.update(element, null);
    }
    fireModifyListeners();
}
Also used : InputDialog(org.eclipse.jface.dialogs.InputDialog) PathElement(org.netxms.ui.eclipse.datacollection.widgets.helpers.PathElement) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IInputValidator(org.eclipse.jface.dialogs.IInputValidator)

Example 43 with IInputValidator

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

the class CodeCompletionPreferencesPage method createFieldEditors.

@Override
protected void createFieldEditors() {
    Composite p = getFieldEditorParent();
    addField(new IntegerFieldEditor(PyCodeCompletionPreferences.CHARS_FOR_CTX_INSENSITIVE_MODULES_COMPLETION, "Number of chars for showing modules in context-insensitive completions?", p));
    addField(new IntegerFieldEditor(PyCodeCompletionPreferences.CHARS_FOR_CTX_INSENSITIVE_TOKENS_COMPLETION, "Number of chars for showing global tokens in context-insensitive completions?", p));
    addField(new BooleanFieldEditor(PyCodeCompletionPreferences.USE_KEYWORDS_CODE_COMPLETION, "Use common tokens auto code completion?", p));
    addField(new LabelFieldEditor("LabelFieldEditor", "", p));
    addField(new BooleanFieldEditor(PyCodeCompletionPreferences.ADD_SPACE_WHEN_NEEDED, "Add <SPACE> for common cases (e.g.: \"and \", \"assert \", etc.)?", p));
    addField(new LabelFieldEditor("LabelFieldEditor", "", p));
    addField(new BooleanFieldEditor(PyCodeCompletionPreferences.ADD_SPACE_AND_COLON_WHEN_NEEDED, "Add <SPACE><COLON> for common cases (e.g.: \"class :\", \"if :\", etc.)?", p));
    addField(new LabelFieldEditor("LabelFieldEditor", "", p));
    addField(new BooleanFieldEditor(PyCodeCompletionPreferences.FORCE_PY3K_PRINT_ON_PY2, "Force print() function on Python 2.x projects?", p));
    addField(new LabelFieldEditor("LabelFieldEditor", "", p));
    addField(new ListEditor(PyCodeCompletionPreferences.KEYWORDS_CODE_COMPLETION, "Tokens to use:", p) {

        @Override
        protected String createList(String[] items) {
            return PyCodeCompletionPreferences.wordsAsString(items);
        }

        @Override
        protected String getNewInputObject() {
            InputDialog d = new InputDialog(getShell(), "New word", "Add the word you wish.", "", new IInputValidator() {

                @Override
                public String isValid(String newText) {
                    if (newText.indexOf(' ') != -1) {
                        return "The input cannot have spaces";
                    }
                    return null;
                }
            });
            int retCode = d.open();
            if (retCode == InputDialog.OK) {
                return d.getValue();
            }
            return null;
        }

        @Override
        protected String[] parseString(String stringList) {
            return PyCodeCompletionPreferences.stringAsWords(stringList);
        }

        @Override
        protected void doFillIntoGrid(Composite parent, int numColumns) {
            super.doFillIntoGrid(parent, numColumns);
            List listControl = getListControl(parent);
            GridData layoutData = (GridData) listControl.getLayoutData();
            layoutData.heightHint = 300;
        }
    });
}
Also used : ListEditor(org.eclipse.jface.preference.ListEditor) InputDialog(org.eclipse.jface.dialogs.InputDialog) Composite(org.eclipse.swt.widgets.Composite) BooleanFieldEditor(org.eclipse.jface.preference.BooleanFieldEditor) LabelFieldEditor(org.python.pydev.shared_ui.field_editors.LabelFieldEditor) GridData(org.eclipse.swt.layout.GridData) IntegerFieldEditor(org.eclipse.jface.preference.IntegerFieldEditor) List(org.eclipse.swt.widgets.List) IInputValidator(org.eclipse.jface.dialogs.IInputValidator)

Example 44 with IInputValidator

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

the class PasteAction method getNameForContentsPasted.

private String getNameForContentsPasted(final IContainer container) {
    final IWorkspace workspace = container.getWorkspace();
    final String[] returnValue = { null };
    final IInputValidator validator = new IInputValidator() {

        @Override
        public String isValid(String string) {
            IStatus status = workspace.validateName(string, IResource.FILE);
            if (!status.isOK()) {
                return status.getMessage();
            }
            if (container.getFile(new Path(string)).exists()) {
                return "File already exists";
            }
            return null;
        }
    };
    String base = "snippet%s.py";
    for (int i = 0; i < 1000; i++) {
        String newCheck;
        if (i == 0) {
            newCheck = StringUtils.format(base, "");
        } else {
            newCheck = StringUtils.format(base, i);
        }
        if (validator.isValid(newCheck) == null) {
            base = newCheck;
            break;
        }
    }
    final String initialValue = base;
    this.shell.getDisplay().syncExec(new Runnable() {

        @Override
        public void run() {
            InputDialog dialog = new InputDialog(shell, "Enter file name", "Please enter the name of the file to be created with the pasted contents.", initialValue, validator) {

                @Override
                protected void createButtonsForButtonBar(Composite parent) {
                    super.createButtonsForButtonBar(parent);
                    Text control = getText();
                    String textInControl = control.getText();
                    int i = textInControl.indexOf('.');
                    if (i >= 0) {
                        control.setSelection(0, i);
                    }
                }
            };
            dialog.setBlockOnOpen(true);
            dialog.open();
            if (dialog.getReturnCode() == Window.CANCEL) {
                returnValue[0] = null;
            } else {
                returnValue[0] = dialog.getValue();
            }
        }
    });
    if (returnValue[0] == null) {
        return null;
    }
    return returnValue[0];
}
Also used : Path(org.eclipse.core.runtime.Path) IStatus(org.eclipse.core.runtime.IStatus) InputDialog(org.eclipse.jface.dialogs.InputDialog) Composite(org.eclipse.swt.widgets.Composite) IWorkspace(org.eclipse.core.resources.IWorkspace) Text(org.eclipse.swt.widgets.Text) IInputValidator(org.eclipse.jface.dialogs.IInputValidator)

Example 45 with IInputValidator

use of org.eclipse.jface.dialogs.IInputValidator in project hale by halestudio.

the class CRSPreferencePage method createContents.

/**
 * @see PreferencePage#createContents(Composite)
 */
@Override
protected Control createContents(Composite parent) {
    Composite page = new Composite(parent, SWT.NONE);
    page.setLayout(new GridLayout(1, false));
    page.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    Label label = new Label(page, SWT.NONE);
    // $NON-NLS-1$
    label.setText(Messages.CRSPreferencePage_0);
    label.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false));
    // code list
    listViewer = new ComboViewer(page);
    listViewer.setContentProvider(ArrayContentProvider.getInstance());
    listViewer.setLabelProvider(new LabelProvider());
    listViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
    codes = WKTPreferencesCRSFactory.getInstance().getCodes();
    listViewer.setInput(codes);
    listViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            ISelection selection = event.getSelection();
            if (selection.isEmpty()) {
                updateEditor(null);
            } else {
                if (selection instanceof IStructuredSelection) {
                    updateEditor((String) ((IStructuredSelection) selection).getFirstElement());
                }
            }
        }
    });
    // fill wkt map
    for (String code : codes) {
        tmpWKTs.put(code, WKTPreferencesCRSFactory.getInstance().getWKT(code));
    }
    // WKT editor
    final Display display = Display.getCurrent();
    CompositeRuler ruler = new CompositeRuler(3);
    LineNumberRulerColumn lineNumbers = new LineNumberRulerColumn();
    // SWT.COLOR_INFO_BACKGROUND));
    lineNumbers.setBackground(display.getSystemColor(SWT.COLOR_GRAY));
    // SWT.COLOR_INFO_FOREGROUND));
    lineNumbers.setForeground(display.getSystemColor(SWT.COLOR_BLACK));
    lineNumbers.setFont(JFaceResources.getTextFont());
    ruler.addDecorator(0, lineNumbers);
    wktEditor = new SourceViewer(page, ruler, SWT.BORDER | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
    wktEditor.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    wktEditor.getTextWidget().setFont(JFaceResources.getTextFont());
    SourceViewerConfiguration conf = new SourceViewerConfiguration();
    wktEditor.configure(conf);
    // create initial document
    IDocument doc = new Document();
    // $NON-NLS-1$
    doc.set("");
    wktEditor.setInput(doc);
    // button bar
    Composite bar = new Composite(page, SWT.NONE);
    bar.setLayout(new GridLayout(2, true));
    bar.setLayoutData(new GridData(SWT.FILL, SWT.END, true, false));
    // add button (using a directory dialog)
    Button add = new Button(bar, SWT.PUSH);
    add.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
    // $NON-NLS-1$
    add.setText(Messages.CRSPreferencePage_2);
    // $NON-NLS-1$
    add.setToolTipText(Messages.CRSPreferencePage_3);
    add.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            final Display display = Display.getCurrent();
            InputDialog dialog = new InputDialog(display.getActiveShell(), // $NON-NLS-1$ //$NON-NLS-2$
            Messages.CRSPreferencePage_4, // $NON-NLS-1$ //$NON-NLS-2$
            Messages.CRSPreferencePage_5, WKTPreferencesCRSFactory.AUTHORITY_PREFIX, new IInputValidator() {

                @Override
                public String isValid(String newText) {
                    if (!newText.startsWith(WKTPreferencesCRSFactory.AUTHORITY_PREFIX)) {
                        return MessageFormat.format(Messages.CRSPreferencePage_6, // $NON-NLS-1$
                        WKTPreferencesCRSFactory.AUTHORITY_PREFIX);
                    }
                    return null;
                }
            });
            if (dialog.open() == InputDialog.OK) {
                String value = dialog.getValue();
                codes.add(value);
                listViewer.refresh(false);
                listViewer.setSelection(new StructuredSelection(value));
            }
        }
    });
    // remove button
    Button remove = new Button(bar, SWT.PUSH);
    remove.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
    // $NON-NLS-1$
    remove.setText(Messages.CRSPreferencePage_7);
    // $NON-NLS-1$
    remove.setToolTipText(Messages.CRSPreferencePage_8);
    remove.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            ISelection selection = listViewer.getSelection();
            if (!selection.isEmpty() && selection instanceof IStructuredSelection) {
                String selected = (String) ((IStructuredSelection) selection).getFirstElement();
                codes.remove(selected);
                listViewer.refresh(false);
                if (!codes.isEmpty()) {
                    listViewer.setSelection(new StructuredSelection(codes.get(0)));
                }
                tmpWKTs.remove(selected);
                // mark as changed
                changed = true;
            }
        }
    });
    // update selection
    if (codes.isEmpty()) {
        listViewer.setSelection(new StructuredSelection());
    } else {
        listViewer.setSelection(new StructuredSelection(codes.get(0)));
    }
    return page;
}
Also used : SourceViewer(org.eclipse.jface.text.source.SourceViewer) Label(org.eclipse.swt.widgets.Label) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) GridLayout(org.eclipse.swt.layout.GridLayout) SourceViewerConfiguration(org.eclipse.jface.text.source.SourceViewerConfiguration) Button(org.eclipse.swt.widgets.Button) ISelection(org.eclipse.jface.viewers.ISelection) SelectionEvent(org.eclipse.swt.events.SelectionEvent) LineNumberRulerColumn(org.eclipse.jface.text.source.LineNumberRulerColumn) InputDialog(org.eclipse.jface.dialogs.InputDialog) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) CompositeRuler(org.eclipse.jface.text.source.CompositeRuler) ComboViewer(org.eclipse.jface.viewers.ComboViewer) GridData(org.eclipse.swt.layout.GridData) LabelProvider(org.eclipse.jface.viewers.LabelProvider) IDocument(org.eclipse.jface.text.IDocument) 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