public void reset() {
    myNoProxyRb.setSelected(true); // default
    HttpConfigurable httpConfigurable = myHttpConfigurable;
    myAutoDetectProxyRb.setSelected(httpConfigurable.USE_PROXY_PAC);
    myPacUrlCheckBox.setSelected(httpConfigurable.USE_PAC_URL);
    myPacUrlTextField.setText(httpConfigurable.PAC_URL);
    myUseHTTPProxyRb.setSelected(httpConfigurable.USE_HTTP_PROXY);
    myProxyAuthCheckBox.setSelected(httpConfigurable.PROXY_AUTHENTICATION);

    enableProxy(httpConfigurable.USE_HTTP_PROXY);

    myProxyLoginTextField.setText(httpConfigurable.PROXY_LOGIN);
    myProxyPasswordTextField.setText(httpConfigurable.getPlainProxyPassword());

    myProxyPortTextField.setText(Integer.toString(httpConfigurable.PROXY_PORT));
    myProxyHostTextField.setText(httpConfigurable.PROXY_HOST);
    myProxyExceptions.setText(httpConfigurable.PROXY_EXCEPTIONS);

    myRememberProxyPasswordCheckBox.setSelected(httpConfigurable.KEEP_PROXY_PASSWORD);
    mySocks.setSelected(httpConfigurable.PROXY_TYPE_IS_SOCKS);
    myHTTP.setSelected(!httpConfigurable.PROXY_TYPE_IS_SOCKS);

    final boolean showError = !StringUtil.isEmptyOrSpaces(httpConfigurable.LAST_ERROR);
    myErrorLabel.setVisible(showError);
    myErrorLabel.setText(showError ? errorText(httpConfigurable.LAST_ERROR) : "");

    final String oldStyleText =
        CommonProxy.getMessageFromProps(CommonProxy.getOldStyleProperties());
    myOtherWarning.setVisible(oldStyleText != null);
    if (oldStyleText != null) {
      myOtherWarning.setText(oldStyleText);
      myOtherWarning.setUI(new MultiLineLabelUI());
      myOtherWarning.setIcon(Messages.getWarningIcon());
    }
  }
 @Override
 public void setAnchor(@Nullable final JComponent anchor) {
   super.setAnchor(anchor);
   myHostLabel.setAnchor(anchor);
   myRepositoryLabel.setAnchor(anchor);
   myTokenLabel.setAnchor(anchor);
 }
  @Override
  protected JComponent createNorthPanel() {
    JBLabel descriptionLabel = new JBLabel("<html>" + makeDescription() + "</html>");

    final JComboBox repositorySelector =
        new JComboBox(ArrayUtil.toObjectArray(myRepositories, GitRepository.class));
    repositorySelector.setRenderer(new GitRepositoryComboboxListCellRenderer(repositorySelector));
    repositorySelector.setSelectedItem(myInitialRepository);
    repositorySelector.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            List<GitCommit> commits =
                myCommits.get((GitRepository) repositorySelector.getSelectedItem());
            myCommitListWithDiffPanel.setCommits(new ArrayList<GitCommit>(commits));
          }
        });

    JPanel repoSelectorPanel = new JPanel(new BorderLayout());
    JBLabel label = new JBLabel("Repository: ");
    label.setLabelFor(repoSelectorPanel);
    repoSelectorPanel.add(label, BorderLayout.WEST);
    repoSelectorPanel.add(repositorySelector);

    if (myRepositories.size() < 2) {
      repoSelectorPanel.setVisible(false);
    }

    JPanel northPanel = new JPanel(new BorderLayout());
    northPanel.add(descriptionLabel);
    northPanel.add(repoSelectorPanel, BorderLayout.SOUTH);
    return northPanel;
  }
  private void addErrorMessage(final FixableMessageInfo message, Icon icon) {
    if (message.myLinkText.length() > 0 || message.myAfterLinkText.length() > 0) {
      HyperlinkLabel warnLabel = new HyperlinkLabel();
      warnLabel.setOpaque(false);
      warnLabel.setHyperlinkText(
          message.myBeforeLinkText, message.myLinkText, message.myAfterLinkText);
      warnLabel.setIcon(icon);

      if (message.myQuickFix != null) {
        warnLabel.addHyperlinkListener(
            new HyperlinkListener() {
              public void hyperlinkUpdate(final HyperlinkEvent e) {
                if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                  message.myQuickFix.run();
                }
              }
            });
      }
      myErrorMessages.add(warnLabel);
    } else {
      JBLabel warnLabel = new JBLabel();
      warnLabel.setOpaque(false);
      warnLabel.setText(
          "<html><body>" + message.myBeforeLinkText.replace("\n", "<br>") + "</body></html>");
      warnLabel.setIcon(icon);
      myErrorMessages.add(warnLabel);
    }
    if (message.myAdditionalFixes != null && message.myAdditionalFixes.size() > 0) {
      JPanel fixesPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 5, 0));
      fixesPanel.setBorder(IdeBorderFactory.createEmptyBorder(3, 0, 10, 0));
      fixesPanel.setOpaque(false);
      fixesPanel.add(Box.createHorizontalStrut(icon.getIconWidth()));

      for (Pair<String, Runnable> pair : message.myAdditionalFixes) {
        HyperlinkLabel fixLabel = new HyperlinkLabel();
        fixLabel.setOpaque(false);
        fixLabel.setHyperlinkText(pair.getFirst());
        final Runnable fix = pair.getSecond();

        fixLabel.addHyperlinkListener(
            new HyperlinkListener() {
              @Override
              public void hyperlinkUpdate(HyperlinkEvent e) {
                if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                  fix.run();
                }
              }
            });
        fixesPanel.add(fixLabel);
      }
      myErrorMessages.add(fixesPanel);
    }
  }
  public ApkStep(ExportSignedPackageWizard wizard) {
    myWizard = wizard;
    myApkPathLabel.setLabelFor(myApkPathField);
    myProguardConfigFilePathLabel.setLabelFor(myProguardConfigFilePathField);

    myApkPathField
        .getButton()
        .addActionListener(
            new SaveFileListener(
                myContentPanel,
                myApkPathField,
                AndroidBundle.message("android.extract.package.choose.dest.apk")) {
              @Override
              protected String getDefaultLocation() {
                Module module = myWizard.getFacet().getModule();
                return getContentRootPath(module);
              }
            });

    myProguardConfigFilePathField
        .getButton()
        .addActionListener(
            new ActionListener() {
              @Override
              public void actionPerformed(ActionEvent e) {
                final String path = myProguardConfigFilePathField.getText().trim();
                VirtualFile defaultFile =
                    path != null && path.length() > 0
                        ? LocalFileSystem.getInstance().findFileByPath(path)
                        : null;
                final AndroidFacet facet = myWizard.getFacet();

                if (defaultFile == null && facet != null) {
                  defaultFile = AndroidRootUtil.getMainContentRoot(facet);
                }
                final VirtualFile file =
                    FileChooser.chooseFile(
                        myContentPanel,
                        FileChooserDescriptorFactory.createSingleFileNoJarsDescriptor(),
                        defaultFile);
                if (file != null) {
                  myProguardConfigFilePathField.setText(
                      FileUtil.toSystemDependentName(file.getPath()));
                }
              }
            });

    myProguardCheckBox.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            final boolean enabled = myProguardCheckBox.isSelected();
            myProguardConfigFilePathLabel.setEnabled(enabled);
            myProguardConfigFilePathField.setEnabled(enabled);
          }
        });
  }
 private void explainTrailingSpaces(
     @NotNull @EditorSettingsExternalizable.StripTrailingSpaces String stripTrailingSpaces) {
   if (EditorSettingsExternalizable.STRIP_TRAILING_SPACES_NONE.equals(stripTrailingSpaces)) {
     myStripTrailingSpacesExplanationLabel.setVisible(false);
     return;
   }
   myStripTrailingSpacesExplanationLabel.setVisible(true);
   boolean isVirtualSpace = myCbVirtualSpace.isSelected();
   String text;
   String virtSpaceText = myCbVirtualSpace.getText();
   if (isVirtualSpace) {
     text =
         "Trailing spaces will be trimmed even in the line under caret.<br>To disable trimming in that line uncheck the '<b>"
             + virtSpaceText
             + "</b>' above.";
   } else {
     text =
         "Trailing spaces will <b><font color=red>NOT</font></b> be trimmed in the line under caret.<br>To enable trimming in that line too check the '<b>"
             + virtSpaceText
             + "</b>' above.";
   }
   myStripTrailingSpacesExplanationLabel.setText(XmlStringUtil.wrapInHtml(text));
 }
  @Override
  public void _init() {
    if (myInited) return;
    Module module = myWizard.getFacet().getModule();

    PropertiesComponent properties = PropertiesComponent.getInstance(module.getProject());
    String lastModule = properties.getValue(ChooseModuleStep.MODULE_PROPERTY);
    String lastApkPath = properties.getValue(APK_PATH_PROPERTY);
    if (lastApkPath != null && module.getName().equals(lastModule)) {
      myApkPathField.setText(FileUtil.toSystemDependentName(lastApkPath));
    } else {
      String contentRootPath = getContentRootPath(module);
      if (contentRootPath != null) {
        String defaultPath =
            FileUtil.toSystemDependentName(contentRootPath + "/" + module.getName() + ".apk");
        myApkPathField.setText(defaultPath);
      }
    }

    final String runProguardPropValue = properties.getValue(RUN_PROGUARD_PROPERTY);
    boolean selected;

    if (runProguardPropValue != null) {
      selected = Boolean.parseBoolean(runProguardPropValue);
    } else {
      selected = false;
    }
    myProguardCheckBox.setSelected(selected);
    myProguardConfigFilePathLabel.setEnabled(selected);
    myProguardConfigFilePathField.setEnabled(selected);

    final String proguardCfgPath = properties.getValue(PROGUARD_CFG_PATH_PROPERTY);
    if (proguardCfgPath != null
        && LocalFileSystem.getInstance().refreshAndFindFileByPath(proguardCfgPath) != null) {
      myProguardConfigFilePathField.setText(FileUtil.toSystemDependentName(proguardCfgPath));
    } else {
      final VirtualFile proguardConfigFile =
          AndroidCompileUtil.getProguardConfigFile(myWizard.getFacet());
      if (proguardConfigFile != null) {
        myProguardConfigFilePathField.setText(
            FileUtil.toSystemDependentName(proguardConfigFile.getPath()));
      }
    }

    myInited = true;
  }
    @Override
    protected void paintComponent(Graphics g) {
      setFont(UIManager.getFont("Table.font"));
      g.setColor(myColor);

      int width = getWidth();

      if (isNarrow) {
        g.fillRect(0, 0, width - ROOT_INDICATOR_WHITE_WIDTH, myUi.getTable().getRowHeight());
        g.setColor(myBorderColor);
        g.fillRect(
            width - ROOT_INDICATOR_WHITE_WIDTH,
            0,
            ROOT_INDICATOR_WHITE_WIDTH,
            myUi.getTable().getRowHeight());
      } else {
        g.fillRect(0, 0, width, myUi.getTable().getRowHeight());
      }

      super.paintComponent(g);
    }
  public HTTPProxySettingsPanel(final HttpConfigurable httpConfigurable) {
    final ButtonGroup group = new ButtonGroup();
    group.add(myUseHTTPProxyRb);
    group.add(myAutoDetectProxyRb);
    group.add(myNoProxyRb);
    myNoProxyRb.setSelected(true);

    final ButtonGroup proxyTypeGroup = new ButtonGroup();
    proxyTypeGroup.add(myHTTP);
    proxyTypeGroup.add(mySocks);
    myHTTP.setSelected(true);

    myProxyExceptions.setBorder(UIUtil.getTextFieldBorder());

    final Boolean property = Boolean.getBoolean(JavaProxyProperty.USE_SYSTEM_PROXY);
    mySystemProxyDefined.setVisible(Boolean.TRUE.equals(property));
    if (Boolean.TRUE.equals(property)) {
      mySystemProxyDefined.setIcon(Messages.getWarningIcon());
      mySystemProxyDefined.setFont(mySystemProxyDefined.getFont().deriveFont(Font.BOLD));
      mySystemProxyDefined.setUI(new MultiLineLabelUI());
    }

    myProxyAuthCheckBox.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            enableProxyAuthentication(myProxyAuthCheckBox.isSelected());
          }
        });
    myPacUrlCheckBox.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            myPacUrlTextField.setEnabled(myPacUrlCheckBox.isSelected());
          }
        });

    final ActionListener listener =
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            enableProxy(myUseHTTPProxyRb.isSelected());
          }
        };
    myUseHTTPProxyRb.addActionListener(listener);
    myAutoDetectProxyRb.addActionListener(listener);
    myNoProxyRb.addActionListener(listener);
    myHttpConfigurable = httpConfigurable;

    myClearPasswordsButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            myHttpConfigurable.clearGenericPasswords();
            Messages.showMessageDialog(
                myMainPanel,
                "Proxy passwords were cleared.",
                "Auto-detected proxy",
                Messages.getInformationIcon());
          }
        });

    if (HttpConfigurable.getInstance() != null) {
      myCheckButton.addActionListener(
          new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
              final String title = "Check Proxy Settings";
              final String answer =
                  Messages.showInputDialog(
                      myMainPanel,
                      "Warning: your settings will be saved.\n\nEnter any URL to check connection to:",
                      title,
                      Messages.getQuestionIcon(),
                      "http://",
                      null);
              if (!StringUtil.isEmptyOrSpaces(answer)) {
                apply();
                final HttpConfigurable instance = HttpConfigurable.getInstance();
                final AtomicReference<IOException> exc = new AtomicReference<IOException>();
                myCheckButton.setEnabled(false);
                myCheckButton.setText("Check connection (in progress...)");
                myConnectionCheckInProgress = true;
                final Application application = ApplicationManager.getApplication();
                application.executeOnPooledThread(
                    new Runnable() {
                      @Override
                      public void run() {
                        HttpURLConnection connection = null;
                        try {
                          // already checked for null above
                          //noinspection ConstantConditions
                          connection = instance.openHttpConnection(answer);
                          connection.setReadTimeout(3 * 1000);
                          connection.setConnectTimeout(3 * 1000);
                          connection.connect();
                          final int code = connection.getResponseCode();
                          if (HttpURLConnection.HTTP_OK != code) {
                            exc.set(new IOException("Error code: " + code));
                          }
                        } catch (IOException e1) {
                          exc.set(e1);
                        } finally {
                          if (connection != null) {
                            connection.disconnect();
                          }
                        }
                        //noinspection SSBasedInspection
                        SwingUtilities.invokeLater(
                            new Runnable() {
                              @Override
                              public void run() {
                                myConnectionCheckInProgress = false;
                                reset(); // since password might have been set
                                Component parent = null;
                                if (myMainPanel.isShowing()) {
                                  parent = myMainPanel;
                                  myCheckButton.setText("Check connection");
                                  myCheckButton.setEnabled(canEnableConnectionCheck());
                                } else {
                                  final IdeFrame frame =
                                      IdeFocusManager.findInstance().getLastFocusedFrame();
                                  if (frame == null) {
                                    return;
                                  }
                                  parent = frame.getComponent();
                                }
                                //noinspection ThrowableResultOfMethodCallIgnored
                                final IOException exception = exc.get();
                                if (exception == null) {
                                  Messages.showMessageDialog(
                                      parent,
                                      "Connection successful",
                                      title,
                                      Messages.getInformationIcon());
                                } else {
                                  final String message = exception.getMessage();
                                  if (instance.USE_HTTP_PROXY) {
                                    instance.LAST_ERROR = message;
                                  }
                                  Messages.showErrorDialog(parent, errorText(message));
                                }
                              }
                            });
                      }
                    });
              }
            }
          });
    } else {
      myCheckButton.setVisible(false);
    }
  }
 @Override
 public void setAnchor(@Nullable final JComponent anchor) {
   super.setAnchor(anchor);
   myProjectLabel.setAnchor(anchor);
   myFilterLabel.setAnchor(anchor);
 }
