From f1cea7adec95ca942c8e7d267ffdfac2f9ee8821 Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Sat, 15 Sep 2012 22:22:11 +0200 Subject: [PATCH] IDEA-91559 (CVS: Import into CVS: disable Finish if the NameInRepository field is empty) --- .../importToCvs/CvsFieldValidator.java | 18 ++++--- .../importToCvs/ImportSettingsStep.form | 4 +- .../importToCvs/ImportSettingsStep.java | 47 ++++++++----------- 3 files changed, 30 insertions(+), 39 deletions(-) diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/ui/experts/importToCvs/CvsFieldValidator.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/ui/experts/importToCvs/CvsFieldValidator.java index 02d943fdc342..274774f26079 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/ui/experts/importToCvs/CvsFieldValidator.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/ui/experts/importToCvs/CvsFieldValidator.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2012 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,10 +31,9 @@ import java.awt.event.ActionListener; public class CvsFieldValidator { public static final char[] INVALID_CHARACTERS = new char[]{'`', '$', '.', ',', ':', ';', '@', '\'', ' '}; - private CvsFieldValidator() { - } + private CvsFieldValidator() {} - private static void reportError(JLabel errorLabel, String message, TagNameFieldOwner tagNameFieldOwner) { + public static void reportError(JLabel errorLabel, String message, TagNameFieldOwner tagNameFieldOwner) { @NonNls final String text = "" + message + ""; errorLabel.setText(text); if (tagNameFieldOwner != null) { @@ -45,6 +44,7 @@ public class CvsFieldValidator { public static void installOn(final TagNameFieldOwner dialog, final JTextField field, final JLabel label) { installOn(dialog, field, label, new AbstractButton[0]); field.getDocument().addDocumentListener(new DocumentAdapter() { + @Override public void textChanged(DocumentEvent event) { checkTagNameField(dialog, field, label); } @@ -57,6 +57,7 @@ public class CvsFieldValidator { final JLabel label, AbstractButton[] buttons) { field.getDocument().addDocumentListener(new DocumentAdapter() { + @Override public void textChanged(DocumentEvent event) { checkTagNameField(dialog, field, label); } @@ -64,6 +65,7 @@ public class CvsFieldValidator { for (AbstractButton button : buttons) { button.addActionListener(new ActionListener() { + @Override public void actionPerformed(ActionEvent e) { checkTagNameField(dialog, field, label); } @@ -86,13 +88,12 @@ public class CvsFieldValidator { } } - public static boolean checkField(JTextField field, JTextField[] shouldDifferFrom, boolean shouldStartFromLetter, JLabel errorMessage, TagNameFieldOwner tagNameFieldOwner) { - String text = field.getText().trim(); - if (text.length() == 0) { + final String text = field.getText().trim(); + if (text.isEmpty()) { reportError(errorMessage, CvsBundle.message("error.message.field.cannot.be.empty"), tagNameFieldOwner); return false; } @@ -112,7 +113,6 @@ public class CvsFieldValidator { } } - if (shouldStartFromLetter && !Character.isLetter(text.charAt(0))) { reportError(errorMessage, CvsBundle.message("error.message.field.value.must.start.with.a.letter"), tagNameFieldOwner); return false; @@ -121,6 +121,4 @@ public class CvsFieldValidator { errorMessage.setText(" "); return true; } - - } diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/ui/experts/importToCvs/ImportSettingsStep.form b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/ui/experts/importToCvs/ImportSettingsStep.form index 986c7878b12f..60237b1fecf2 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/ui/experts/importToCvs/ImportSettingsStep.form +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/ui/experts/importToCvs/ImportSettingsStep.form @@ -21,7 +21,7 @@ - + @@ -69,7 +69,7 @@ - + diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/ui/experts/importToCvs/ImportSettingsStep.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/ui/experts/importToCvs/ImportSettingsStep.java index faaed5aad74b..55ede23b1ef7 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/ui/experts/importToCvs/ImportSettingsStep.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/ui/experts/importToCvs/ImportSettingsStep.java @@ -20,10 +20,10 @@ import com.intellij.cvsSupport2.config.ImportConfiguration; import com.intellij.cvsSupport2.ui.experts.CvsWizard; import com.intellij.cvsSupport2.ui.experts.WizardStep; import com.intellij.openapi.project.Project; +import com.intellij.ui.DocumentAdapter; import javax.swing.*; import javax.swing.event.DocumentEvent; -import javax.swing.event.DocumentListener; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; @@ -33,6 +33,7 @@ import java.util.Collection; * author: lesya */ public class ImportSettingsStep extends WizardStep { + private JPanel myPanel; private JTextField myModuleName; private JTextField myVendor; @@ -47,9 +48,10 @@ public class ImportSettingsStep extends WizardStep { private JCheckBox myCheckoutAfterImport; private JCheckBox myMakeCheckedOutFilesReadOnly; + private JLabel myModuleNameErrorMessage; private JLabel myVendorErrorMessage; private JLabel myReleaseTagErrorMessage; - private JLabel myNameLabel; + private JLabel myModuleNameLabel; private JLabel myVendorLabel; private JLabel myReleaseTagLabel; private JLabel myLogMessageLabel; @@ -70,14 +72,18 @@ public class ImportSettingsStep extends WizardStep { mySelectImportLocationStep = selectImportLocationStep; myImportConfiguration = importConfiguration; - checkFields(); - - final MyDocumentListener listener = new MyDocumentListener(); + final DocumentAdapter listener = new DocumentAdapter() { + @Override + protected void textChanged(DocumentEvent e) { + checkFields(); + } + }; + myModuleName.getDocument().addDocumentListener(listener); myVendor.getDocument().addDocumentListener(listener); myReleaseTag.getDocument().addDocumentListener(listener); myLogMessageLabel.setLabelFor(myLogMessage); - myNameLabel.setLabelFor(myModuleName); + myModuleNameLabel.setLabelFor(myModuleName); myReleaseTagLabel.setLabelFor(myReleaseTag); myVendorLabel.setLabelFor(myVendor); @@ -115,6 +121,13 @@ public class ImportSettingsStep extends WizardStep { final JTextField[] fields = new JTextField[]{myReleaseTag, myVendor}; boolean result = CvsFieldValidator.checkField(myVendor, fields, true, myVendorErrorMessage, null); result &= CvsFieldValidator.checkField(myReleaseTag, fields, true, myReleaseTagErrorMessage, null); + final String moduleName = myModuleName.getText().trim(); + if (moduleName.isEmpty()) { + CvsFieldValidator.reportError(myModuleNameErrorMessage, CvsBundle.message("error.message.field.cannot.be.empty"), null); + } + else { + myModuleNameErrorMessage.setText(" "); + } return result; } @@ -187,24 +200,4 @@ public class ImportSettingsStep extends WizardStep { public Collection getFileExtensions() { return myImportConfiguration.getExtensions(); } - - private class MyDocumentListener implements DocumentListener { - - public MyDocumentListener() {} - - @Override - public void changedUpdate(DocumentEvent e) { - checkFields(); - } - - @Override - public void insertUpdate(DocumentEvent e) { - checkFields(); - } - - @Override - public void removeUpdate(DocumentEvent e) { - checkFields(); - } - } -} +} \ No newline at end of file