use of com.intellij.openapi.ui.ValidationInfo in project intellij-community by JetBrains.
the class GenerateVisitorByHierarchyAction method actionPerformed.
public void actionPerformed(AnActionEvent e) {
final Ref<String> visitorNameRef = Ref.create("MyVisitor");
final Ref<PsiClass> parentClassRef = Ref.create(null);
final Project project = e.getData(CommonDataKeys.PROJECT);
assert project != null;
final PsiNameHelper helper = PsiNameHelper.getInstance(project);
final PackageChooserDialog dialog = new PackageChooserDialog("Choose Target Package and Hierarchy Root Class", project) {
@Override
protected ValidationInfo doValidate() {
PsiDocumentManager.getInstance(project).commitAllDocuments();
if (!helper.isQualifiedName(visitorNameRef.get())) {
return new ValidationInfo("Visitor class name is not valid");
} else if (parentClassRef.isNull()) {
return new ValidationInfo("Hierarchy root class should be specified");
} else if (parentClassRef.get().isAnnotationType() || parentClassRef.get().isEnum()) {
return new ValidationInfo("Hierarchy root class should be an interface or a class");
}
return super.doValidate();
}
protected JComponent createCenterPanel() {
final JPanel panel = new JPanel(new BorderLayout());
panel.add(super.createCenterPanel(), BorderLayout.CENTER);
panel.add(createNamePanel(), BorderLayout.NORTH);
panel.add(createBaseClassPanel(), BorderLayout.SOUTH);
return panel;
}
private JComponent createNamePanel() {
LabeledComponent<JTextField> labeledComponent = new LabeledComponent<>();
labeledComponent.setText("Visitor class");
final JTextField nameField = new JTextField(visitorNameRef.get());
labeledComponent.setComponent(nameField);
nameField.getDocument().addDocumentListener(new DocumentAdapter() {
protected void textChanged(final DocumentEvent e) {
visitorNameRef.set(nameField.getText());
}
});
return labeledComponent;
}
private JComponent createBaseClassPanel() {
LabeledComponent<EditorTextField> labeledComponent = new LabeledComponent<>();
labeledComponent.setText("Hierarchy root class");
final JavaCodeFragmentFactory factory = JavaCodeFragmentFactory.getInstance(project);
final PsiTypeCodeFragment codeFragment = factory.createTypeCodeFragment("", null, true, JavaCodeFragmentFactory.ALLOW_VOID);
final Document document = PsiDocumentManager.getInstance(project).getDocument(codeFragment);
final EditorTextField editorTextField = new EditorTextField(document, project, StdFileTypes.JAVA);
labeledComponent.setComponent(editorTextField);
editorTextField.addDocumentListener(new com.intellij.openapi.editor.event.DocumentAdapter() {
public void documentChanged(final com.intellij.openapi.editor.event.DocumentEvent e) {
parentClassRef.set(null);
try {
final PsiType psiType = codeFragment.getType();
final PsiClass psiClass = psiType instanceof PsiClassType ? ((PsiClassType) psiType).resolve() : null;
parentClassRef.set(psiClass);
} catch (PsiTypeCodeFragment.IncorrectTypeException e1) {
// ok
}
}
});
return labeledComponent;
}
};
final PsiElement element = CommonDataKeys.PSI_ELEMENT.getData(e.getDataContext());
if (element instanceof PsiPackage) {
dialog.selectPackage(((PsiPackage) element).getQualifiedName());
} else if (element instanceof PsiDirectory) {
final PsiPackage aPackage = JavaDirectoryService.getInstance().getPackage((PsiDirectory) element);
if (aPackage != null) {
dialog.selectPackage(aPackage.getQualifiedName());
}
}
dialog.show();
if (dialog.getExitCode() != DialogWrapper.OK_EXIT_CODE || dialog.getSelectedPackage() == null || dialog.getSelectedPackage().getQualifiedName().length() == 0 || parentClassRef.isNull()) {
return;
}
final String visitorQName = generateEverything(dialog.getSelectedPackage(), parentClassRef.get(), visitorNameRef.get());
final IdeView ideView = LangDataKeys.IDE_VIEW.getData(e.getDataContext());
final PsiClass visitorClass = JavaPsiFacade.getInstance(project).findClass(visitorQName, GlobalSearchScope.projectScope(project));
if (ideView != null && visitorClass != null) {
ideView.selectElement(visitorClass);
}
}
use of com.intellij.openapi.ui.ValidationInfo in project intellij-community by JetBrains.
the class CreatePatchConfigurationPanel method verifyBaseDirPath.
@Nullable
private ValidationInfo verifyBaseDirPath() {
String baseDirName = getBaseDirName();
if (StringUtil.isEmptyOrSpaces(baseDirName))
return new ValidationInfo("Base path can't be empty!", myBasePathField);
File baseFile = new File(baseDirName);
if (!baseFile.exists())
return new ValidationInfo("Base dir doesn't exist", myBasePathField);
if (myCommonParentDir != null && !FileUtil.isAncestor(baseFile, myCommonParentDir, false)) {
return new ValidationInfo(String.format("Base path doesn't contain all selected changes (use %s)", myCommonParentDir.getPath()), myBasePathField);
}
return null;
}
use of com.intellij.openapi.ui.ValidationInfo in project intellij-community by JetBrains.
the class ShelfStorageConfigurationDialog method doValidate.
@Nullable
@Override
protected ValidationInfo doValidate() {
updateOkAction();
if (myUseCustomShelfDirectory.isSelected()) {
File toFile = new File(myShelfDirectoryPath.getText());
// check that file can be created after OK button pressed;
if (!toFile.exists())
return null;
String validationError = null;
if (!toFile.canRead()) {
validationError = "Destination shelf directory should have read access";
}
if (!toFile.canWrite()) {
validationError = "Destination shelf directory should have write access";
}
if (validationError != null)
return new ValidationInfo(validationError, myShelfDirectoryPath);
}
return super.doValidate();
}
use of com.intellij.openapi.ui.ValidationInfo in project android by JetBrains.
the class CreateFileFromTemplateDialog method doValidate.
@Nullable
@Override
protected ValidationInfo doValidate() {
if (myInputValidator != null) {
String nameText = myNameField.getText();
String superclassAsString = mySuperclassField.getText();
String packageText = myPackageField.getText();
if (!myInputValidator.checkInput(nameText)) {
String errorText = LangBundle.message("incorrect.name");
String message = myInputValidator.getErrorText(nameText);
if (message != null) {
errorText = message;
}
return new ValidationInfo(errorText, myNameField);
}
if (!superclassAsString.isEmpty()) {
Type superclassAsType = Type.newType(superclassAsString, myProject);
if (mySuperclassField.isVisible() && (!superclassAsType.canUseAsClass() || !myInputValidator.checkSuperclass(superclassAsString))) {
return new ValidationInfo(myInputValidator.getSuperclassErrorText(superclassAsString), mySuperclassField);
}
}
for (String interfaceAsString : Splitter.on(',').trimResults().omitEmptyStrings().split(getInterfaces())) {
Type interfaceAsType = Type.newType(interfaceAsString, myProject);
if (!interfaceAsType.canUseAsInterface() || !myInputValidator.checkInterface(interfaceAsString)) {
return new ValidationInfo(myInputValidator.getInterfacesErrorText(interfaceAsString), myInterfacesField);
}
}
if (!myInputValidator.checkPackage(packageText)) {
return new ValidationInfo(myInputValidator.getPackageErrorText(packageText), myPackageField);
}
}
return super.doValidate();
}
use of com.intellij.openapi.ui.ValidationInfo in project android by JetBrains.
the class EditLogFilterDialog method doValidate.
@Override
protected ValidationInfo doValidate() {
if (!myFilterNameField.isEnabled()) {
return null;
}
final String name = myFilterNameField.getText().trim();
if (name.isEmpty()) {
return new ValidationInfo(AndroidBundle.message("android.logcat.new.filter.dialog.name.not.specified.error"), myFilterNameField);
}
if (name.equals(AndroidLogcatView.NO_FILTERS) || name.equals(AndroidLogcatView.SELECTED_APP_FILTER) || name.equals(AndroidLogcatView.EDIT_FILTER_CONFIGURATION)) {
return new ValidationInfo(AndroidBundle.message("android.logcat.new.filter.dialog.name.busy.error", name));
}
for (FilterData filter : myFilters) {
if (filter != myActiveFilter && name.equals(filter.getName())) {
return new ValidationInfo(AndroidBundle.message("android.logcat.new.filter.dialog.name.busy.error", name));
}
}
if (myTagField.getParseError() != null) {
return new ValidationInfo(AndroidBundle.message("android.logcat.new.filter.dialog.incorrect.log.tag.pattern.error") + '\n' + myTagField.getParseError());
}
if (myLogMessageField.getParseError() != null) {
return new ValidationInfo(AndroidBundle.message("android.logcat.new.filter.dialog.incorrect.message.pattern.error") + '\n' + myLogMessageField.getParseError());
}
if (myPackageNameField.getParseError() != null) {
return new ValidationInfo(AndroidBundle.message("android.logcat.new.filter.dialog.incorrect.application.name.pattern.error") + '\n' + myPackageNameField.getParseError());
}
boolean validPid = false;
try {
final String pidStr = myPidField.getText().trim();
final Integer pid = pidStr.length() > 0 ? Integer.parseInt(pidStr) : null;
if (pid == null || pid.intValue() >= 0) {
validPid = true;
}
} catch (NumberFormatException ignored) {
}
if (!validPid) {
return new ValidationInfo(AndroidBundle.message("android.logcat.new.filter.dialog.incorrect.pid.error"));
}
return null;
}
Aggregations