Simplify "CopyOptionsDialog"

This commit is contained in:
Konstantin Kolosovsky
2017-06-25 15:40:48 +03:00
parent a5b4ffc46e
commit 8934b00d85
@@ -31,7 +31,7 @@ import com.intellij.ui.CollectionComboBoxModel;
import com.intellij.ui.DocumentAdapter;
import com.intellij.ui.PopupHandler;
import com.intellij.util.ui.GridBag;
import com.intellij.util.ui.JBUI;
import com.intellij.util.ui.components.BorderLayoutPanel;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -41,7 +41,6 @@ import org.jetbrains.idea.svn.dialogs.RepositoryBrowserDialog;
import org.jetbrains.idea.svn.dialogs.RepositoryTreeNode;
import org.tmatesoft.svn.core.SVNException;
import org.tmatesoft.svn.core.SVNURL;
import org.tmatesoft.svn.core.internal.util.SVNPathUtil;
import javax.swing.*;
import javax.swing.event.DocumentEvent;
@@ -51,6 +50,12 @@ import java.util.Collections;
import java.util.List;
import java.util.function.Consumer;
import static com.intellij.openapi.util.text.StringUtil.isEmpty;
import static com.intellij.util.ui.JBUI.Borders.emptyTop;
import static com.intellij.util.ui.JBUI.Panels.simplePanel;
import static com.intellij.util.ui.JBUI.insets;
import static org.tmatesoft.svn.core.internal.util.SVNPathUtil.tail;
public class CopyOptionsDialog extends DialogWrapper {
private final SVNURL myURL;
@@ -60,37 +65,30 @@ public class CopyOptionsDialog extends DialogWrapper {
private JLabel myURLLabel;
private RepositoryBrowserComponent myBrowser;
private JLabel myTargetURL;
private JPanel myMainPanel;
private BorderLayoutPanel myMainPanel;
public CopyOptionsDialog(String title, Project project, final RepositoryTreeNode root, final RepositoryTreeNode node,
final boolean copy) {
public CopyOptionsDialog(String title, Project project, RepositoryTreeNode root, RepositoryTreeNode node, boolean copy) {
super(project, true);
myProject = project;
myURL = node.getURL();
createUI();
if (copy) {
myTargetURL.setForeground(FileStatus.ADDED.getColor());
setOKButtonText("Copy");
} else {
myTargetURL.setForeground(FileStatus.MODIFIED.getColor());
setOKButtonText("Move");
}
myTargetURL.setForeground(copy ? FileStatus.ADDED.getColor() : FileStatus.MODIFIED.getColor());
setOKButtonText(copy ? "Copy" : "Move");
myURLLabel.setText(myURL.toString());
final TreeNode[] path = node.getSelfPath();
final TreeNode[] subPath = new TreeNode[path.length - 1];
TreeNode[] path = node.getSelfPath();
TreeNode[] subPath = new TreeNode[path.length - 1];
System.arraycopy(path, 1, subPath, 0, path.length - 1);
myBrowser.setRepositoryURL(root.getURL(), false,
new OpeningExpander.Factory(subPath, (RepositoryTreeNode)((node.getParent() instanceof RepositoryTreeNode) ? node.getParent() : null)));
myBrowser.setRepositoryURL(root.getURL(), false, new OpeningExpander.Factory(
subPath, node.getParent() instanceof RepositoryTreeNode ? (RepositoryTreeNode)node.getParent() : null));
myBrowser.addChangeListener(e -> update());
myNameField.setText(SVNPathUtil.tail(myURL.getPath()));
myNameField.setText(tail(myURL.getPath()));
myNameField.selectAll();
myNameField.getDocument().addDocumentListener(new DocumentAdapter() {
protected void textChanged(final DocumentEvent e) {
protected void textChanged(DocumentEvent e) {
update();
}
});
@@ -123,10 +121,10 @@ public class CopyOptionsDialog extends DialogWrapper {
}
private void createUI() {
myMainPanel = new JPanel(new BorderLayout());
myMainPanel = simplePanel();
myBrowser = new RepositoryBrowserComponent(SvnVcs.getInstance(myProject));
final DefaultActionGroup group = new DefaultActionGroup();
DefaultActionGroup group = new DefaultActionGroup();
group.add(new RepositoryBrowserDialog.MkDirAction(myBrowser) {
@Override
public void update(AnActionEvent e) {
@@ -136,8 +134,8 @@ public class CopyOptionsDialog extends DialogWrapper {
});
group.add(new RepositoryBrowserDialog.DeleteAction(myBrowser));
group.add(new RepositoryBrowserDialog.RefreshAction(myBrowser));
final ActionPopupMenu popupMenu = ActionManager.getInstance().createActionPopupMenu("", group);
final JPopupMenu component = popupMenu.getComponent();
ActionPopupMenu popupMenu = ActionManager.getInstance().createActionPopupMenu("", group);
JPopupMenu component = popupMenu.getComponent();
myBrowser.getRepositoryTree().addMouseListener(new PopupHandler() {
@Override
public void invokePopup(Component comp, int x, int y) {
@@ -145,80 +143,59 @@ public class CopyOptionsDialog extends DialogWrapper {
}
});
final Splitter splitter = new Splitter(true);
splitter.setProportion(0.7f);
final JPanel wrapper = createBrowserPartWrapper();
splitter.setFirstComponent(wrapper);
final JPanel commitMessageWrapper = createCommitMessageWrapper();
splitter.setSecondComponent(commitMessageWrapper);
Splitter splitter = new Splitter(true, 0.7f);
splitter.setFirstComponent(createBrowserPartWrapper());
splitter.setSecondComponent(createCommitMessageWrapper());
myMainPanel.add(splitter, BorderLayout.CENTER);
final JPanel recentMessagesWrapper = new JPanel(new BorderLayout());
recentMessagesWrapper.add(new JLabel("Recent Messages:"), BorderLayout.NORTH);
myMainPanel.addToCenter(splitter);
ComboBox<String> messagesBox = configureRecentMessagesComponent(myProject, new ComboBox<>(), message -> {
if (message != null) {
myCommitMessage.setText(message);
myCommitMessage.getEditorField().selectAll();
}
});
recentMessagesWrapper.add(messagesBox, BorderLayout.SOUTH);
recentMessagesWrapper.setBorder(JBUI.Borders.emptyTop(4));
myMainPanel.add(recentMessagesWrapper, BorderLayout.SOUTH);
myMainPanel.addToBottom(simplePanel().addToTop(new JLabel("Recent Messages:")).addToBottom(messagesBox).withBorder(emptyTop(4)));
}
@NotNull
private JPanel createCommitMessageWrapper() {
final JPanel commitMessageWrapper = new JPanel(new BorderLayout());
commitMessageWrapper.add(new JLabel("Commit Message:"), BorderLayout.NORTH);
myCommitMessage = new CommitMessage(myProject, false, false, true);
commitMessageWrapper.add(myCommitMessage, BorderLayout.CENTER);
return commitMessageWrapper;
return simplePanel(myCommitMessage).addToTop(new JLabel("Commit Message:"));
}
@NotNull
private JPanel createBrowserPartWrapper() {
final JPanel wrapper = new JPanel(new GridBagLayout());
final GridBag gridBag = new GridBag().setDefaultAnchor(GridBagConstraints.NORTHWEST)
.setDefaultFill(GridBagConstraints.NONE).setDefaultInsets(JBUI.insets(1)).setDefaultWeightX(1).setDefaultWeightY(0);
JPanel wrapper = new JPanel(new GridBagLayout());
GridBag gridBag =
new GridBag().setDefaultAnchor(GridBagConstraints.NORTHWEST).setDefaultFill(GridBagConstraints.NONE).setDefaultInsets(insets(1))
.setDefaultWeightX(1).setDefaultWeightY(0);
gridBag.nextLine().next();
gridBag.weightx(0);
gridBag.nextLine().next().weightx(0);
wrapper.add(new JLabel("Source URL:"), gridBag);
gridBag.next();
gridBag.fillCellHorizontally();
gridBag.next().fillCellHorizontally();
myURLLabel = new JLabel();
myURLLabel.setFont(myURLLabel.getFont().deriveFont(Font.BOLD));
wrapper.add(myURLLabel, gridBag);
gridBag.nextLine().next();
gridBag.weightx(0);
gridBag.pady(4);
gridBag.nextLine().next().weightx(0).pady(4);
wrapper.add(new JLabel("Target Location:"), gridBag);
gridBag.nextLine().next();
gridBag.fillCell();
gridBag.weighty(1);
gridBag.coverLine(2);
gridBag.nextLine().next().fillCell().weighty(1).coverLine(2);
wrapper.add(myBrowser, gridBag);
gridBag.nextLine().next();
gridBag.weightx(0);
gridBag.pady(4);
gridBag.nextLine().next().weightx(0).pady(4);
wrapper.add(new JLabel("Target Name:"), gridBag);
gridBag.next();
gridBag.fillCellHorizontally();
gridBag.next().fillCellHorizontally();
myNameField = new JTextField();
wrapper.add(myNameField, gridBag);
gridBag.nextLine().next();
gridBag.weightx(0);
gridBag.pady(2);
gridBag.nextLine().next().weightx(0).pady(2);
wrapper.add(new JLabel("Target URL:"), gridBag);
gridBag.next();
gridBag.fillCellHorizontally();
gridBag.next().fillCellHorizontally();
myTargetURL = new JLabel();
myTargetURL.setFont(myTargetURL.getFont().deriveFont(Font.BOLD));
wrapper.add(myTargetURL, gridBag);
@@ -247,8 +224,8 @@ public class CopyOptionsDialog extends DialogWrapper {
if (getOKAction().isEnabled()) {
try {
return SVNURL.parseURIEncoded(myTargetURL.getText());
} catch (SVNException e) {
//
}
catch (SVNException ignored) {
}
}
return null;
@@ -273,14 +250,13 @@ public class CopyOptionsDialog extends DialogWrapper {
}
SVNURL baseURL = baseNode.getURL();
String name = myNameField.getText();
if (name == null || "".equals(name)) {
if (isEmpty(name)) {
getOKAction().setEnabled(false);
return;
}
try {
baseURL = baseURL.appendPath(myNameField.getText(), false);
} catch (SVNException e) {
//
getOKAction().setEnabled(false);
return;
}