|
|
|
@ -1,151 +1,104 @@
|
|
|
|
|
package org.gcube.portlets.widgets.githubconnector.client;
|
|
|
|
|
|
|
|
|
|
import org.gcube.portlets.widgets.githubconnector.client.util.GWTMessages;
|
|
|
|
|
import org.gcube.portlets.widgets.githubconnector.client.wizard.WizardCard;
|
|
|
|
|
import org.gcube.portlets.widgets.githubconnector.shared.git.credential.GitHubCredential;
|
|
|
|
|
import org.gcube.portlets.widgets.githubconnector.shared.git.credential.GitHubCredentialType;
|
|
|
|
|
import org.gcube.portlets.widgets.githubconnector.shared.git.data.credential.GitHubCredentialAnonymous;
|
|
|
|
|
import org.gcube.portlets.widgets.githubconnector.shared.git.data.credential.GitHubCredentialLogin;
|
|
|
|
|
import org.gcube.portlets.widgets.githubconnector.shared.git.data.credential.GitHubCredentialOAuth2;
|
|
|
|
|
|
|
|
|
|
import com.google.gwt.core.shared.GWT;
|
|
|
|
|
import com.google.gwt.event.logical.shared.ValueChangeEvent;
|
|
|
|
|
import com.google.gwt.event.logical.shared.ValueChangeHandler;
|
|
|
|
|
import com.google.gwt.dom.client.Style.Unit;
|
|
|
|
|
import com.google.gwt.event.dom.client.ClickEvent;
|
|
|
|
|
import com.google.gwt.event.dom.client.ClickHandler;
|
|
|
|
|
import com.google.gwt.user.client.Command;
|
|
|
|
|
import com.google.gwt.user.client.ui.DecoratorPanel;
|
|
|
|
|
import com.google.gwt.user.client.ui.CheckBox;
|
|
|
|
|
import com.google.gwt.user.client.ui.FlexTable;
|
|
|
|
|
import com.google.gwt.user.client.ui.HorizontalPanel;
|
|
|
|
|
import com.google.gwt.user.client.ui.RadioButton;
|
|
|
|
|
import com.google.gwt.user.client.ui.SimplePanel;
|
|
|
|
|
import com.google.gwt.user.client.ui.TabLayoutPanel;
|
|
|
|
|
import com.google.gwt.user.client.ui.TextBox;
|
|
|
|
|
|
|
|
|
|
public class GitHubConnectorCredentialCard extends WizardCard {
|
|
|
|
|
|
|
|
|
|
private GitHubCredential gitHubCredential;
|
|
|
|
|
private GitHubCredentialType selected;
|
|
|
|
|
private SimplePanel simplePanel;
|
|
|
|
|
private FlexTable layout;
|
|
|
|
|
private TabLayoutPanel tabPanel;
|
|
|
|
|
private TextBox userName;
|
|
|
|
|
private TextBox password;
|
|
|
|
|
private TextBox token;
|
|
|
|
|
//private DecoratorPanel decPanel;
|
|
|
|
|
private CheckBox anonymousCheck;
|
|
|
|
|
|
|
|
|
|
// private DecoratorPanel decPanel;
|
|
|
|
|
|
|
|
|
|
public GitHubConnectorCredentialCard() {
|
|
|
|
|
super("Credential", "Select the credentials to use");
|
|
|
|
|
selected = GitHubCredentialType.Anonymous;
|
|
|
|
|
|
|
|
|
|
simplePanel = new SimplePanel();
|
|
|
|
|
// Form
|
|
|
|
|
layout = new FlexTable();
|
|
|
|
|
layout.setCellSpacing(16);
|
|
|
|
|
|
|
|
|
|
tabPanel = new TabLayoutPanel(2.5, Unit.EM);
|
|
|
|
|
tabPanel.setAnimationDuration(1000);
|
|
|
|
|
tabPanel.setAnimationVertical(true);
|
|
|
|
|
tabPanel.getElement().getStyle().setMarginBottom(10.0, Unit.PX);
|
|
|
|
|
tabPanel.setHeight("120px");
|
|
|
|
|
tabPanel.setWidth("265px");
|
|
|
|
|
|
|
|
|
|
// Add Login Tab
|
|
|
|
|
SimplePanel loginContainer = new SimplePanel();
|
|
|
|
|
userName = new TextBox();
|
|
|
|
|
userName.setWidth("166px");
|
|
|
|
|
userName.setEnabled(false);
|
|
|
|
|
|
|
|
|
|
password = new TextBox();
|
|
|
|
|
token = new TextBox();
|
|
|
|
|
password.setWidth("166px");
|
|
|
|
|
password.setEnabled(false);
|
|
|
|
|
|
|
|
|
|
anonymousCheck = new CheckBox("Anonymous");
|
|
|
|
|
anonymousCheck.setValue(true);
|
|
|
|
|
anonymousCheck.ensureDebugId("credentialCheckBoxAnonymous");
|
|
|
|
|
anonymousCheck.addClickHandler(new ClickHandler() {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(ClickEvent event) {
|
|
|
|
|
if (anonymousCheck.getValue()) {
|
|
|
|
|
userName.setEnabled(false);
|
|
|
|
|
password.setEnabled(false);
|
|
|
|
|
userName.setValue("");
|
|
|
|
|
password.setValue("");
|
|
|
|
|
} else {
|
|
|
|
|
userName.setEnabled(true);
|
|
|
|
|
password.setEnabled(true);
|
|
|
|
|
userName.setValue("");
|
|
|
|
|
password.setValue("");
|
|
|
|
|
|
|
|
|
|
// Add some standard form options
|
|
|
|
|
HorizontalPanel hPanel = new HorizontalPanel();
|
|
|
|
|
hPanel.setSpacing(10);
|
|
|
|
|
|
|
|
|
|
for (GitHubCredentialType type : GitHubCredentialType.values()) {
|
|
|
|
|
|
|
|
|
|
RadioButton radioButton = new RadioButton("credentialType",
|
|
|
|
|
type.getLabel());
|
|
|
|
|
radioButton.getElement().setAttribute("itemId", type.name());
|
|
|
|
|
radioButton.ensureDebugId("radioButton-credentialType-"
|
|
|
|
|
+ type.name());
|
|
|
|
|
radioButton
|
|
|
|
|
.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onValueChange(
|
|
|
|
|
ValueChangeEvent<Boolean> event) {
|
|
|
|
|
if (event.getValue()) {
|
|
|
|
|
RadioButton radioButton = (RadioButton) event
|
|
|
|
|
.getSource();
|
|
|
|
|
String selectedCredential = radioButton
|
|
|
|
|
.getElement().getAttribute("itemId");
|
|
|
|
|
GWT.log("Selected Credential: "
|
|
|
|
|
+ selectedCredential);
|
|
|
|
|
if (selectedCredential != null) {
|
|
|
|
|
selected = GitHubCredentialType
|
|
|
|
|
.valueOf(selectedCredential);
|
|
|
|
|
|
|
|
|
|
if (selected != null) {
|
|
|
|
|
switch (selected) {
|
|
|
|
|
case Anonymous:
|
|
|
|
|
GWT.log("Anonymous");
|
|
|
|
|
setAnonymous();
|
|
|
|
|
break;
|
|
|
|
|
case Login:
|
|
|
|
|
GWT.log("Login");
|
|
|
|
|
setLogin();
|
|
|
|
|
break;
|
|
|
|
|
case OAuth2:
|
|
|
|
|
GWT.log("OAuth2");
|
|
|
|
|
setOAuth2();
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
GWT.log("OAuth2");
|
|
|
|
|
setAnonymous();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
selected = GitHubCredentialType.Anonymous;
|
|
|
|
|
setAnonymous();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
if (type.compareTo(GitHubCredentialType.Anonymous) == 0) {
|
|
|
|
|
radioButton.setValue(true);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
hPanel.add(radioButton);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
layout.setHTML(1, 0, "Type:");
|
|
|
|
|
layout.setWidget(1, 1, hPanel);
|
|
|
|
|
FlexTable loginFlexTable = new FlexTable();
|
|
|
|
|
loginFlexTable.setCellSpacing(16);
|
|
|
|
|
loginFlexTable.setHTML(1, 0, "Anonymous:");
|
|
|
|
|
loginFlexTable.setWidget(1, 1, anonymousCheck);
|
|
|
|
|
|
|
|
|
|
// Wrap the content in a DecoratorPanel
|
|
|
|
|
//decPanel = new DecoratorPanel();
|
|
|
|
|
//decPanel.setWidget(layout);
|
|
|
|
|
loginFlexTable.setHTML(2, 0, "User:");
|
|
|
|
|
loginFlexTable.setWidget(2, 1, userName);
|
|
|
|
|
|
|
|
|
|
simplePanel.add(layout);
|
|
|
|
|
setContent(simplePanel);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
loginFlexTable.setHTML(3, 0, "Password:");
|
|
|
|
|
loginFlexTable.setWidget(3, 1, password);
|
|
|
|
|
|
|
|
|
|
private void setAnonymous() {
|
|
|
|
|
if (selected.compareTo(GitHubCredentialType.Anonymous) != 0) {
|
|
|
|
|
for (int i = 1; i <= layout.getRowCount(); i++) {
|
|
|
|
|
layout.removeRow(i);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
loginContainer.add(loginFlexTable);
|
|
|
|
|
tabPanel.add(loginContainer, "Login");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
// Add OAuth2 Tab
|
|
|
|
|
SimplePanel oAuth2Container = new SimplePanel();
|
|
|
|
|
token = new TextBox();
|
|
|
|
|
token.setWidth("200px");
|
|
|
|
|
|
|
|
|
|
private void setOAuth2() {
|
|
|
|
|
if (selected.compareTo(GitHubCredentialType.OAuth2) != 0) {
|
|
|
|
|
for (int i = 1; i <= layout.getRowCount(); i++) {
|
|
|
|
|
layout.removeRow(i);
|
|
|
|
|
}
|
|
|
|
|
layout.setHTML(2, 0, "Token:");
|
|
|
|
|
layout.add(token);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
FlexTable oAuth2FlexTable = new FlexTable();
|
|
|
|
|
oAuth2FlexTable.setCellSpacing(16);
|
|
|
|
|
oAuth2FlexTable.setHTML(1, 0, "Token:");
|
|
|
|
|
oAuth2FlexTable.setWidget(1, 1, token);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
oAuth2Container.add(oAuth2FlexTable);
|
|
|
|
|
tabPanel.add(oAuth2Container, "OAuth2");
|
|
|
|
|
|
|
|
|
|
private void setLogin() {
|
|
|
|
|
if (selected.compareTo(GitHubCredentialType.Login) != 0) {
|
|
|
|
|
for (int i = 1; i <= layout.getRowCount(); i++) {
|
|
|
|
|
layout.removeRow(i);
|
|
|
|
|
}
|
|
|
|
|
layout.setHTML(2, 0, "User:");
|
|
|
|
|
layout.add(userName);
|
|
|
|
|
tabPanel.selectTab(0);
|
|
|
|
|
tabPanel.ensureDebugId("credentialTabPanel");
|
|
|
|
|
|
|
|
|
|
layout.setHTML(3, 0, "Password:");
|
|
|
|
|
layout.add(password);
|
|
|
|
|
}
|
|
|
|
|
setContent(tabPanel);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -154,12 +107,9 @@ public class GitHubConnectorCredentialCard extends WizardCard {
|
|
|
|
|
Command sayNextCard = new Command() {
|
|
|
|
|
|
|
|
|
|
public void execute() {
|
|
|
|
|
try {
|
|
|
|
|
GWT.log("NextCard");
|
|
|
|
|
getWizardWindow().nextCard();
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
GWT.log("sayNextCard :" + e.getLocalizedMessage());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
checkData();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
@ -171,6 +121,7 @@ public class GitHubConnectorCredentialCard extends WizardCard {
|
|
|
|
|
getWizardWindow().previousCard();
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
GWT.log("sayPreviousCard :" + e.getLocalizedMessage());
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
@ -184,4 +135,67 @@ public class GitHubConnectorCredentialCard extends WizardCard {
|
|
|
|
|
setNextButtonVisible(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void checkData() {
|
|
|
|
|
int selectedIndex = tabPanel.getSelectedIndex();
|
|
|
|
|
if (selectedIndex > -1) {
|
|
|
|
|
GWT.log("Selected Tab:" + selectedIndex);
|
|
|
|
|
if (selectedIndex == 0) {
|
|
|
|
|
if (anonymousCheck.getValue()) {
|
|
|
|
|
GitHubConnectorWizard wiz = (GitHubConnectorWizard) getWizardWindow();
|
|
|
|
|
wiz.getGitHubCloneSession().setGitHubCredential(
|
|
|
|
|
new GitHubCredentialAnonymous());
|
|
|
|
|
|
|
|
|
|
goNext();
|
|
|
|
|
} else {
|
|
|
|
|
String userN = userName.getValue();
|
|
|
|
|
if (userN == null || userN.isEmpty()) {
|
|
|
|
|
GWTMessages.alert("Attention", "Enter a user name!");
|
|
|
|
|
} else {
|
|
|
|
|
String pwd = password.getValue();
|
|
|
|
|
if (pwd == null || pwd.isEmpty()) {
|
|
|
|
|
GWTMessages.alert("Attention",
|
|
|
|
|
"Enter a user password!");
|
|
|
|
|
} else {
|
|
|
|
|
GitHubConnectorWizard wiz = (GitHubConnectorWizard) getWizardWindow();
|
|
|
|
|
wiz.getGitHubCloneSession().setGitHubCredential(
|
|
|
|
|
new GitHubCredentialLogin(userN, pwd));
|
|
|
|
|
goNext();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (selectedIndex == 1) {
|
|
|
|
|
String tk = token.getValue();
|
|
|
|
|
if (tk == null || tk.isEmpty()) {
|
|
|
|
|
GWTMessages.alert("Attention", "Enter a token!");
|
|
|
|
|
} else {
|
|
|
|
|
GitHubConnectorWizard wiz = (GitHubConnectorWizard) getWizardWindow();
|
|
|
|
|
wiz.getGitHubCloneSession().setGitHubCredential(
|
|
|
|
|
new GitHubCredentialOAuth2(tk));
|
|
|
|
|
goNext();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
GWTMessages.alert("Attention", "Select a valid tab!");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void goNext() {
|
|
|
|
|
try {
|
|
|
|
|
GWT.log("NextCard: GitHubConnectorRepositorySelectionCard");
|
|
|
|
|
GitHubConnectorRepositorySelectionCard card = new GitHubConnectorRepositorySelectionCard();
|
|
|
|
|
getWizardWindow().addCard(card);
|
|
|
|
|
getWizardWindow().nextCard();
|
|
|
|
|
} catch (Throwable e) {
|
|
|
|
|
GWT.log("sayNextCard :" + e.getLocalizedMessage());
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|