/** Init components */
  private void initListeners() {
    FileChooserDescriptor fcd = FileChooserDescriptorFactory.createSingleFolderDescriptor();
    fcd.setShowFileSystemRoots(true);
    fcd.setTitle(GitBundle.getString("clone.destination.directory.title"));
    fcd.setDescription(GitBundle.getString("clone.destination.directory.description"));
    fcd.setHideIgnored(false);
    myParentDirectory.addActionListener(
        new ComponentWithBrowseButton.BrowseFolderActionListener<JTextField>(
            fcd.getTitle(),
            fcd.getDescription(),
            myParentDirectory,
            myProject,
            fcd,
            TextComponentAccessor.TEXT_FIELD_WHOLE_TEXT) {
          @Override
          protected VirtualFile getInitialFile() {
            // suggest project base directory only if nothing is typed in the component.
            String text = getComponentText();
            if (text.length() == 0) {
              VirtualFile file = myProject.getBaseDir();
              if (file != null) {
                return file;
              }
            }
            return super.getInitialFile();
          }
        });

    final DocumentListener updateOkButtonListener =
        new DocumentAdapter() {
          @Override
          protected void textChanged(DocumentEvent e) {
            updateButtons();
          }
        };
    myParentDirectory.getChildComponent().getDocument().addDocumentListener(updateOkButtonListener);
    String parentDir = GitRememberedInputs.getInstance().getCloneParentDir();
    if (StringUtil.isEmptyOrSpaces(parentDir)) {
      parentDir = ProjectUtil.getBaseDir();
    }
    myParentDirectory.setText(parentDir);

    myDirectoryName.getDocument().addDocumentListener(updateOkButtonListener);

    myTestButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(final ActionEvent e) {
            test();
          }
        });

    setOKActionEnabled(false);
    myTestButton.setEnabled(false);
  }
 private static String getChooserTitle(final FileChooserDescriptor descriptor) {
   final String title = descriptor.getTitle();
   return title != null ? title : UIBundle.message("file.chooser.default.title");
 }
Ejemplo n.º 3
0
  /** Init components */
  private void initListeners() {
    FileChooserDescriptor fcd = new FileChooserDescriptor(false, true, false, false, false, false);
    fcd.setShowFileSystemRoots(true);
    fcd.setTitle(GitBundle.getString("clone.destination.directory.title"));
    fcd.setDescription(GitBundle.getString("clone.destination.directory.description"));
    fcd.setHideIgnored(false);
    myParentDirectory.addActionListener(
        new ComponentWithBrowseButton.BrowseFolderActionListener<JTextField>(
            fcd.getTitle(),
            fcd.getDescription(),
            myParentDirectory,
            myProject,
            fcd,
            TextComponentAccessor.TEXT_FIELD_WHOLE_TEXT) {
          @Override
          protected VirtualFile getInitialFile() {
            // suggest project base directory only if nothing is typed in the component.
            String text = getComponentText();
            if (text.length() == 0) {
              VirtualFile file = myProject.getBaseDir();
              if (file != null) {
                return file;
              }
            }
            return super.getInitialFile();
          }
        });
    final DocumentListener updateOkButtonListener =
        new DocumentListener() {
          // update Ok button state depending on the current state of the fields
          public void insertUpdate(final DocumentEvent e) {
            updateOkButton();
          }

          public void removeUpdate(final DocumentEvent e) {
            updateOkButton();
          }

          public void changedUpdate(final DocumentEvent e) {
            updateOkButton();
          }
        };
    myParentDirectory.getChildComponent().getDocument().addDocumentListener(updateOkButtonListener);
    myDirectoryName.getDocument().addDocumentListener(updateOkButtonListener);
    myOriginName.getDocument().addDocumentListener(updateOkButtonListener);
    myRepositoryURL
        .getDocument()
        .addDocumentListener(
            new DocumentListener() {
              // enable test button only if something is entered in repository URL
              public void insertUpdate(final DocumentEvent e) {
                changed();
              }

              public void removeUpdate(final DocumentEvent e) {
                changed();
              }

              public void changedUpdate(final DocumentEvent e) {
                changed();
              }

              private void changed() {
                final String url = myRepositoryURL.getText();
                myTestButton.setEnabled(url.length() != 0);
                if (myDefaultDirectoryName.equals(myDirectoryName.getText())
                    || myDirectoryName.getText().length() == 0) {
                  // modify field if it was unmodified or blank
                  myDefaultDirectoryName = defaultDirectoryName(url);
                  myDirectoryName.setText(myDefaultDirectoryName);
                }
                updateOkButton();
              }
            });
    myTestButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(final ActionEvent e) {
            myTestURL = myRepositoryURL.getText();
            String output =
                GitHandlerUtil.doSynchronously(
                    GitSimpleHandler.checkRepository(myProject, myTestURL),
                    GitBundle.message("clone.testing", myTestURL),
                    "connection test");
            if (output != null) {
              Messages.showInfoMessage(
                  myTestButton,
                  GitBundle.message("clone.test.success.message", myTestURL),
                  GitBundle.getString("clone.test.success"));
              myTestResult = Boolean.TRUE;
            } else {
              myTestResult = Boolean.FALSE;
            }
            updateOkButton();
          }
        });
    setOKActionEnabled(false);
  }