Updatde component

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-column-widget@91001 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2014-02-06 18:29:23 +00:00
parent 155ed57c5a
commit 878fe368b8
5 changed files with 478 additions and 3 deletions

View File

@ -11,6 +11,7 @@ import org.gcube.portlets.user.td.columnwidget.client.store.ColumnTypeCodeElemen
import org.gcube.portlets.user.td.columnwidget.client.store.ColumnTypeCodeStore;
import org.gcube.portlets.user.td.gwtservice.client.rpc.TDGWTServiceAsync;
import org.gcube.portlets.user.td.gwtservice.shared.tr.ColumnData;
import org.gcube.portlets.user.td.gwtservice.shared.tr.column.type.ChangeColumnTypeSession;
import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId;
import org.gcube.portlets.user.td.widgetcommonevent.shared.tr.column.ColumnDataType;
import org.gcube.portlets.user.td.widgetcommonevent.shared.tr.column.ColumnTypeCode;
@ -40,7 +41,9 @@ 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.HideEvent;
import com.sencha.gxt.widget.core.client.event.SelectEvent;
import com.sencha.gxt.widget.core.client.event.HideEvent.HideHandler;
import com.sencha.gxt.widget.core.client.event.SelectEvent.SelectHandler;
import com.sencha.gxt.widget.core.client.form.ComboBox;
import com.sencha.gxt.widget.core.client.form.FieldLabel;
import com.sencha.gxt.widget.core.client.form.TextField;
@ -62,7 +65,11 @@ public class ChangeColumnTypePanel extends FramedPanel {
protected ComboBox<ColumnDataTypeElement> comboAttributeType = null;
protected FieldLabel comboAttributeTypeLabel;
protected ListLoader<ListLoadConfig, ListLoadResult<ColumnData>> loader;
protected TextButton change;
protected ChangeColumnTypeSession changeColumnTypeSession;
public ChangeColumnTypePanel(TRId trId, String columnName, EventBus eventBus) {
setWidth(WIDTH);
setHeight(HEIGHT);
@ -189,6 +196,16 @@ public class ChangeColumnTypePanel extends FramedPanel {
"Attribute Type");
comboAttributeTypeLabel.setVisible(false);
change=new TextButton("Change");
SelectHandler changeHandler=new SelectHandler() {
public void onSelect(SelectEvent event) {
onChangeTypeColumn();
}
};
change.addSelectHandler(changeHandler);
VerticalLayoutContainer v = new VerticalLayoutContainer();
v.add(new FieldLabel(comboColumn, "Column"), new VerticalLayoutData(1,
-1));
@ -196,7 +213,7 @@ public class ChangeColumnTypePanel extends FramedPanel {
new VerticalLayoutData(1, -1));
v.add(comboMeasureTypeLabel, new VerticalLayoutData(1, -1));
v.add(comboAttributeTypeLabel, new VerticalLayoutData(1, -1));
v.add(new TextButton("Change"), new VerticalLayoutData(-1, -1,
v.add(change, new VerticalLayoutData(-1, -1,
new Margins(10, 0, 10, 0)));
add(v, new VerticalLayoutData(-1, -1, new Margins()));
@ -362,17 +379,24 @@ public class ChangeColumnTypePanel extends FramedPanel {
protected void updateComboStatus(ColumnData cd) {
Log.debug("ColumnData: " + cd.toString());
changeColumnTypeSession=new ChangeColumnTypeSession();
changeColumnTypeSession.setColumnData(cd);
comboColumn.setValue(cd);
comboColumnTypeCode.setValue(ColumnTypeCodeStore.selectedElement(cd
.getTypeCode()));
ColumnTypeCode type = ColumnTypeCodeStore.selected(cd.getTypeCode());
changeColumnTypeSession.setColumnTypeCode(type);
updateColumnType(type);
if (type == ColumnTypeCode.MEASURE) {
changeColumnTypeSession.setColumnDataType(ColumnDataTypeStore
.selectedMeasure(cd.getDataTypeName()));
comboMeasureType.setValue(ColumnDataTypeStore
.selectedMeasureElement(cd.getDataTypeName()));
} else {
if (type == ColumnTypeCode.ATTRIBUTE) {
changeColumnTypeSession.setColumnDataType(ColumnDataTypeStore
.selectedAttribute(cd.getDataTypeName()));
comboAttributeType.setValue(ColumnDataTypeStore
.selectedAttributeElement(cd.getDataTypeName()));
} else {
@ -387,4 +411,81 @@ public class ChangeColumnTypePanel extends FramedPanel {
this.columnName = columnName;
loader.load();
}
protected void onChangeTypeColumn(){
ColumnData columnData=comboColumn.getCurrentValue();
if(columnData!=null){
ColumnTypeCodeElement columnTypeCodeElement= comboColumnTypeCode.getCurrentValue();
if(columnTypeCodeElement!=null){
ColumnTypeCode type=columnTypeCodeElement.getCode();
if (type == ColumnTypeCode.MEASURE) {
changeColumnTypeSession.setColumnTypeCodeTarget(type);
ColumnDataTypeElement columnDataTypeElement=comboMeasureType.getCurrentValue();
if(columnDataTypeElement!=null){
ColumnDataType dataType=columnDataTypeElement.getType();
if(dataType!=null){
changeColumnTypeSession.setColumnDataTypeTarget(dataType);
callChangeColumnToMeasure();
} else {
alert("Attention","Column data type not selected!");
}
} else {
alert("Attention","Column data type not selected!");
}
} else {
if (type == ColumnTypeCode.ATTRIBUTE) {
changeColumnTypeSession.setColumnTypeCodeTarget(type);
ColumnDataTypeElement columnDataTypeElement=comboAttributeType.getCurrentValue();
if(columnDataTypeElement!=null){
ColumnDataType dataType=columnDataTypeElement.getType();
if(dataType!=null){
changeColumnTypeSession.setColumnDataTypeTarget(dataType);
callChangeColumnToAttribute();
} else {
alert("Attention","Column data type not selected!");
}
} else {
alert("Attention","Column data type not selected!");
}
} else {
alert("Attention","This column type is not supported now!");
}
}
} else {
alert("Attention","Select a column type!");
}
} else {
alert("Attention","Select a column!");
}
}
private void callChangeColumnToAttribute() {
// TODO Auto-generated method stub
}
private void callChangeColumnToMeasure() {
// TODO Auto-generated method stub
}
protected void alert(String title,String message){
final AlertMessageBox d = new AlertMessageBox(title, message);
d.addHideHandler(new HideHandler() {
public void onHide(HideEvent event) {
d.hide();
}
});
d.show();
}
}

View File

@ -0,0 +1,68 @@
/**
*
*/
package org.gcube.portlets.user.td.columnwidget.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;
/**
* Updates a {@link ProgressBar} progress and text based on {@link CSVImportProgressListener} events.
*
* @author "Giancarlo Panichi"
* <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class ChangeColumnTypeProgressBarUpdater implements ChangeColumnTypeProgressListener {
protected ProgressBar progressBar;
/**
* Creates a new {@link ProgressBar} updater.
* @param progressBar the {@link ProgressBar} to update.
*/
public ChangeColumnTypeProgressBarUpdater(ProgressBar progressBar) {
this.progressBar = progressBar;
}
/**
* {@inheritDoc}
*/
public void operationComplete(TRId trId) {
Log.info("Import completed");
progressBar.updateProgress(1, "Import completed.");
}
/**
* {@inheritDoc}
*/
public void operationFailed(Throwable caught, String reason, String failureDetails) {
Log.info("Import failed");
progressBar.updateText("Import failed.");
}
public void operationInitializing() {
Log.info("Inport Inizializing");
progressBar.updateProgress(0, "Initializing...");
}
public void operationUpdate(float elaborated) {
Log.info("Import 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+"% Importing...");
}
if (elaborated == 1) progressBar.updateProgress(1, "Completing...");
}
}

View File

@ -0,0 +1,92 @@
package org.gcube.portlets.user.td.columnwidget.client.progress;
import org.gcube.portlets.user.td.gwtservice.shared.tr.column.type.ChangeColumnTypeSession;
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.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.BoxLayoutContainer.BoxLayoutData;
import com.sencha.gxt.widget.core.client.event.SelectEvent;
import com.sencha.gxt.widget.core.client.event.SelectEvent.SelectHandler;
public class ChangeColumnTypeProgressDialog extends Window implements ChangeColumnTypeProgressListener {
public static final int STATUS_POLLING_DELAY = 1000;
protected String WIDTH = "650px";
protected String HEIGHT = "530px";
protected ChangeColumnTypeSession changeColumnTypeSession;
protected EventBus eventBus;
protected ChangeColumnTypeProgressUpdater progressUpdater;
protected TextButton ok;
protected TRId trId;
public ChangeColumnTypeProgressDialog(ChangeColumnTypeSession changeColumnTypeSession, EventBus eventBus) {
this.changeColumnTypeSession=changeColumnTypeSession;
this.eventBus=eventBus;
setWidth(WIDTH);
setHeight(HEIGHT);
setBodyBorder(false);
setResizable(false);
setModal(true);
setHeadingText("Change Column Type Progress");
trId=null;
ProgressBar progressBar = new ProgressBar();
add(progressBar, new BoxLayoutData(
new Margins(10, 5, 10, 5)));
ok=new TextButton("Ok");
ok.setVisible(false);
ok.addSelectHandler(new SelectHandler() {
public void onSelect(SelectEvent event) {
updateInvocation();
}
});
addButton(ok);
progressUpdater = new ChangeColumnTypeProgressUpdater();
progressUpdater.addListener(new ChangeColumnTypeProgressBarUpdater(progressBar));
progressUpdater.addListener(this);
}
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());
ok.setVisible(true);
this.trId=trId;
}
public void operationFailed(Throwable caught, String reason,
String failureDetails) {
ok.setVisible(true);
this.trId=null;
}
public void updateInvocation(){
if(trId!=null){
ChangeTableRequestEvent changeTableRequestEvent=
new ChangeTableRequestEvent(ChangeTableRequestType.CHANGECOLUMNTYPE, trId);
eventBus.fireEvent(changeTableRequestEvent);
}
hide();
}
}

View File

@ -0,0 +1,42 @@
/**
*
*/
package org.gcube.portlets.user.td.columnwidget.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 ChangeColumnTypeProgressListener {
/**
* 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);
}

View File

@ -0,0 +1,172 @@
/**
*
*/
package org.gcube.portlets.user.td.columnwidget.client.progress;
import java.util.ArrayList;
import org.gcube.portlets.user.td.gwtservice.client.rpc.TDGWTServiceAsync;
import org.gcube.portlets.user.td.gwtservice.shared.tr.column.type.ChangeColumnTypeMonitor;
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;
import com.sencha.gxt.widget.core.client.box.AlertMessageBox;
import com.sencha.gxt.widget.core.client.event.HideEvent;
import com.sencha.gxt.widget.core.client.event.HideEvent.HideHandler;
/**
* This {@link Timer} retrieves {@link OperationProgress} from the specified
* {@link OperationProgressSource} with the scheduled interval. The retrieved
* information are spread to the subscribed {@link ChangeColumnTypeProgressListener}.
*
* @author "Giancarlo Panichi" <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class ChangeColumnTypeProgressUpdater extends Timer {
protected ArrayList<ChangeColumnTypeProgressListener> listeners = new ArrayList<ChangeColumnTypeProgressListener>();
/**
* {@inheritDoc}
*/
@Override
public void run() {
Log.debug("requesting operation progress");
TDGWTServiceAsync.INSTANCE
.getChangeColumnTypeMonitor(new AsyncCallback<ChangeColumnTypeMonitor>() {
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(ChangeColumnTypeMonitor result) {
Log.info("retrieved CMonitor: "
+ result.getStatus());
switch (result.getStatus()) {
case INITIALIZING:
Log.info("CSV Import Initializing...");
fireOperationInitializing();
break;
case ABORTED:
cancel();
Log.info("CSV Import Operation Aborted");
break;
case IN_PROGRESS:
fireOperationUpdate(result.getProgress());
break;
case VALIDATING_RULES:
fireOperationUpdate(result.getProgress());
break;
case STOPPED:
cancel();
errorMessage(result);
break;
case FAILED:
cancel();
errorMessage(result);
break;
case SUCCEDED:
cancel();
Log.info("Import fisnish TableId :"
+ result.getTrId());
fireOperationComplete(result.getTrId());
break;
default:
Log.info("Unknow State");
break;
}
}
});
}
protected void errorMessage(ChangeColumnTypeMonitor result) {
Log.info("Change Column Type Failed");
Throwable th = null;
String failure = null;
String details = null;
if (result.getError() != null) {
th = result.getError();
failure = "Failed Client Library Chanche Column Type";
details = result.getError().getLocalizedMessage();
} else {
th = new Throwable("Failed");
failure = "Failed Client Library Chanche Column Type";
details = "Error Change Column Type";
}
fireOperationFailed(th, failure, details);
AlertMessageBox d = new AlertMessageBox("Error in Change Column Type", details);
d.addHideHandler(new HideHandler() {
public void onHide(HideEvent event) {
}
});
d.show();
}
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 (ChangeColumnTypeProgressListener listener : listeners)
listener.operationInitializing();
}
protected void fireOperationUpdate(float elaborated) {
for (ChangeColumnTypeProgressListener listener : listeners)
listener.operationUpdate(elaborated);
}
protected void fireOperationComplete(TRId trId) {
for (ChangeColumnTypeProgressListener listener : listeners)
listener.operationComplete(trId);
}
protected void fireOperationFailed(Throwable caught, String failure,
String failureDetails) {
for (ChangeColumnTypeProgressListener listener : listeners)
listener.operationFailed(caught, failure, failureDetails);
}
/**
* Add a new {@link ChangeColumnTypeProgressListener} to this
* {@link ChangeColumnTypeProgressUpdater}.
*
* @param listener
* the listener to add.
*/
public void addListener(ChangeColumnTypeProgressListener listener) {
listeners.add(listener);
}
/**
* Removes the specified {@link ChangeColumnTypeProgressListener} from this
* {@link ChangeColumnTypeProgressUpdater}.
*
* @param listener
* the listener to remove.
*/
public void removeListener(ChangeColumnTypeProgressListener listener) {
listeners.remove(listener);
}
}