/** * Check destination directory and set appropriate error text if there are problems * * @return true if destination components are OK. */ private boolean checkDestination() { if (myParentDirectory.getText().length() == 0 || myDirectoryName.getText().length() == 0) { setErrorText(null); setOKActionEnabled(false); return false; } File file = new File(myParentDirectory.getText(), myDirectoryName.getText()); if (file.exists()) { setErrorText(GitBundle.message("clone.destination.exists.error", file)); setOKActionEnabled(false); return false; } else if (!file.getParentFile().exists()) { setErrorText(GitBundle.message("clone.parent.missing.error", file.getParent())); setOKActionEnabled(false); return false; } return true; }
/** * Check origin and set appropriate error text if there are problems * * @return true if origin name is OK. */ private boolean checkOrigin() { String origin = myOriginName.getText(); if (origin.length() != 0 && !GitBranchNameValidator.INSTANCE.checkInput(origin)) { setErrorText(GitBundle.getString("clone.invalid.origin")); setOKActionEnabled(false); return false; } return true; }
/** 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); }
/** * Check repository URL and set appropriate error text if there are problems * * @return true if repository URL is OK. */ private boolean checkRepositoryURL() { String repository = myRepositoryURL.getText(); if (repository.length() == 0) { setErrorText(null); setOKActionEnabled(false); return false; } if (myTestResult != null && repository.equals(myTestURL)) { if (!myTestResult.booleanValue()) { setErrorText(GitBundle.getString("clone.test.failed.error")); setOKActionEnabled(false); return false; } else { return true; } } try { if (new URI(repository).isAbsolute()) { return true; } } catch (URISyntaxException urlExp) { // do nothing } // check if ssh url pattern if (SSH_URL_PATTERN.matcher(repository).matches()) { return true; } try { File file = new File(repository); if (file.exists()) { if (!file.isDirectory()) { setErrorText(GitBundle.getString("clone.url.is.not.directory.error")); setOKActionEnabled(false); } return true; } } catch (Exception fileExp) { // do nothing } setErrorText(GitBundle.getString("clone.invalid.url")); setOKActionEnabled(false); return false; }
public String getDirectoryName() { return myDirectoryName.getText(); }
/** @return the URL of the source repository */ public String getSourceRepositoryURL() { return myRepositoryURL.getText(); }
/** 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); }
/** @return the origin name to use */ public String getOriginName() { return myOriginName.getText(); }