Hide GitHub credentials from the settings

Ground:
* It fixes AE happening because of the necessary fix for IDEA-78716.
* It makes master password not appear during navigation through the settings.

Remove host, login and password fields.
Rename "Test" button to "Change credentials", fix layout.
Pressing the button invokes the standard GithubLoginDialog with credentials filled from the GitHubSettings (possibly with master password prompt).
Connection failure notification is not needed, since the dialog doesn't allow to OK on failure.
Connection success notification is shown, fix the parent of the Message.
This commit is contained in:
Kirill Likhodedov
2012-03-28 18:34:59 +04:00
parent 777bf85b5f
commit 97c80e446f
3 changed files with 18 additions and 113 deletions
@@ -2,8 +2,6 @@ package org.jetbrains.plugins.github.ui;
import com.intellij.openapi.options.ConfigurationException;
import com.intellij.openapi.options.SearchableConfigurable;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.IconLoader;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.plugins.github.GithubSettings;
import org.jetbrains.plugins.github.GithubUtil;
@@ -29,38 +27,27 @@ public class GitHubSettingsConfigurable implements SearchableConfigurable {
return GithubUtil.GITHUB_ICON;
}
@NotNull
public String getHelpTopic() {
return "settings.github";
}
public JComponent createComponent() {
if (mySettingsPane == null) {
mySettingsPane = new GithubSettingsPanel();
mySettingsPane = new GithubSettingsPanel(mySettings);
}
reset();
return mySettingsPane.getPanel();
}
public boolean isModified() {
return mySettingsPane != null && (!Comparing.equal(mySettings.getLogin(), mySettingsPane.getLogin()) ||
!Comparing.strEqual(mySettings.getPassword(), mySettingsPane.getPassword()) ||
!Comparing.equal(mySettings.getHost(), mySettingsPane.getHost()));
return false;
}
public void apply() throws ConfigurationException {
if (mySettingsPane != null) {
mySettings.setLogin(mySettingsPane.getLogin());
mySettings.setPassword(mySettingsPane.getPassword());
mySettings.setHost(mySettingsPane.getHost());
}
}
public void reset() {
if (mySettingsPane != null) {
mySettingsPane.setLogin(mySettings.getLogin());
mySettingsPane.setPassword(mySettings.getPassword());
mySettingsPane.setHost(mySettings.getHost());
}
}
public void disposeUIResources() {
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="org.jetbrains.plugins.github.ui.GithubSettingsPanel">
<grid id="27dc6" binding="myPane" layout-manager="GridLayoutManager" row-count="5" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="27dc6" binding="myPane" 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="563" height="400"/>
@@ -8,36 +8,9 @@
<properties/>
<border type="none"/>
<children>
<component id="e76ec" class="javax.swing.JTextField" binding="myLoginTextField">
<constraints>
<grid row="1" column="1" row-span="1" col-span="2" 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/>
<clientProperties>
<caretAspectRatio class="java.lang.Float" value="0.04"/>
</clientProperties>
</component>
<component id="c0234" 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>
<text value="Login:"/>
</properties>
</component>
<component id="d7c6c" class="javax.swing.JLabel">
<constraints>
<grid row="2" 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>
<text value="Password:"/>
</properties>
</component>
<component id="28ddd" class="javax.swing.JTextPane" binding="mySignupTextField">
<constraints>
<grid row="3" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="2" anchor="0" fill="1" indent="0" use-parent-layout="false">
<grid row="1" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="2" anchor="0" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="10"/>
</grid>
</constraints>
@@ -45,55 +18,25 @@
<contentType value="text/html"/>
<editable value="false"/>
<enabled value="true"/>
<margin top="0" left="6" bottom="0" right="0"/>
</properties>
<clientProperties>
<JEditorPane.honorDisplayProperties class="java.lang.Boolean" value="true"/>
<caretAspectRatio class="java.lang.Float" value="0.04"/>
</clientProperties>
</component>
<component id="9edbd" class="javax.swing.JPasswordField" binding="myPasswordField">
<constraints>
<grid row="2" column="1" row-span="1" col-span="2" 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/>
<clientProperties>
<caretAspectRatio class="java.lang.Float" value="0.04"/>
</clientProperties>
</component>
<component id="8a6dd" class="javax.swing.JButton" binding="myTestButton" default-binding="true">
<constraints>
<grid row="3" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Test"/>
</properties>
</component>
<vspacer id="6ace">
<constraints>
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
<grid row="2" column="0" 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="45bab" class="javax.swing.JLabel">
<component id="8a6dd" class="javax.swing.JButton" binding="myTestButton" default-binding="true">
<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>
<text value="Host:"/>
<text value="Change credentials"/>
</properties>
</component>
<component id="3352a" class="javax.swing.JTextField" binding="myHostTextField">
<constraints>
<grid row="0" column="1" row-span="1" col-span="2" 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/>
<clientProperties>
<caretAspectRatio class="java.lang.Float" value="0.04"/>
</clientProperties>
</component>
</children>
</grid>
</form>
@@ -16,11 +16,11 @@
package org.jetbrains.plugins.github.ui;
import com.intellij.ide.BrowserUtil;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectManager;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.ui.HyperlinkAdapter;
import org.jetbrains.plugins.github.GithubUtil;
import org.jetbrains.plugins.github.GithubSettings;
import javax.swing.*;
import javax.swing.event.HyperlinkEvent;
@@ -33,14 +33,11 @@ import java.awt.event.ActionListener;
* @date 10/20/10
*/
public class GithubSettingsPanel {
private JTextField myLoginTextField;
private JPasswordField myPasswordField;
private JTextPane mySignupTextField;
private JPanel myPane;
private JButton myTestButton;
private JTextField myHostTextField;
public GithubSettingsPanel() {
public GithubSettingsPanel(final GithubSettings settings) {
mySignupTextField.addHyperlinkListener(new HyperlinkAdapter() {
@Override
protected void hyperlinkActivated(final HyperlinkEvent e) {
@@ -54,10 +51,12 @@ public class GithubSettingsPanel {
myTestButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (GithubUtil.checkCredentials(ProjectManager.getInstance().getDefaultProject(), getHost(), getLogin(), getPassword())){
Messages.showInfoMessage("Connection successful", "Success");
} else {
Messages.showErrorDialog("Cannot login to the " + getHost() + " using given credentials", "Failure");
Project project = ProjectManager.getInstance().getDefaultProject();
final GithubLoginDialog dialog = new GithubLoginDialog(project);
dialog.show();
if (dialog.isOK()){
// the dialog won't let close after pressing OK if the connection is not successful
Messages.showInfoMessage(myPane, "Connection successful", "Success");
}
}
});
@@ -67,29 +66,5 @@ public class GithubSettingsPanel {
return myPane;
}
public void setLogin(final String login) {
myLoginTextField.setText(login);
}
public void setPassword(final String password) {
// Show password as blank if password is empty
myPasswordField.setText(StringUtil.isEmpty(password) ? null : password);
}
public String getLogin() {
return myLoginTextField.getText().trim();
}
public String getPassword() {
return String.valueOf(myPasswordField.getPassword());
}
public void setHost(final String host) {
myHostTextField.setText(host);
}
public String getHost() {
return myHostTextField.getText().trim();
}
}