refs:3772: SAI - Create a github project importer

https://support.d4science.org/issues/3772

Added usage example

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/widgets/github-connector@129144 82a268e6-3cf1-43bd-a215-b396298e98cf
master
Giancarlo Panichi 8 years ago
parent 95f5eeb637
commit e8d96e5d75

@ -2,7 +2,9 @@ package org.gcube.portlets.widgets.githubconnector.client;
import org.gcube.portlets.user.gcubewidgets.client.ClientScopeHelper;
import org.gcube.portlets.widgets.githubconnector.client.util.GWTMessages;
import org.gcube.portlets.widgets.githubconnector.client.wizard.event.WizardEvent;
import com.allen_sauer.gwt.log.client.Log;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.Scheduler;
import com.google.gwt.core.client.Scheduler.ScheduledCommand;
@ -67,6 +69,26 @@ public class GitHubConnectorManager implements EntryPoint {
private void loadMainPanel() {
GWT.log("GitHubConnectorManager");
//Example
WizardEvent.WizardEventHandler handler=new WizardEvent.WizardEventHandler() {
@Override
public void onResponse(WizardEvent event) {
Log.debug("Wizard Response: "+event.getWizardEventType());
}
};
GitHubConnectorWizard wizard=new GitHubConnectorWizard("0cfde9e2-a6f0-451f-a048-adbd42d7d57f");
wizard.addWizardEventHandler(handler);
wizard.show();
/*
WaitDialog progressDialog=new WaitDialog();
progressDialog.show();
*/
/*
WizardWindow wizardWindow = new WizardWindow("TestWindow");
SimpleWizardCard simple1=new SimpleWizardCard("Test Title 1","Test Footer 1", "This is 1 card");
@ -78,16 +100,7 @@ public class GitHubConnectorManager implements EntryPoint {
wizardWindow.show();
*/
GitHubConnectorWizard wizard=new GitHubConnectorWizard("0cfde9e2-a6f0-451f-a048-adbd42d7d57f");
wizard.show();
/*
WaitDialog progressDialog=new WaitDialog();
progressDialog.show();
*/
}
/*

@ -7,6 +7,8 @@ import org.gcube.portlets.widgets.githubconnector.client.rpc.GitHubConnectorServ
import org.gcube.portlets.widgets.githubconnector.client.util.GWTMessages;
import org.gcube.portlets.widgets.githubconnector.client.util.WaitDialog;
import org.gcube.portlets.widgets.githubconnector.client.wizard.WizardCard;
import org.gcube.portlets.widgets.githubconnector.client.wizard.event.WizardEvent;
import org.gcube.portlets.widgets.githubconnector.client.wizard.event.WizardEventType;
import org.gcube.portlets.widgets.githubconnector.shared.exception.ExpiredSessionServiceException;
import org.gcube.portlets.widgets.githubconnector.shared.git.data.GitHubRepository;
@ -102,11 +104,11 @@ public class GitHubConnectorRepositorySelectionCard extends WizardCard {
GWT.log("Error retrieving repositories: "
+ caught.getMessage());
if (caught instanceof ExpiredSessionServiceException) {
GWTMessages.alert("Error", "Expired Session");
showErrorAndHide("Error", "Expired Session");
wiz.sessionExpiredShowDelayed();
} else {
GWTMessages.alert(
showErrorAndHide(
"Error",
"Retrieving repositories: "
+ caught.getLocalizedMessage());
@ -193,11 +195,11 @@ public class GitHubConnectorRepositorySelectionCard extends WizardCard {
GWT.log("Error in clone repository: "
+ caught.getMessage());
if (caught instanceof ExpiredSessionServiceException) {
GWTMessages.alert("Error", "Expired Session");
showErrorAndHide("Error", "Expired Session");
wiz.sessionExpiredShowDelayed();
} else {
GWTMessages.alert(
showErrorAndHide(
"Error",
"In clone repository: "
+ caught.getLocalizedMessage());
@ -217,6 +219,8 @@ public class GitHubConnectorRepositorySelectionCard extends WizardCard {
private void goNext() {
try {
GWT.log("NextCard");
WizardEvent event=new WizardEvent(WizardEventType.Completed);
getWizardWindow().fireEvent(event);
getWizardWindow().close(false);
} catch (Exception e) {
GWT.log("sayNextCard :" + e.getLocalizedMessage());

@ -217,11 +217,18 @@ public class WizardCard extends SimplePanel {
return (indexPosition>=0)?indexPosition+1:indexPosition;
}
public void showErrorAndHide(String title, final String message, String details, final Throwable throwable)
public void showErrorAndHide(String title, final String message, final Throwable throwable)
{
wizardWindow.showErrorAndHide(title, message, details, throwable);
wizardWindow.showErrorAndHide(title, message, throwable);
}
public void showErrorAndHide(String title, final String message)
{
wizardWindow.showErrorAndHide(title, message);
}
public void hideWindow()
{
wizardWindow.hide();

@ -1,42 +0,0 @@
/**
*
*/
package org.gcube.portlets.widgets.githubconnector.client.wizard;
/**
*
* @author "Giancarlo Panichi"
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public interface WizardListener {
/**
* Called when the wizard is completed without errors
*/
public void completed(String id);
/**
* Called when the operation is put in background
*/
public void putInBackground();
/**
* Called when the wizard has been aborted by the user.
*/
public void aborted();
/**
* Called when the something in the wizard is failed.
* @param title
* @param message the failure reason.
* @param details the failure details.
* @param throwable the exception.
*/
public void failed(String title, String message, String details, Throwable throwable);
}

