org.eclipse.jface.dialogs.IInputValidator Java Examples

The following examples show how to use org.eclipse.jface.dialogs.IInputValidator. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FallPlaneRechnung.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
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;
					}
					return Messages.FallPlaneRechnung_PlanBillingPleaseEnterPositiveInteger;
				}
			});
	if (dlg.open() == Dialog.OK) {
		return dlg.getValue();
	}
	return null;
}
 
Example #2
Source File: InputURLDialog.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
/**
   * Creates an input URL dialog with OK and Cancel buttons. Note that the dialog
   * will have no visual representation (no widgets) until it is told to open.
   * <p>
   * Note that the <code>open</code> method blocks for input dialogs.
   * </p>
   * 
   * @param parentShell
   *            the parent shell, or <code>null</code> to create a top-level
   *            shell
   * @param dialogTitle
   *            the dialog title, or <code>null</code> if none
   * @param dialogMessage
   *            the dialog message, or <code>null</code> if none
   * @param initialValue
   *            the initial input value, or <code>null</code> if none
   *            (equivalent to the empty string)
   */
  public InputURLDialog(Shell parentShell, String dialogTitle,
          String dialogMessage, String initialValue) {
      super(parentShell);
      this.title = dialogTitle;
      message = dialogMessage;
      if (initialValue == null) {
	value = StringUtil.EMPTY;
} else {
	value = initialValue;
}
      this.validator = new IInputValidator() {
	public String isValid(String newText) {
		try {
			new URI(newText).toURL();
		} catch (Exception e) {
			return EplMessages.InputURLDialog_InvalidURL;
		}
		return null;
	}
      };
  }
 
Example #3
Source File: RenameResourceAction.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Return the new name to be given to the target resource.
 *
 * @return java.lang.String
 * @param resource
 *            the resource to query status on
 */
protected String queryNewResourceName(final IResource resource) {
	final IWorkspace workspace = IDEWorkbenchPlugin.getPluginWorkspace();
	final IPath prefix = resource.getFullPath().removeLastSegments(1);
	final IInputValidator validator = string -> {
		if (resource.getName().equals(string)) {
			return IDEWorkbenchMessages.RenameResourceAction_nameMustBeDifferent;
		}
		final 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;
	};

	final InputDialog dialog =
			new InputDialog(WorkbenchHelper.getShell(), IDEWorkbenchMessages.RenameResourceAction_inputDialogTitle,
					IDEWorkbenchMessages.RenameResourceAction_inputDialogMessage, resource.getName(), validator);
	dialog.setBlockOnOpen(true);
	final int result = dialog.open();
	if (result == Window.OK) { return dialog.getValue(); }
	return null;
}
 
Example #4
Source File: DialogHelpers.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
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;
}
 
Example #5
Source File: NewNameQueries.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private static INewNameQuery createStaticQuery(final IInputValidator validator, final String message, final String initial, final Shell shell){
	return new INewNameQuery(){
		public String getNewName() throws OperationCanceledException {
			InputDialog dialog= new InputDialog(shell, ReorgMessages.ReorgQueries_nameConflictMessage, message, initial, validator) {
				/* (non-Javadoc)
				 * @see org.eclipse.jface.dialogs.InputDialog#createDialogArea(org.eclipse.swt.widgets.Composite)
				 */
				@Override
				protected Control createDialogArea(Composite parent) {
					Control area= super.createDialogArea(parent);
					TextFieldNavigationHandler.install(getText());
					return area;
				}
			};
			if (dialog.open() == Window.CANCEL)
				throw new OperationCanceledException();
			return dialog.getValue();
		}
	};
}
 
