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
.help
.HelpManager
;
19 import com
.intellij
.openapi
.project
.Project
;
20 import com
.intellij
.openapi
.ui
.DialogWrapper
;
21 import org
.jetbrains
.annotations
.NonNls
;
22 import org
.jetbrains
.idea
.svn
.SvnBundle
;
25 import javax
.swing
.event
.DocumentEvent
;
26 import javax
.swing
.event
.DocumentListener
;
32 public class SimpleCredentialsDialog
extends DialogWrapper
implements DocumentListener
{
33 private boolean myAllowSave
;
34 private String myUserName
;
36 private String myRealm
;
37 private JTextField myUserNameText
;
38 private JCheckBox myAllowSaveCheckBox
;
39 private JPasswordField myPasswordText
;
41 @NonNls private static final String HELP_ID
= "vcs.subversion.authentication";
43 protected SimpleCredentialsDialog(Project project
) {
48 public void setup(String realm
, String userName
, boolean allowSave
) {
50 myUserName
= userName
;
51 myAllowSave
= allowSave
;
52 getHelpAction().setEnabled(true);
55 protected void doHelpAction() {
56 HelpManager
.getInstance().invokeHelp(HELP_ID
);
59 protected Action
[] createActions() {
60 return new Action
[]{getOKAction(), getCancelAction(), getHelpAction()};
63 protected JComponent
createCenterPanel() {
64 JPanel panel
= new JPanel();
65 panel
.setLayout(new GridBagLayout());
67 GridBagConstraints gb
= new GridBagConstraints();
70 gb
.insets
= new Insets(2, 2, 2, 2);
77 gb
.anchor
= GridBagConstraints
.WEST
;
78 gb
.fill
= GridBagConstraints
.HORIZONTAL
;
80 JLabel label
= new JLabel(SvnBundle
.message("label.auth.authentication.realm", myRealm
));
87 gb
.fill
= GridBagConstraints
.NONE
;
89 label
= new JLabel(SvnBundle
.message("label.auth.user.name"));
95 gb
.fill
= GridBagConstraints
.HORIZONTAL
;
97 myUserNameText
= new JTextField();
98 panel
.add(myUserNameText
, gb
);
99 label
.setLabelFor(myUserNameText
);
101 if (myUserName
!= null) {
102 myUserNameText
.setText(myUserName
);
104 myUserNameText
.selectAll();
105 myUserNameText
.getDocument().addDocumentListener(this);
110 gb
.fill
= GridBagConstraints
.NONE
;
113 label
= new JLabel(SvnBundle
.message("label.auth.password"));
114 panel
.add(label
, gb
);
119 gb
.fill
= GridBagConstraints
.HORIZONTAL
;
121 myPasswordText
= new JPasswordField();
122 panel
.add(myPasswordText
, gb
);
123 label
.setLabelFor(myPasswordText
);
129 gb
.fill
= GridBagConstraints
.HORIZONTAL
;
130 myAllowSaveCheckBox
= new JCheckBox(SvnBundle
.message("checkbox.auth.keep.for.current.session"));
131 panel
.add(myAllowSaveCheckBox
, gb
);
133 panel
.add(new JSeparator(), gb
);
135 myAllowSaveCheckBox
.setSelected(false);
136 myAllowSaveCheckBox
.setEnabled(myAllowSave
);
141 protected String
getDimensionServiceKey() {
142 return "svn.passwordDialog";
145 public JComponent
getPreferredFocusedComponent() {
146 return myUserNameText
;
149 public boolean shouldCloseOnCross() {
153 public boolean isOKActionEnabled() {
154 return myUserNameText
!= null && myUserNameText
.getText().trim().length() > 0
155 && myPasswordText
!= null && myPasswordText
.getPassword() != null;
158 public String
getUserName() {
159 return isOK() && myUserNameText
!= null ? myUserNameText
.getText() : null;
162 public String
getPassword() {
163 if (isOK() && myPasswordText
!= null) {
164 char[] pwd
= myPasswordText
.getPassword();
166 return new String(pwd
);
172 public boolean isSaveAllowed() {
173 return isOK() && myAllowSave
&& myAllowSaveCheckBox
!= null && myAllowSaveCheckBox
.isSelected();
176 public void insertUpdate(DocumentEvent e
) {
180 public void removeUpdate(DocumentEvent e
) {
184 public void changedUpdate(DocumentEvent e
) {
188 private void updateOKButton() {
189 getOKAction().setEnabled(isOKActionEnabled());