@ -7,6 +7,9 @@ import java.util.ArrayList;
import org.gcube.portlets.widgets.githubconnector.client.resource.GCResources;
import org.gcube.portlets.widgets.githubconnector.client.util.GWTMessages;
import org.gcube.portlets.widgets.githubconnector.client.wizard.event.WizardEvent;
import org.gcube.portlets.widgets.githubconnector.client.wizard.event.WizardEventType;
import org.gcube.portlets.widgets.githubconnector.client.wizard.event.WizardEvent.WizardEventHandler;
import com.google.gwt.core.client.Callback;
import com.google.gwt.core.client.GWT;
@ -38,13 +41,12 @@ import com.google.gwt.user.client.ui.Widget;
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class WizardWindow extends DialogBox {
public class WizardWindow extends DialogBox implements WizardEvent.HasWizardEventHandler {
private HandlerRegistration resizeHandlerRegistration;
protected boolean WIZARD_RESIZABLE = false;
protected boolean WIZARD_COLLAPSIBLE = true;
protected ArrayList<WizardListener> listeners;
protected EventBus eventBus;
protected String title;
@ -93,7 +95,6 @@ public class WizardWindow extends DialogBox {
initHandler();
addToolIcon();
listeners = new ArrayList<WizardListener>();
deckPanel = new DeckPanel();
backButton = new Button("<div><img class='"
@ -178,13 +179,6 @@ public class WizardWindow extends DialogBox {
this.originalTitle = title;
}
public void addListener(WizardListener listener) {
listeners.add(listener);
}
public void removeListener(WizardListener listener) {
listeners.remove(listener);
}
/**
* Shows the next available card.
@ -517,28 +511,42 @@ public class WizardWindow extends DialogBox {
public ArrayList<WizardCard> getCardStack() {
return cardStack;
}
public void showErrorAndHide(final String title, final String message) {
showErrorAndHide(title, message,
new Throwable());
}
public void showErrorAndHide(final String title, final String message,
final String details, final Throwable throwable) {
GWTMessages.alert(title, message + " " + details,
new Callback<Void, Void>() {
final Throwable throwable) {
final WizardEvent event=new WizardEvent(WizardEventType.Failed);
event.setErrorMessage(message);
event.setException(new Exception(throwable));
GWTMessages.alert(title, message, new Callback<Void, Void>() {
@Override
public void onFailure(Void reason) {
hide();
@Override
public void onFailure(Void reason) {
fireEvent(event);
hide();
}
}
@Override
public void onSuccess(Void result) {
hide();
@Override
public void onSuccess(Void result) {
fireEvent(event);
hide();
}
}
});
});
}
private Node closeEventTarget = null;
private void addToolIcon() {
@ -566,6 +574,8 @@ public class WizardWindow extends DialogBox {
if (!event.isCanceled() && (event.getTypeInt() == Event.ONCLICK)
&& isCloseEvent(nativeEvent)) {
final WizardEvent wizardEvent=new WizardEvent(WizardEventType.Aborted);
fireEvent(wizardEvent);
this.hide();
}
super.onPreviewNativeEvent(event);
@ -580,4 +590,10 @@ public class WizardWindow extends DialogBox {
// DOM elements
}
@Override
public HandlerRegistration addWizardEventHandler(WizardEventHandler handler) {
return addHandler(handler, WizardEvent.getType());
}
}

@ -0,0 +1,85 @@
package org.gcube.portlets.widgets.githubconnector.client.wizard.event;
import com.google.gwt.event.shared.EventHandler;
import com.google.gwt.event.shared.GwtEvent;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.event.shared.HasHandlers;
/**
* Wizard Event
*
*
* @author "Giancarlo Panichi" <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class WizardEvent extends GwtEvent<WizardEvent.WizardEventHandler> {
public static Type<WizardEventHandler> TYPE = new Type<WizardEventHandler>();
private WizardEventType wizardEventType;
private String errorMessage;
private Exception exception;
public interface WizardEventHandler extends EventHandler {
void onResponse(WizardEvent event);
}
public interface HasWizardEventHandler extends HasHandlers {
public HandlerRegistration addWizardEventHandler(
WizardEventHandler handler);
}
public WizardEvent(WizardEventType wizardEventType) {
this.wizardEventType = wizardEventType;
}
@Override
protected void dispatch(WizardEventHandler handler) {
handler.onResponse(this);
}
@Override
public Type<WizardEventHandler> getAssociatedType() {
return TYPE;
}
public static Type<WizardEventHandler> getType() {
return TYPE;
}
public static void fire(HasHandlers source, WizardEvent deleteItemEvent) {
source.fireEvent(deleteItemEvent);
}
public WizardEventType getWizardEventType() {
return wizardEventType;
}
public void setWizardEventType(WizardEventType wizardEventType) {
this.wizardEventType = wizardEventType;
}
public String getErrorMessage() {
return errorMessage;
}
public void setErrorMessage(String errorMessage) {
this.errorMessage = errorMessage;
}
public Exception getException() {
return exception;
}
public void setException(Exception exception) {
this.exception = exception;
}
@Override
public String toString() {
return "WizardEvent [wizardEventType=" + wizardEventType
+ ", errorMessage=" + errorMessage + ", exception=" + exception
+ "]";
}
}

@ -0,0 +1,60 @@
package org.gcube.portlets.widgets.githubconnector.client.wizard.event;
import java.util.Arrays;
import java.util.List;
/**
*
* @author Giancarlo Panichi email: <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public enum WizardEventType {
Completed("Completed"), Failed("Failed"), Aborted("Aborted"), Background(
"Background");
/**
* @param text
*/
private WizardEventType(final String id) {
this.id = id;
}
private final String id;
@Override
public String toString() {
return id;
}
public String getLabel() {
return id;
}
public String getId() {
return id;
}
/**
*
* @param id
* @return
*/
public static WizardEventType getTypeFromId(String id) {
if (id == null || id.isEmpty())
return null;
for (WizardEventType type : values()) {
if (type.id.compareToIgnoreCase(id) == 0) {
return type;
}
}
return null;
}
public static List<WizardEventType> asList() {
List<WizardEventType> list = Arrays.asList(values());
return list;
}
}
Loading…
Cancel
Save