Skip to content

Commit

Permalink
Added cancel button to the wait for VM and remote debugging dialogs. …
Browse files Browse the repository at this point in the history
…Issue #142
  • Loading branch information
itaiag committed Feb 16, 2015
1 parent e7a2c7c commit 29f5fed
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,27 +34,34 @@ public class WaitDialog extends JDialog {

private String title;

private JButton cancel = new JButton("Cancel");

private JButton cancelBtn = new JButton("Cancel");
private static Object staticLock = new Object();

private final WaitDialogListner listner;

/**
* Default constructor
*
* @param title
* the message to be displayed in the window's titlebar
*
*/
public WaitDialog(Frame parent, String title) {
public WaitDialog(Frame parent, String title, WaitDialogListner listener) {
super(parent, title);
this.parent = parent;
this.title = title;
this.listner = listener;
/*
* Set the dialog to be modal
*/
setModalityType(ModalityType.DOCUMENT_MODAL);
initComponents();
}

/**
* Default constructor
*
* @param title
* the message to be displayed in the window's titlebar
*
*/
public WaitDialog(Frame parent, String title) {
this(parent,title,null);
}

public WaitDialog(Dialog parent, String title) {
super(parent, title);
Expand All @@ -65,6 +72,7 @@ public WaitDialog(Dialog parent, String title) {
*/
setModalityType(ModalityType.DOCUMENT_MODAL);
initComponents();
this.listner = null;
}

public WaitDialog(String title) {
Expand All @@ -75,6 +83,7 @@ public WaitDialog(String title) {
*/
setModalityType(ModalityType.DOCUMENT_MODAL);
initComponents();
this.listner = null;
}

public WaitDialog() {
Expand All @@ -83,6 +92,7 @@ public WaitDialog() {
*/
setModalityType(ModalityType.DOCUMENT_MODAL);
initComponents();
this.listner = null;
}

private void initComponents() {
Expand All @@ -91,7 +101,7 @@ private void initComponents() {
panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

JProgressBar bar = new JProgressBar();
bar.setPreferredSize(new Dimension(200, 20));
bar.setPreferredSize(new Dimension(150 + (title != null ? title.length() : 0) * 4, 20));
bar.setIndeterminate(true);
bar.setStringPainted(true);
bar.setString(title);
Expand All @@ -102,9 +112,13 @@ private void initComponents() {
buttons.setLayout(new BoxLayout(buttons, BoxLayout.X_AXIS));
buttons.add(Box.createHorizontalGlue());
buttons.add(Box.createHorizontalGlue());
buttons.add(cancelBtn);
panel.add(buttons, BorderLayout.SOUTH);
cancel.addActionListener(new ActionListener() {
cancelBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (listner != null){
listner.cancel();
}
dispose();
}
});
Expand All @@ -117,14 +131,11 @@ public void actionPerformed(ActionEvent e) {

private static WaitDialog dialog = null;

public synchronized static void launchWaitDialog(final String title) {
if (dialog != null) { // probebly sum kind of error
return;
}
public synchronized static void launchWaitDialog(final String title, WaitDialogListner listner) {
/*
* Execute the open of the dialog in a thread as the dialog is modal
*/
dialog = new WaitDialog(TestRunnerFrame.guiMainFrame, title);
dialog = new WaitDialog(TestRunnerFrame.guiMainFrame, title, listner);
(new Thread() {
public void run() {
dialog.setVisible(true);
Expand All @@ -137,7 +148,7 @@ public void run() {
}
}
}

public static void endWaitDialog() {
synchronized(staticLock){
if (dialog == null) {
Expand All @@ -149,7 +160,7 @@ public static void endWaitDialog() {
}

public static void main(String[] args) {
launchWaitDialog("Just wait");
launchWaitDialog("Just wait",null);
try {
Thread.sleep(4000);
} catch (Exception e) {
Expand All @@ -159,4 +170,10 @@ public static void main(String[] args) {
endWaitDialog();
}

public interface WaitDialogListner {
void cancel();
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.io.ObjectOutputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
Expand All @@ -31,6 +32,7 @@
import jsystem.framework.scenario.ScenariosManager;
import jsystem.runner.ErrorLevel;
import jsystem.runner.WaitDialog;
import jsystem.runner.WaitDialog.WaitDialogListner;
import jsystem.runner.agent.publisher.Publisher;
import jsystem.runner.agent.publisher.PublisherManager;
import jsystem.runner.agent.tests.PublishTest;
Expand Down Expand Up @@ -149,20 +151,49 @@ public void run(String antFile, String[] targets, Properties additional) throws
* (test vm) manually with the information as execution parameters:
* -port 1999 -host 127.0.0.1
*/
String vmParams = JSystemProperties.getInstance().getPreference(FrameworkOptions.TEST_VM_PARMS);
boolean testDebug = "true".equals(JSystemProperties.getInstance().getPreference(FrameworkOptions.TESTS_DEBUG));
String waitMessage;

if (testDebug) {
waitMessage = "Run Eclipse remote debugger and connect it to port 8787";
if (testDebug || (vmParams != null && vmParams.contains("-Xdebug"))) {
waitMessage = "Waiting for remote debugging connection";
} else {
waitMessage = "Wait for remote VM";
}

File antHome = CommonResources.getAntDirectory();
WaitDialog.launchWaitDialog(waitMessage);
WaitDialog.launchWaitDialog(waitMessage, new WaitDialogListner() {

@Override
public void cancel() {
interrupted = true;
if (ss != null) {
try {
// ITAI: This will cause the socket to throw exception
// and
// release the blocking state
ss.close();
} catch (IOException e) {
// Don't care
}
}
try {
// ITAI: Needs to give time for the ScenarioExecutor to get
// to the
// waitForRunEnd method.
Thread.sleep(100);
} catch (InterruptedException e) {
}

// ITAI: Telling everyone that the execution was ended.
runEndListener.endRun();
runEndListener.remoteExit();

// Let's close everything.
close();
}
});
File antLauncher = new File(antHome + File.separator + "lib", "ant-launcher.jar");
String vmParams = JSystemProperties.getInstance().getPreference(FrameworkOptions.TEST_VM_PARMS);
String[] vmParamsArr = new String[0];
if (vmParams != null) {
// replaces socket number templates with free socket numbers
Expand Down Expand Up @@ -228,15 +259,20 @@ public void run(String antFile, String[] targets, Properties additional) throws

cmd.setDir(new File(System.getProperty("user.dir")));
Execute.execute(cmd, false, true, false);
try {
socket = ss.accept();

socket = ss.accept();
} catch (SocketException e) {
// ITAI: This will happen if the execution was cancelled by th user.
log.info("Execution was cancelled by the user ");
return;
}
in = new ObjectInputStream(socket.getInputStream());
out = new ObjectOutputStream(socket.getOutputStream());
running = true;
closed = false;
reader = new ReaderThread();
reader.start();

}

private class ReaderThread extends Thread {
Expand Down Expand Up @@ -485,7 +521,7 @@ public void run() {
// SystemObjectCheckWindow.getInstance().setSysObjStatus(m.getField(0),
// SOCheckStatus.valueOf(m.getField(1)), m.getField(2));
break;

default:
System.out.println("Unkown message type local: " + m.getType());
}
Expand Down

0 comments on commit 29f5fed

Please sign in to comment.