Example #6
Source File: NewNameQueries.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private static IInputValidator createResourceNameValidator(final IResource res){
	IInputValidator validator= new IInputValidator(){
		public String isValid(String newText) {
			if (newText == null || "".equals(newText) || res.getParent() == null) //$NON-NLS-1$
				return INVALID_NAME_NO_MESSAGE;
			if (res.getParent().findMember(newText) != null)
				return ReorgMessages.ReorgQueries_resourceWithThisNameAlreadyExists;
			if (! res.getParent().getFullPath().isValidSegment(newText))
				return ReorgMessages.ReorgQueries_invalidNameMessage;
			IStatus status= res.getParent().getWorkspace().validateName(newText, res.getType());
			if (status.getSeverity() == IStatus.ERROR)
				return status.getMessage();

			if (res.getName().equalsIgnoreCase(newText))
				return ReorgMessages.ReorgQueries_resourceExistsWithDifferentCaseMassage;

			return null;
		}
	};
	return validator;
}
 
Example #7
Source File: DjangoMakeMigrations.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void run(IAction action) {
    IInputValidator validator = new IInputValidator() {

        @Override
        public String isValid(String newText) {
            if (newText.trim().length() == 0) {
                return "Name cannot be empty";
            }
            return null;
        }
    };
    InputDialog d = new InputDialog(EditorUtils.getShell(), "App name",
            "Name of the django app to makemigrations on", "",
            validator);

    int retCode = d.open();
    if (retCode == InputDialog.OK) {
        createApp(d.getValue().trim());
    }
}
 
Example #8
Source File: DjangoCreateApp.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void run(IAction action) {
    IInputValidator validator = new IInputValidator() {

        @Override
        public String isValid(String newText) {
            if (newText.trim().length() == 0) {
                return "Name cannot be empty";
            }
            return null;
        }
    };
    InputDialog d = new InputDialog(EditorUtils.getShell(), "App name", "Name of the django app to be created", "",
            validator);

    int retCode = d.open();
    if (retCode == InputDialog.OK) {
        createApp(d.getValue().trim());
    }
}
 
Example #9
Source File: SdkToolsControl.java    From xds-ide with Eclipse Public License 1.0 6 votes vote down vote up
private String editGroupName(String initialName, final Set<String> usedNames) {
    InputDialog dlg = new InputDialog(getShell(), Messages.SdkToolsControl_NewGroupName, 
            Messages.SdkToolsControl_EnterGroupName+':', initialName, 
            new IInputValidator() 
    {
        @Override
        public String isValid(String newText) {
            newText = newText.trim();
            if (newText.isEmpty()) {
                return Messages.SdkToolsControl_NameIsEmpty;
            } else if (usedNames.contains(newText)) {
                return Messages.SdkToolsControl_NameIsUsed;
            }
            return null;
        }
    });
    if (dlg.open() == Window.OK) {
        return dlg.getValue().trim();
    }
    return null;
}
 
Example #10
Source File: NewNameQueries.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private static IInputValidator createCompilationUnitNameValidator(final ICompilationUnit cu) {
	IInputValidator validator= new IInputValidator(){
		public String isValid(String newText) {
			if (newText == null || "".equals(newText)) //$NON-NLS-1$
				return INVALID_NAME_NO_MESSAGE;
			String newCuName= JavaModelUtil.getRenamedCUName(cu, newText);
			IStatus status= JavaConventionsUtil.validateCompilationUnitName(newCuName, cu);
			if (status.getSeverity() == IStatus.ERROR)
				return status.getMessage();
			RefactoringStatus refStatus;
			refStatus= Checks.checkCompilationUnitNewName(cu, newText);
			if (refStatus.hasFatalError())
				return refStatus.getMessageMatchingSeverity(RefactoringStatus.FATAL);

			if (cu.getElementName().equalsIgnoreCase(newCuName))
				return ReorgMessages.ReorgQueries_resourceExistsWithDifferentCaseMassage;

			return null;
		}
	};
	return validator;
}
 
Example #11
Source File: NpmNameAndVersionValidatorHelper.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
private IInputValidator getBasicPackageValidator() {
	return InputFunctionalValidator.from(
			(final String name) -> {
				N4JSProjectName projectName = new N4JSProjectName(name);
				if (npmCli.invalidPackageName(projectName))
					return "The npm package name should be specified.";
				for (int i = 0; i < name.length(); i++) {
					if (Character.isWhitespace(name.charAt(i)))
						return "The npm package name must not contain any whitespaces.";

					if (Character.isUpperCase(name.charAt(i)))
						return "The npm package name must not contain any upper case letter.";
				}
				return null;
			});
}
 
