private void initControls(final LauncherParameters launcherParameters) {
    final LauncherParameters.LauncherType launcherType = launcherParameters.getLauncherType();
    myDefaultOSApplicationRadioButton.setSelected(
        launcherType == LauncherParameters.LauncherType.OSDefault);
    myBrowserRadioButton.setSelected(launcherType == LauncherParameters.LauncherType.Browser);
    myPlayerRadioButton.setSelected(launcherType == LauncherParameters.LauncherType.Player);

    myBrowserSelector.setSelected(launcherParameters.getBrowser());

    myPlayerTextWithBrowse.setText(
        FileUtil.toSystemDependentName(launcherParameters.getPlayerPath()));
    myPlayerTextWithBrowse.addBrowseFolderListener(
        null,
        null,
        myProject,
        new FileChooserDescriptor(true, true, false, false, false, false) {
          @Override
          public boolean isFileSelectable(final VirtualFile file) {
            return SystemInfo.isMac
                    && file.isDirectory()
                    && "app".equalsIgnoreCase(file.getExtension())
                || !file.isDirectory();
          }
        });
    myNewPlayerInstanceCheckBox.setVisible(SystemInfo.isMac);
  }
  private void initializeUI() {
    myTree = new Tree();
    myTreeBuilder = new CertificateTreeBuilder(myTree);

    // are not fully functional by now
    myCheckHostname.setVisible(false);
    myCheckValidityPeriod.setVisible(false);

    myTrustManager = CertificateManager.getInstance().getCustomTrustManager();
    // show newly added certificates
    myTrustManager.addListener(this);

    myTree.getEmptyText().setText("No certificates");
    myTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    myTree.setRootVisible(false);
    // myTree.setShowsRootHandles(false);

    ToolbarDecorator decorator = ToolbarDecorator.createDecorator(myTree).disableUpDownActions();
    decorator
        .setAddAction(
            new AnActionButtonRunnable() {
              @Override
              public void run(AnActionButton button) {
                // show choose file dialog, add certificate
                FileChooser.chooseFile(
                    CERTIFICATE_DESCRIPTOR,
                    null,
                    null,
                    file -> {
                      String path = file.getPath();
                      X509Certificate certificate = CertificateUtil.loadX509Certificate(path);
                      if (certificate == null) {
                        Messages.showErrorDialog(
                            myRootPanel, "Malformed X509 server certificate", "Not Imported");
                      } else if (myCertificates.contains(certificate)) {
                        Messages.showWarningDialog(
                            myRootPanel, "Certificate already exists", "Not Imported");
                      } else {
                        myCertificates.add(certificate);
                        myTreeBuilder.addCertificate(certificate);
                        addCertificatePanel(certificate);
                        myTreeBuilder.selectCertificate(certificate);
                      }
                    });
              }
            })
        .setRemoveAction(
            new AnActionButtonRunnable() {
              @Override
              public void run(AnActionButton button) {
                // allow to delete several certificates at once
                for (X509Certificate certificate : myTreeBuilder.getSelectedCertificates(true)) {
                  myCertificates.remove(certificate);
                  myTreeBuilder.removeCertificate(certificate);
                }
                if (myCertificates.isEmpty()) {
                  showCard(EMPTY_PANEL);
                } else {
                  myTreeBuilder.selectFirstCertificate();
                }
              }
            });

    myTree.addTreeSelectionListener(
        new TreeSelectionListener() {
          @Override
          public void valueChanged(TreeSelectionEvent e) {
            X509Certificate certificate = myTreeBuilder.getFirstSelectedCertificate(true);
            if (certificate != null) {
              showCard(getCardName(certificate));
            }
          }
        });
    myCertificatesListPanel.add(decorator.createPanel(), BorderLayout.CENTER);
  }
  public CloudAttachDialog(@NotNull Project project) {
    super(project, true);

    myProject = project;
    init();
    initValidation();
    setTitle(GctBundle.getString("clouddebug.attachtitle"));
    setOKButtonText(GctBundle.getString("clouddebug.attach"));
    mySyncStashCheckbox.setVisible(false);
    mySyncStashCheckbox.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            if (mySyncStashCheckbox.isVisible()) {
              myWarningLabel.setVisible(!mySyncStashCheckbox.isSelected());
              myWarningLabel2.setVisible(!mySyncStashCheckbox.isSelected());
              myInfoPanel.setVisible(mySyncStashCheckbox.isSelected());
              if (mySyncStashCheckbox.isSelected()) {
                setOKButtonText(
                    isContinued()
                        ? GctBundle.getString("clouddebug.continuesession")
                        : GctBundle.getString("clouddebug.attach"));
              } else {
                setOKButtonText(
                    isContinued()
                        ? GctBundle.getString("clouddebug.continueanyway")
                        : GctBundle.getString("clouddebug.attach.anyway"));
              }
            }
          }
        });

    myWarningLabel.setVisible(false);
    myWarningLabel.setFont(
        new Font(
            myWarningLabel.getFont().getName(), Font.BOLD, myWarningLabel.getFont().getSize() - 1));
    myWarningLabel.setForeground(JBColor.RED);
    myWarningLabel2.setVisible(false);
    myWarningLabel2.setFont(
        new Font(
            myWarningLabel2.getFont().getName(),
            Font.PLAIN,
            myWarningLabel.getFont().getSize() - 1));
    myWarningLabel2.setText(GctBundle.getString("clouddebug.sourcedoesnotmatch"));

    myInfoPanel.setFont(
        new Font(
            myWarningLabel2.getFont().getName(),
            Font.PLAIN,
            myWarningLabel.getFont().getSize() - 1));
    Border paddingBorder = BorderFactory.createEmptyBorder(2, 0, 2, 0);
    myInfoPanel.setBorder(paddingBorder);

    Window myWindow = getWindow();
    if (myWindow != null) {
      myWindow.setPreferredSize(new Dimension(355, 175));
    }
    BasicAction.saveAll();

    myWireup = new ProjectDebuggeeBinding(myElysiumProjectId, myDebuggeeTarget);
    myDebuggeeTarget.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            buildResult();
            checkSyncStashState();
            setOKActionEnabled(doValidate() == null);
          }
        });

    setOKActionEnabled(isContinued() || doValidate() == null);
  }
  /** Checks whether a stash or sync is needed based on the chosen target and local state. */
  private void checkSyncStashState() {
    if (myProcessResultState == null) {
      LOG.error("unexpected result state during a check sync stash state");
      return;
    }
    mySyncResult = new ProjectRepositoryValidator(myProcessResultState).checkSyncStashState();

    if (mySyncResult.needsStash() && mySyncResult.needsSync()) {
      setOKButtonText(
          isContinued()
              ? GctBundle.getString("clouddebug.continuesession")
              : GctBundle.getString("clouddebug.attach"));
      mySyncStashCheckbox.setVisible(true);
      assert mySyncResult.getTargetSyncSHA() != null;
      mySyncStashCheckbox.setText(
          GctBundle.getString(
              "clouddebug.stash.local.changes.and.sync",
              mySyncResult.getTargetSyncSHA().substring(0, 7)));
      mySyncStashCheckbox.setSelected(true);
      myWarningLabel.setVisible(false);
      myWarningLabel2.setVisible(false);
      myInfoPanel.setVisible(true);
    } else if (mySyncResult.needsStash()) {
      setOKButtonText(
          isContinued()
              ? GctBundle.getString("clouddebug.continuesession")
              : GctBundle.getString("clouddebug.attach"));
      mySyncStashCheckbox.setVisible(true);
      mySyncStashCheckbox.setText(GctBundle.getString("clouddebug.stashbuttontext"));
      mySyncStashCheckbox.setSelected(true);
      myWarningLabel.setVisible(false);
      myWarningLabel2.setVisible(false);
      myInfoPanel.setVisible(true);
    } else if (mySyncResult.needsSync()) {
      setOKButtonText(
          isContinued()
              ? GctBundle.getString("clouddebug.continuesession")
              : GctBundle.getString("clouddebug.attach"));
      mySyncStashCheckbox.setVisible(true);
      assert mySyncResult.getTargetSyncSHA() != null;
      mySyncStashCheckbox.setText("Sync to " + mySyncResult.getTargetSyncSHA().substring(0, 7));
      mySyncStashCheckbox.setSelected(true);
      myWarningLabel.setVisible(false);
      myWarningLabel2.setVisible(false);
      myInfoPanel.setVisible(true);
    } else if (mySyncResult.needsSync() && mySyncResult.getTargetSyncSHA() == null) {
      setOKButtonText(
          isContinued()
              ? GctBundle.getString("clouddebug.continueanyway")
              : GctBundle.getString("clouddebug.attach.anyway"));
      myWarningLabel.setVisible(true);
      myWarningLabel2.setVisible(true);
      myInfoPanel.setVisible(true);
      myWarningLabel2.setText(GctBundle.getString("clouddebug.no.matching.sha"));
    } else if (!mySyncResult.hasRemoteRepository()) {
      setOKButtonText(
          isContinued()
              ? GctBundle.getString("clouddebug.continueanyway")
              : GctBundle.getString("clouddebug.attach.anyway"));
      myWarningLabel.setVisible(true);
      myWarningLabel2.setVisible(true);
      myInfoPanel.setVisible(true);
      if (mySyncResult.getRepositoryType() != null) {
        myWarningLabel2.setText(
            GctBundle.getString(
                "clouddebug.repositories.are.not.supported", mySyncResult.getRepositoryType()));
      } else {
        myWarningLabel2.setText(GctBundle.getString("clouddebug.no.remote.repository"));
      }
    } else {
      setOKButtonText(
          isContinued()
              ? GctBundle.getString("clouddebug.continuesession")
              : GctBundle.getString("clouddebug.attach"));
      mySyncStashCheckbox.setVisible(false);
      myWarningLabel.setVisible(false);
      myWarningLabel2.setVisible(false);
      myInfoPanel.setVisible(true);
    }
  }