mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
svn: Refactored "AddRepositoryLocationDialog" - fixed warnings, cleanup
This commit is contained in:
+39
-39
@@ -16,32 +16,35 @@
|
||||
package org.jetbrains.idea.svn.dialogs;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.ComboBox;
|
||||
import com.intellij.openapi.ui.DialogWrapper;
|
||||
import com.intellij.openapi.ui.MultiLineLabelUI;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.ui.JBDimension;
|
||||
import com.intellij.ui.CollectionComboBoxModel;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.idea.svn.SvnBundle;
|
||||
import org.tmatesoft.svn.core.SVNException;
|
||||
import org.tmatesoft.svn.core.SVNURL;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.idea.svn.commandLine.SvnBindException;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static com.intellij.util.containers.ContainerUtil.sorted;
|
||||
import static com.intellij.util.ui.JBUI.*;
|
||||
import static java.awt.GridBagConstraints.*;
|
||||
import static org.jetbrains.idea.svn.SvnBundle.message;
|
||||
import static org.jetbrains.idea.svn.SvnUtil.createUrl;
|
||||
|
||||
public class AddRepositoryLocationDialog extends DialogWrapper {
|
||||
private final List<String> myPreviousLocations;
|
||||
@NotNull private final List<String> myPreviousLocations;
|
||||
private JComboBox myCombo;
|
||||
private String mySelected;
|
||||
private JTextField myComboField;
|
||||
|
||||
public AddRepositoryLocationDialog(final Project project, final List<String> values) {
|
||||
public AddRepositoryLocationDialog(@NotNull Project project, @NotNull List<String> values) {
|
||||
super(project, true);
|
||||
myPreviousLocations = new ArrayList<>(values);
|
||||
Collections.sort(myPreviousLocations);
|
||||
myPreviousLocations = sorted(values);
|
||||
|
||||
setTitle(getTitle());
|
||||
init();
|
||||
@@ -50,7 +53,7 @@ public class AddRepositoryLocationDialog extends DialogWrapper {
|
||||
|
||||
@Override
|
||||
public String getTitle() {
|
||||
return SvnBundle.message("repository.browser.add.location.title");
|
||||
return message("repository.browser.add.location.title");
|
||||
}
|
||||
|
||||
protected String initText() {
|
||||
@@ -63,78 +66,75 @@ public class AddRepositoryLocationDialog extends DialogWrapper {
|
||||
}
|
||||
|
||||
protected JComponent createCenterPanel() {
|
||||
final JLabel selectText = new JLabel(SvnBundle.message("repository.browser.add.location.prompt"));
|
||||
JLabel selectText = new JLabel(message("repository.browser.add.location.prompt"));
|
||||
selectText.setUI(new MultiLineLabelUI());
|
||||
|
||||
final JPanel mainPanel = new JPanel(new GridBagLayout());
|
||||
final GridBagConstraints gb =
|
||||
new GridBagConstraints(0, 0, 1, 1, 1, 0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0);
|
||||
JPanel mainPanel = new JPanel(new GridBagLayout());
|
||||
GridBagConstraints gb = new GridBagConstraints(0, 0, 1, 1, 1, 0, NORTHWEST, NONE, insets(5), 0, 0);
|
||||
|
||||
mainPanel.add(selectText, gb);
|
||||
|
||||
++ gb.gridy;
|
||||
++gb.gridy;
|
||||
|
||||
myCombo = new JComboBox(ArrayUtil.toObjectArray(myPreviousLocations));
|
||||
myCombo = new ComboBox<>(new CollectionComboBoxModel<>(myPreviousLocations));
|
||||
myCombo.setEditable(true);
|
||||
myCombo.setMinimumSize(new JBDimension(250, 20));
|
||||
gb.fill = GridBagConstraints.HORIZONTAL;
|
||||
myCombo.setMinimumSize(size(250, 20));
|
||||
gb.fill = HORIZONTAL;
|
||||
mainPanel.add(myCombo, gb);
|
||||
gb.fill = GridBagConstraints.NONE;
|
||||
gb.fill = NONE;
|
||||
|
||||
myComboField = (JTextField)myCombo.getEditor().getEditorComponent();
|
||||
myComboField.addInputMethodListener(new InputMethodListener() {
|
||||
public void inputMethodTextChanged(final InputMethodEvent event) {
|
||||
public void inputMethodTextChanged(InputMethodEvent event) {
|
||||
validateMe();
|
||||
}
|
||||
|
||||
public void caretPositionChanged(final InputMethodEvent event) {
|
||||
public void caretPositionChanged(InputMethodEvent event) {
|
||||
validateMe();
|
||||
}
|
||||
});
|
||||
myComboField.addKeyListener(new KeyListener() {
|
||||
public void keyTyped(final KeyEvent e) {
|
||||
public void keyTyped(KeyEvent e) {
|
||||
validateMe();
|
||||
}
|
||||
|
||||
public void keyPressed(final KeyEvent e) {
|
||||
public void keyPressed(KeyEvent e) {
|
||||
validateMe();
|
||||
}
|
||||
|
||||
public void keyReleased(final KeyEvent e) {
|
||||
public void keyReleased(KeyEvent e) {
|
||||
validateMe();
|
||||
}
|
||||
});
|
||||
|
||||
myCombo.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(final ActionEvent e) {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
validateMe();
|
||||
}
|
||||
});
|
||||
validateMe();
|
||||
|
||||
final JPanel wrapper = new JPanel(new GridBagLayout());
|
||||
wrapper.add(mainPanel, new GridBagConstraints(0,0,1,1,1,1,GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL,
|
||||
new Insets(0,0,0,0), 0,0));
|
||||
wrapper.setPreferredSize(new Dimension(400, 70));
|
||||
JPanel wrapper = new JPanel(new GridBagLayout());
|
||||
wrapper.add(mainPanel, new GridBagConstraints(0, 0, 1, 1, 1, 1, NORTHWEST, HORIZONTAL, emptyInsets(), 0, 0));
|
||||
wrapper.setPreferredSize(size(400, 70));
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
private void validateMe() {
|
||||
final String inputString = myComboField.getText();
|
||||
setOKActionEnabled(urlValid(inputString));
|
||||
setOKActionEnabled(isUrlValid(myComboField.getText()));
|
||||
}
|
||||
|
||||
private boolean urlValid(final String inputString) {
|
||||
private static boolean isUrlValid(@Nullable String inputString) {
|
||||
if (inputString == null) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
final SVNURL svnurl = SVNURL.parseURIDecoded(inputString.trim());
|
||||
return svnurl != null;
|
||||
} catch (SVNException e) {
|
||||
//
|
||||
createUrl(inputString.trim(), false);
|
||||
return true;
|
||||
}
|
||||
catch (SvnBindException ignore) {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -71,6 +71,7 @@ public class RepositoryBrowserComponent extends JPanel implements Disposable, Da
|
||||
return myRepositoryTree;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Project getProject() {
|
||||
return myVCS.getProject();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user