Example #12
Source File: DialogComboSelection.java    From arx with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new instance
 * @param parentShell
 * @param dialogTitle
 * @param dialogMessage
 * @param choices
 * @param initialValue
 * @param validator
 */
public DialogComboSelection(Shell parentShell,
                            String dialogTitle,
                            String dialogMessage,
                            String[] choices,
                            String initialValue,
                            IInputValidator validator) {
    super(parentShell);
    this.title = dialogTitle;
    message = dialogMessage;
    this.choices = choices;
    if (initialValue == null) {
        value = "";//$NON-NLS-1$
    } else {
        value = initialValue;
    }
    this.validator = validator;
}
 
Example #13
Source File: AbstractPyCreateClassOrMethodOrField.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void execute(RefactoringInfo refactoringInfo, int locationStrategy) {
    try {
        String creationStr = this.getCreationStr();
        final String asTitle = StringUtils.getWithFirstUpper(creationStr);

        PySelection pySelection = refactoringInfo.getPySelection();
        Tuple<String, Integer> currToken = pySelection.getCurrToken();
        String actTok = currToken.o1;
        List<String> parametersAfterCall = null;
        if (actTok.length() == 0) {
            InputDialog dialog = new InputDialog(EditorUtils.getShell(), asTitle + " name",
                    "Please enter the name of the " + asTitle + " to be created.", "", new IInputValidator() {

                        @Override
                        public String isValid(String newText) {
                            if (newText.length() == 0) {
                                return "The " + asTitle + " name may not be empty";
                            }
                            if (StringUtils.containsWhitespace(newText)) {
                                return "The " + asTitle + " name may not contain whitespaces.";
                            }
                            return null;
                        }
                    });
            if (dialog.open() != InputDialog.OK) {
                return;
            }
            actTok = dialog.getValue();
        } else {
            parametersAfterCall = pySelection.getParametersAfterCall(currToken.o2 + actTok.length());

        }

        execute(refactoringInfo, actTok, parametersAfterCall, locationStrategy);
    } catch (BadLocationException e) {
        Log.log(e);
    }
}
 
Example #14
Source File: InstallNpmDependencyDialog.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/** Creates dialog with custom validators. */
public InstallNpmDependencyDialog(Shell parentShell, IInputValidator packageNameValidator,
		IInputValidator packageVersionValidator) {
	super(parentShell);
	this.packageNameValidator = packageNameValidator;
	this.packageVersionValidator = packageVersionValidator;
}
 
Example #15
Source File: SaveAsTemplateAction.java    From texlipse with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Creates a window for entering the template name, checks the user's input and
 * proceeds to save the template. 
 */
public void run(IAction action) {
    
    IFile file = ((FileEditorInput)editor.getEditorInput()).getFile();
    String fullname = file.getFullPath().toString();
    
    // create dialog
    InputQueryDialog dialog = new InputQueryDialog(editor.getEditorSite().getShell(),
            TexlipsePlugin.getResourceString("templateSaveDialogTitle"),
            TexlipsePlugin.getResourceString("templateSaveDialogMessage").replaceAll("%s", fullname),
            file.getName().substring(0,file.getName().lastIndexOf('.')),
            new IInputValidator() {
        public String isValid(String newText) {
            if (newText != null && newText.length() > 0) {
                return null; // no error
            }
            return TexlipsePlugin.getResourceString("templateSaveErrorFileName");
        }});
    
    if (dialog.open() == InputDialog.OK) {
        String newName = dialog.getInput();
        
        // check existing
        boolean reallySave = true;
        if (ProjectTemplateManager.templateExists(newName)) {
            reallySave = MessageDialog.openConfirm(editor.getSite().getShell(),
                    TexlipsePlugin.getResourceString("templateSaveOverwriteTitle"),
                    TexlipsePlugin.getResourceString("templateSaveOverwriteText").replaceAll("%s", newName));
        }
        
        if (reallySave) {
            ProjectTemplateManager.saveProjectTemplate(file, newName);
        }
    }
}
 
