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
;
26 import org
.jetbrains
.annotations
.NonNls
;
27 import org
.jetbrains
.idea
.svn
.SvnBundle
;
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
;
40 private static final String HELP_ID
= "vcs.subversion.authentication";
42 protected UserNameCredentialsDialog(Project project
) {
47 public void setup(String realm
, String userName
, boolean allowSave
) {
49 myUserName
= userName
;
50 myAllowSave
= allowSave
;
51 getHelpAction().setEnabled(true);
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();
69 gb
.insets
= new Insets(2, 2, 2, 2);
76 gb
.anchor
= GridBagConstraints
.WEST
;
77 gb
.fill
= GridBagConstraints
.HORIZONTAL
;
79 JLabel label
= new JLabel(SvnBundle
.message("label.auth.authentication.realm", myRealm
));
86 gb
.fill
= GridBagConstraints
.NONE
;
88 label
= new JLabel(SvnBundle
.message("label.auth.user.name"));
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);
110 gb
.fill
= GridBagConstraints
.HORIZONTAL
;
111 myAllowSaveCheckBox
= new JCheckBox(SvnBundle
.message("checkbox.auth.keep.for.current.session"));
112 panel
.add(myAllowSaveCheckBox
, gb
);
114 panel
.add(new JSeparator(), gb
);
116 myAllowSaveCheckBox
.setSelected(false);
117 myAllowSaveCheckBox
.setEnabled(myAllowSave
);
122 protected String
getDimensionServiceKey() {
123 return "svn.userNameDialog";
126 public JComponent
getPreferredFocusedComponent() {
127 return myUserNameText
;
130 public boolean shouldCloseOnCross() {
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
) {
150 public void removeUpdate(DocumentEvent e
) {
154 public void changedUpdate(DocumentEvent e
) {
158 private void updateOKButton() {
159 getOKAction().setEnabled(isOKActionEnabled());