Minor Update

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-table-widget@94890 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2014-04-16 10:19:40 +00:00 committed by Giancarlo Panichi
parent 4e7c12668f
commit 665462b168
19 changed files with 667 additions and 2 deletions

View File

@ -0,0 +1,3 @@
.image {
cursor: pointer;
}

View File

@ -0,0 +1 @@
<div class="{style.image}" title="{title}">{img}</div>

View File

@ -0,0 +1,84 @@
package org.gcube.portlets.user.td.tablewidget.client.custom;
import com.google.gwt.cell.client.ValueUpdater;
import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Element;
import com.google.gwt.dom.client.NativeEvent;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.resources.client.ImageResource;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
import com.sencha.gxt.cell.core.client.ResizeCell;
import com.sencha.gxt.core.client.dom.XElement;
import com.sencha.gxt.widget.core.client.event.BeforeSelectEvent;
import com.sencha.gxt.widget.core.client.event.SelectEvent;
import com.sencha.gxt.widget.core.client.event.SelectEvent.HasSelectHandlers;
import com.sencha.gxt.widget.core.client.event.SelectEvent.SelectHandler;
/**
*
* @author "Giancarlo Panichi"
*
*/
public class ActionButtonCell extends ResizeCell<String> implements HasSelectHandlers {
private final ActionButtonCellAppearance appearance;
private ImageResource icon;
private String title;
public ActionButtonCell() {
this(GWT.<ActionButtonCellAppearance> create(ActionButtonCellAppearance.class));
}
public ActionButtonCell(ActionButtonCellAppearance appearance) {
super("click");
this.appearance = appearance;
}
public void setIcon(ImageResource icon) {
this.icon = icon;
}
public void setTitle(String title) {
this.title = title;
}
@Override
public HandlerRegistration addSelectHandler(SelectHandler handler) {
return addHandler(handler, SelectEvent.getType());
}
@Override
public void render(Context context,
String value, SafeHtmlBuilder sb) {
this.appearance.icon = icon;
this.appearance.title = title;
this.appearance.render(sb);
}
@Override
public void onBrowserEvent(Context context,
Element parent, String value, NativeEvent event,
ValueUpdater<String> valueUpdater) {
Element target = event.getEventTarget().cast();
// ignore the parent element
if (isDisableEvents() || !parent.getFirstChildElement().isOrHasChild(target)) {
return;
}
XElement p = parent.cast();
String eventType = event.getType();
if ("click".equals(eventType)) {
onClick(context, p, value, event, valueUpdater);
}
}
private void onClick(Context context, XElement p, String value, NativeEvent event, ValueUpdater<String> valueUpdater) {
if (!isDisableEvents() && fireCancellableEvent(context, new BeforeSelectEvent(context))) {
fireEvent(context, new SelectEvent(context));
}
}
}

View File

@ -0,0 +1,65 @@
package org.gcube.portlets.user.td.tablewidget.client.custom;
import com.google.gwt.core.client.GWT;
import com.google.gwt.resources.client.ClientBundle;
import com.google.gwt.resources.client.CssResource;
import com.google.gwt.resources.client.ImageResource;
import com.google.gwt.safehtml.shared.SafeHtml;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
import com.google.gwt.safehtml.shared.SafeHtmlUtils;
import com.google.gwt.user.client.ui.AbstractImagePrototype;
import com.sencha.gxt.core.client.XTemplates;
/**
*
* @author "Giancarlo Panichi"
*
*/
public class ActionButtonCellAppearance {
public interface Style extends CssResource {
String image();
}
public interface Template extends XTemplates {
@XTemplate(source = "ActionButton.html")
SafeHtml template(Style style, SafeHtml img, String title);
}
public interface Resources extends ClientBundle {
@Source("ActionButton.css")
Style style();
}
private final Style style;
private final Template template;
public ImageResource icon;
public String title;
public ActionButtonCellAppearance(){
this((Resources) GWT.create(Resources.class));
}
public ActionButtonCellAppearance(Resources resources){
this.style = resources.style();
this.style.ensureInjected();
this.template = GWT.create(Template.class);
}
public void render(SafeHtmlBuilder sb) {
sb.append(template.template(style, makeImage(icon), title));
}
/**
* Make icons available as SafeHtml to be displayed inside the table
*
* @param resource
* @return
*/
private static SafeHtml makeImage(ImageResource resource) {
AbstractImagePrototype proto = AbstractImagePrototype.create(resource);
String html = proto.getHTML();
return SafeHtmlUtils.fromTrustedString(html);
}
}