Example #16
Source File: MainWindow.java    From arx with Apache License 2.0 5 votes vote down vote up
/**
 * Shows an input dialog for selecting a charset.
 *
 * @param shell
 * @return
 */
public Charset showCharsetInputDialog(final Shell shell) {

    // Validator
    final IInputValidator validator = new IInputValidator() {
        @Override
        public String isValid(final String arg0) {
            return null;
        }
    };

    // Extract list of formats
    List<String> charsets = new ArrayList<String>();
    for (String charset : Charsets.getNamesOfAvailableCharsets()) {
        charsets.add(charset);
    }

    // Open dialog
    final DialogComboSelection dlg = new DialogComboSelection(shell, Resources.getMessage("MainWindow.19"), //$NON-NLS-1$
                                                              Resources.getMessage("MainWindow.20"), //$NON-NLS-1$
                                                              charsets.toArray(new String[] {}),
                                                              Charsets.getNameOfDefaultCharset(),
                                                              validator);

    // Return value
    if (dlg.open() == Window.OK) {
        return Charsets.getCharsetForName(dlg.getValue());
    } else {
        return null;
    }
}
 
Example #17
Source File: PyCodeCoverageView.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void run() {
    InputDialog d = new InputDialog(EditorUtils.getShell(), "Enter number of columns",
            "Enter the number of columns to be used for the name.", ""
                    + PyCoveragePreferences.getNameNumberOfColumns(),
            new IInputValidator() {

                @Override
                public String isValid(String newText) {
                    if (newText.trim().length() == 0) {
                        return "Please enter a number > 5";
                    }
                    try {
                        int i = Integer.parseInt(newText);
                        if (i < 6) {
                            return "Please enter a number > 5";
                        }
                        if (i > 256) {
                            return "Please enter a number <= 256";
                        }
                    } catch (NumberFormatException e) {
                        return "Please enter a number > 5";
                    }
                    return null;
                }
            });
    int retCode = d.open();
    if (retCode == InputDialog.OK) {
        PyCoveragePreferences.setNameNumberOfColumns(Integer.parseInt(d.getValue()));
        onSelectedFileInTree(lastSelectedFile);
    }

}
 
Example #18
Source File: NpmNameAndVersionValidatorHelper.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Validator that checks if given name is valid package name and can be used to uninstall new package (i.e. there is
 * installed package with the same name).
 *
 * @return validator checking if provided name can be used to install new package
 */
IInputValidator getPackageNameToUninstallValidator() {
	return InputComposedValidator.compose(
			getBasicPackageValidator(), InputFunctionalValidator.from(
					(final String name) -> isNpmWithNameInstalled(new N4JSProjectName(name)) ? null
							/* error case */
							: "The npm package '" + name + "' is not installed."));
}
 
Example #19
Source File: PySetupCustomFilters.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
@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();
            }
        }
    });
}
 
Example #20
Source File: PyRenameResourceAction.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 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;
    }
}
 
Example #21
Source File: TermDbManagerDialog.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 创建新库 ;
 */
private void createNewDatabase() {
	// 数据库连接参数输入合法性检查
	IStatus status = validator();
	if (status.getSeverity() != IStatus.OK) {
		MessageDialog.openInformation(getShell(), Messages.getString("dialog.TermDbManagerDialog.msgTitle"),
				status.getMessage());
		return;
	}
	SystemDBOperator sysDbOp = getCurrSysDbOp();

	if (sysDbOp == null) {
		return;
	}

	// 连接检查
	if (!sysDbOp.checkDbConnection()) {
		MessageDialog.openInformation(getShell(), Messages.getString("dialog.TermDbManagerDialog.msgTitle"),
				Messages.getString("dialog.TermDbManagerDialog.msg1"));
		return;
	}

	TermDbNameInputDialog inputDbNameialog = new TermDbNameInputDialog(getShell(),
			Messages.getString("dialog.TermDbManagerDialog.inputDbNameialogTitle"),
			Messages.getString("dialog.TermDbManagerDialog.inputDbNameialogMsg"), "", new IInputValidator() {
				public String isValid(String newText) {
					String vRs = DbValidator.valiateDbName(newText);
					return vRs;
				}
			});
	inputDbNameialog.setSystemDbOp(sysDbOp);
	if (inputDbNameialog.open() == Window.OK) {
		executeSearch(sysDbOp); // 刷新界面
	}
}
 
