/*
- * Copyright 2000-2009 JetBrains s.r.o.
+ * Copyright 2000-2010 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*/
package com.intellij.util.net;
+import org.jetbrains.annotations.Nullable;
+
import javax.swing.*;
/**
- * Created by IntelliJ IDEA.
- * User: stathik
- * Date: Sep 12, 2003
- * Time: 8:40:40 PM
- * To change this template use Options | File Templates.
+ * Panel for authentication - contains text fields for login and password, and a checkbox to remember
+ * password in the Password Safe.
+ *
+ * @author stathik
+ * @author Kirill Likhodedov
*/
public class AuthenticationPanel extends JPanel {
private JPanel myMainPanel;
private JPasswordField myPasswordTextField;
private JCheckBox rememberPasswordCheckBox;
- public AuthenticationPanel(String description, String login, String password, boolean rememberPassword) {
+ /**
+ * @param description Description text above the text fields.
+ * @param login Initial login value.
+ * @param password Initial password value.
+ * @param rememberPassword Default value for the 'remember password' checkbox.
+ */
+ public AuthenticationPanel(@Nullable String description, @Nullable String login, @Nullable String password, boolean rememberPassword) {
add(myMainPanel);
myDescriptionLabel.setText(description);
myLoginTextField.setText(login);
public boolean isRememberPassword () {
return rememberPasswordCheckBox.isSelected();
}
+
+ /**
+ * @return the component which should be focused when the dialog appears on the screen. May be used in dialogs.
+ * @see com.intellij.openapi.ui.DialogWrapper#getPreferredFocusedComponent()
+ */
+ public JComponent getPreferredFocusedComponent() {
+ return getLogin().isEmpty() ? myLoginTextField : myPasswordTextField;
+ }
+
}
hg4idea.warning.no-default-update-path=Skipped \"{0}\". No default update path.
hg4idea.merge.please-commit=Merged heads, please commit repository \"{0}\"
hg4idea.error.invalidExecutable=\"{0}\" is not a valid mercurial executable
-hg4idea.integrate.other.head=Other head: {0}
\ No newline at end of file
+hg4idea.integrate.other.head=Other head: {0}
+
+hgidea.dialog.login.password.required=Login and password required
\ No newline at end of file
import org.jetbrains.annotations.Nullable;
import java.nio.charset.Charset;
+import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
private String repositoryURL;
private String directory;
+ private final HgCommandAuthenticator authenticator = new HgCommandAuthenticator();
public HgCloneCommand(Project project) {
this.project = project;
@Nullable
public HgCommandResult execute() {
- List<String> arguments = new LinkedList<String>();
+ final List<String> arguments = new ArrayList<String>(2);
arguments.add(repositoryURL);
arguments.add(directory);
- return HgCommandService.getInstance(project).execute(null, Collections.<String>emptyList(), "clone", arguments, Charset.defaultCharset());
+ return authenticator.executeCommandAndAuthenticateIfNecessary(project, null, repositoryURL, "clone", arguments);
}
}
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.vcsUtil.VcsUtil;
+import org.jetbrains.annotations.Nullable;
import org.zmlx.hg4idea.ui.HgUsernamePasswordDialog;
import java.net.URISyntaxException;
*/
class HgCommandAuthenticator {
+ @Nullable
protected HgCommandResult executeCommandAndAuthenticateIfNecessary(Project project, VirtualFile localRepository, String remoteRepository, String command, List<String> arguments) {
HgCommandService service = HgCommandService.getInstance(project);
HgCommandResult result = service.execute(localRepository, command, arguments);
}
public void run() {
- HgUsernamePasswordDialog dialog = new HgUsernamePasswordDialog(project);
- dialog.setUsername(hgUrl.getUsername());
+ final HgUsernamePasswordDialog dialog = new HgUsernamePasswordDialog(project, hgUrl.getUsername());
dialog.show();
if (dialog.isOK()) {
import org.jetbrains.annotations.Nullable;
import java.nio.charset.Charset;
+import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
public class HgIdentifyCommand {
- private final Project project;
+ private final Project project;
+ private final HgCommandAuthenticator authenticator = new HgCommandAuthenticator();
private String source;
public HgIdentifyCommand(Project project) {
@Nullable
public HgCommandResult execute() {
- List<String> arguments = new LinkedList<String>();
+ final List<String> arguments = new LinkedList<String>();
arguments.add(source);
-
- HgCommandService hgCommandService = HgCommandService.getInstance(project);
- return hgCommandService.execute(null, Collections.<String>emptyList(), "identify", arguments, Charset.defaultCharset());
+ return authenticator.executeCommandAndAuthenticateIfNecessary(project, null, source, "identify", arguments);
}
}
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="org.zmlx.hg4idea.ui.HgUsernamePasswordDialog">
- <grid id="27dc6" binding="basePanel" layout-manager="GridLayoutManager" row-count="3" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
- <margin top="0" left="0" bottom="0" right="0"/>
- <constraints>
- <xy x="20" y="20" width="500" height="400"/>
- </constraints>
- <properties/>
- <border type="none"/>
- <children>
- <component id="24f37" class="javax.swing.JLabel">
- <constraints>
- <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
- </constraints>
- <properties>
- <labelFor value="f28fb"/>
- <text value="&Username"/>
- </properties>
- </component>
- <component id="f28fb" class="javax.swing.JTextField" binding="usernameTxt">
- <constraints>
- <grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
- <preferred-size width="150" height="-1"/>
- </grid>
- </constraints>
- <properties/>
- </component>
- <component id="b8a4d" class="javax.swing.JLabel">
- <constraints>
- <grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
- </constraints>
- <properties>
- <labelFor value="78233"/>
- <text value="&Password"/>
- </properties>
- </component>
- <vspacer id="c29cf">
- <constraints>
- <grid row="2" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
- </constraints>
- </vspacer>
- <component id="78233" class="javax.swing.JPasswordField" binding="passwordTxt">
- <constraints>
- <grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
- <preferred-size width="150" height="-1"/>
- </grid>
- </constraints>
- <properties>
- <text value=""/>
- </properties>
- </component>
- </children>
- </grid>
-</form>
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogWrapper;
+import com.intellij.util.net.AuthenticationPanel;
+import org.zmlx.hg4idea.HgVcsMessages;
import javax.swing.*;
public class HgUsernamePasswordDialog extends DialogWrapper {
- private JPanel basePanel;
- private JTextField usernameTxt;
- private JPasswordField passwordTxt;
+ private AuthenticationPanel authPanel;
- public HgUsernamePasswordDialog(Project project) {
+ public HgUsernamePasswordDialog(Project project, String login) {
super(project, false);
- setTitle("Username and password required");
+ setTitle(HgVcsMessages.message("hgidea.dialog.login.password.required"));
+ authPanel = new AuthenticationPanel(null, login, "", false);
init();
}
- public void setUsername(String username) {
- usernameTxt.setText(username);
+ protected JComponent createCenterPanel() {
+ return authPanel;
}
- public String getUsername() {
- return usernameTxt.getText();
+ @Override
+ public JComponent getPreferredFocusedComponent() {
+ return authPanel.getPreferredFocusedComponent();
}
- public char[] getPassword() {
- return passwordTxt.getPassword();
+ public String getUsername() {
+ return authPanel.getLogin();
}
- protected JComponent createCenterPanel() {
- return basePanel;
+ public char[] getPassword() {
+ return authPanel.getPassword().toCharArray();
}
-}
+}
\ No newline at end of file