View File

@ -5,13 +5,18 @@ import java.util.List;
import org.gcube.portlets.user.td.gwtservice.client.rpc.TDGWTServiceAsync;
import org.gcube.portlets.user.td.gwtservice.shared.history.OpHistory;
import org.gcube.portlets.user.td.gwtservice.shared.history.RollBackSession;
import org.gcube.portlets.user.td.gwtservice.shared.tr.TableData;
import org.gcube.portlets.user.td.tablewidget.client.custom.ActionButtonCell;
import org.gcube.portlets.user.td.tablewidget.client.progress.RollBackProgressDialog;
import org.gcube.portlets.user.td.tablewidget.client.properties.OpHistoryProperties;
import org.gcube.portlets.user.td.tablewidget.client.resources.ResourceBundle;
import org.gcube.portlets.user.td.tablewidget.client.util.UtilsGXT3;
import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId;
import com.allen_sauer.gwt.log.client.Log;
import com.google.gwt.cell.client.AbstractCell;
import com.google.gwt.cell.client.Cell.Context;
import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.Scheduler;
import com.google.gwt.core.client.Scheduler.ScheduledCommand;
@ -31,6 +36,8 @@ import com.sencha.gxt.data.shared.loader.LoadResultListStoreBinding;
import com.sencha.gxt.widget.core.client.FramedPanel;
import com.sencha.gxt.widget.core.client.container.VerticalLayoutContainer;
import com.sencha.gxt.widget.core.client.container.VerticalLayoutContainer.VerticalLayoutData;
import com.sencha.gxt.widget.core.client.event.SelectEvent;
import com.sencha.gxt.widget.core.client.event.SelectEvent.SelectHandler;
import com.sencha.gxt.widget.core.client.grid.ColumnConfig;
import com.sencha.gxt.widget.core.client.grid.ColumnModel;
import com.sencha.gxt.widget.core.client.grid.Grid;
@ -56,6 +63,9 @@ public class HistoryPanel extends FramedPanel {
protected ListStore<OpHistory> store;
protected ListLoader<ListLoadConfig, ListLoadResult<OpHistory>> loader;
protected Grid<OpHistory> grid;
private OpHistory currentOpHistory;
private int currentRowIndex;
private RollBackSession rollBackSession;
public HistoryPanel(EventBus eventBus) {
super();
@ -103,8 +113,27 @@ public class HistoryPanel extends FramedPanel {
ColumnConfig<OpHistory, String> nameCol = new ColumnConfig<OpHistory, String>(
props.name(), 32, "Name");
ColumnConfig<OpHistory, String> dateCol = new ColumnConfig<OpHistory, String>(
props.date(), 32, "Date");
props.date(), 26, "Date");
ColumnConfig<OpHistory, String> rollBackColumn = new ColumnConfig<OpHistory, String>(
props.name(), 24);
ActionButtonCell button = new ActionButtonCell();
button.setIcon(ResourceBundle.INSTANCE.undo());
button.setTitle("Rollback");
button.addSelectHandler(new SelectHandler() {
@Override
public void onSelect(SelectEvent event) {
Log.debug("Button RollBack Pressed");
Context c = event.getContext();
int rowIndex = c.getIndex();
startReplaceEntry(rowIndex);
}
});
rollBackColumn.setCell(button);
List<ColumnConfig<OpHistory, ?>> l = new ArrayList<ColumnConfig<OpHistory, ?>>();
l.add(expander);
l.add(nameCol);
@ -162,7 +191,45 @@ public class HistoryPanel extends FramedPanel {
add(v);
}
protected void startReplaceEntry(int rowIndex) {
currentRowIndex = rowIndex;
currentOpHistory = store.get(rowIndex);
Log.debug(currentOpHistory.toString() + " was clicked.[rowIndex="
+ currentRowIndex + " ]");
callRollBack();
}
protected void callRollBack(){
rollBackSession=new RollBackSession(trId, currentOpHistory.getHistoryId());
TDGWTServiceAsync.INSTANCE.rollBack(rollBackSession, new AsyncCallback<Void>() {
public void onFailure(Throwable caught) {
Log.error("Error in rollback: "
+ caught.getLocalizedMessage());
UtilsGXT3.alert("Error in rollback",
"Error in rollback");
}
public void onSuccess(Void result) {
Log.debug("Rollback started");
callRollBackProgressDialog();
}
});
}
protected void callRollBackProgressDialog() {
RollBackProgressDialog dialog = new RollBackProgressDialog(
rollBackSession, eventBus);
dialog.show();
}
protected void loadData(ListLoadConfig loadConfig,
final AsyncCallback<ListLoadResult<OpHistory>> callback) {

View File

@ -0,0 +1,75 @@
/**
*
*/
package org.gcube.portlets.user.td.tablewidget.client.progress;
import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId;
import com.allen_sauer.gwt.log.client.Log;
import com.sencha.gxt.widget.core.client.ProgressBar;
/**
*
* @author "Giancarlo Panichi"
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class RollBackProgressBarUpdater implements RollBackProgressListener {
protected ProgressBar progressBar;
/**
* Creates a new {@link ProgressBar} updater.
* @param progressBar the {@link ProgressBar} to update.
*/
public RollBackProgressBarUpdater(ProgressBar progressBar) {
this.progressBar = progressBar;
}
/**
* {@inheritDoc}
*/
public void operationComplete(TRId trId) {
Log.info("Completed");
progressBar.updateProgress(1, "Completed");
}
/**
* {@inheritDoc}
*/
public void operationFailed(Throwable caught, String reason, String failureDetails) {
Log.info("Failed");
progressBar.updateText("Failed");
}
public void operationInitializing() {
Log.info("Inizializing");
progressBar.updateProgress(0, "Initializing...");
}
public void operationUpdate(float elaborated) {
Log.info("Elaborated: "+elaborated);
if (elaborated == 0) progressBar.updateProgress(0, "Initializing...");
if (elaborated>0 && elaborated<1) {
Log.trace("progress "+elaborated);
int elab=new Float(elaborated*100).intValue();
progressBar.updateProgress(elaborated,elab+"% Progress...");
}
if (elaborated == 1) progressBar.updateProgress(1, "Completing...");
}
@Override
public void operationStopped(TRId trId,String reason, String details) {
Log.debug("Operation Stopped: ["+trId.toString()+", "+reason+", "+details+"]");
progressBar.updateText("Validations failed");
}
}

View File

@ -0,0 +1,125 @@
package org.gcube.portlets.user.td.tablewidget.client.progress;
import org.gcube.portlets.user.td.gwtservice.shared.history.RollBackSession;
import org.gcube.portlets.user.td.tablewidget.client.util.UtilsGXT3;
import org.gcube.portlets.user.td.widgetcommonevent.client.event.ChangeTableRequestEvent;
import org.gcube.portlets.user.td.widgetcommonevent.client.type.ChangeTableRequestType;
import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId;
import com.allen_sauer.gwt.log.client.Log;
import com.google.web.bindery.event.shared.EventBus;
import com.sencha.gxt.core.client.util.Margins;
import com.sencha.gxt.widget.core.client.FramedPanel;
import com.sencha.gxt.widget.core.client.ProgressBar;
import com.sencha.gxt.widget.core.client.Window;
import com.sencha.gxt.widget.core.client.button.TextButton;
import com.sencha.gxt.widget.core.client.container.VerticalLayoutContainer;
import com.sencha.gxt.widget.core.client.container.VerticalLayoutContainer.VerticalLayoutData;
import com.sencha.gxt.widget.core.client.event.SelectEvent;
import com.sencha.gxt.widget.core.client.event.SelectEvent.SelectHandler;
/**
*
*
* @author "Giancarlo Panichi"
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class RollBackProgressDialog extends Window implements RollBackProgressListener {
public static final int STATUS_POLLING_DELAY = 1000;
protected String WIDTH = "400px";
protected String HEIGHT = "120px";
protected RollBackSession rollBackSession;
protected EventBus eventBus;
protected RollBackProgressUpdater progressUpdater;
protected TextButton ok;
protected TRId trId;
public RollBackProgressDialog(RollBackSession rollBackSession, EventBus eventBus) {
this.rollBackSession=rollBackSession;
this.eventBus=eventBus;
setWidth(WIDTH);
setHeight(HEIGHT);
setBodyBorder(false);
setResizable(true);
setModal(true);
setHeadingText("Rollback Progress");
trId=null;
FramedPanel panel=new FramedPanel();
panel.setHeaderVisible(false);
panel.setBodyBorder(false);
VerticalLayoutContainer v = new VerticalLayoutContainer();
ProgressBar progressBar = new ProgressBar();
ok=new TextButton("OK");
ok.addSelectHandler(new SelectHandler() {
public void onSelect(SelectEvent event) {
updateInvocation();
}
});
v.add(progressBar, new VerticalLayoutData(1,
1, new Margins(5, 5, 5, 5)));
panel.add(v);
panel.addButton(ok);
add(panel);
progressUpdater = new RollBackProgressUpdater();
progressUpdater.addListener(new RollBackProgressBarUpdater(progressBar));
progressUpdater.addListener(this);
progressUpdater.scheduleRepeating(STATUS_POLLING_DELAY);
show();
ok.setVisible(false);
}
public void operationInitializing() {
// TODO Auto-generated method stub
}
public void operationUpdate(float elaborated) {
// TODO Auto-generated method stub
}
public void operationComplete(TRId trId) {
Log.debug("Operation Complete return: "+trId.toString());
this.trId=trId;
updateInvocation();
}
public void operationFailed(Throwable caught, String reason,
String failureDetails) {
ok.setVisible(true);
this.trId=null;
UtilsGXT3.alert("Error in RollBack", reason);
}
public void updateInvocation(){
if(trId!=null){
ChangeTableRequestEvent changeTableRequestEvent=
new ChangeTableRequestEvent(ChangeTableRequestType.DELETEROWS, trId);
eventBus.fireEvent(changeTableRequestEvent);
}
hide();
}
@Override
public void operationStopped(TRId trId,String reason, String details) {
Log.debug("Operation Stopped: ["+trId.toString()+", "+reason+", "+details+"]");
ok.setVisible(true);
this.trId=trId;
}
}

View File

@ -0,0 +1,52 @@
/**
*
*/
package org.gcube.portlets.user.td.tablewidget.client.progress;
import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId;
/**
* Defines a listener for operation progress.
*
* @author "Giancarlo Panichi"
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public interface RollBackProgressListener {
/**
* Called when the operation is starting.
*/
public void operationInitializing();
/**
* Called when there is a progress for the operation.
* @param elaborated the elaborated part.
*/
public void operationUpdate(float elaborated);
/**
* Called when the operation is complete.
*/
public void operationComplete(TRId trId);
/**
* Called when the operation is failed.
* @param caught the failure exception.
* @param reason the failure reason.
*/
public void operationFailed(Throwable caught, String reason, String failureDetails);
/**
* Called when the operation is stopped
*
* @param trId
* @param reason
* @param details
*/
public void operationStopped(TRId trId, String reason, String details);
}

View File

@ -0,0 +1,181 @@
/**
*
*/
package org.gcube.portlets.user.td.tablewidget.client.progress;
import java.util.ArrayList;
import org.gcube.portlets.user.td.gwtservice.client.rpc.TDGWTServiceAsync;
import org.gcube.portlets.user.td.gwtservice.shared.history.RollBackSessionMonitor;
import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId;
import com.allen_sauer.gwt.log.client.Log;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.rpc.AsyncCallback;
/**
*
* @author "Giancarlo Panichi"
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class RollBackProgressUpdater extends Timer {
protected ArrayList<RollBackProgressListener> listeners = new ArrayList<RollBackProgressListener>();
/**
* {@inheritDoc}
*/
@Override
public void run() {
Log.debug("requesting operation progress");
TDGWTServiceAsync.INSTANCE
.getRollBackMonitor(new AsyncCallback<RollBackSessionMonitor>() {
public void onFailure(Throwable caught) {
cancel();
Log.error("Error retrieving the operation state",
caught);
String message = getStack(caught);
fireOperationFailed(caught,
"Failed getting operation updates", message);
}
public void onSuccess(RollBackSessionMonitor result) {
Log.info("retrieved DeleteRowsMonitor: "
+ result.getStatus());
switch (result.getStatus()) {
case INITIALIZING:
Log.info("Initializing...");
fireOperationInitializing();
break;
case ABORTED:
cancel();
Log.info("Delete Rows Operation Aborted");
break;
case IN_PROGRESS:
fireOperationUpdate(result.getProgress());
break;
case VALIDATING_RULES:
fireOperationUpdate(result.getProgress());
break;
case STOPPED:
cancel();
stopMessage(result);
break;
case FAILED:
cancel();
errorMessage(result);
break;
case SUCCEDED:
cancel();
Log.info("Fisnish TableId :"
+ result.getTrId());
fireOperationComplete(result.getTrId());
break;
default:
Log.info("Unknow State");
break;
}
}
});
}
protected void errorMessage(RollBackSessionMonitor result) {
Log.info("RollBack Failed");
Throwable th = null;
String failure = null;
String details = null;
if (result.getError() != null) {
th = result.getError();
failure = "Failed Client Library rollback";
details = result.getError().getLocalizedMessage();
} else {
th = new Throwable("Failed");
failure = "Failed Client Library rollback";
details = "Rollback failed";
}
fireOperationFailed(th, failure, details);
}
protected void stopMessage(RollBackSessionMonitor result) {
Log.info("RollBack Stopped");
String failure = null;
String details = null;
if (result.getError() != null) {
failure = "Stopped rollback";
details = result.getError().getLocalizedMessage();
} else {
failure = "Stopped rollback";
details = "Rollback stopped";
}
fireOperationStopped(result.getTrId(),failure, details);
}
protected String getStack(Throwable e) {
String message = e.getLocalizedMessage() + " -> <br>";
Throwable c = e.getCause();
if (c != null)
message += getStack(c);
return message;
}
protected void fireOperationInitializing() {
for (RollBackProgressListener listener : listeners)
listener.operationInitializing();
}
protected void fireOperationUpdate(float elaborated) {
for (RollBackProgressListener listener : listeners)
listener.operationUpdate(elaborated);
}
protected void fireOperationComplete(TRId trId) {
for (RollBackProgressListener listener : listeners)
listener.operationComplete(trId);
}
protected void fireOperationFailed(Throwable caught, String failure,
String failureDetails) {
for (RollBackProgressListener listener : listeners)
listener.operationFailed(caught, failure, failureDetails);
}
protected void fireOperationStopped(TRId trId, String reason, String details) {
for (RollBackProgressListener listener : listeners)
listener.operationStopped(trId,reason, details);
}
/**
* Add a new {@link RollBackProgressListener} to this
* {@link RollBackProgressUpdater}.
*
* @param listener
* the listener to add.
*/
public void addListener(RollBackProgressListener listener) {
listeners.add(listener);
}
/**
* Removes the specified {@link RollBackProgressListener} from this
* {@link RollBackProgressUpdater}.
*
* @param listener
* the listener to remove.
*/
public void removeListener(RollBackProgressListener listener) {
listeners.remove(listener);
}
}

View File

@ -20,7 +20,7 @@ public interface OpHistoryProperties extends
ModelKeyProvider<OpHistory> id();
ValueProvider<OpHistory,String> name();
ValueProvider<OpHistory, String> decription();
ValueProvider<OpHistory, String> description();
ValueProvider<OpHistory, String> date();
}

View File

@ -52,4 +52,16 @@ public interface ResourceBundle extends ClientBundle {
@Source("ok_32.png")
ImageResource ok32();
@Source("arrow-undo.png")
ImageResource undo();
@Source("arrow-undo_32.png")
ImageResource undo32();
@Source("arrow-undo-all.png")
ImageResource undoAll();
@Source("arrow-undo-all_32.png")
ImageResource undoAll32();
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 775 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 542 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 775 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 542 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB