mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Support for own github installation
This commit is contained in:
@@ -100,7 +100,7 @@ public class GithubOpenInBrowserAction extends DumbAwareAction {
|
||||
|
||||
final String pushUrl = githubRemote.pushUrl();
|
||||
int index = -1;
|
||||
if (pushUrl.startsWith(GithubUtil.GITHUB_HOST)) {
|
||||
if (pushUrl.startsWith(GithubUtil.getHttpsUrl())) {
|
||||
index = pushUrl.lastIndexOf('/');
|
||||
if (index == -1) {
|
||||
Messages.showErrorDialog(project, "Cannot extract info about repository name: " + pushUrl, CANNOT_OPEN_IN_BROWSER);
|
||||
|
||||
@@ -25,21 +25,25 @@ public class GithubSettings implements PersistentStateComponent<Element> {
|
||||
private static final String GITHUB_SETTINGS_TAG = "GithubSettings";
|
||||
private static final String LOGIN = "Login";
|
||||
private static final String PASSWORD = "Password";
|
||||
private static final String HOST = "Host";
|
||||
private static final String GITHUB = "github.com";
|
||||
|
||||
private String myLogin;
|
||||
private String myPassword;
|
||||
private String myHost;
|
||||
|
||||
public static GithubSettings getInstance(){
|
||||
return ServiceManager.getService(GithubSettings.class);
|
||||
}
|
||||
|
||||
public Element getState() {
|
||||
if (StringUtil.isEmptyOrSpaces(myLogin) && StringUtil.isEmptyOrSpaces(myPassword)) {
|
||||
if (StringUtil.isEmptyOrSpaces(myLogin) && StringUtil.isEmptyOrSpaces(myPassword) && StringUtil.isEmptyOrSpaces(myHost)) {
|
||||
return null;
|
||||
}
|
||||
final Element element = new Element(GITHUB_SETTINGS_TAG);
|
||||
element.setAttribute(LOGIN, getLogin());
|
||||
element.setAttribute(PASSWORD, getEncodedPassword());
|
||||
element.setAttribute(HOST, getHost());
|
||||
return element;
|
||||
}
|
||||
|
||||
@@ -60,6 +64,7 @@ public class GithubSettings implements PersistentStateComponent<Element> {
|
||||
try {
|
||||
setLogin(element.getAttributeValue(LOGIN));
|
||||
setEncodedPassword(element.getAttributeValue(PASSWORD));
|
||||
setHost(element.getAttributeValue(HOST));
|
||||
}
|
||||
catch (Exception e) {
|
||||
// ignore
|
||||
@@ -76,6 +81,10 @@ public class GithubSettings implements PersistentStateComponent<Element> {
|
||||
return myPassword != null ? myPassword : "";
|
||||
}
|
||||
|
||||
public String getHost() {
|
||||
return myHost != null ? myHost : GITHUB;
|
||||
}
|
||||
|
||||
public void setLogin(final String login) {
|
||||
myLogin = login != null ? login : "";
|
||||
}
|
||||
@@ -83,4 +92,9 @@ public class GithubSettings implements PersistentStateComponent<Element> {
|
||||
public void setPassword(final String password) {
|
||||
myPassword = password != null ? password : "";
|
||||
}
|
||||
|
||||
public void setHost(final String host) {
|
||||
myHost = host != null ? host : GITHUB;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -94,7 +94,7 @@ public class GithubShareAction extends DumbAwareAction {
|
||||
@Override
|
||||
public Boolean compute() {
|
||||
ProgressManager.getInstance().getProgressIndicator().setText("Trying to login to GitHub");
|
||||
return GithubUtil.isPrivateRepoAllowed(settings.getLogin(), settings.getPassword());
|
||||
return GithubUtil.isPrivateRepoAllowed(settings.getHost(), settings.getLogin(), settings.getPassword());
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -112,7 +112,7 @@ public class GithubShareAction extends DumbAwareAction {
|
||||
final String description = shareDialog.getDescription();
|
||||
try {
|
||||
LOG.info("Creating GitHub repository");
|
||||
GithubUtil.doREST(settings.getLogin(), settings.getPassword(),
|
||||
GithubUtil.doREST(settings.getHost(), settings.getLogin(), settings.getPassword(),
|
||||
"/repos/create?name=" + name + "&description=" + description + "&public=" + (isPrivate ? "0" : "1"), true);
|
||||
LOG.info("Successfully created GitHub repository");
|
||||
}
|
||||
|
||||
@@ -35,12 +35,17 @@ import java.util.List;
|
||||
* @author oleg
|
||||
*/
|
||||
public class GithubUtil {
|
||||
public static final String GITHUB_HOST = "https://github.com";
|
||||
public static final String GITHUB_HOST_GIT = "git@github.com";
|
||||
|
||||
private static final String API_URL = "/api/v2/xml";
|
||||
private static final Logger LOG = Logger.getInstance(GithubUtil.class.getName());
|
||||
|
||||
public static String getHttpsUrl() {
|
||||
return "https://" + GithubSettings.getInstance().getHost();
|
||||
}
|
||||
|
||||
public static String getHostByUrl(final String url) {
|
||||
return url.startsWith("https://") ? url.substring(8) : url.startsWith("http://") ? url.substring(7) : url.startsWith("git@") ? url.substring(4) : url;
|
||||
}
|
||||
|
||||
public static <T> T accessToGithubWithModalProgress(final Project project, final Computable<T> computable) throws CancelledException {
|
||||
final Ref<T> result = new Ref<T>();
|
||||
ProgressManager.getInstance().run(new Task.Modal(project, "Access to GitHub", true) {
|
||||
@@ -69,9 +74,9 @@ public class GithubUtil {
|
||||
});
|
||||
}
|
||||
|
||||
public static boolean testConnection(final String login, final String password) {
|
||||
public static boolean testConnection(final String url, final String login, final String password) {
|
||||
try {
|
||||
final HttpMethod method = doREST(login, password, "/user/show/" + login, false);
|
||||
final HttpMethod method = doREST(url, login, password, "/user/show/" + login, false);
|
||||
final InputStream stream = method.getResponseBodyAsStream();
|
||||
final Element element = new SAXBuilder(false).build(stream).getRootElement();
|
||||
if ("error".equals(element.getName())){
|
||||
@@ -86,10 +91,10 @@ public class GithubUtil {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static HttpMethod doREST(final String login, final String password, final String request, final boolean post) throws Exception {
|
||||
public static HttpMethod doREST(final String url, final String login, final String password, final String request, final boolean post) throws Exception {
|
||||
final HttpClient client = getHttpClient(login, password);
|
||||
client.getParams().setContentCharset("UTF-8");
|
||||
final String uri = JDOMUtil.escapeText(getUrl() + request, true, true);
|
||||
final String uri = JDOMUtil.escapeText("https://" + getHostByUrl(url) + API_URL + request, true, true);
|
||||
final HttpMethod method = post ? new PostMethod(uri) : new GetMethod(uri);
|
||||
client.executeMethod(method);
|
||||
return method;
|
||||
@@ -111,14 +116,10 @@ public class GithubUtil {
|
||||
return client;
|
||||
}
|
||||
|
||||
private static String getUrl() {
|
||||
return GITHUB_HOST + API_URL;
|
||||
}
|
||||
|
||||
public static List<RepositoryInfo> getAvailableRepos(final String login, final String password, final boolean ownOnly) {
|
||||
public static List<RepositoryInfo> getAvailableRepos(final String url, final String login, final String password, final boolean ownOnly) {
|
||||
try {
|
||||
final String request = (ownOnly ? "/repos/show/" : "/repos/watched/") + login;
|
||||
final HttpMethod method = doREST(login, password, request, false);
|
||||
final HttpMethod method = doREST(url, login, password, request, false);
|
||||
final InputStream stream = method.getResponseBodyAsStream();
|
||||
final Element element = new SAXBuilder(false).build(stream).getRootElement();
|
||||
if ("error".equals(element.getName())){
|
||||
@@ -140,10 +141,10 @@ public class GithubUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static RepositoryInfo getDetailedRepoInfo(final String login, final String password, final String name) {
|
||||
public static RepositoryInfo getDetailedRepoInfo(final String url, final String login, final String password, final String name) {
|
||||
try {
|
||||
final String request = "/repos/show/" + login + "/" + name;
|
||||
final HttpMethod method = doREST(login, password, request, false);
|
||||
final HttpMethod method = doREST(url, login, password, request, false);
|
||||
final InputStream stream = method.getResponseBodyAsStream();
|
||||
final Element element = new SAXBuilder(false).build(stream).getRootElement();
|
||||
if ("error".equals(element.getName())){
|
||||
@@ -158,10 +159,10 @@ public class GithubUtil {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean isPrivateRepoAllowed(final String login, final String password) {
|
||||
public static boolean isPrivateRepoAllowed(final String url, final String login, final String password) {
|
||||
try {
|
||||
final String request = "/user/show/" + login;
|
||||
final HttpMethod method = doREST(login, password, request, false);
|
||||
final HttpMethod method = doREST(url, login, password, request, false);
|
||||
final InputStream stream = method.getResponseBodyAsStream();
|
||||
final Element element = new SAXBuilder(false).build(stream).getRootElement();
|
||||
if ("error".equals(element.getName())){
|
||||
@@ -180,9 +181,9 @@ public class GithubUtil {
|
||||
}
|
||||
|
||||
public static boolean checkCredentials(final Project project) {
|
||||
return checkCredentials(project, null, null);
|
||||
return checkCredentials(project, null, null, null);
|
||||
}
|
||||
public static boolean checkCredentials(final Project project, @Nullable final String login, @Nullable final String password) {
|
||||
public static boolean checkCredentials(final Project project, @Nullable final String url, @Nullable final String login, @Nullable final String password) {
|
||||
if (login == null && password == null && areCredentialsEmpty()){
|
||||
return false;
|
||||
}
|
||||
@@ -191,11 +192,11 @@ public class GithubUtil {
|
||||
@Override
|
||||
public Boolean compute() {
|
||||
ProgressManager.getInstance().getProgressIndicator().setText("Trying to login to GitHub");
|
||||
if (login != null && password != null){
|
||||
return testConnection(login, password);
|
||||
if (url != null && login != null && password != null){
|
||||
return testConnection(url, login, password);
|
||||
}
|
||||
final GithubSettings settings = GithubSettings.getInstance();
|
||||
return testConnection(settings.getLogin(), settings.getPassword());
|
||||
return testConnection(settings.getHost(), settings.getLogin(), settings.getPassword());
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -225,7 +226,7 @@ public class GithubUtil {
|
||||
@Override
|
||||
public Boolean compute() {
|
||||
ProgressManager.getInstance().getProgressIndicator().setText("Trying to login to GitHub");
|
||||
return testConnection(settings.getLogin(), settings.getPassword());
|
||||
return testConnection(settings.getHost(), settings.getLogin(), settings.getPassword());
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -245,7 +246,7 @@ public class GithubUtil {
|
||||
@Override
|
||||
public List<RepositoryInfo> compute() {
|
||||
ProgressManager.getInstance().getProgressIndicator().setText("Extracting info about available repositories");
|
||||
return getAvailableRepos(settings.getLogin(), settings.getPassword(), ownOnly);
|
||||
return getAvailableRepos(settings.getHost(), settings.getLogin(), settings.getPassword(), ownOnly);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -268,7 +269,7 @@ public class GithubUtil {
|
||||
@Override
|
||||
public Boolean compute() {
|
||||
ProgressManager.getInstance().getProgressIndicator().setText("Trying to login to GitHub");
|
||||
return testConnection(settings.getLogin(), settings.getPassword());
|
||||
return testConnection(settings.getHost(), settings.getLogin(), settings.getPassword());
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -288,7 +289,7 @@ public class GithubUtil {
|
||||
@Override
|
||||
public RepositoryInfo compute() {
|
||||
ProgressManager.getInstance().getProgressIndicator().setText("Extracting detailed info about repository ''" + name + "''");
|
||||
return getDetailedRepoInfo(settings.getLogin(), settings.getPassword(), name);
|
||||
return getDetailedRepoInfo(settings.getHost(), settings.getLogin(), settings.getPassword(), name);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -312,10 +313,11 @@ public class GithubUtil {
|
||||
public static GitRemote findGitHubRemoteBranch(final Project project, final VirtualFile root) {
|
||||
try {
|
||||
// Check that given repository is properly configured git repository
|
||||
final String host = GithubSettings.getInstance().getHost();
|
||||
final List<GitRemote> gitRemotes = GitRemote.list(project, root);
|
||||
for (GitRemote gitRemote : gitRemotes) {
|
||||
final String pushUrl = gitRemote.pushUrl();
|
||||
if (pushUrl.startsWith(GITHUB_HOST) || pushUrl.startsWith(GITHUB_HOST_GIT)) {
|
||||
if (pushUrl.contains(host)) {
|
||||
return gitRemote;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,13 +42,15 @@ public class GitHubSettingsConfigurable implements SearchableConfigurable {
|
||||
|
||||
public boolean isModified() {
|
||||
return mySettingsPane == null || !mySettings.getLogin().equals(mySettingsPane.getLogin()) ||
|
||||
!mySettings.getPassword().equals(mySettingsPane.getPassword());
|
||||
!mySettings.getPassword().equals(mySettingsPane.getPassword()) ||
|
||||
!mySettings.getHost().equals(mySettingsPane.getHost());
|
||||
}
|
||||
|
||||
public void apply() throws ConfigurationException {
|
||||
if (mySettingsPane != null) {
|
||||
mySettings.setLogin(mySettingsPane.getLogin());
|
||||
mySettings.setPassword(mySettingsPane.getPassword());
|
||||
mySettings.setHost(mySettingsPane.getHost());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,6 +58,7 @@ public class GitHubSettingsConfigurable implements SearchableConfigurable {
|
||||
if (mySettingsPane != null) {
|
||||
mySettingsPane.setLogin(mySettings.getLogin());
|
||||
mySettingsPane.setPassword(mySettings.getPassword());
|
||||
mySettingsPane.setHost(mySettings.getHost());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ public class GithubLoginDialog extends DialogWrapper {
|
||||
myProject = project;
|
||||
myGithubLoginPanel = new GithubLoginPanel(this);
|
||||
final GithubSettings settings = GithubSettings.getInstance();
|
||||
myGithubLoginPanel.setHost(settings.getHost());
|
||||
myGithubLoginPanel.setLogin(settings.getLogin());
|
||||
myGithubLoginPanel.setPassword(settings.getPassword());
|
||||
setTitle("Login to GitHub");
|
||||
@@ -51,7 +52,8 @@ public class GithubLoginDialog extends DialogWrapper {
|
||||
protected void doOKAction() {
|
||||
final String login = myGithubLoginPanel.getLogin();
|
||||
final String password = myGithubLoginPanel.getPassword();
|
||||
if (GithubUtil.checkCredentials(myProject, login, password)) {
|
||||
final String host = myGithubLoginPanel.getHost();
|
||||
if (GithubUtil.checkCredentials(myProject, host, login, password)) {
|
||||
final GithubSettings settings = GithubSettings.getInstance();
|
||||
settings.setLogin(login);
|
||||
settings.setPassword(password);
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
<?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.GithubLoginPanel">
|
||||
<grid id="27dc6" binding="myPane" layout-manager="GridLayoutManager" row-count="4" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<grid id="27dc6" binding="myPane" layout-manager="GridLayoutManager" row-count="5" 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="106"/>
|
||||
<xy x="20" y="20" width="500" height="137"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="e76ec" class="javax.swing.JTextField" binding="myLoginTextField">
|
||||
<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">
|
||||
<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>
|
||||
@@ -21,7 +21,7 @@
|
||||
</component>
|
||||
<component id="c0234" 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"/>
|
||||
<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"/>
|
||||
@@ -29,7 +29,7 @@
|
||||
</component>
|
||||
<component id="d7c6c" 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"/>
|
||||
<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"/>
|
||||
@@ -37,7 +37,7 @@
|
||||
</component>
|
||||
<component id="28ddd" class="javax.swing.JTextPane" binding="mySignupTextField">
|
||||
<constraints>
|
||||
<grid row="2" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||
<grid row="3" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||
<minimum-size width="-1" height="20"/>
|
||||
<preferred-size width="150" height="20"/>
|
||||
</grid>
|
||||
@@ -54,7 +54,7 @@
|
||||
</component>
|
||||
<component id="9edbd" class="javax.swing.JPasswordField" binding="myPasswordField">
|
||||
<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">
|
||||
<grid row="2" 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>
|
||||
@@ -65,9 +65,28 @@
|
||||
</component>
|
||||
<vspacer id="9b306">
|
||||
<constraints>
|
||||
<grid row="3" 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="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"/>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
<component id="dbea1" 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>
|
||||
<text value="Host"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="f5630" class="javax.swing.JTextField" binding="myHostTextField">
|
||||
<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/>
|
||||
<clientProperties>
|
||||
<caretAspectRatio class="java.lang.Float" value="0.04"/>
|
||||
</clientProperties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
||||
|
||||
@@ -18,7 +18,6 @@ package org.jetbrains.plugins.github.ui;
|
||||
import com.intellij.ide.BrowserUtil;
|
||||
import com.intellij.ui.DocumentAdapter;
|
||||
import com.intellij.ui.HyperlinkAdapter;
|
||||
import org.jetbrains.plugins.github.GithubUtil;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.DocumentEvent;
|
||||
@@ -34,6 +33,7 @@ public class GithubLoginPanel {
|
||||
private JPasswordField myPasswordField;
|
||||
private JTextPane mySignupTextField;
|
||||
private JPanel myPane;
|
||||
private JTextField myHostTextField;
|
||||
|
||||
public GithubLoginPanel(final GithubLoginDialog dialog) {
|
||||
mySignupTextField.addHyperlinkListener(new HyperlinkAdapter() {
|
||||
@@ -43,7 +43,7 @@ public class GithubLoginPanel {
|
||||
}
|
||||
});
|
||||
mySignupTextField.setText(
|
||||
"<html>Do not have an account? <a href=\"" + GithubUtil.GITHUB_HOST + "\">" + "Sign up" + "</a></html>");
|
||||
"<html>Do not have an account at github.com? <a href=\"https://github.com\">" + "Sign up" + "</a></html>");
|
||||
mySignupTextField.setBackground(myPane.getBackground());
|
||||
mySignupTextField.setCursor(new Cursor(Cursor.HAND_CURSOR));
|
||||
myLoginTextField.getDocument().addDocumentListener(new DocumentAdapter() {
|
||||
@@ -64,6 +64,10 @@ public class GithubLoginPanel {
|
||||
return myPane;
|
||||
}
|
||||
|
||||
public void setHost(final String host) {
|
||||
myHostTextField.setText(host);
|
||||
}
|
||||
|
||||
public void setLogin(final String login) {
|
||||
myLoginTextField.setText(login);
|
||||
}
|
||||
@@ -72,8 +76,12 @@ public class GithubLoginPanel {
|
||||
myPasswordField.setText(password);
|
||||
}
|
||||
|
||||
public String getHost() {
|
||||
return myHostTextField.getText().trim();
|
||||
}
|
||||
|
||||
public String getLogin() {
|
||||
return myLoginTextField.getText();
|
||||
return myLoginTextField.getText().trim();
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
|
||||
@@ -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="4" 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="5" column-count="3" 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"/>
|
||||
@@ -10,7 +10,7 @@
|
||||
<children>
|
||||
<component id="e76ec" class="javax.swing.JTextField" binding="myLoginTextField">
|
||||
<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">
|
||||
<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>
|
||||
@@ -21,7 +21,7 @@
|
||||
</component>
|
||||
<component id="c0234" 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"/>
|
||||
<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"/>
|
||||
@@ -29,7 +29,7 @@
|
||||
</component>
|
||||
<component id="d7c6c" 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"/>
|
||||
<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"/>
|
||||
@@ -37,7 +37,7 @@
|
||||
</component>
|
||||
<component id="28ddd" class="javax.swing.JTextPane" binding="mySignupTextField">
|
||||
<constraints>
|
||||
<grid row="2" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||
<grid row="3" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="150" height="10"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
@@ -53,7 +53,7 @@
|
||||
</component>
|
||||
<component id="9edbd" class="javax.swing.JPasswordField" binding="myPasswordField">
|
||||
<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">
|
||||
<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>
|
||||
@@ -64,7 +64,7 @@
|
||||
</component>
|
||||
<component id="8a6dd" class="javax.swing.JButton" binding="myTestButton" default-binding="true">
|
||||
<constraints>
|
||||
<grid row="2" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
<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"/>
|
||||
@@ -72,9 +72,28 @@
|
||||
</component>
|
||||
<vspacer id="6ace">
|
||||
<constraints>
|
||||
<grid row="3" 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="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"/>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
<component id="45bab" 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>
|
||||
<text value="Host"/>
|
||||
</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>
|
||||
|
||||
@@ -37,6 +37,7 @@ public class GithubSettingsPanel {
|
||||
private JTextPane mySignupTextField;
|
||||
private JPanel myPane;
|
||||
private JButton myTestButton;
|
||||
private JTextField myHostTextField;
|
||||
|
||||
public GithubSettingsPanel() {
|
||||
mySignupTextField.addHyperlinkListener(new HyperlinkAdapter() {
|
||||
@@ -46,14 +47,14 @@ public class GithubSettingsPanel {
|
||||
}
|
||||
});
|
||||
mySignupTextField.setText(
|
||||
"<html>Do not have an account? <a href=\"" + GithubUtil.GITHUB_HOST + "\">" + "Sign up" + "</a></html>");
|
||||
"<html>Do not have an account at github.com? <a href=\"https://github.com\">" + "Sign up" + "</a></html>");
|
||||
mySignupTextField.setBackground(myPane.getBackground());
|
||||
mySignupTextField.setCursor(new Cursor(Cursor.HAND_CURSOR));
|
||||
myTestButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
final boolean result = GithubUtil.checkCredentials(ProjectManager.getInstance().getDefaultProject(), getLogin(), getPassword());
|
||||
Messages.showInfoMessage(result ? "Connection successful" : "Cannot login using given credentials", result ? "Success" : "Fail");
|
||||
final boolean result = GithubUtil.checkCredentials(ProjectManager.getInstance().getDefaultProject(), getHost(), getLogin(), getPassword());
|
||||
Messages.showInfoMessage(result ? "Connection successful" : "Cannot login to the " + getHost() + " using given credentials", result ? "Success" : "Failure");
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -71,11 +72,19 @@ public class GithubSettingsPanel {
|
||||
}
|
||||
|
||||
public String getLogin() {
|
||||
return myLoginTextField.getText();
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user