Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXavier Coulon2015-06-01 12:39:38 +0000
committerRoland Grunberg2015-09-04 20:30:02 +0000
commitc0ac37aa2e711d23b4b1fe466b7b528346981577 (patch)
tree4650d4f914cb8c2121fcd2832c6338c1202544fa
parent177b8d138bf21ccdfde1dcd443a2dd4d5ab3d4c7 (diff)
downloadorg.eclipse.linuxtools-c0ac37aa2e711d23b4b1fe466b7b528346981577.tar.gz
org.eclipse.linuxtools-c0ac37aa2e711d23b4b1fe466b7b528346981577.tar.xz
org.eclipse.linuxtools-c0ac37aa2e711d23b4b1fe466b7b528346981577.zip
Bug 475504 - Creating a connection with the same name results
...in duplicate entries in combo boxes Added validation to prevent empty and duplicate connection name in the "New Connection" wizard. Reverted the order in which widgets are enabled to set focus on first enabled text field (when applicable) Change-Id: Ia8d6e3465048c8959832ba21c76a2b4a487659d8 Signed-off-by: Xavier Coulon <xcoulon@redhat.com> Reviewed-on: https://git.eclipse.org/r/55221 Tested-by: Hudson CI Reviewed-by: Roland Grunberg <rgrunber@redhat.com> Tested-by: Roland Grunberg <rgrunber@redhat.com> Reviewed-on: https://git.eclipse.org/r/55338
-rw-r--r--containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/DockerConnectionManager.java10
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/NewDockerConnectionPage.java63
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/WizardMessages.properties2
3 files changed, 60 insertions, 15 deletions
diff --git a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/DockerConnectionManager.java b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/DockerConnectionManager.java
index 96b1ed95f5..4d5c420701 100644
--- a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/DockerConnectionManager.java
+++ b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/DockerConnectionManager.java
@@ -178,10 +178,12 @@ public class DockerConnectionManager {
return connections.toArray(new IDockerConnection[connections.size()]);
}
- public IDockerConnection findConnection(String name) {
- for (IDockerConnection connection : connections) {
- if (connection.getName().equals(name))
- return connection;
+ public IDockerConnection findConnection(final String name) {
+ if (name != null) {
+ for (IDockerConnection connection : connections) {
+ if (connection.getName().equals(name))
+ return connection;
+ }
}
return null;
}
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/NewDockerConnectionPage.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/NewDockerConnectionPage.java
index 51eff9bf6a..1510389ba6 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/NewDockerConnectionPage.java
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/NewDockerConnectionPage.java
@@ -40,6 +40,7 @@ import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.layout.GridLayoutFactory;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.linuxtools.docker.core.DockerConnectionManager;
import org.eclipse.linuxtools.docker.core.DockerException;
import org.eclipse.linuxtools.docker.ui.Activator;
import org.eclipse.linuxtools.internal.docker.core.DockerConnection;
@@ -84,8 +85,10 @@ public class NewDockerConnectionPage extends WizardPage {
GridLayoutFactory.fillDefaults().numColumns(1).applyTo(container);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL)
.applyTo(container);
- retrieveDefaultConnectionSettings();
createConnectionSettingsContainer(container);
+ // attach the Databinding context status to this wizard page.
+ WizardPageSupport.create(this, this.dbc);
+ retrieveDefaultConnectionSettings();
setControl(container);
}
@@ -308,6 +311,8 @@ public class NewDockerConnectionPage extends WizardPage {
// validations will be performed when the user changes the value
// only, not at the dialog opening
dbc.addValidationStatusProvider(
+ new ConnectionNameValidator(connectionNameModelObservable));
+ dbc.addValidationStatusProvider(
new UnixSocketValidator(unixSocketBindingModeModelObservable,
unixSocketPathModelObservable));
dbc.addValidationStatusProvider(
@@ -316,8 +321,7 @@ public class NewDockerConnectionPage extends WizardPage {
dbc.addValidationStatusProvider(new TcpCertificatesValidator(
tcpConnectionBindingModeModelObservable,
tcpTlsVerifyModelObservable, tcpCertPathModelObservable));
- // attach the Databinding context status to this wizard page.
- WizardPageSupport.create(this, this.dbc);
+
// give focus to connectionName text at first
connectionNameText.setFocus();
// set widgets initial state
@@ -378,15 +382,15 @@ public class NewDockerConnectionPage extends WizardPage {
"NewDockerConnectionPage.retrieveTask"), //$NON-NLS-1$
1);
final DockerConnection.Defaults defaults = new DockerConnection.Defaults();
+ model.setTcpCertPath(defaults.getTcpCertPath());
+ model.setTcpTLSVerify(defaults.getTcpTlsVerify());
+ model.setTcpHost(defaults.getTcpHost());
+ model.setUnixSocketPath(
+ defaults.getUnixSocketPath());
+ model.setBindingMode(defaults.getBindingMode());
model.setCustomSettings(
!defaults.isSettingsResolved());
model.setConnectionName(defaults.getName());
- model.setBindingMode(defaults.getBindingMode());
- model.setUnixSocketPath(
- defaults.getUnixSocketPath());
- model.setTcpHost(defaults.getTcpHost());
- model.setTcpTLSVerify(defaults.getTcpTlsVerify());
- model.setTcpCertPath(defaults.getTcpCertPath());
monitor.done();
}
});
@@ -479,8 +483,13 @@ public class NewDockerConnectionPage extends WizardPage {
control.setEnabled(enabled);
}
// set the focus on the fist element of the group.
- if (controls.length > 0 && enabled) {
- controls[0].setFocus();
+ if (enabled) {
+ for (Control control : controls) {
+ if (control instanceof Text) {
+ control.setFocus();
+ break;
+ }
+ }
}
}
@@ -588,6 +597,38 @@ public class NewDockerConnectionPage extends WizardPage {
}
}
+ private static class ConnectionNameValidator extends MultiValidator {
+
+ private final IObservableValue connectionNameModelObservable;
+
+ public ConnectionNameValidator(
+ final IObservableValue connectionNameModelObservable) {
+ this.connectionNameModelObservable = connectionNameModelObservable;
+ }
+
+ @Override
+ public IObservableList getTargets() {
+ WritableList targets = new WritableList();
+ targets.add(connectionNameModelObservable);
+ return targets;
+ }
+
+ @Override
+ protected IStatus validate() {
+ final String connectionName = (String) this.connectionNameModelObservable
+ .getValue();
+ if (connectionName == null || connectionName.isEmpty()) {
+ return ValidationStatus.cancel(WizardMessages.getString(
+ "NewDockerConnectionPage.validation.missingConnectionName.msg")); //$NON-NLS-1$
+ } else if (DockerConnectionManager.getInstance()
+ .findConnection(connectionName) != null) {
+ return ValidationStatus.error(WizardMessages.getString(
+ "NewDockerConnectionPage.validation.duplicateConnectionName.msg")); //$NON-NLS-1$
+ }
+ return ValidationStatus.ok();
+ }
+ }
+
private static class UnixSocketValidator extends MultiValidator {
private final IObservableValue unixSocketBindingModeModelObservable;
diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/WizardMessages.properties b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/WizardMessages.properties
index 6a7be88e32..e902ff3154 100644
--- a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/WizardMessages.properties
+++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/WizardMessages.properties
@@ -168,6 +168,8 @@ NewDockerConnectionPage.failure=Failure
NewDockerConnectionPage.pingFailure=Ping failed !
NewDockerConnection.failure=Failure
NewDockerConnection.failMessage=Failed to connect!
+NewDockerConnectionPage.validation.missingConnectionName.msg=Provide a unique name to identify the new connection.
+NewDockerConnectionPage.validation.duplicateConnectionName.msg=A connection with the same name already exists.
NewDockerConnectionPage.validation.missingUnixSocket.msg=Unix socket path is missing
NewDockerConnectionPage.validation.invalidUnixSocketScheme.msg=Unix socket scheme is invalid: only "unix" is allowed
NewDockerConnectionPage.validation.invalidUnixSocketPath.msg=Unix socket path is invalid

Back to the top