diff --git a/plugins/cvs/cvs-core/src/com/intellij/cvsSupport2/CvsBundle.properties b/plugins/cvs/cvs-core/src/com/intellij/cvsSupport2/CvsBundle.properties
index cbe822070bdd..1bcc61876fdf 100644
--- a/plugins/cvs/cvs-core/src/com/intellij/cvsSupport2/CvsBundle.properties
+++ b/plugins/cvs/cvs-core/src/com/intellij/cvsSupport2/CvsBundle.properties
@@ -88,11 +88,8 @@ dialog.title.cvs.roots=CVS Roots
action.name.add=Add
action.name.remove=Remove
action.name.copy=Duplicate CVS Root
-configure.root.field.name.user=User
-configure.root.field.name.host=Host
-configure.root.field.name.repository=Repository
-error.message.value.cannot.be.empty=''{0}'' value cannot be empty
-error.message.invalid.port.value=Invalid port value: {0}
+error.message.value.cannot.be.empty=''{0}'' should not be empty
+error.message.invalid.value=Invalid ''{0}'' value: {1}
button.text.configure.cvs.roots=&Configure...
dialog.title.select.cvs.root.configuration=Select CVS Root Configuration
cvs.root.description.ssh.internal.implementation=ssh (internal implementation)
@@ -254,7 +251,7 @@ checkbox.make.new.files.read.only=Make new files read-only
checkbox.prune.empty.directories=Prune empty directories
info.text.selected.modules.will.be.checked.out.to=Selected modules will be checked out to:
dialog.title.check.out.to=Check Out {0} to:
-error.message.field.cannot.be.empty=cannot be empty
+error.message.field.cannot.be.empty=should not be empty
error.message.field.contains.invalid.characters=must not contain the characters ` $.:;@'
error.message.duplicate.field.value=was specified more than once
error.message.field.value.must.start.with.a.letter=must start with a letter
diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/config/CvsRootConfiguration.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/config/CvsRootConfiguration.java
index 74267fcf5f3a..ec247dbc400c 100644
--- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/config/CvsRootConfiguration.java
+++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/config/CvsRootConfiguration.java
@@ -82,11 +82,14 @@ public class CvsRootConfiguration extends AbstractConfiguration implements CvsEn
}
private static String createFieldByFieldCvsRoot(CvsRepository cvsRepository) {
- return createStringRepresentationOn(CvsMethod.getValue(cvsRepository.getMethod()), cvsRepository.getUser(), cvsRepository.getHost(),
- String.valueOf(cvsRepository.getPort()), cvsRepository.getRepository());
+ return createStringRepresentationOn(CvsMethod.getValue(cvsRepository.getMethod()),
+ cvsRepository.getUser(),
+ cvsRepository.getHost(),
+ cvsRepository.getPort(),
+ cvsRepository.getRepository());
}
- public static String createStringRepresentationOn(CvsMethod method, String user, String host, String port, String repository) {
+ public static String createStringRepresentationOn(CvsMethod method, String user, String host, int port, String repository) {
if (method == CvsMethod.LOCAL_METHOD) {
final StringBuilder result = new StringBuilder();
result.append(SEPARATOR);
@@ -102,7 +105,7 @@ public class CvsRootConfiguration extends AbstractConfiguration implements CvsEn
result.append(user);
result.append(AT);
result.append(host);
- if (port.length() > 0) {
+ if (port > 0) {
result.append(SEPARATOR);
result.append(port);
}
@@ -115,12 +118,12 @@ public class CvsRootConfiguration extends AbstractConfiguration implements CvsEn
public String toString() {
if (useBranch()) {
- return CvsBundle
- .message("cvs.root.configuration.on.branch.string.representation", getCvsRootAsString(), DATE_OR_REVISION_SETTINGS.BRANCH);
+ return CvsBundle.message("cvs.root.configuration.on.branch.string.representation", getCvsRootAsString(),
+ DATE_OR_REVISION_SETTINGS.BRANCH);
}
else if (useDate()) {
- return CvsBundle
- .message("cvs.root.configuration.on.date.string.representation", getCvsRootAsString(), DATE_OR_REVISION_SETTINGS.getDate());
+ return CvsBundle.message("cvs.root.configuration.on.date.string.representation", getCvsRootAsString(),
+ DATE_OR_REVISION_SETTINGS.getDate());
}
else {
return getCvsRootAsString();
@@ -128,11 +131,11 @@ public class CvsRootConfiguration extends AbstractConfiguration implements CvsEn
}
private boolean useDate() {
- return DATE_OR_REVISION_SETTINGS.USE_DATE && (DATE_OR_REVISION_SETTINGS.getDate().length() > 0);
+ return DATE_OR_REVISION_SETTINGS.USE_DATE && !DATE_OR_REVISION_SETTINGS.getDate().isEmpty();
}
private boolean useBranch() {
- return DATE_OR_REVISION_SETTINGS.USE_BRANCH && (DATE_OR_REVISION_SETTINGS.BRANCH.length() > 0);
+ return DATE_OR_REVISION_SETTINGS.USE_BRANCH && !DATE_OR_REVISION_SETTINGS.BRANCH.isEmpty();
}
public CvsRootConfiguration getMyCopy() {
diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/config/ui/CvsRootAsStringConfigurationPanel.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/config/ui/CvsRootAsStringConfigurationPanel.java
index b5ac499797b5..3eb7cf414bf6 100644
--- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/config/ui/CvsRootAsStringConfigurationPanel.java
+++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/config/ui/CvsRootAsStringConfigurationPanel.java
@@ -19,6 +19,7 @@ import com.intellij.cvsSupport2.config.CvsApplicationLevelConfiguration;
import com.intellij.cvsSupport2.config.CvsRootConfiguration;
import com.intellij.cvsSupport2.cvsoperations.cvsEdit.ui.EditCvsConfigurationFieldByFieldDialog;
import com.intellij.cvsSupport2.ui.CvsRootChangeListener;
+import com.intellij.cvsSupport2.ui.FormUtils;
import com.intellij.openapi.util.Ref;
import com.intellij.ui.DocumentAdapter;
@@ -88,7 +89,7 @@ public class CvsRootAsStringConfigurationPanel {
}
public void saveTo(CvsRootConfiguration config) {
- config.CVS_ROOT = myCvsRoot.getText().trim();
+ config.CVS_ROOT = FormUtils.getFieldValue(myCvsRoot, true);
}
public String getCvsRoot() {
diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/config/ui/CvsRootFieldByFieldConfigurationPanel.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/config/ui/CvsRootFieldByFieldConfigurationPanel.java
index f745498ad291..84faf4f5c28f 100644
--- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/config/ui/CvsRootFieldByFieldConfigurationPanel.java
+++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/config/ui/CvsRootFieldByFieldConfigurationPanel.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2009 JetBrains s.r.o.
+ * Copyright 2000-2011 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.
@@ -15,11 +15,10 @@
*/
package com.intellij.cvsSupport2.config.ui;
-import com.intellij.CvsBundle;
import com.intellij.cvsSupport2.config.CvsRootConfiguration;
import com.intellij.cvsSupport2.connections.CvsMethod;
import com.intellij.cvsSupport2.connections.CvsRootData;
-import com.intellij.openapi.ui.InputException;
+import com.intellij.cvsSupport2.ui.FormUtils;
import javax.swing.*;
import java.awt.event.ActionEvent;
@@ -40,8 +39,8 @@ public class CvsRootFieldByFieldConfigurationPanel {
public void updateFrom(CvsRootData config) {
myMethods.removeAllItems();
- for (int i = 0; i < CvsMethod.AVAILABLE_METHODS.length; i++) {
- myMethods.addItem(CvsMethod.AVAILABLE_METHODS[i]);
+ for (CvsMethod method : CvsMethod.AVAILABLE_METHODS) {
+ myMethods.addItem(method);
}
myMethods.addActionListener(new ActionListener() {
@@ -65,33 +64,14 @@ public class CvsRootFieldByFieldConfigurationPanel {
}
public String getSettings() {
- final String port = myPort.getText().trim();
- if (port.length() > 0) {
- try {
- final int intPort = Integer.parseInt(port);
- if (intPort <= 0) throw new InputException(CvsBundle.message("error.message.invalid.port.value", port), myPort);
- }
- catch (NumberFormatException ex) {
- throw new InputException(CvsBundle.message("error.message.invalid.port.value", port), myPort);
- }
- }
-
+ final int port = FormUtils.getPositiveIntFieldValue(myPort, true, true);
final CvsMethod cvsMethod = (CvsMethod)myMethods.getSelectedItem();
- final String user = checkedField(myUser, CvsBundle.message("configure.root.field.name.user"), cvsMethod.hasUserValue());
- final String host = checkedField(myHost, CvsBundle.message("configure.root.field.name.host"), cvsMethod.hasHostValue());
- final String repository = checkedField(myRepository, CvsBundle.message("configure.root.field.name.repository"), true);
-
+ final String user = FormUtils.getFieldValue(myUser, cvsMethod.hasUserValue());
+ final String host = FormUtils.getFieldValue(myHost, cvsMethod.hasHostValue());
+ final String repository = FormUtils.getFieldValue(myRepository, true);
return CvsRootConfiguration.createStringRepresentationOn(cvsMethod, user, host, port, repository);
}
- private static String checkedField(JTextField field, String name, boolean checkParameters) {
- final String value = field.getText().trim();
- if (checkParameters && (value.length() == 0)) {
- throw new InputException(CvsBundle.message("error.message.value.cannot.be.empty", name), field);
- }
- return value;
- }
-
public JComponent getPanel() {
return myPanel;
}
diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/connections/ssh/ui/SshConnectionSettingsPanel.form b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/connections/ssh/ui/SshConnectionSettingsPanel.form
index 60fbd3e64245..7a27eb7c5f7a 100644
--- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/connections/ssh/ui/SshConnectionSettingsPanel.form
+++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/connections/ssh/ui/SshConnectionSettingsPanel.form
@@ -45,6 +45,7 @@
+
diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/connections/ssh/ui/SshConnectionSettingsPanel.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/connections/ssh/ui/SshConnectionSettingsPanel.java
index fd49751db614..18814bdb1784 100644
--- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/connections/ssh/ui/SshConnectionSettingsPanel.java
+++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/connections/ssh/ui/SshConnectionSettingsPanel.java
@@ -18,8 +18,8 @@ package com.intellij.cvsSupport2.connections.ssh.ui;
import com.intellij.CvsBundle;
import com.intellij.cvsSupport2.config.SshSettings;
import com.intellij.cvsSupport2.config.ui.CvsConfigurationPanel;
+import com.intellij.cvsSupport2.ui.FormUtils;
import com.intellij.openapi.project.Project;
-import com.intellij.openapi.ui.InputException;
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
import javax.swing.*;
@@ -48,9 +48,9 @@ public class SshConnectionSettingsPanel {
return myPanel;
}
- public void updateFrom(SshSettings ssh_configuration) {
- myUsePrivateKeyFile.setSelected(ssh_configuration.USE_PPK);
- myPathToPrivateKeyFile.setText(ssh_configuration.PATH_TO_PPK);
+ public void updateFrom(SshSettings sshConfiguration) {
+ myUsePrivateKeyFile.setSelected(sshConfiguration.USE_PPK);
+ myPathToPrivateKeyFile.setText(sshConfiguration.PATH_TO_PPK);
setPathToPPKEnabled();
}
@@ -65,19 +65,15 @@ public class SshConnectionSettingsPanel {
}
}
- public void saveTo(SshSettings ssh_configuration) {
- if (myUsePrivateKeyFile.isSelected() && myPathToPrivateKeyFile.getText().trim().length() == 0){
- throw new InputException(CvsBundle.message("error.message.path.to.private.key.file.must.not.be.empty"),
- myPathToPrivateKeyFile.getTextField());
- }
- ssh_configuration.USE_PPK = myUsePrivateKeyFile.isSelected();
- ssh_configuration.PATH_TO_PPK = myPathToPrivateKeyFile.getText().trim();
+ public void saveTo(SshSettings sshConfiguration) {
+ sshConfiguration.USE_PPK = myUsePrivateKeyFile.isSelected();
+ sshConfiguration.PATH_TO_PPK = FormUtils.getFieldValue(myPathToPrivateKeyFile, sshConfiguration.USE_PPK);
}
- public boolean equalsTo(SshSettings ssh_configuration) {
- if (ssh_configuration.USE_PPK != myUsePrivateKeyFile.isSelected()) {
+ public boolean equalsTo(SshSettings sshConfiguration) {
+ if (sshConfiguration.USE_PPK != myUsePrivateKeyFile.isSelected()) {
return false;
}
- return ssh_configuration.PATH_TO_PPK.equals(myPathToPrivateKeyFile.getText().trim());
+ return sshConfiguration.PATH_TO_PPK.equals(myPathToPrivateKeyFile.getText().trim());
}
}
diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/connections/ui/ProxySettingsPanel.form b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/connections/ui/ProxySettingsPanel.form
index 3adf71200799..25bc6b92b151 100644
--- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/connections/ui/ProxySettingsPanel.form
+++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/connections/ui/ProxySettingsPanel.form
@@ -74,6 +74,7 @@
+
@@ -82,6 +83,7 @@
+
@@ -106,6 +108,7 @@
+
@@ -114,6 +117,7 @@
+
diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/connections/ui/ProxySettingsPanel.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/connections/ui/ProxySettingsPanel.java
index 171c8b791118..2cae92d30401 100644
--- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/connections/ui/ProxySettingsPanel.java
+++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/connections/ui/ProxySettingsPanel.java
@@ -15,10 +15,9 @@
*/
package com.intellij.cvsSupport2.connections.ui;
-import com.intellij.CvsBundle;
import com.intellij.cvsSupport2.config.ProxySettings;
import com.intellij.cvsSupport2.connections.CvsRootData;
-import com.intellij.openapi.ui.InputException;
+import com.intellij.cvsSupport2.ui.FormUtils;
import javax.swing.*;
import java.awt.*;
@@ -36,9 +35,8 @@ public class ProxySettingsPanel {
private JPasswordField myPassword;
private JTextField myLogin;
-
public ProxySettingsPanel() {
- ButtonGroup buttonGroup = new ButtonGroup();
+ final ButtonGroup buttonGroup = new ButtonGroup();
buttonGroup.add(myHTTP);
buttonGroup.add(mySocks4);
buttonGroup.add(mySocks5);
@@ -55,7 +53,6 @@ public class ProxySettingsPanel {
}
}
});
-
}
public void disableAll(boolean disableUseProxyButton) {
@@ -121,18 +118,16 @@ public class ProxySettingsPanel {
}
}
- public boolean equalsTo(ProxySettings proxy_settings) {
- try {
- return myUseProxy.isSelected() == proxy_settings.USE_PROXY
- && myProxyHost.getText().equals(proxy_settings.PROXY_HOST)
- && getIntPortValue(myProxyPort.getText(), myProxyPort) == proxy_settings.PROXY_PORT
- && getSelectedType() == proxy_settings.getType()
- && proxy_settings.getLogin().equals(myLogin.getText())
- && proxy_settings.getPassword().equals(new String(myPassword.getPassword()));
- }
- catch (Exception e) {
- return false;
+ public boolean equalsTo(ProxySettings proxySettings) {
+ if (!myUseProxy.isSelected()) {
+ return !proxySettings.USE_PROXY;
}
+ return myUseProxy.isSelected() == proxySettings.USE_PROXY
+ && myProxyHost.getText().equals(proxySettings.PROXY_HOST)
+ && FormUtils.getPositiveIntFieldValue(myProxyPort, false, false) == proxySettings.PROXY_PORT
+ && getSelectedType() == proxySettings.getType()
+ && myLogin.getText().equals(proxySettings.getLogin())
+ && new String(myPassword.getPassword()).equals(proxySettings.getPassword());
}
private int getSelectedType() {
@@ -147,29 +142,15 @@ public class ProxySettingsPanel {
}
}
- private static int getIntPortValue(String text, JComponent component) {
- try {
- final int result = Integer.parseInt(text);
- if (result < 0) {
- throw new InputException(CvsBundle.message("error.message.invalid.port.value", text), component);
- }
- return result;
- }
- catch (NumberFormatException e) {
- throw new InputException(CvsBundle.message("error.message.invalid.port.value", text), component);
- }
+ public void saveTo(ProxySettings proxySettings) {
+ proxySettings.USE_PROXY = myUseProxy.isSelected();
+ proxySettings.PROXY_HOST = FormUtils.getFieldValue(myProxyHost, proxySettings.USE_PROXY);
+ proxySettings.PROXY_PORT = FormUtils.getPositiveIntFieldValue(myProxyPort, true, false);
+ proxySettings.TYPE = getSelectedType();
+ proxySettings.LOGIN = myLogin.getText();
+ proxySettings.PASSWORD = new String(myPassword.getPassword());
}
- public void saveTo(ProxySettings proxy_settings) {
- proxy_settings.USE_PROXY = myUseProxy.isSelected();
- proxy_settings.PROXY_HOST = myProxyHost.getText();
- proxy_settings.PROXY_PORT = getIntPortValue(myProxyPort.getText(), myProxyPort);
- proxy_settings.TYPE = getSelectedType();
- proxy_settings.LOGIN = myLogin.getText();
- proxy_settings.PASSWORD = new String(myPassword.getPassword());
- }
-
-
public void disablePanel() {
disableAll(true);
}
diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/ui/FormUtils.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/ui/FormUtils.java
new file mode 100644
index 000000000000..7f668384e00e
--- /dev/null
+++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/ui/FormUtils.java
@@ -0,0 +1,78 @@
+/*
+ * Copyright 2011 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.intellij.cvsSupport2.ui;
+
+import com.intellij.CvsBundle;
+import com.intellij.openapi.ui.InputException;
+import com.intellij.openapi.ui.TextFieldWithBrowseButton;
+
+import javax.swing.*;
+
+public class FormUtils {
+
+ private FormUtils() {
+ }
+
+ public static String getFieldValue(JTextField field, boolean check) {
+ final String value = field.getText().trim();
+ if (check && value.isEmpty()) {
+ throw new InputException(CvsBundle.message("error.message.value.cannot.be.empty", getLabelText(field)), field);
+ }
+ return value;
+ }
+
+ public static String getFieldValue(TextFieldWithBrowseButton field, boolean check) {
+ final String value = field.getText().trim();
+ if (check && value.isEmpty()) {
+ throw new InputException(CvsBundle.message("error.message.value.cannot.be.empty", getLabelText(field)), field);
+ }
+ return value;
+ }
+
+ private static String getLabelText(JComponent field) {
+ final JLabel label = (JLabel)field.getClientProperty("labeledBy");
+ String text = label.getText();
+ if (text.endsWith(":")) {
+ text = text.substring(0, text.length() - 1);
+ }
+ return text;
+ }
+
+ public static int getPositiveIntFieldValue(JTextField field, boolean check, boolean emptyAllowed) {
+ final String text = field.getText().trim();
+ if (text.isEmpty()) {
+ if (check && !emptyAllowed) {
+ throw new InputException(CvsBundle.message("error.message.value.cannot.be.empty", getLabelText(field)), field);
+ }
+ return -1;
+ }
+ else {
+ try {
+ final int intPort = Integer.parseInt(text);
+ if (check && intPort <= 0) {
+ throw new InputException(CvsBundle.message("error.message.invalid.value", getLabelText(field), text), field);
+ }
+ return intPort;
+ }
+ catch (NumberFormatException ex) {
+ if (check) {
+ throw new InputException(CvsBundle.message("error.message.invalid.value", getLabelText(field), text), field);
+ }
+ return -1;
+ }
+ }
+ }
+}