SVN auth
[fedora-idea.git] / plugins / svn4idea / src / org / jetbrains / idea / svn / dialogs / UserNameCredentialsDialog.java
blob158a00af955968ac517bbd2dedacee367365e6c4
1 /*
2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.jetbrains.idea.svn.dialogs;
18 import com.intellij.openapi.ui.DialogWrapper;
19 import com.intellij.openapi.project.Project;
20 import com.intellij.openapi.help.HelpManager;
22 import javax.swing.event.DocumentListener;
23 import javax.swing.event.DocumentEvent;
24 import javax.swing.*;
26 import org.jetbrains.annotations.NonNls;
27 import org.jetbrains.idea.svn.SvnBundle;
29 import java.awt.*;
31 public class UserNameCredentialsDialog extends DialogWrapper implements DocumentListener {
32 private boolean myAllowSave;
33 private String myUserName;
35 private String myRealm;
36 private JTextField myUserNameText;
37 private JCheckBox myAllowSaveCheckBox;
39 @NonNls
40 private static final String HELP_ID = "vcs.subversion.authentication";
42 protected UserNameCredentialsDialog(Project project) {
43 super(project, true);
44 setResizable(false);
47 public void setup(String realm, String userName, boolean allowSave) {
48 myRealm = realm;
49 myUserName = userName;
50 myAllowSave = allowSave;
51 getHelpAction().setEnabled(true);
52 init();
54 protected void doHelpAction() {
55 HelpManager.getInstance().invokeHelp(HELP_ID);
58 protected Action[] createActions() {
59 return new Action[]{getOKAction(), getCancelAction(), getHelpAction()};
62 protected JComponent createCenterPanel() {
63 JPanel panel = new JPanel();
64 panel.setLayout(new GridBagLayout());
66 GridBagConstraints gb = new GridBagConstraints();
68 // top label.
69 gb.insets = new Insets(2, 2, 2, 2);
70 gb.weightx = 1;
71 gb.weighty = 0;
72 gb.gridwidth = 2;
73 gb.gridheight = 1;
74 gb.gridx = 0;
75 gb.gridy = 0;
76 gb.anchor = GridBagConstraints.WEST;
77 gb.fill = GridBagConstraints.HORIZONTAL;
79 JLabel label = new JLabel(SvnBundle.message("label.auth.authentication.realm", myRealm));
80 panel.add(label, gb);
82 // user name
83 gb.gridy += 1;
84 gb.gridwidth = 1;
85 gb.weightx = 0;
86 gb.fill = GridBagConstraints.NONE;
88 label = new JLabel(SvnBundle.message("label.auth.user.name"));
89 panel.add(label, gb);
91 // user name field
92 gb.gridx = 1;
93 gb.weightx = 1;
94 gb.fill = GridBagConstraints.HORIZONTAL;
96 myUserNameText = new JTextField();
97 panel.add(myUserNameText, gb);
98 label.setLabelFor(myUserNameText);
100 if (myUserName != null) {
101 myUserNameText.setText(myUserName);
103 myUserNameText.selectAll();
104 myUserNameText.getDocument().addDocumentListener(this);
106 gb.gridy += 1;
107 gb.gridx = 0;
108 gb.gridwidth = 2;
109 gb.weightx = 1;
110 gb.fill = GridBagConstraints.HORIZONTAL;
111 myAllowSaveCheckBox = new JCheckBox(SvnBundle.message("checkbox.auth.keep.for.current.session"));
112 panel.add(myAllowSaveCheckBox, gb);
113 gb.gridy += 1;
114 panel.add(new JSeparator(), gb);
116 myAllowSaveCheckBox.setSelected(false);
117 myAllowSaveCheckBox.setEnabled(myAllowSave);
119 return panel;
122 protected String getDimensionServiceKey() {
123 return "svn.userNameDialog";
126 public JComponent getPreferredFocusedComponent() {
127 return myUserNameText;
130 public boolean shouldCloseOnCross() {
131 return true;
134 public boolean isOKActionEnabled() {
135 return myUserNameText != null && myUserNameText.getText().trim().length() != 0;
138 public String getUserName() {
139 return isOK() && myUserNameText != null ? myUserNameText.getText() : null;
142 public boolean isSaveAllowed() {
143 return isOK() && myAllowSave && myAllowSaveCheckBox != null && myAllowSaveCheckBox.isSelected();
146 public void insertUpdate(DocumentEvent e) {
147 updateOKButton();
150 public void removeUpdate(DocumentEvent e) {
151 updateOKButton();
154 public void changedUpdate(DocumentEvent e) {
155 updateOKButton();
158 private void updateOKButton() {
159 getOKAction().setEnabled(isOKActionEnabled());