/** 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 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; }
public String getParentDirectory() { return myParentDirectory.getText(); }