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
.project
.Project
;
19 import com
.intellij
.openapi
.ui
.DialogWrapper
;
20 import com
.intellij
.openapi
.help
.HelpManager
;
23 import javax
.swing
.event
.DocumentEvent
;
24 import javax
.swing
.event
.DocumentListener
;
27 import org
.jetbrains
.annotations
.NonNls
;
28 import org
.jetbrains
.idea
.svn
.SvnBundle
;
31 * Created by IntelliJ IDEA.
35 * To change this template use File | Settings | File Templates.
37 public class SimpleCredentialsDialog
extends DialogWrapper
implements DocumentListener
{
38 private boolean myAllowSave
;
39 private String myUserName
;
41 private String myRealm
;
42 private JTextField myUserNameText
;
43 private JCheckBox myAllowSaveCheckBox
;
44 private JPasswordField myPasswordText
;
46 @NonNls private static final String HELP_ID
= "vcs.subversion.authentication";
48 protected SimpleCredentialsDialog(Project project
) {
53 public void setup(String realm
, String userName
, boolean allowSave
) {
55 myUserName
= userName
;
56 myAllowSave
= allowSave
;
57 getHelpAction().setEnabled(true);
60 protected void doHelpAction() {
61 HelpManager
.getInstance().invokeHelp(HELP_ID
);
64 protected Action
[] createActions() {
65 return new Action
[]{getOKAction(), getCancelAction(), getHelpAction()};
68 protected JComponent
createCenterPanel() {
69 JPanel panel
= new JPanel();
70 panel
.setLayout(new GridBagLayout());
72 GridBagConstraints gb
= new GridBagConstraints();
75 gb
.insets
= new Insets(2, 2, 2, 2);
82 gb
.anchor
= GridBagConstraints
.WEST
;
83 gb
.fill
= GridBagConstraints
.HORIZONTAL
;
85 JLabel label
= new JLabel(SvnBundle
.message("label.auth.authentication.realm", myRealm
));
92 gb
.fill
= GridBagConstraints
.NONE
;
94 label
= new JLabel(SvnBundle
.message("label.auth.user.name"));
100 gb
.fill
= GridBagConstraints
.HORIZONTAL
;
102 myUserNameText
= new JTextField();
103 panel
.add(myUserNameText
, gb
);
104 label
.setLabelFor(myUserNameText
);
106 if (myUserName
!= null) {
107 myUserNameText
.setText(myUserName
);
109 myUserNameText
.selectAll();
110 myUserNameText
.getDocument().addDocumentListener(this);
115 gb
.fill
= GridBagConstraints
.NONE
;
118 label
= new JLabel(SvnBundle
.message("label.auth.password"));
119 panel
.add(label
, gb
);
124 gb
.fill
= GridBagConstraints
.HORIZONTAL
;
126 myPasswordText
= new JPasswordField();
127 panel
.add(myPasswordText
, gb
);
128 label
.setLabelFor(myPasswordText
);
134 gb
.fill
= GridBagConstraints
.HORIZONTAL
;
135 myAllowSaveCheckBox
= new JCheckBox(SvnBundle
.message("checkbox.auth.keep.for.current.session"));
136 panel
.add(myAllowSaveCheckBox
, gb
);
138 panel
.add(new JSeparator(), gb
);
140 myAllowSaveCheckBox
.setSelected(false);
141 myAllowSaveCheckBox
.setEnabled(myAllowSave
);
146 protected String
getDimensionServiceKey() {
147 return "svn.passwordDialog";
150 public JComponent
getPreferredFocusedComponent() {
151 return myUserNameText
;
154 public boolean shouldCloseOnCross() {
158 public boolean isOKActionEnabled() {
159 return myUserNameText
!= null && myUserNameText
.getText().trim().length() > 0
160 && myPasswordText
!= null && myPasswordText
.getPassword() != null;
163 public String
getUserName() {
164 return isOK() && myUserNameText
!= null ? myUserNameText
.getText() : null;
167 public String
getPassword() {
168 if (isOK() && myPasswordText
!= null) {
169 char[] pwd
= myPasswordText
.getPassword();
171 return new String(pwd
);
177 public boolean isSaveAllowed() {
178 return isOK() && myAllowSave
&& myAllowSaveCheckBox
!= null && myAllowSaveCheckBox
.isSelected();
181 public void insertUpdate(DocumentEvent e
) {
185 public void removeUpdate(DocumentEvent e
) {
189 public void changedUpdate(DocumentEvent e
) {
193 private void updateOKButton() {
194 getOKAction().setEnabled(isOKActionEnabled());