Example #22
Source File: RenameResourceAndCloseEditorAction.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return the new name to be given to the target resource.
 * 
 * @return java.lang.String
 * @param resource
 *            the resource to query status on
 */
protected String queryNewResourceName(final IResource resource) {
	final IWorkspace workspace = IDEWorkbenchPlugin.getPluginWorkspace();
	final IPath prefix = resource.getFullPath().removeLastSegments(1);
	IInputValidator validator = new IInputValidator() {
		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(shellProvider.getShell(),
			IDEWorkbenchMessages.RenameResourceAction_inputDialogTitle,
			IDEWorkbenchMessages.RenameResourceAction_inputDialogMessage,
			resource.getName(), validator);
	dialog.setBlockOnOpen(true);
	int result = dialog.open();
	if (result == Window.OK)
		return dialog.getValue();
	return null;
}
 
Example #23
Source File: DialogHelpers.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
public static String openInputRequest(String title, String message, Shell shell, IInputValidator validator) {
    if (shell == null) {
        shell = EditorUtils.getShell();
    }
    String initialValue = "";
    InputDialog dialog = new InputDialog(shell, title, message, initialValue, validator);
    dialog.setBlockOnOpen(true);
    if (dialog.open() == Window.OK) {
        return dialog.getValue();
    }
    return null;
}
 
Example #24
Source File: TmDbManagerDialog.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 创建新库 ;
 */
private void createNewDatabase() {
	// 数据库连接参数输入合法性检查
	IStatus status = validator();
	if (status.getSeverity() != IStatus.OK) {
		MessageDialog.openInformation(getShell(), Messages.getString("dialog.TmDbManagerDialog.msgTitle"),
				status.getMessage());
		return;
	}
	SystemDBOperator sysDbOp = getCurrSysDbOp();

	if (sysDbOp == null) {
		return;
	}

	// 连接检查
	if (!sysDbOp.checkDbConnection()) {
		MessageDialog.openInformation(getShell(), Messages.getString("dialog.TmDbManagerDialog.msgTitle"),
				Messages.getString("dialog.TmDbManagerDialog.msg1"));
		return;
	}

	DatabaseNameInputDialog inputDbNameialog = new DatabaseNameInputDialog(getShell(),
			Messages.getString("dialog.TmDbManagerDialog.inputDbNameialogTitle"),
			Messages.getString("dialog.TmDbManagerDialog.inputDbNameialogMsg"), "", new IInputValidator() {
				public String isValid(String newText) {
					String vRs = DbValidator.valiateDbName(newText);						
					return vRs;
				}
			});
	inputDbNameialog.setSystemDbOp(sysDbOp);
	if (inputDbNameialog.open() == Window.OK) {
		executeSearch(sysDbOp); // 刷新界面
	}
}
 
Example #25
Source File: TmDbManagerDialog.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 创建新库 ;
 */
private void createNewDatabase() {
	// 数据库连接参数输入合法性检查
	IStatus status = validator();
	if (status.getSeverity() != IStatus.OK) {
		MessageDialog.openInformation(getShell(), Messages.getString("dialog.TmDbManagerDialog.msgTitle"),
				status.getMessage());
		return;
	}
	SystemDBOperator sysDbOp = getCurrSysDbOp();

	if (sysDbOp == null) {
		return;
	}

	// 连接检查
	if (!sysDbOp.checkDbConnection()) {
		MessageDialog.openInformation(getShell(), Messages.getString("dialog.TmDbManagerDialog.msgTitle"),
				Messages.getString("dialog.TmDbManagerDialog.msg1"));
		return;
	}

	DatabaseNameInputDialog inputDbNameialog = new DatabaseNameInputDialog(getShell(),
			Messages.getString("dialog.TmDbManagerDialog.inputDbNameialogTitle"),
			Messages.getString("dialog.TmDbManagerDialog.inputDbNameialogMsg"), "", new IInputValidator() {
				public String isValid(String newText) {
					String vRs = DbValidator.valiateDbName(newText);
					return vRs;
				}
			});
	inputDbNameialog.setSystemDbOp(sysDbOp);
	if (inputDbNameialog.open() == Window.OK) {
		executeSearch(sysDbOp); // 刷新界面
	}
}
 
Example #26
Source File: TermDbManagerDialog.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 创建新库 ;
 */
private void createNewDatabase() {
	// 数据库连接参数输入合法性检查
	IStatus status = validator();
	if (status.getSeverity() != IStatus.OK) {
		MessageDialog.openInformation(getShell(), Messages.getString("dialog.TermDbManagerDialog.msgTitle"),
				status.getMessage());
		return;
	}
	SystemDBOperator sysDbOp = getCurrSysDbOp();

	if (sysDbOp == null) {
		return;
	}

	// 连接检查
	if (!sysDbOp.checkDbConnection()) {
		MessageDialog.openInformation(getShell(), Messages.getString("dialog.TermDbManagerDialog.msgTitle"),
				Messages.getString("dialog.TermDbManagerDialog.msg1"));
		return;
	}

	TermDbNameInputDialog inputDbNameialog = new TermDbNameInputDialog(getShell(),
			Messages.getString("dialog.TermDbManagerDialog.inputDbNameialogTitle"),
			Messages.getString("dialog.TermDbManagerDialog.inputDbNameialogMsg"), "", new IInputValidator() {
				public String isValid(String newText) {
					String vRs = DbValidator.valiateDbName(newText);
					return vRs;
				}
			});
	inputDbNameialog.setSystemDbOp(sysDbOp);
	if (inputDbNameialog.open() == Window.OK) {
		executeSearch(sysDbOp); // 刷新界面
	}
}
 
Example #27
Source File: RenameResourceAndCloseEditorAction.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return the new name to be given to the target resource.
 * 
 * @return java.lang.String
 * @param resource
 *            the resource to query status on
 */
protected String queryNewResourceName(final IResource resource) {
	final IWorkspace workspace = IDEWorkbenchPlugin.getPluginWorkspace();
	final IPath prefix = resource.getFullPath().removeLastSegments(1);
	IInputValidator validator = new IInputValidator() {
		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(shellProvider.getShell(),
			IDEWorkbenchMessages.RenameResourceAction_inputDialogTitle,
			IDEWorkbenchMessages.RenameResourceAction_inputDialogMessage,
			resource.getName(), validator);
	dialog.setBlockOnOpen(true);
	int result = dialog.open();
	if (result == Window.OK)
		return dialog.getValue();
	return null;
}
 
Example #28
Source File: DialogHelpers.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
public static String openInputRequest(String title, String message, Shell shell) {
    IInputValidator validator = new IInputValidator() {

        @Override
        public String isValid(String newText) {
            if (newText.length() == 0) {
                return "At least 1 char must be provided.";
            }
            return null;
        }
    };
    return openInputRequest(title, message, shell, validator);
}
 
Example #29
Source File: NewNameQueries.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static IInputValidator createPackageFragmentRootNameValidator(final IPackageFragmentRoot root) {
	return new IInputValidator() {
		IInputValidator resourceNameValidator= createResourceNameValidator(root.getResource());
		public String isValid(String newText) {
			return resourceNameValidator.isValid(newText);
		}
	};
}
 
Example #30
Source File: Input.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
private static <T> T prompt(String title, String message, String defaultValue, Function<String, T> converter,
		IInputValidator validator) {
	InputDialog dialog = new InputDialog(UI.shell(), title, message, defaultValue, validator);
	if (dialog.open() != IDialogConstants.OK_ID)
		return null;
	return converter.apply(dialog.getValue());
}