// Path: src/com/jetbrains/crucible/connection/CrucibleTestConnectionTask.java
// public class CrucibleTestConnectionTask extends Task.Modal {
//   private static final int CHECK_CANCEL_INTERVAL = 500;
//   private static final Logger LOG = Logger.getInstance(CrucibleTestConnectionTask.class.getName());
// 
//   public CrucibleTestConnectionTask(@Nullable Project project) {
//     super(project, "Testing Connection", true);
//     setCancelText("Stop");
//   }
// 
//   @Override
//   public void run(@NotNull ProgressIndicator indicator) {
//     indicator.setText("Connecting...");
//     indicator.setFraction(0);
//     indicator.setIndeterminate(true);
// 
//     final CrucibleTestConnector connector = new CrucibleTestConnector(myProject);
//     connector.run();
// 
//     while (connector.getConnectionState() == CrucibleTestConnector.ConnectionState.NOT_FINISHED) {
//       try {
//         if (indicator.isCanceled()) {
//           connector.setInterrupted();
//           break;
//         }
//         else {
//           Thread.sleep(CHECK_CANCEL_INTERVAL);
//         }
//       }
//       catch (InterruptedException e) {
//         LOG.info(e.getMessage());
//       }
//     }
// 
//     CrucibleTestConnector.ConnectionState state = connector.getConnectionState();
//     switch (state) {
//       case FAILED:
//         EventQueue.invokeLater(new Runnable() {
//           public void run() {
//             Messages.showDialog(myProject, "Reason:  " + connector.getErrorMessage(), "Connection Failed", new String[]{"Ok"}, 0, null);
//           }
//         });
//         break;
//       case INTERRUPTED:
//         LOG.debug("'Test Connection' canceled");
//         break;
//       case SUCCEEDED:
//         EventQueue.invokeLater(new Runnable() {
//           public void run() {
//             Messages.showDialog(myProject, "Connected successfully", "Connection OK", new String[]{"Ok"}, 0, null);
//           }
//         });
//         break;
//       default: //NOT_FINISHED:
//         LOG.warn("Unexpected 'Test Connection' state: "
//                  + connector.getConnectionState().toString());
//     }
//   }
// }


import com.intellij.openapi.options.ConfigurationException;
import com.intellij.openapi.options.SearchableConfigurable;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.progress.Task;
import com.intellij.openapi.project.ProjectManager;
import com.intellij.openapi.util.text.StringUtil;
import com.jetbrains.crucible.connection.CrucibleTestConnectionTask;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
package com.jetbrains.crucible.configuration;



/**
 * User: ktisha
 */
public class CrucibleConfigurable implements SearchableConfigurable {
  private JPanel myMainPanel;
  private JTextField myServerField;
  private JTextField myUsernameField;
  private JPasswordField myPasswordField;
  private JButton myTestButton;
  private final CrucibleSettings myCrucibleSettings;
  private static final String DEFAULT_PASSWORD_TEXT = "************";
  private boolean myPasswordModified;


  public CrucibleConfigurable() {
    myCrucibleSettings = CrucibleSettings.getInstance();

    myTestButton.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
        saveSettings();
// Path: src/com/jetbrains/crucible/connection/CrucibleTestConnectionTask.java
// public class CrucibleTestConnectionTask extends Task.Modal {
//   private static final int CHECK_CANCEL_INTERVAL = 500;
//   private static final Logger LOG = Logger.getInstance(CrucibleTestConnectionTask.class.getName());
// 
//   public CrucibleTestConnectionTask(@Nullable Project project) {
//     super(project, "Testing Connection", true);
//     setCancelText("Stop");
//   }
// 
//   @Override
//   public void run(@NotNull ProgressIndicator indicator) {
//     indicator.setText("Connecting...");
//     indicator.setFraction(0);
//     indicator.setIndeterminate(true);
// 
//     final CrucibleTestConnector connector = new CrucibleTestConnector(myProject);
//     connector.run();
// 
//     while (connector.getConnectionState() == CrucibleTestConnector.ConnectionState.NOT_FINISHED) {
//       try {
//         if (indicator.isCanceled()) {
//           connector.setInterrupted();
//           break;
//         }
//         else {
//           Thread.sleep(CHECK_CANCEL_INTERVAL);
//         }
//       }
//       catch (InterruptedException e) {
//         LOG.info(e.getMessage());
//       }
//     }
// 
//     CrucibleTestConnector.ConnectionState state = connector.getConnectionState();
//     switch (state) {
//       case FAILED:
//         EventQueue.invokeLater(new Runnable() {
//           public void run() {
//             Messages.showDialog(myProject, "Reason:  " + connector.getErrorMessage(), "Connection Failed", new String[]{"Ok"}, 0, null);
//           }
//         });
//         break;
//       case INTERRUPTED:
//         LOG.debug("'Test Connection' canceled");
//         break;
//       case SUCCEEDED:
//         EventQueue.invokeLater(new Runnable() {
//           public void run() {
//             Messages.showDialog(myProject, "Connected successfully", "Connection OK", new String[]{"Ok"}, 0, null);
//           }
//         });
//         break;
//       default: //NOT_FINISHED:
//         LOG.warn("Unexpected 'Test Connection' state: "
//                  + connector.getConnectionState().toString());
//     }
//   }
// }


// Path: src/com/jetbrains/crucible/configuration/CrucibleConfigurable.java
import com.intellij.openapi.options.ConfigurationException;
import com.intellij.openapi.options.SearchableConfigurable;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.progress.Task;
import com.intellij.openapi.project.ProjectManager;
import com.intellij.openapi.util.text.StringUtil;
import com.jetbrains.crucible.connection.CrucibleTestConnectionTask;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

package com.jetbrains.crucible.configuration;



/**
 * User: ktisha
 */
public class CrucibleConfigurable implements SearchableConfigurable {
  private JPanel myMainPanel;
  private JTextField myServerField;
  private JTextField myUsernameField;
  private JPasswordField myPasswordField;
  private JButton myTestButton;
  private final CrucibleSettings myCrucibleSettings;
  private static final String DEFAULT_PASSWORD_TEXT = "************";
  private boolean myPasswordModified;


  public CrucibleConfigurable() {
    myCrucibleSettings = CrucibleSettings.getInstance();

    myTestButton.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
        saveSettings();
        final Task.Modal testConnectionTask = new CrucibleTestConnectionTask(ProjectManager.getInstance().getDefaultProject());