Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoland Grunberg2016-08-18 19:41:21 +0000
committerRoland Grunberg2016-08-20 01:35:00 +0000
commitf56f878a974ca0fc317185d28102b681d290904e (patch)
tree0ed39d65cc076356c234d283ddf899dc16c7b22a
parente030879f8df927ea658b088d2f8a931464e3283c (diff)
downloadorg.eclipse.linuxtools-f56f878a974ca0fc317185d28102b681d290904e.tar.gz
org.eclipse.linuxtools-f56f878a974ca0fc317185d28102b681d290904e.tar.xz
org.eclipse.linuxtools-f56f878a974ca0fc317185d28102b681d290904e.zip
Bug 471673: Support populating connection wizard with clipboard data.
Change-Id: I15a06eee1e1673cd0f1f193b96b1772b41660819 Reviewed-on: https://git.eclipse.org/r/79296 Tested-by: Hudson CI Reviewed-by: Roland Grunberg <rgrunber@redhat.com>
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/wizards/NewDockerConnectionSWTBotTest.java51
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/NewDockerConnectionPage.java55
2 files changed, 105 insertions, 1 deletions
diff --git a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/wizards/NewDockerConnectionSWTBotTest.java b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/wizards/NewDockerConnectionSWTBotTest.java
index b24f856614..ee0b57de8e 100644
--- a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/wizards/NewDockerConnectionSWTBotTest.java
+++ b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/internal/docker/ui/wizards/NewDockerConnectionSWTBotTest.java
@@ -26,6 +26,11 @@ import org.eclipse.linuxtools.internal.docker.ui.testutils.swt.TextAssertion;
import org.eclipse.linuxtools.internal.docker.ui.views.DockerContainersView;
import org.eclipse.linuxtools.internal.docker.ui.views.DockerExplorerView;
import org.eclipse.linuxtools.internal.docker.ui.views.DockerImagesView;
+import org.eclipse.swt.dnd.Clipboard;
+import org.eclipse.swt.dnd.DND;
+import org.eclipse.swt.dnd.TextTransfer;
+import org.eclipse.swt.dnd.Transfer;
+import org.eclipse.swt.widgets.Display;
import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
@@ -166,4 +171,50 @@ public class NewDockerConnectionSWTBotTest {
.isNotNull();
}
+ @Test
+ public void shouldPopulateConnectionWithClipboard() {
+ final int [] DND_TYPE = {DND.SELECTION_CLIPBOARD, DND.CLIPBOARD};
+ for (int i = 0; i < DND_TYPE.length; i++) {
+ // Clear the clipboards
+ Display.getDefault().syncExec(() -> {
+ Clipboard clip = new Clipboard(Display.getCurrent());
+ clip.clearContents(DND.CLIPBOARD);
+ clip.clearContents(DND.SELECTION_CLIPBOARD);
+ });
+
+ // given
+ final int DND_VALUE = DND_TYPE[i];
+ final String[] connectionData = new String[] {
+ "DOCKER_HOST=https://1.2.3.4:1234 DOCKER_CERT_PATH=/path/to/certs DOCKER_TLS_VERIFY=1" };
+ Display.getDefault().syncExec(() -> {
+ Clipboard clip = new Clipboard(Display.getCurrent());
+ clip.setContents(connectionData, new Transfer[] { TextTransfer.getInstance() },
+ DND_VALUE);
+ });
+ // when
+ addConnectionButton.click();
+ // then
+ // Connection name
+ TextAssertion.assertThat(bot.text(0)).isEnabled().isEmpty();
+ // "Use custom connection settings" should be enabled and checked
+ CheckBoxAssertion.assertThat(bot.checkBox(0)).isEnabled().isChecked();
+ // "Unix socket" radio should be enabled and unselected
+ RadioAssertion.assertThat(bot.radio(0)).isEnabled().isNotSelected();
+ // "Unix socket path" text should be disabled and empty
+ TextAssertion.assertThat(bot.text(1)).isNotEnabled().isEmpty();
+ // "TCP Connection" radio should be enabled and selected
+ RadioAssertion.assertThat(bot.radio(1)).isEnabled().isSelected();
+ // "URI" should be enabled and not empty
+ TextAssertion.assertThat(bot.text(2)).isEnabled().textEquals("https://1.2.3.4:1234");
+ // "Enable Auth" checkbox should be enabled and selected
+ CheckBoxAssertion.assertThat(bot.checkBox(1)).isEnabled().isChecked();
+ // "Path" for certs should be enabled and not empty
+ TextAssertion.assertThat(bot.text(3)).isEnabled().textEquals("/path/to/certs");
+
+ // Close wizard
+ bot.button("Cancel").click();
+ }
+
+ }
+
}
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 d0c4d7df2d..bb0321f7f2 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
@@ -21,6 +21,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
+import java.util.StringTokenizer;
import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.databinding.beans.BeanProperties;
@@ -48,6 +49,7 @@ import org.eclipse.linuxtools.docker.core.DockerException;
import org.eclipse.linuxtools.docker.core.EnumDockerConnectionSettings;
import org.eclipse.linuxtools.docker.core.IDockerConnectionSettings;
import org.eclipse.linuxtools.docker.ui.Activator;
+import org.eclipse.linuxtools.internal.docker.core.DefaultDockerConnectionSettingsFinder;
import org.eclipse.linuxtools.internal.docker.core.DockerConnection;
import org.eclipse.linuxtools.internal.docker.core.DockerMachine;
import org.eclipse.linuxtools.internal.docker.core.TCPConnectionSettings;
@@ -56,6 +58,9 @@ import org.eclipse.linuxtools.internal.docker.ui.SWTImagesFactory;
import org.eclipse.linuxtools.internal.docker.ui.preferences.PreferenceConstants;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ScrolledComposite;
+import org.eclipse.swt.dnd.Clipboard;
+import org.eclipse.swt.dnd.DND;
+import org.eclipse.swt.dnd.TextTransfer;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
@@ -115,7 +120,20 @@ public class NewDockerConnectionPage extends WizardPage {
createConnectionSettingsContainer(container);
// attach the Databinding context status to this wizard page.
WizardPageSupport.create(this, this.dbc);
- retrieveDefaultConnectionSettings();
+
+ Clipboard clip = new Clipboard(Display.getCurrent());
+ String content = (String) clip.getContents(TextTransfer.getInstance(), DND.SELECTION_CLIPBOARD);
+ // DOCKER_HOST is the minimal property needed
+ if (content != null && content.contains(DefaultDockerConnectionSettingsFinder.DOCKER_HOST)) {
+ retrieveConnectionSettings(content);
+ } else {
+ content = (String) clip.getContents(TextTransfer.getInstance(), DND.CLIPBOARD);
+ if (content != null && content.contains(DefaultDockerConnectionSettingsFinder.DOCKER_HOST)) {
+ retrieveConnectionSettings(content);
+ } else {
+ retrieveDefaultConnectionSettings();
+ }
+ }
scrollTop.setContent(container);
Point point = container.computeSize(SWT.DEFAULT, SWT.DEFAULT);
@@ -466,6 +484,41 @@ public class NewDockerConnectionPage extends WizardPage {
}
+ private void retrieveConnectionSettings(String content) {
+ final String EQUAL = "="; //$NON-NLS-1$
+ StringTokenizer tok = new StringTokenizer(content);
+ while (tok.hasMoreTokens()) {
+ String line = tok.nextToken();
+ String[] tokens;
+ if (line.startsWith(DefaultDockerConnectionSettingsFinder.DOCKER_HOST)) {
+ tokens = line.split(EQUAL);
+ if (tokens.length == 2) {
+ String host = tokens[1];
+ if (host.startsWith("unix")) { //$NON-NLS-1$
+ model.setUnixSocketBindingMode(true);
+ model.setUnixSocketPath(host);
+ } else {
+ model.setTcpConnectionBindingMode(true);
+ model.setTcpHost(host);
+ }
+ model.setCustomSettings(true);
+ }
+ } else if (line.startsWith(DefaultDockerConnectionSettingsFinder.DOCKER_CERT_PATH)) {
+ tokens = line.split(EQUAL);
+ if (tokens.length == 2) {
+ model.setTcpCertPath(tokens[1]);
+ }
+ } else if (line.startsWith(DefaultDockerConnectionSettingsFinder.DOCKER_TLS_VERIFY)) {
+ tokens = line.split(EQUAL);
+ if (tokens.length == 2) {
+ model.setTcpTLSVerify(
+ DefaultDockerConnectionSettingsFinder.DOCKER_TLS_VERIFY_TRUE
+ .equals(tokens[1]));
+ }
+ }
+ }
+ }
+
private void updateWidgetsState(
final Control[] bindingModeSelectionControls,
final Control[] unixSocketControls,

Back to the top