diff --git a/de.gebit.integrity.eclipse/src/de/gebit/integrity/eclipse/views/ConnectDialog.java b/de.gebit.integrity.eclipse/src/de/gebit/integrity/eclipse/views/ConnectDialog.java new file mode 100644 index 000000000..bf490c23c --- /dev/null +++ b/de.gebit.integrity.eclipse/src/de/gebit/integrity/eclipse/views/ConnectDialog.java @@ -0,0 +1,62 @@ +/******************************************************************************* + * Copyright (c) 2013 Rene Schneider, GEBIT Solutions GmbH and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + *******************************************************************************/ +package de.gebit.integrity.eclipse.views; + +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.dialogs.IInputValidator; +import org.eclipse.jface.dialogs.InputDialog; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Shell; + +/** + * + * + * @author Rene Schneider - initial API and implementation + * + */ +public class ConnectDialog extends InputDialog { + + /** + * Whether auto-retry was chosen. + */ + private boolean autoRetryEnabled; + + /** + * @param parentShell + * @param aDialogTitle + * @param aDialogMessage + * @param anInitialValue + * @param aValidator + */ + public ConnectDialog(Shell aParentShell, String anInitialValue, IInputValidator aValidator) { + super(aParentShell, "Connect to test runner", "Please enter the hostname or IP address to connect to", + anInitialValue, null); + } + + @Override + protected void createButtonsForButtonBar(Composite aParent) { + super.createButtonsForButtonBar(aParent); + + createButton(aParent, IDialogConstants.RETRY_ID, "OK (retry)", false); + } + + @Override + protected void buttonPressed(int aButtonId) { + if (aButtonId == IDialogConstants.RETRY_ID) { + autoRetryEnabled = true; + super.buttonPressed(IDialogConstants.OK_ID); + } else { + super.buttonPressed(aButtonId); + } + } + + public boolean isAutoRetryEnabled() { + return autoRetryEnabled; + } + +} diff --git a/de.gebit.integrity.eclipse/src/de/gebit/integrity/eclipse/views/IntegrityTestRunnerView.java b/de.gebit.integrity.eclipse/src/de/gebit/integrity/eclipse/views/IntegrityTestRunnerView.java index 88c11e842..f5a1373d1 100644 --- a/de.gebit.integrity.eclipse/src/de/gebit/integrity/eclipse/views/IntegrityTestRunnerView.java +++ b/de.gebit.integrity.eclipse/src/de/gebit/integrity/eclipse/views/IntegrityTestRunnerView.java @@ -49,7 +49,6 @@ import org.eclipse.jface.action.MenuManager; import org.eclipse.jface.action.Separator; import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.dialogs.InputDialog; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.resource.JFaceResources; import org.eclipse.jface.viewers.ArrayContentProvider; @@ -641,6 +640,11 @@ public class IntegrityTestRunnerView extends ViewPart { */ private ILaunchConfiguration launchConfiguration; + /** + * The currently active autoconnect thread. + */ + private AutoConnectThread autoConnectThread; + /** * The constructor. */ @@ -1550,8 +1554,7 @@ private void makeActions() { @Override public void run() { if (client == null || !client.isActive()) { - InputDialog tempDialog = new InputDialog(getSite().getShell(), "Connect to test runner", - "Please enter the hostname or IP address to connect to", lastHostname, null); + ConnectDialog tempDialog = new ConnectDialog(getSite().getShell(), lastHostname, null); if (tempDialog.open() == IStatus.OK && tempDialog.getValue() != null && tempDialog.getValue().length() > 0) { lastHostname = tempDialog.getValue(); @@ -1569,7 +1572,23 @@ public void run() { } tempHost = tempHost.substring(0, tempHost.indexOf(':')); } - connectToTestRunnerAsync(tempHost, tempPort); + + if (tempDialog.isAutoRetryEnabled()) { + if (autoConnectThread != null && autoConnectThread.isAlive()) { + autoConnectThread.kill(); + autoConnectThread = null; + } + if (autoConnectThread == null || !autoConnectThread.isAlive()) { + autoConnectThread = new AutoConnectThread(tempHost, tempPort); + autoConnectThread.start(); + } + } else { + connectToTestRunnerAsync(tempHost, tempPort); + } + } else { + if (autoConnectThread != null && autoConnectThread.isAlive()) { + autoConnectThread.kill(); + } } } else { disconnectFromTestRunner(); @@ -1709,7 +1728,11 @@ public void run() { executeTestAction.setEnabled(false); executeDebugTestAction.setEnabled(false); final ILaunch tempLaunch = launchConfiguration.launch(ILaunchManager.RUN_MODE, null); - new AutoConnectThread(tempLaunch).start(); + if (autoConnectThread != null && autoConnectThread.isAlive()) { + autoConnectThread.kill(); + } + autoConnectThread = new AutoConnectThread(tempLaunch); + autoConnectThread.start(); } catch (CoreException exc) { showException(exc); } @@ -1727,7 +1750,11 @@ public void run() { executeTestAction.setEnabled(false); executeDebugTestAction.setEnabled(false); final ILaunch tempLaunch = launchConfiguration.launch(ILaunchManager.DEBUG_MODE, null); - new AutoConnectThread(tempLaunch).start(); + if (autoConnectThread != null && autoConnectThread.isAlive()) { + autoConnectThread.kill(); + } + autoConnectThread = new AutoConnectThread(tempLaunch); + autoConnectThread.start(); } catch (CoreException exc) { showException(exc); } @@ -2854,6 +2881,21 @@ private class AutoConnectThread extends Thread { */ private ILaunch launch; + /** + * The host to connect to. + */ + private String host = "localhost"; + + /** + * The port to connect to. + */ + private int port = IntegrityRemotingConstants.DEFAULT_PORT; + + /** + * Used to kill this thread gracefully. + */ + private boolean killSwitch; + /** * Creates a new instance. */ @@ -2862,15 +2904,28 @@ private class AutoConnectThread extends Thread { launch = aLaunch; } + /** + * Creates a new instance. + */ + AutoConnectThread(String aHost, int aPort) { + super("Integrity Autoconnect Thread"); + host = aHost; + port = aPort; + } + + public void kill() { + killSwitch = true; + } + @Override public void run() { boolean tempSuccess = false; - while (!launch.isTerminated()) { + while (!killSwitch && (launch == null || !launch.isTerminated())) { try { if (!tempSuccess && !isConnected()) { // try to connect at least once - connectToTestRunner("localhost", IntegrityRemotingConstants.DEFAULT_PORT); + connectToTestRunner(host, IntegrityRemotingConstants.DEFAULT_PORT); tempSuccess = true; } else { // Now we'll wait until the launch has terminated @@ -2893,6 +2948,10 @@ public void run() { // don't care } } + + if (!tempSuccess) { + updateStatus("Aborted connection attempts"); + } executeTestAction.setEnabled(true); executeDebugTestAction.setEnabled(true); };