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;
}
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;
}
});
}
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;
}
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;
}
}
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();
}
}
});
}
Aggregations