Exemple #11
0
 public FormBuilder addTooltip(final String text) {
   final JBLabel label = new JBLabel(text, UIUtil.ComponentStyle.SMALL, UIUtil.FontColor.BRIGHTER);
   label.setBorder(new EmptyBorder(0, 10, 0, 0));
   return addComponentToRightColumn(label, 1);
 }
  /** 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);
    }
  }
 @NotNull
 @Override
 protected JComponent createComponent(@NotNull CreationContext creationContext) {
   JPanel panel = new JPanel(new GridBagLayout());
   {
     GridBagConstraints c =
         new GridBagConstraints(
             0,
             0,
             1,
             1,
             0.0,
             0.0,
             GridBagConstraints.EAST,
             GridBagConstraints.NONE,
             new Insets(UIUtil.DEFAULT_VGAP, 0, 0, UIUtil.DEFAULT_HGAP),
             0,
             0);
     myLabel.setDisplayedMnemonic('C');
     myLabel.setHorizontalAlignment(SwingConstants.RIGHT);
     myLabel.setLabelFor(myConfigFileTextFieldWithBrowseButton.getTextField());
     panel.add(myLabel, c);
   }
   {
     GridBagConstraints c =
         new GridBagConstraints(
             1,
             0,
             1,
             1,
             1.0,
             0.0,
             GridBagConstraints.WEST,
             GridBagConstraints.HORIZONTAL,
             new Insets(UIUtil.DEFAULT_VGAP, 0, 0, 0),
             0,
             0);
     final Project project = creationContext.getProject();
     final FileChooserDescriptor descriptor =
         new FileChooserDescriptor(true, false, false, false, false, false) {
           @Override
           public boolean isFileVisible(VirtualFile file, boolean showHiddenFiles) {
             boolean visible = super.isFileVisible(file, showHiddenFiles);
             if (visible && !file.isDirectory() && !showHiddenFiles) {
               visible = JstdConfigFileUtils.isJstdConfigFile(file);
             }
             return visible;
           }
         };
     final JTextField configFileTextField = myConfigFileTextFieldWithBrowseButton.getTextField();
     FileChooserFactory.getInstance()
         .installFileCompletion(configFileTextField, descriptor, false, null);
     myConfigFileTextFieldWithBrowseButton.addActionListener(
         new ActionListener() {
           @Override
           public void actionPerformed(ActionEvent e) {
             PsiFile initialPsiFile = getConfigFile(project);
             TreeFileChooserDialog fileChooser =
                 new TreeFileChooserDialog(
                     project,
                     "Select JsTestDriver configuration file",
                     initialPsiFile,
                     JstdConfigFileType.INSTANCE,
                     new TreeFileChooser.PsiFileFilter() {
                       @Override
                       public boolean accept(PsiFile psiFile) {
                         return true;
                       }
                     },
                     false,
                     false);
             boolean jstdConfigFilesExists = JstdSettingsUtil.areJstdConfigFilesInProject(project);
             if (jstdConfigFilesExists) {
               fileChooser.selectSearchByNameTab();
             }
             fileChooser.showDialog();
             PsiFile psiFile = fileChooser.getSelectedFile();
             if (psiFile != null) {
               VirtualFile vFile = psiFile.getVirtualFile();
               if (vFile != null) {
                 String path = FileUtil.toSystemDependentName(vFile.getPath());
                 configFileTextField.setText(path);
               }
             }
           }
         });
     panel.add(myConfigFileTextFieldWithBrowseButton, c);
   }
   SwingUtils.addGreedyBottomRow(panel);
   return panel;
 }
  public DirDiffPanel(DirDiffTableModel model, DirDiffWindow wnd) {
    myModel = model;
    myDiffWindow = wnd;
    mySourceDirField.setText(model.getSourceDir().getPath());
    myTargetDirField.setText(model.getTargetDir().getPath());
    mySourceDirField.setBorder(JBUI.Borders.emptyRight(8));
    myTargetDirField.setBorder(JBUI.Borders.emptyRight(12));
    mySourceDirLabel.setIcon(model.getSourceDir().getIcon());
    myTargetDirLabel.setIcon(model.getTargetDir().getIcon());
    myTargetDirLabel.setBorder(JBUI.Borders.emptyLeft(8));
    myModel.setTable(myTable);
    myModel.setPanel(this);
    Disposer.register(this, myModel);
    myTable.setModel(myModel);
    new TableSpeedSearch(myTable);

    final DirDiffTableCellRenderer renderer = new DirDiffTableCellRenderer();
    myTable.setExpandableItemsEnabled(false);
    myTable.setDefaultRenderer(Object.class, renderer);
    myTable.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    final Project project = myModel.getProject();
    myTable
        .getSelectionModel()
        .addListSelectionListener(
            new ListSelectionListener() {
              @Override
              public void valueChanged(ListSelectionEvent e) {
                final int lastIndex = e.getLastIndex();
                final int firstIndex = e.getFirstIndex();
                final DirDiffElementImpl last = myModel.getElementAt(lastIndex);
                final DirDiffElementImpl first = myModel.getElementAt(firstIndex);
                if (last == null || first == null) {
                  update(false);
                  return;
                }
                if (last.isSeparator()) {
                  final int ind = lastIndex + ((lastIndex < firstIndex) ? 1 : -1);
                  myTable.getSelectionModel().addSelectionInterval(ind, ind);
                } else if (first.isSeparator()) {
                  final int ind = firstIndex + ((firstIndex < lastIndex) ? 1 : -1);
                  myTable.getSelectionModel().addSelectionInterval(ind, ind);
                } else {
                  update(false);
                }
                myDiffWindow.setTitle(myModel.getTitle());
              }
            });
    if (model.isOperationsEnabled()) {
      new AnAction("Change diff operation") {
        @Override
        public void actionPerformed(AnActionEvent e) {
          changeOperationForSelection();
        }
      }.registerCustomShortcutSet(CustomShortcutSet.fromString("SPACE"), myTable);
      new ClickListener() {
        @Override
        public boolean onClick(@NotNull MouseEvent e, int clickCount) {
          if (e.getButton() == MouseEvent.BUTTON3) return false;
          if (myTable.getRowCount() > 0) {
            final int row = myTable.rowAtPoint(e.getPoint());
            final int col = myTable.columnAtPoint(e.getPoint());

            if (row != -1 && col == ((myTable.getColumnCount() - 1) / 2)) {
              changeOperationForSelection();
            }
          }
          return true;
        }
      }.installOn(myTable);
    }
    myTable.addKeyListener(
        new KeyAdapter() {
          @Override
          public void keyPressed(KeyEvent e) {
            final int keyCode = e.getKeyCode();

            int row;
            if (keyCode == KeyEvent.VK_DOWN) {
              row = getNextRow();
            } else if (keyCode == KeyEvent.VK_UP) {
              row = getPrevRow();
            } else {
              row = -1;
            }

            if (row != -1) {
              selectRow(row, e.isShiftDown());
              e.consume();
            }
          }
        });
    final TableColumnModel columnModel = myTable.getColumnModel();
    final TableColumn operationColumn =
        columnModel.getColumn((columnModel.getColumnCount() - 1) / 2);
    operationColumn.setMaxWidth(JBUI.scale(25));
    operationColumn.setMinWidth(JBUI.scale(25));
    for (int i = 0; i < columnModel.getColumnCount(); i++) {
      final String name = myModel.getColumnName(i);
      final TableColumn column = columnModel.getColumn(i);
      if (DirDiffTableModel.COLUMN_DATE.equals(name)) {
        column.setMaxWidth(JBUI.scale(90));
        column.setMinWidth(JBUI.scale(90));
      } else if (DirDiffTableModel.COLUMN_SIZE.equals(name)) {
        column.setMaxWidth(JBUI.scale(120));
        column.setMinWidth(JBUI.scale(120));
      }
    }
    final DirDiffToolbarActions actions = new DirDiffToolbarActions(myModel, myDiffPanel);
    final ActionManager actionManager = ActionManager.getInstance();
    final ActionToolbar toolbar = actionManager.createActionToolbar("DirDiff", actions, true);
    registerCustomShortcuts(actions, myTable);
    myToolBarPanel.add(toolbar.getComponent(), BorderLayout.CENTER);
    final JBLabel label =
        new JBLabel(
            "Use Space button or mouse click to change operation for the selected elements."
                + " Enter to perform.",
            SwingConstants.CENTER);
    label.setForeground(UIUtil.getInactiveTextColor());
    UIUtil.applyStyle(UIUtil.ComponentStyle.MINI, label);
    DataManager.registerDataProvider(myFilesPanel, this);
    myTable.addMouseListener(
        new PopupHandler() {
          @Override
          public void invokePopup(Component comp, int x, int y) {
            final JPopupMenu popupMenu =
                actionManager
                    .createActionPopupMenu(
                        "DirDiffPanel", (ActionGroup) actionManager.getAction("DirDiffMenu"))
                    .getComponent();
            popupMenu.show(comp, x, y);
          }
        });
    myFilesPanel.add(label, BorderLayout.SOUTH);
    final JBLoadingPanel loadingPanel = new JBLoadingPanel(new BorderLayout(), wnd.getDisposable());
    loadingPanel.addListener(
        new JBLoadingPanelListener.Adapter() {
          boolean showHelp = true;

          @Override
          public void onLoadingFinish() {
            if (showHelp && myModel.isOperationsEnabled() && myModel.getRowCount() > 0) {
              final long count =
                  PropertiesComponent.getInstance().getOrInitLong("dir.diff.space.button.info", 0);
              if (count < 3) {
                JBPopupFactory.getInstance()
                    .createBalloonBuilder(new JLabel(" Use Space button to change operation"))
                    .setFadeoutTime(5000)
                    .setContentInsets(JBUI.insets(15))
                    .createBalloon()
                    .show(
                        new RelativePoint(myTable, new Point(myTable.getWidth() / 2, 0)),
                        Balloon.Position.above);
                PropertiesComponent.getInstance()
                    .setValue("dir.diff.space.button.info", String.valueOf(count + 1));
              }
            }
            showHelp = false;
          }
        });
    loadingPanel.add(myComponent, BorderLayout.CENTER);
    myTable.putClientProperty(myModel.DECORATOR, loadingPanel);
    myTable.addComponentListener(
        new ComponentAdapter() {
          @Override
          public void componentShown(ComponentEvent e) {
            myTable.removeComponentListener(this);
            myModel.reloadModel(false);
          }
        });
    myRootPanel.removeAll();
    myRootPanel.add(loadingPanel, BorderLayout.CENTER);
    myFilter =
        new FilterComponent("dir.diff.filter", 15, false) {
          @Override
          public void filter() {
            fireFilterUpdated();
          }

          @Override
          protected void onEscape(KeyEvent e) {
            e.consume();
            focusTable();
          }

          @Override
          protected JComponent getPopupLocationComponent() {
            return UIUtil.findComponentOfType(
                super.getPopupLocationComponent(), JTextComponent.class);
          }
        };

    myModel.addModelListener(
        new DirDiffModelListener() {
          @Override
          public void updateStarted() {
            myFilter.setEnabled(false);
          }

          @Override
          public void updateFinished() {
            myFilter.setEnabled(true);
          }
        });
    myFilter.getTextEditor().setColumns(10);
    myFilter.setFilter(myModel.getSettings().getFilter());
    // oldFilter = myFilter.getText();
    oldFilter = myFilter.getFilter();
    myFilterPanel.add(myFilter, BorderLayout.CENTER);
    myFilterLabel.setLabelFor(myFilter);
    final Callable<DiffElement> srcChooser = myModel.getSourceDir().getElementChooser(project);
    final Callable<DiffElement> trgChooser = myModel.getTargetDir().getElementChooser(project);
    mySourceDirField.setEditable(false);
    myTargetDirField.setEditable(false);

    if (srcChooser != null && myModel.getSettings().enableChoosers) {
      mySourceDirField.setButtonEnabled(true);
      mySourceDirField.addActionListener(
          new AbstractAction() {
            @Override
            public void actionPerformed(ActionEvent e) {
              try {
                final Callable<DiffElement> chooser =
                    myModel.getSourceDir().getElementChooser(project);
                if (chooser == null) return;
                final DiffElement newElement = chooser.call();
                if (newElement != null) {
                  if (!StringUtil.equals(mySourceDirField.getText(), newElement.getPath())) {
                    myModel.setSourceDir(newElement);
                    mySourceDirField.setText(newElement.getPath());
                    String shortcutsText =
                        KeymapUtil.getShortcutsText(
                            RefreshDirDiffAction.REFRESH_SHORTCUT.getShortcuts());
                    myModel.clearWithMessage(
                        "Source or Target has been changed."
                            + " Please run Refresh ("
                            + shortcutsText
                            + ")");
                  }
                }
              } catch (Exception ignored) {
              }
            }
          });
    } else {
      Dimension preferredSize = mySourceDirField.getPreferredSize();
      mySourceDirField.setButtonEnabled(false);
      mySourceDirField.getButton().setVisible(false);
      mySourceDirField.setPreferredSize(preferredSize);
    }

    if (trgChooser != null && myModel.getSettings().enableChoosers) {
      myTargetDirField.setButtonEnabled(true);
      myTargetDirField.addActionListener(
          new AbstractAction() {
            @Override
            public void actionPerformed(ActionEvent e) {
              try {
                final Callable<DiffElement> chooser =
                    myModel.getTargetDir().getElementChooser(project);
                if (chooser == null) return;
                final DiffElement newElement = chooser.call();
                if (newElement != null) {
                  myModel.setTargetDir(newElement);
                  myTargetDirField.setText(newElement.getPath());
                }
              } catch (Exception ignored) {
              }
            }
          });
    } else {
      Dimension preferredSize = myTargetDirField.getPreferredSize();
      myTargetDirField.setButtonEnabled(false);
      myTargetDirField.getButton().setVisible(false);
      myTargetDirField.setPreferredSize(preferredSize);
    }

    myDiffRequestProcessor = new MyDiffRequestProcessor(project);
    Disposer.register(this, myDiffRequestProcessor);
    myDiffPanel.add(myDiffRequestProcessor.getComponent(), BorderLayout.CENTER);

    myPrevNextDifferenceIterable = new MyPrevNextDifferenceIterable();
  }
  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);
  }
 @Override
 public void setAnchor(@Nullable JComponent anchor) {
   super.setAnchor(anchor);
   myLabel.setAnchor(anchor);
 }
  public CreateXmlResourceDialog(
      @NotNull Module module,
      @NotNull ResourceType resourceType,
      @Nullable String predefinedName,
      @Nullable String predefinedValue,
      boolean chooseName,
      @Nullable VirtualFile defaultFile) {
    super(module.getProject());
    myResourceType = resourceType;

    if (predefinedName != null && predefinedName.length() > 0) {
      if (!chooseName) {
        myNameLabel.setVisible(false);
        myNameField.setVisible(false);
      }
      myNameField.setText(predefinedName);
    }

    if (predefinedValue != null && predefinedValue.length() > 0) {
      myValueLabel.setVisible(false);
      myValueField.setVisible(false);
      myValueField.setText(predefinedValue);
    }
    final Set<Module> modulesSet = new HashSet<Module>();
    modulesSet.add(module);

    for (AndroidFacet depFacet : AndroidUtils.getAllAndroidDependencies(module, true)) {
      modulesSet.add(depFacet.getModule());
    }

    assert modulesSet.size() > 0;

    if (modulesSet.size() == 1) {
      myModule = module;
      myModuleLabel.setVisible(false);
      myModuleCombo.setVisible(false);
    } else {
      myModule = null;

      final Module[] modules = modulesSet.toArray(new Module[modulesSet.size()]);
      Arrays.sort(
          modules,
          new Comparator<Module>() {
            @Override
            public int compare(Module m1, Module m2) {
              return m1.getName().compareTo(m2.getName());
            }
          });

      myModuleCombo.setModel(new DefaultComboBoxModel(modules));
      myModuleCombo.setSelectedItem(module);
      myModuleCombo.setRenderer(new ModuleListCellRendererWrapper(myModuleCombo.getRenderer()));
    }

    if (defaultFile == null) {
      final String defaultFileName = AndroidResourceUtil.getDefaultResourceFileName(resourceType);

      if (defaultFileName != null) {
        myFileNameCombo.getEditor().setItem(defaultFileName);
      }
    }
    myDirectoriesList = new CheckBoxList();
    myDirectoriesLabel.setLabelFor(myDirectoriesList);
    final ToolbarDecorator decorator = ToolbarDecorator.createDecorator(myDirectoriesList);

    decorator.setEditAction(null);
    decorator.disableUpDownActions();

    decorator.setAddAction(
        new AnActionButtonRunnable() {
          @Override
          public void run(AnActionButton button) {
            doAddNewDirectory();
          }
        });

    decorator.setRemoveAction(
        new AnActionButtonRunnable() {
          @Override
          public void run(AnActionButton button) {
            doDeleteDirectory();
          }
        });

    final AnActionButton selectAll =
        new AnActionButton("Select All", null, PlatformIcons.SELECT_ALL_ICON) {
          @Override
          public void actionPerformed(AnActionEvent e) {
            doSelectAllDirs();
          }
        };
    decorator.addExtraAction(selectAll);

    final AnActionButton unselectAll =
        new AnActionButton("Unselect All", null, PlatformIcons.UNSELECT_ALL_ICON) {
          @Override
          public void actionPerformed(AnActionEvent e) {
            doUnselectAllDirs();
          }
        };
    decorator.addExtraAction(unselectAll);

    myDirectoriesPanel.add(decorator.createPanel());

    updateDirectories(true);

    myModuleCombo.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            updateDirectories(true);
          }
        });
    final JCheckBox valuesCheckBox = myCheckBoxes.get(SdkConstants.FD_RES_VALUES);
    if (valuesCheckBox != null) {
      valuesCheckBox.setSelected(true);
    }

    if (defaultFile != null) {
      resetFromFile(defaultFile, module.getProject());
    }
    init();
  }
  public void reset() {
    EditorSettingsExternalizable editorSettings = EditorSettingsExternalizable.getInstance();
    CodeInsightSettings codeInsightSettings = CodeInsightSettings.getInstance();
    UISettings uiSettings = UISettings.getInstance();
    VcsApplicationSettings vcsSettings = VcsApplicationSettings.getInstance();

    // Display

    myCbSmoothScrolling.setSelected(editorSettings.isSmoothScrolling());

    // Brace highlighting

    myCbHighlightBraces.setSelected(codeInsightSettings.HIGHLIGHT_BRACES);
    myCbHighlightScope.setSelected(codeInsightSettings.HIGHLIGHT_SCOPE);
    myCbHighlightIdentifierUnderCaret.setSelected(
        codeInsightSettings.HIGHLIGHT_IDENTIFIER_UNDER_CARET);

    // Virtual space

    myCbUseSoftWrapsAtEditor.setSelected(
        editorSettings.isUseSoftWraps(SoftWrapAppliancePlaces.MAIN_EDITOR));
    myCbUseCustomSoftWrapIndent.setSelected(editorSettings.isUseCustomSoftWrapIndent());
    myCustomSoftWrapIndent.setText(Integer.toString(editorSettings.getCustomSoftWrapIndent()));
    myCbShowSoftWrapsOnlyOnCaretLine.setSelected(!editorSettings.isAllSoftWrapsShown());
    updateSoftWrapSettingsRepresentation();

    myCbVirtualSpace.setSelected(editorSettings.isVirtualSpace());
    myCbCaretInsideTabs.setSelected(editorSettings.isCaretInsideTabs());
    myCbVirtualPageAtBottom.setSelected(editorSettings.isAdditionalPageAtBottom());

    // Limits
    myClipboardContentLimitTextField.setText(Integer.toString(uiSettings.MAX_CLIPBOARD_CONTENTS));

    // Strip trailing spaces on save

    String stripTrailingSpaces = editorSettings.getStripTrailingSpaces();
    if (EditorSettingsExternalizable.STRIP_TRAILING_SPACES_NONE.equals(stripTrailingSpaces)) {
      myStripTrailingSpacesCombo.setSelectedItem(STRIP_NONE);
    } else if (EditorSettingsExternalizable.STRIP_TRAILING_SPACES_CHANGED.equals(
        stripTrailingSpaces)) {
      myStripTrailingSpacesCombo.setSelectedItem(STRIP_CHANGED);
    } else if (EditorSettingsExternalizable.STRIP_TRAILING_SPACES_WHOLE.equals(
        stripTrailingSpaces)) {
      myStripTrailingSpacesCombo.setSelectedItem(STRIP_ALL);
    }
    explainTrailingSpaces(stripTrailingSpaces);

    myCbEnsureBlankLineBeforeCheckBox.setSelected(editorSettings.isEnsureNewLineAtEOF());
    myCbShowQuickDocOnMouseMove.setSelected(editorSettings.isShowQuickDocOnMouseOverElement());
    myQuickDocDelayTextField.setText(
        Long.toString(editorSettings.getQuickDocOnMouseOverElementDelayMillis()));
    myQuickDocDelayTextField.setEnabled(editorSettings.isShowQuickDocOnMouseOverElement());
    myQuickDocDelayLabel.setEnabled(editorSettings.isShowQuickDocOnMouseOverElement());

    // Advanced mouse
    myCbEnableDnD.setSelected(editorSettings.isDndEnabled());
    myCbEnableWheelFontChange.setSelected(editorSettings.isWheelFontChangeEnabled());
    myCbHonorCamelHumpsWhenSelectingByClicking.setSelected(
        editorSettings.isMouseClickSelectionHonorsCamelWords());

    myRbPreferMovingCaret.setSelected(editorSettings.isRefrainFromScrolling());
    myRbPreferScrolling.setSelected(!editorSettings.isRefrainFromScrolling());

    myRecentFilesLimitField.setText(Integer.toString(uiSettings.RECENT_FILES_LIMIT));

    myCbRenameLocalVariablesInplace.setSelected(editorSettings.isVariableInplaceRenameEnabled());
    myPreselectCheckBox.setSelected(editorSettings.isPreselectRename());
    myShowInlineDialogForCheckBox.setSelected(editorSettings.isShowInlineLocalDialog());

    myShowNotificationAfterReformatCodeCheckBox.setSelected(
        editorSettings.getOptions().SHOW_NOTIFICATION_AFTER_REFORMAT_CODE_ACTION);
    myShowNotificationAfterOptimizeImportsCheckBox.setSelected(
        editorSettings.getOptions().SHOW_NOTIFICATION_AFTER_OPTIMIZE_IMPORTS_ACTION);

    myShowLSTInGutterCheckBox.setSelected(vcsSettings.SHOW_LST_GUTTER_MARKERS);
    myShowWhitespacesModificationsInLSTGutterCheckBox.setSelected(
        vcsSettings.SHOW_WHITESPACES_IN_LST);
    myShowWhitespacesModificationsInLSTGutterCheckBox.setEnabled(
        myShowLSTInGutterCheckBox.isSelected());

    myErrorHighlightingPanel.reset();

    RichCopySettings settings = RichCopySettings.getInstance();
    myCbEnableRichCopyByDefault.setSelected(settings.isEnabled());
    myRichCopyColorSchemeComboBox.removeAllItems();
    EditorColorsScheme[] schemes = EditorColorsManager.getInstance().getAllSchemes();
    myRichCopyColorSchemeComboBox.addItem(RichCopySettings.ACTIVE_GLOBAL_SCHEME_MARKER);
    for (EditorColorsScheme scheme : schemes) {
      myRichCopyColorSchemeComboBox.addItem(scheme.getName());
    }
    String toSelect = settings.getSchemeName();
    if (!StringUtil.isEmpty(toSelect)) {
      myRichCopyColorSchemeComboBox.setSelectedItem(toSelect);
    }
  }
  public OutOfMemoryDialog(MemoryKind memoryKind) {
    super(false);
    myMemoryKind = memoryKind;
    setTitle(DiagnosticBundle.message("diagnostic.out.of.memory.title"));

    myMessageLabel.setIcon(Messages.getErrorIcon());
    myMessageLabel.setText(
        DiagnosticBundle.message(
            "diagnostic.out.of.memory.error",
            memoryKind == MemoryKind.HEAP
                ? VMOptions.XMX_OPTION_NAME
                : memoryKind == MemoryKind.PERM_GEN
                    ? VMOptions.PERM_GEN_OPTION_NAME
                    : VMOptions.CODE_CACHE_OPTION_NAME,
            ApplicationNamesInfo.getInstance().getProductName()));

    final String path = VMOptions.getSettingsFilePath();
    if (path != null) {
      mySettingsFileHintLabel.setText(
          DiagnosticBundle.message("diagnostic.out.of.memory.willBeSavedTo", path));
    } else {
      mySettingsFileHintLabel.setVisible(false);
    }

    myIgnoreAction =
        new AbstractAction(DiagnosticBundle.message("diagnostic.out.of.memory.ignore")) {
          public void actionPerformed(ActionEvent e) {
            save();
            close(0);
          }
        };

    myShutdownAction =
        new AbstractAction(DiagnosticBundle.message("diagnostic.out.of.memory.shutdown")) {
          public void actionPerformed(ActionEvent e) {
            save();
            System.exit(0);
          }
        };
    myShutdownAction.putValue(DialogWrapper.DEFAULT_ACTION, true);

    configControls(
        VMOptions.XMX_OPTION_NAME,
        VMOptions.readXmx(),
        memoryKind == MemoryKind.HEAP,
        myHeapSizeLabel,
        myHeapSizeField,
        myHeapUnitsLabel,
        myHeapCurrentValueLabel);

    configControls(
        VMOptions.PERM_GEN_OPTION_NAME,
        VMOptions.readMaxPermGen(),
        memoryKind == MemoryKind.PERM_GEN,
        myPermGenSizeLabel,
        myPermGenSizeField,
        myPermGenUnitsLabel,
        myPermGenCurrentValueLabel);

    configControls(
        VMOptions.CODE_CACHE_OPTION_NAME,
        VMOptions.readCodeCache(),
        memoryKind == MemoryKind.CODE_CACHE,
        myCodeCacheSizeLabel,
        myCodeCacheSizeField,
        myCodeCacheUnitsLabel,
        myCodeCacheCurrentValueLabel);

    init();
  }
  public GoToHashOrRefPopup(
      @NotNull final Project project,
      @NotNull Collection<VcsRef> variants,
      Collection<VirtualFile> roots,
      @NotNull Function<String, Future> onSelectedHash,
      @NotNull Function<VcsRef, Future> onSelectedRef,
      @NotNull VcsLogColorManager colorManager,
      @NotNull Comparator<VcsRef> comparator) {
    myOnSelectedHash = onSelectedHash;
    myOnSelectedRef = onSelectedRef;
    myTextField =
        new TextFieldWithProgress<VcsRef>(
            project,
            new VcsRefCompletionProvider(project, variants, roots, colorManager, comparator)) {
          @Override
          public void onOk() {
            if (myFuture == null) {
              final Future future =
                  ((mySelectedRef == null || (!mySelectedRef.getName().equals(getText().trim())))
                      ? myOnSelectedHash.fun(getText().trim())
                      : myOnSelectedRef.fun(mySelectedRef));
              myFuture = future;
              showProgress();
              ApplicationManager.getApplication()
                  .executeOnPooledThread(
                      new Runnable() {
                        @Override
                        public void run() {
                          try {
                            future.get();
                            okPopup();
                          } catch (CancellationException ex) {
                            cancelPopup();
                          } catch (InterruptedException ex) {
                            cancelPopup();
                          } catch (ExecutionException ex) {
                            LOG.error(ex);
                            cancelPopup();
                          }
                        }
                      });
            }
          }
        };
    myTextField.setAlignmentX(Component.LEFT_ALIGNMENT);

    JBLabel label = new JBLabel("Enter hash or branch/tag name:");
    label.setFont(UIUtil.getLabelFont().deriveFont(Font.BOLD));
    label.setAlignmentX(Component.LEFT_ALIGNMENT);

    JPanel panel = new JPanel();
    BoxLayout layout = new BoxLayout(panel, BoxLayout.PAGE_AXIS);
    panel.setLayout(layout);
    panel.add(label);
    panel.add(myTextField);
    panel.setBorder(new EmptyBorder(2, 2, 2, 2));

    myPopup =
        JBPopupFactory.getInstance()
            .createComponentPopupBuilder(panel, myTextField.getPreferableFocusComponent())
            .setCancelOnClickOutside(true)
            .setCancelOnWindowDeactivation(true)
            .setCancelKeyEnabled(true)
            .setRequestFocus(true)
            .createPopup();
    myPopup.addListener(
        new JBPopupListener.Adapter() {
          @Override
          public void onClosed(LightweightWindowEvent event) {
            if (!event.isOk()) {
              if (myFuture != null) {
                myFuture.cancel(true);
              }
            }
            myFuture = null;
            myTextField.hideProgress();
          }
        });
  }
 @Override
 public void setAnchor(@Nullable JComponent anchor) {
   super.setAnchor(anchor);
   myLabel.setAnchor(anchor);
   myTestCaseRunSettingsSection.setAnchor(anchor);
 }
 private void setDefaultComponentsEnabledState(boolean selected) {
   myDestBranchTextField.setEnabled(selected);
   myComment.setEnabled(selected);
   myRemoteSelector.setEnabled(selected);
 }
  @NotNull
  @Override
  protected JComponent createComponent(@NotNull CreationContext creationContext) {
    JPanel panel = new JPanel(new GridBagLayout());
    {
      GridBagConstraints c =
          new GridBagConstraints(
              0,
              0,
              2,
              1,
              0.0,
              0.0,
              GridBagConstraints.NORTHWEST,
              GridBagConstraints.HORIZONTAL,
              new Insets(0, 0, 0, 0),
              0,
              0);
      JComponent testCaseComponent = myTestCaseRunSettingsSection.getComponent(creationContext);
      panel.add(testCaseComponent, c);
    }

    {
      myLabel.setDisplayedMnemonic('M');
      myLabel.setLabelFor(myTestNameTextField);
      myLabel.setHorizontalAlignment(SwingConstants.RIGHT);
      GridBagConstraints c =
          new GridBagConstraints(
              0,
              1,
              1,
              1,
              0.0,
              0.0,
              GridBagConstraints.WEST,
              GridBagConstraints.NONE,
              new Insets(UIUtil.DEFAULT_VGAP, 0, 0, UIUtil.DEFAULT_HGAP),
              0,
              0);
      panel.add(myLabel, c);
    }
    {
      GridBagConstraints c =
          new GridBagConstraints(
              1,
              1,
              1,
              1,
              1.0,
              0.0,
              GridBagConstraints.WEST,
              GridBagConstraints.HORIZONTAL,
              new Insets(UIUtil.DEFAULT_VGAP, 0, 0, 0),
              0,
              0);
      panel.add(myTestNameTextField, c);
      myLabel.setLabelFor(myTestNameTextField);
    }
    SwingUtils.addGreedyBottomRow(panel);
    return panel;
  }