Better error reporting when creating new cvs root

This commit is contained in:
Bas Leijdekkers
2011-12-12 15:42:46 +01:00
parent fca6e26348
commit 7dddeb7cac
9 changed files with 137 additions and 96 deletions
@@ -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
@@ -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() {
@@ -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() {
@@ -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;
}
@@ -45,6 +45,7 @@
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="4" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<labelFor value="1f45b"/>
<text resource-bundle="com/intellij/cvsSupport2/CvsBundle" key="label.configure.ext.path.to.private.key.file"/>
</properties>
</component>
@@ -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());
}
}
@@ -74,6 +74,7 @@
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="4" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<labelFor value="6c959"/>
<text resource-bundle="com/intellij/cvsSupport2/CvsBundle" key="label.configure.proxy.login"/>
</properties>
</component>
@@ -82,6 +83,7 @@
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="4" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<labelFor value="f4e35"/>
<text resource-bundle="com/intellij/cvsSupport2/CvsBundle" key="label.configure.proxy.password"/>
</properties>
</component>
@@ -106,6 +108,7 @@
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="4" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<labelFor value="327d8"/>
<text resource-bundle="com/intellij/cvsSupport2/CvsBundle" key="label.configure.proxy.proxy.host"/>
</properties>
</component>
@@ -114,6 +117,7 @@
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="4" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<labelFor value="802e6"/>
<text resource-bundle="com/intellij/cvsSupport2/CvsBundle" key="label.configure.proxy.proxy.port"/>
</properties>
</component>
@@ -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);
}
@@ -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;
}
}
}
}